gpt4 book ai didi

mysql - 为什么行数存在差异?

转载 作者:行者123 更新时间:2023-11-29 08:44:07 26 4
gpt4 key购买 nike

嗨,我不明白为什么我的 MYSQL 表现得很奇怪。

这里我想知道表site_details中存在的记录数,以便得到我已经执行的 从 site_details 中选择 count(*);我得到的结果为

+----------+
| count(*) |
+----------+
| 2024 |
+----------+

然后再次验证我已经执行了 mysql> 从 msp 显示表状态,如“site_details”\G我得到的结果是这样的

 *************************** 1. row ***************************
Name: site_details
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 1612
Avg_row_length: 71
Data_length: 114688
Max_data_length: 0
Index_length: 81920
Data_free: 7340032
Auto_increment: NULL
Create_time: 2012-10-01 08:05:09
Update_time: NULL
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)

观察两个查询的行数之间的计数差异

然后在没有修改我的表的情况下,我再次执行了相同的查询 mysql> 从 msp 显示表状态,如“site_details”\G奇怪的是我得到的结果是这样的

 *************************** 1. row ***************************
Name: site_details
Engine: InnoDB
Version: 10
Row_format: Compact
Rows: 1934
Avg_row_length: 59
Data_length: 114688
Max_data_length: 0
Index_length: 81920
Data_free: 7340032
Auto_increment: NULL
Create_time: 2012-10-01 08:05:09
Update_time: NULL
Check_time: NULL
Collation: utf8_general_ci
Checksum: NULL
Create_options:
Comment:
1 row in set (0.00 sec)

观察上述查询的行列,我得到了类似 2024 1612 1934 的结果

为什么会发生这种情况?

最佳答案

select count(*)...

现在为您提供实际行数

select count(1)...

给出第一列不为空的行数

其他是基于数据库字典的指标,它们不会实时更新,而是依赖于统计数据等。

请参阅此处了解有关 COUNT 的信息:

http://dev.mysql.com/doc/refman/5.1/en/group-by-functions.html#function_count

因此,如果您想要确切的行数 - 重复项和所有行 - 立即(开放事务可能除外,具体取决于隔离级别),使用 COUNT(*) .

关于mysql - 为什么行数存在差异?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12975598/

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