mysql - Is it better to have many columns, or many tables? -
imagine hypothetical database, storing products. each product have have 100 attributes, although given product have values set ~50 of these. can see 3 ways store data:
a single table 100 columns,
a single table few (say 10 columns have value every product), , table columns (product_id, attribute, value). i.e, eav data store.
a separate table every columns. core products table might have 2 columns, , there 98 other tables, each 2 columns (product_id, value).
setting aside shades of grey between these extremes, pure efficiency standpoint, best use? assume depends on types of queries being run, i.e. if queries several attributes of product, or value of single attribute several products. how affect efficiency?
assume mysql database using innodb, , tables have appropriate foreign keys, , index on product_id. imagine attribute names , values strings, , not indexed.
in general sense, asking whether accessing big table takes more or less time query many joins.
i found similar question here: best have hundreds of columns or split multiple tables?
the difference is, question asking specific case, , doesn't tell me efficiency in general case. other similar questions talking best way organize data, want know how different organizational systems impact speed of queries.
in general sense, asking whether accessing big table takes more or less time query many joins.
join slower.
however, if query specific subset of columns, , subset "vertically partitioned" own separate table, querying such "lean" table typically quicker querying "fat" table columns.
but specific , fragile (easy break-apart system evolves) situation , should test before going down path. default starting position should 1 table.
Comments
Post a Comment