I'm just wondering which is the best practice:
I have开发者_运维百科 a table and I want to hide a record so should I use a column like visible = 1
or should I create another table and transfer the data.
thanks!
I would recommend adding a isHidden field for this purpose. I usually use a tinyint for this.
Tables don't have performance—queries have performance. When you're trying to decide how to optimize, concentrate on the queries you will run against the table.
It could be worth moving the data to another table, for example if 90% of the data is "hidden" and rows seldom change their hidden state, you could greatly improve performance for queries against the non-hidden data by keeping that table small.
On the other hand, if you have a mix of queries where you sometimes include and sometimes exclude the "hidden" rows, or rows frequently change their hidden state, it would be more convenient to keep them in the same table.
Both strategies are valid in different circumstances. You need to take all your uses of the data into account.
精彩评论