最有效的方式来获取表行计数 [英] Most efficient way to get table row count

查看:111
本文介绍了最有效的方式来获取表行计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有一个数据库,有超过600万行和不断增长。我目前做SELECT COUNT(id)FROM表;为了显示我的用户数,但数据库越来越大,我没有必要存储所有这些行,除了能够显示的数字。有没有办法选择要显示的auto_increment值,以便我可以清除数据库中的大多数行?使用 LAST_INSERT_ID()似乎无效。

I currently have a database with over 6 million rows and growing. I currently do SELECT COUNT(id) FROM table; in order to display the number to my users, but the database is getting large and I have no need to store all of those rows except to be able to show the number. Is there a way to select the auto_increment value to display so that I can clear out most of the rows in the database? Using LAST_INSERT_ID() doesn't seem to work.

推荐答案

它只是获取我建议使用的记录数(行):

If it's only about getting the number of records (rows) I'd suggest using:

SELECT TABLE_ROWS
FROM information_schema.tables 
WHERE table_name='the_table_you_want' -- Can end here if only 1 DB 
  AND table_schema = DATABASE();      -- See comment below if > 1 DB

(至少对于MySQL)。

(at least for MySQL) instead.

这篇关于最有效的方式来获取表行计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆