ruby on rails - SQL COUNT - greater than some number without having to get the exact count? -


there's thread @ https://github.com/amatsuda/kaminari/issues/545 talking problem ruby pagination gem when encounters large tables.

when number of records large, pagination display like:

[1][2][3][4][5][6][7][8][9][10][...][end]

this can incur performance penalties when number of records huge, because getting exact count of, say, 50m+ records take time. however, that's needed know in case count greater the number of pages show * number of records per page.

is there faster sql operation getting exact count, merely assert count greater value x?

you try with

sql server:

select count(*) (select top 1000 * mytable) x 

mysql:

select count(*) (select * mytable limit 1000) x 

with little luck, sql server/mysql optimize query. instead of 1000 should put maximum number of pages want * number of rows per page.


Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -