WorkHolic
MySQL: Fastest way to count number of rows 데이터의 수량을 빨르게 확인하는 방법
gromet
2023. 9. 23. 20:57
728x90
반응형
MySQL: Fastest way to count number of rows
데이터의 수량을 빨르게 확인하는 방법
MySQL DB replication을 하고 있는데 중간에 오류가 났다.
2개 DB의 데이터가 얼마나 틀리는지 알고 싶었다.
150GB의 DB데이터를 빨리 비교하는 방법을 확인해 보았다.
This is the best query able to get the fastest results.
SELECT SQL_CALC_FOUND_ROWS 1 FROM `orders`;
SELECT FOUND_ROWS();
일반적으로 많이 사용하지만 느리다
SELECT COUNT(*) FROM ... WHERE ...
SELECT 1 FROM ... WHERE ...
I did some benchmarks to compare the execution time of COUNT(*) vs COUNT(id)
(id is the primary key of the table - indexed).
Number of trials: 10 * 1000 queries
Results: COUNT(*) is faster 7%
결과가 빠르게 나오기는 하지만, 결과값이 의심스럽다.
EXPLAIN SELECT id FROM ....
see the number of rows under rows column of the result.
MySQL: Fastest way to count number of rows
MySQL: Fastest way to count number of rows
Which way to count a number of rows should be faster in MySQL? This: SELECT COUNT(*) FROM ... WHERE ... Or, the alternative: SELECT 1 FROM ... WHERE ... // and then count the results with a bu...
stackoverflow.com
728x90
SMALL