當前我有下面的SQL Select語句的下列元素。儘管如此,查詢似乎仍然很慢(10.000條記錄)。你有什麼建議?PostgreSQL索引優化
- 指數CATEGORY_ID
- 指數DELIVERY_DATE
- 上的product_id指數,PRODUCT_NAME
這裏是我的DDL:
Create table product (
product_id serial,
category_id int2,
product_name varchar(50),
delivery_date timestamp,
subtitle varchar(20),
price numeric(10,2),
retail_price numeric(10,2),
language_id int2,
store_id int2,
reseller_id int2
);
和SQL:
Select *
from product
WHERE delivery_date > '2012-10-20 06:00:00' AND category_id = 1
ORDER BY product_id, product_name;
任何幫助,將不勝感激。
下面的輸出EXPLAIN分析一下:
Sort (cost=18.11..18.12 rows=1 width=119) (actual time=0.064..0.064 rows=0 loops=1)
Sort Key: product_id, product_name
Sort Method: quicksort Memory: 25kB
-> Seq Scan on product (cost=0.00..18.10 rows=1 width=119) (actual time=0.019..0.019 rows=0 loops=1)
Filter: ((delivery_date > '2012-10-20 06:00:00'::timestamp without time zone) AND (category_id = 1))
Total runtime: 0.098 ms
編輯你的問題,並粘貼'explain analyze <你的選擇語句>'的輸出。 –
請參閱http://stackoverflow.com/tags/postgresql-performance/info - 請顯示Pg版本,'EXPLAIN(BUFFERS,ANALYZE)'輸出等。 –