场景 1
我有一张 table ,可以说“成员(member)”。在该表“member”中,我有 7 个字段(memid、login_name、password、age、city、phone、country)。在我的表中,我有 10K 条记录。我需要获取一条记录。所以我使用这样的查询
mysql_query("select * from member where memid=999");
场景 2
我有同一张名为“member”的表,但我像这个member和member_txt一样拆分表。所以在我的member_txt表中我有memid,age,phone,city,country)并且在我的member表中我有memid ,登录名,密码。
哪种场景是快速获取数据的最佳方案?要么使用单个表,要么将表分成两个引用?
注意:我需要在 PHP 和 MYSQL 中获取特定数据。请让我知道哪种方法是最好的。 我们有 10K 条记录
最佳答案
为了您自己的健康,请使用单表方法。
只要您使用 memid
主键,事情就会快如闪电。这是因为 PRIMARY KEY
自动分配一个索引,该索引基本上可以告诉数据的确切位置,并且无需像其他方式那样检查数据。
来自http://dev.mysql.com/doc/refman/5.0/en/mysql-indexes.html
Indexes are used to find rows with specific column values quickly. Without an index, MySQL must begin with the first row and then read through the entire table to find the relevant rows. The larger the table, the more this costs. If the table has an index for the columns in question, MySQL can quickly determine the position to seek to in the middle of the data file without having to look at all the data. If a table has 1,000 rows, this is at least 100 times faster than reading sequentially. If you need to access most of the rows, it is faster to read sequentially, because this minimizes disk seeks.
第二种方法只会使您的系统变得更加复杂,并且没有任何好处。
使用场景 1。
关于php - MYSQL和PHP获取记录的性能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10749119/