| From: | Rodrigo De León <rdeleonp(at)gmail(dot)com> |
|---|---|
| To: | "Andreas Joseph Krogh" <andreak(at)officenet(dot)no> |
| Cc: | pgsql-sql(at)postgresql(dot)org |
| Subject: | Re: PG won't use index on ORDER BY <expression> |
| Date: | 2007-08-09 20:57:35 |
| Message-ID: | a55915760708091357m4632c952s10bdafd235765941@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-sql |
On 8/9/07, Andreas Joseph Krogh <andreak(at)officenet(dot)no> wrote:
> Ooops, just fugured that out. But - it still doesn't use the index if I remove
> the "varchar_pattern_ops".
Huh?
CREATE INDEX person_lowerfullname_idx
ON person
((lower(COALESCE(firstname, '')) || lower(COALESCE(lastname, ''))));
EXPLAIN ANALYZE select id from person order by
(lower(COALESCE(firstname, '')) ||
lower(COALESCE(lastname, ''))) ASC limit 1;
Limit (cost=0.00..0.08 rows=1 width=68) (actual time=0.030..0.030
rows=0 loops=1)
-> Index Scan using person_lowerfullname_idx on person
(cost=0.00..62.25 rows=800 width=68) (actual time=0.018..0.018 rows=0
loops=1)
Total runtime: 0.318 ms
EXPLAIN ANALYZE select id from person
where (lower(COALESCE(firstname, '')) ||
lower(COALESCE(lastname, ''))) like 'A%'
order by (lower(COALESCE(firstname, '')) || lower(COALESCE(lastname, '')))
ASC limit 1;
Limit (cost=0.01..5.10 rows=1 width=68) (actual time=0.038..0.038
rows=0 loops=1)
-> Index Scan using person_lowerfullname_idx on person
(cost=0.01..20.34 rows=4 width=68) (actual time=0.032..0.032 rows=0
loops=1)
Index Cond: (((lower((COALESCE(firstname, ''::character
varying))::text) || lower((COALESCE(lastname, ''::character
varying))::text)) >= 'A'::text) AND ((lower((COALESCE(firstname,
''::character varying))::text) || lower((COALESCE(lastname,
''::character varying))::text)) < 'B'::text))
Filter: ((lower((COALESCE(firstname, ''::character
varying))::text) || lower((COALESCE(lastname, ''::character
varying))::text)) ~~ 'A%'::text)
Total runtime: 0.138 ms
Works for me.
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Andreas Joseph Krogh | 2007-08-09 21:10:52 | Re: PG won't use index on ORDER BY <expression> |
| Previous Message | Andreas Joseph Krogh | 2007-08-09 20:38:46 | Re: PG won't use index on ORDER BY <expression> |