gpt4 book ai didi

php - MYSQL和PHP抓取记录的性能

转载 作者:行者123 更新时间:2023-11-29 02:32:37 24 4
gpt4 key购买 nike

场景一

我有一张 table 可以说“成员(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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com