简体   繁体   中英

Database structure - Single design table with category_id (Many rows) or Multiple design category tables (Few rows)

I have a database schema for design of multiple categories, all of which have the same structure. There are two scenarios and I am not sure which one to go depending on the performance.

  1. Single Table: 1 Master table (Categories), 1 Design Table (category_id), 2 tables related to design (label and colors) and 1 table with label_color relation. There may be around 20 categories, atleast 100 designs per category, atleast 20 labels and 10 colors per design. So a total of 4 tables, with the lower bound approximately 400,000 records in label_color relation table.

  2. Multiple Tables: 1 Master Table (Categories), a designs table (category1_designs, category2_designs ...) for each category along with label and color table related to category1_design and label_color table relating labels to color. Using the same estimate as before, with 20 categories and 4 related tables to each design, there are 80 tables to maintain (plus the master categories table). Moreover, for getting designs from a specific category or adding a design in a specific category, the server will have a switch case scenario so that it takes the records from the right category, making it rigid and hardcoded. Also adding a new category would mean manually creating 4 new tables for that category. Lower bound for this is only 20000 rows but spread over 20 tables.

I am using MySQL database with InnoDB engine, so considering the performance and scalability, which approach is better for implementing this concept? Also note that write operations won't be frequent and the tables will only be used specifically for reading and perhaps overwriting.

Go with 1. Single (categories) Table. This is the way I would do it and have seen it done many times. De-normalizing using many categories tables will be difficult to maintain and require lots of copy/paste or generated string queries.

With 100 max rows per non-associative table, performance will be of no concern as long as your queries and indexes match up.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM