Mysql table design advice
NickName:user3382380 Ask DateTime:2014-11-28T17:53:29

Mysql table design advice

I have a general question about MySQL database table design. I have a table that contains ~ 650 thousand records, with approximately 100 thousand added per year. The data is requested quite frequently, 1.6 times per second on average.

It has the following structure right now

id   port_id         date        product1_price    product2_price    product3_price
 1         1   2012-01-01                100.00            200.00            155.00
 2         2   2012-01-01                  NULL            150.00            255.00
 3         3   2012-01-01                300.00              NULL            355.00
 4         1   2012-01-02                200.00            250.00            355.00
 5         2   2012-01-02                400.00            230.00            255.00

Wouln't it be better to store the data in this manner?

id     port_id         date    product   price
1            1   2012-01-01          1     100
1            2   2012-01-01          1     200
1            3   2012-01-01          1     300
1            1   2012-01-02          1     240

Advantages of the alternative design:

  • with the second design we don't have to store NULL values (if there is no such product in the port)
  • we can add new products easily - comparing to the first design, where each new product requires a new column

Disadvantages of the alternative design:

  • The number of records will increase from 650 000 to 650 000 * number_of_products minus all NULL records; that will be approximately 2.1 million records.

In both cases we have id column as PRIMARY_KEY and UNIQUE key on combination of port_id and date.

So the question is: which way to go? Disk space does not matter, the speed of the queries is the most important aspect.

Thank you for your attention.

Copyright Notice:Content Author:「user3382380」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/27185988/mysql-table-design-advice

More about “Mysql table design advice” related questions

Mysql table design advice

I have a general question about MySQL database table design. I have a table that contains ~ 650 thousand records, with approximately 100 thousand added per year. The data is requested quite frequen...

Show Detail

Advice on mysql table design

Currently I am updating database design and I am at point where I need some guidance. Current Structure: Table called "person_skill" has following columns: id person_id Skill Name And We are go...

Show Detail

DB design advice wanted

I am looking for some advice on a design I'm working at. This is the case : I got a database with a meeting table and a user table. Each meeting has a organisor, which corresponds to the ID of a u...

Show Detail

General mysql table design advice

i have got some specific data set which regards to the SLA (Service level agreement) for a particular work as follows. here x represents no of hours. once a task completed within given time range

Show Detail

MongoDB design advice needed

I got an API build with PHP and MySQL. I want to migrate the database to MongoDB but need some advice about the design. The API contains users and friends. I got one table for the users and one fo...

Show Detail

NoSQL (Redis) design advice

I am still new to NoSQL database and have been using RDBMS (Oracle, MySQL) for years. Now, we are considering migrating one of our database to In-memory NoSQL DB and we are stuck with the best design

Show Detail

Need advice on fixing MySQL database design & table structure

I am planning to create a web application that using php-mysql, I created database to provide to store the form results. I create each column for each input fields in the database, It's working fine

Show Detail

Need advice for database design

I'd like to do some Php graphs with MySQL datas, but first I have to think about the best design for my database, I prefer ask you some advice because I'm a newbie and I think there is a better way...

Show Detail

Table-Per-Type Database Design Advice

I'm looking for advice for designing a database that has generic entities that want to be related to several different other entity types. Horrible intro sentence, I know ... so please let me expl...

Show Detail

design advice - dynamic table structure

I'm in a position where I can design both the database structure and the software for an application which the user imports his own data into the system, and I need yo use that data. Since the dat...

Show Detail