Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re: Well Designed RDBMS

by dga (Hermit)
on Apr 07, 2003 at 14:56 UTC ( #248624=note: print w/replies, xml ) Need Help??


in reply to Well Designed RDBMS

If you are only going to query the attributes rarely and want flexibility, personally I woud probably use a seperate table.

The main table would have something to uniquely identify the blob and the other table would be like:

create table attribute_table ( blob_uni int, attribute text, value tex +t ); create unique index a_t_uni on attribute_table ( blob_uni, attribute ) +;

If I were going to have a lot of attributes or they were going to have long names, I would make a 3rd table with attribute_id and attribute_name then use the attribute_id in the attribute_table. Also a varchar field may be handy instead of text on the attribute name field if a combined table is used.

When a lookup by attribute is wanted would be the only time this table is referenced and also it will be a fast lookup and much cheaper than a LIKE on a sizeable piece of text. The unique index will speed this up and prevent duplicate attributes of the same kind on a single blob.

select * from blob_table where id IN ( select blob_id from attribute_t +able where attribute='color' and value='red );

This design doesn't require the attributes to be known at design time and they can be added or removed at any time and attributes which do not apply to a given blob use no space at all.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://248624]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (2)
As of 2021-06-18 05:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (88 votes). Check out past polls.

    Notices?