The database design problem of one field with multiple values now involves field. The value is single. for example, the value is 3.
There is one field with multiple values. For example, field B may be 1, 2, 3, or 4.
Now we need to find all records that contain the value of field. For example:
Records:, 5, and 7 (compliant)
Records, 8, and 9 (non-conforming)
How can I design a database reasonably? Fully considering performance optimization.
Reply to discussion (solution)
I seem to have thought of methods.
In this way, the data of field B is saved in the database.
| 2 | 4 | 6 | 3 |
If you want to query whether 3. like % | 3 | %. Is this feasible?
Yes, or use commas to separate them.
If the value range cannot exceed 64, you can use the set type directly.
If you do not want to use the set type, the value range is more than 64.
The varchar or text type can be used.
Data is composed of strings separated by commas (,), such as 2, 4, 6, and 3.
Mysql provides the find_in_set function for searching.
If the value range cannot exceed 64, you can use the set type directly.
If you do not want to use the set type, the value range is more than 64.
The varchar or text type can be used.
Data is composed of strings separated by commas (,), such as 2, 4, 6, and 3.
Mysql provides the find_in_set function for searching.
Can you talk about the optimal solution?
Few value ranges. Under 20. The value is selected from a fixed array.
Performance is a concern. If tens of thousands or even tens of thousands of lines are fake, it is too slow to find matching data.
If the value range cannot exceed 64, you can use the set type directly.
If you do not want to use the set type, the value range is more than 64.
The varchar or text type can be used.
Data is composed of strings separated by commas (,), such as 2, 4, 6, and 3.
Mysql provides the find_in_set function for searching.
Taught. For the first time, I learned about the mysql field and the set type. Mysql also has the find_in_set function.
Both methods can solve the problem. If you have time, I will test which method is the fastest!
Like, find_in_set, and in
They are all looking for "whether it is in it", and the performance will certainly not be high.
Package the data together, and change the space by time.
To achieve high-speed purposes, of course, you cannot package together, but store and add indexes independently. of course, you must add the host id.
This is the so-called space for time