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
Posted by gromet

블로그 이미지
나는 운이 좋은 사람이다 나는 나날이 점점 더 좋아진다 내가 하는 선택과 행동은 반드시 성공으로 이어진다 내게는 인내력과 지속력이 있다 네게는 좋은것들만 모여든다
gromet

공지사항

Yesterday
Today
Total
반응형

달력

 « |  » 2024.7
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31

최근에 올라온 글

최근에 달린 댓글

최근에 받은 트랙백

글 보관함

160x600