sourcetip

큰 테이블에서 SELECT COUNT(0)가 느립니다.

fileupload 2023. 9. 10. 12:30
반응형

큰 테이블에서 SELECT COUNT(0)가 느립니다.

SELECT COUNT(0) FROM ts_client
LEFT JOIN ts_shop_client ON shop_client_id_client = client_id
WHERE client_email IS NOT NULL AND shop_client_id_shop = 1

설명:

ts_client의 행은 4904908이고 ts_shop_client의 행은 3547939입니다.

인덱스를 제대로 설정했고 sql이 느린 시간은 5,49 - 9,50초입니다.

안녕하세요, 여러분.

sql 속도를 높일 수 있는 해결책이 있습니까?

Tables_client

enter image description here

Tablets_shop_client

enter image description here

인덱스 ts_shop_client

enter image description here 고마워요

더하다

INDEX(shop_client_id_client, shop_client_id_shop) -- in either order.

이러한 색인을 사용하면 볼 필요가 있는 행의 수가 줄어듭니다.이렇게 하면 일이 빨라집니다.

그 전에는 각 행을 읽고 건너뛸 수 밖에 없었습니다.shop_client_id_shop1이 아니었습니다.

언급URL : https://stackoverflow.com/questions/32356854/select-count0-on-big-table-is-slow

반응형