index usage for min() vs. "order by asc limit 1"
От | Ben Chobot |
---|---|
Тема | index usage for min() vs. "order by asc limit 1" |
Дата | |
Msg-id | F954C233-D0D3-40F8-9486-E403B1DEE8B5@silentmedia.com обсуждение исходный текст |
Ответы |
Re: index usage for min() vs. "order by asc limit 1"
|
Список | pgsql-performance |
I have two queries in PG 9.1. One uses an index like I would like, the other does not. Is this expected behavior? If so,is there any way around it? postgres=# explain analyze select min(id) from delayed_jobs where strand='sis_batch:account:15' group by strand; QUERY PLAN -------------------------------------------------------------------------------------------------------------------------- GroupAggregate (cost=0.00..8918.59 rows=66 width=29) (actual time=226.759..226.760 rows=1 loops=1) -> Seq Scan on delayed_jobs (cost=0.00..8553.30 rows=72927 width=29) (actual time=0.014..169.941 rows=72268 loops=1) Filter: ((strand)::text = 'sis_batch:account:15'::text) Total runtime: 226.817 ms (4 rows) postgres=# explain analyze select id from delayed_jobs where strand='sis_batch:account:15' order by id limit 1; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..0.33 rows=1 width=8) (actual time=0.097..0.098 rows=1 loops=1) -> Index Scan using index_delayed_jobs_on_strand on delayed_jobs (cost=0.00..24181.74 rows=72927 width=8) (actual time=0.095..0.095rows=1 loops=1) Index Cond: ((strand)::text = 'sis_batch:account:15'::text) Total runtime: 0.129 ms (4 rows)
В списке pgsql-performance по дате отправления: