Reputation: 1435
I have a mysql table with up to 2.000.000 Records
How can in the fastest time calculate the number of rows in the table?
Upvotes: 0
Views: 148
Reputation: 255
For exact count for all storage engines:
select count(*) from table1;
For faster MyISAM exact count or InnoDB estimated count:
show table status;
or
select table_schema, table_name, table_rows from information_schema where table_name = 'table1' and table_schema = 'schema1';
see MySQL show status documentation
see MySQL infromation_schema.tables documentation
Upvotes: 1
Reputation: 595
SELECT COUNT(*) FROM table_name;
is the fastest way to calculate the numbers of rows because it uses column indexes. if you're using MyISAM engine then it actually stores row count and it doesn't count rows each time you issue SELECT COUNT(*) FROM table_name
Further Clarification is here
Upvotes: 0
Reputation: 151
This fastet
SELECT COUNT(1) FROM `sometable` WHERE somefield = 'somecondition'
Upvotes: 0