두 개의 동일한 인덱스가 동일한 쿼리를 실행하는 동일한 테이블에 2 개의 동일한 (배정 밀도) 열이 있습니다. 아직 한 사람은 다른 사람보다 10 배 빨리 달린다. 이게 뭐야? 28ms의PostgreSQL 인덱스 쿼리 속도 불일치
1) SELECT MIN("reports"."longitude") AS min_id FROM "reports" WHERE (area2 = 18)
2) SELECT MIN("reports"."latitude") AS min_id FROM "reports" WHERE (area2 = 18)
1 실행하고 여기>이 300ms
2 개 실행은 '설명'은 다음과 같습니다
1)
Result (cost=6.07..6.08 rows=1 width=0)"
InitPlan 1 (returns $0)"
-> Limit (cost=0.00..6.07 rows=1 width=8)"
-> Index Scan using longitude on reports (cost=0.00..139617.49 rows=22983 width=8)"
Index Cond: (longitude IS NOT NULL)"
Filter: (area2 = 18)"
2)
Result (cost=5.95..5.96 rows=1 width=0)"
InitPlan 1 (returns $0)"
-> Limit (cost=0.00..5.95 rows=1 width=8)"
-> Index Scan using latitude on reports (cost=0.00..136754.07 rows=22983 width=8)"
Index Cond: (latitude IS NOT NULL)"
Filter: (area2 = 18)"
요청시
... (가) 출력을 분석 설명 여기에 에드
1)
Result (cost=6.07..6.08 rows=1 width=0) (actual time=10.992..10.993 rows=1 loops=1)"
InitPlan 1 (returns $0)"
-> Limit (cost=0.00..6.07 rows=1 width=8) (actual time=10.985..10.986 rows=1 loops=1)"
-> Index Scan using longitude on reports (cost=0.00..139617.49 rows=22983 width=8) (actual time=10.983..10.983 rows=1 loops=1)"
Index Cond: (longitude IS NOT NULL)"
Filter: (area2 = 18)"
Total runtime: 11.033 ms"
2)
Result (cost=5.95..5.96 rows=1 width=0) (actual time=259.749..259.749 rows=1 loops=1)"
InitPlan 1 (returns $0)"
-> Limit (cost=0.00..5.95 rows=1 width=8) (actual time=259.740..259.740 rows=1 loops=1)"
-> Index Scan using latitude on reports (cost=0.00..136754.07 rows=22983 width=8) (actual time=259.739..259.739 rows=1 loops=1)"
Index Cond: (latitude IS NOT NULL)"
Filter: (area2 = 18)"
Total runtime: 259.789 ms"
---------------------
무슨 일입니까? 두 번째 쿼리를 올바르게 실행하고 빠르게 실행할 수있는 방법은 무엇입니까? 두 설정 모두 내가 말할 수있는 한 동일합니다.
이전에 '진공관 전체 분석'을 수행 했습니까? 당신은'EXPLAIN ANALYZE' 또는 단지'EXPLAIN'을 했습니까? – ckruse
복합 색인이 관련되어 있습니까?우리에게 테이블 정의를 보여 주시고,'explain analyze'의 결과를 출력하십시오 – wildplasser
정말 정확한 테이블과 인덱스 정의를 이와 같은 질문에 포함시켜야합니다. 어떤 열이'NOT NULL'입니까? 색인 크기? 'VACUUM FULL ANALYZE'가 아무 것도 변경합니까? 'CLUSTER가 USING USING idx1'을보고하고 'CLUSTER가 USING USING idx2를보고합니다'라는 보고서가 변경됩니까? (나는 그것을 기대할 것이다!) –