Database design - “Separate Tables Vs One table” for Select Queries

后端 未结 1 583
栀梦
栀梦 2021-01-07 11:38

I have a MySQL table like following

Books Table

book-id      category    author     author_place       book_name   book_price --------other 50 colu         


        
1条回答
  •  南笙
    南笙 (楼主)
    2021-01-07 12:12

    This question has it's answer from Mr. Edgar F. Codd himself - the inventor of the relation model upon which all RDBMS are build.

    Shortly after releasing the relational model papers he and his team followed with papers on the so called normal forms. There are few of them but the first 3 (at least) should be generally considered mandatory:

    • First normal form (1NF)
    • Second normal form (2NF)
    • Third normal form (3NF)

    When you read them you'll see that your initial design is in violation of 2NF and you have come with a solution that more or less respects it. Go ahead with a the NF-compliant design without any doubts.

    To elaborate a bit on your concerns with Join's performance. This is not an issue as long as the following criteria is met:

    • your database schema is well designed (2NF compliant at least)
    • you use Foreign keys to link the tables (MySQL's docs)
    • you join the tables by their FK
    • you have the hardware resources necessary to run your data efficiently

    e.g. on MySQL with InnoDB, on 2NF compliant schema using Foreign keys the join performance by the FK will be among the last things you'd ever be concerned.

    Historically there was a DB engine in MySQL - the MyISAM - that did not support foreign key constraints. Perhaps it's the main source of feedback about poor join performance (along poor schema designs of course).

    0 讨论(0)
提交回复
热议问题