in reply to arrays in database

Only to add my 2 cents worth. If you are looking at storing perl data structures with unknown lengths. Modules such as FreezeThaw, Data::Dumper and Storable will convert a perl data structure such as an array or a hash or any mixture thereof in a format that you can import back into your program from the database. These modules turn a structure into a simple text format which can be easily stored and retrieved from any RDBMS.

BlackJudas

Replies are listed 'Best First'.
Re: Re: arrays in database
by JayBonci (Curate) on May 18, 2002 at 20:21 UTC
    Actually, perl structures with unknown lengths are not best handled by the FreezeThaw and Data::Dumper modules. Perl structures of unknown complexity are handled very well by them. Lets say I have a structure that is a string of numbers. Using freeze or nfreeze to put it in the database means that there is an operation to expand or put it away. We're starting to drift off into database design, but it's a good general principle to think about. If i need to flick something in the middle of the array the operation is:
    1. Get the record
    2. Thaw it
    3. Change the value
    4. Freeze it
    5. Put it away
    If you had a series of updates to do on different arrays, it doesn't make much sense to freeze it. Another reason is that it doesn't scale very well. There is a finite amount of data that it can hold (albeit quite large).

    A simple way of thinking about a flat array in a database would be (and this is how nodegroups are handled in ecore, the system that runs this site):
    • INCLUSION_ID - A unique primary key
    • ARRAY_ID - The descriptor of the array
    • ARRAY_POSITION - Something to order by
    • STUFF - The thing you need to hold
    SELECT * FROM INCLUSIONS WHERE ARRAY_ID='42' ORDER BY ARRAY_POSITION
    This scales as big as you need it, plus allows you to do mundane operations such as changing order of items, etc etc, without having to pull the entire glob out of the db and shove it back in. However, whether the SELECT or the thaw is faster depends on that dataset. YMMV.

        --jb