B
B
beduin012021-08-27 15:10:40
PostgreSQL
beduin01, 2021-08-27 15:10:40

Why doesn't PostgreSQL use indexes?

There is a request:

SELECT region,
       COUNT(*) as total,
       COUNT(*) FILTER (WHERE t1.insert_status = 'success' ) as completed,
       COUNT(*) FILTER (WHERE t1.insert_status IS NULL AND t1.insert_status IS NULL ) as waiting,
       COUNT(*) FILTER (WHERE t1.insert_status = 'failed' ) as insert_failed
FROM xml_files_2 t1
WHERE t1.section_name = 'payments' AND
      t1.processed_date >='2010-01-28' AND t1.processed_date <='2021-08-28'        
GROUP BY region;


There are 300 thousand files in the test sample. The request is completed in 0.5 seconds.
I expose single indexes for all fields of request. The request continues to run for 0.5 seconds.
I make a composite index which includes all query fields - the execution time drops to 0.22 seconds.

Question. Why with indexes and without a difference any? And why did only composite indexes work?

If that data is on a very fast SSD drive. Could it be that PG doesn't use indexes because of this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan Shumov, 2021-08-27
@inoise

It is useless to understand blindly. Make an EXPLAIN request

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question