MySQL database design question - storing lists/arrays of indexes -


i'm wondering how store list of id indexes each id in table. these form "relations" between ids. here's main table far:

table main:

  • id, integer, primary key

  • name, varchar

  • text_info_1, varchar

  • text_info_2, varchar

and each row, there list of other rows' ids show me how 1 row relates next. example, row id #5 might related ids 6,7,9,25,...etc.

here options i've considered:

  1. create new column text field , store serialized list of these integer values. unserialize when want them.

  2. create new table called "relations" columns relation_id (int auto increment primary key), name1, name2, [and optional other fields specifying relation type, nice].

i feel option 1 bit of hack. i've done before , works, perhaps option 2 better design?

i'm worried speed though. option 1 can select relations main id = $id, , unserialize result , have array integer indices. option 2 i'll have browse through table many times (10x or more) larger, , "select name1, name2 relations".

speed main priority here. i'm not sure 1 better space, though curious find out.

so option should go with? there other options haven't considered? i'd appreciate general pointers on database design!

thanks bunch.

second option better. if want better in database design, should read database normalization. sadly, materials i've used not in english. wikipedia link start.

table relations:

relation_id (int auto increment primary key) id_one (int) id_two (int) ... 

instead of storing names in relations table, store ids.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -