I have a request:
select count(*) from `table` where `something`>123
If the table contains several million records, the query is very slow, although there is an index in the something
column. However, in fact, I'm interested in the meaning:
min(100000, count(*))
So, is there a way to prevent MySQL row counting when it already found 100k? I found something like:
select count(*) from (select 1 from `table` where `something`>123 limit 100000) as `asd`
This is much faster than count(*)
if the table contains several million matching records, but count(*)
is much faster when there are less than 100,000 matches.
Is there any way to make this faster?
Sebastian nowak
source share