From: | Andreas Kretschmer <akretschmer(at)spamfence(dot)net> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: Seeking for the fore-part of the key |
Date: | 2009-01-11 21:17:48 |
Message-ID: | 20090111211748.GA21207@tux |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
Havasvölgyi Ottó <havasvolgyi(dot)otto(at)gmail(dot)com> schrieb:
> Hi,
>
> Let's assume I have a table (called tbl) with a column 'name' and an index on
> it.
> How to optimally find records whose name column begins with - say - "Pre"?
> I know it can be done with LIKE (WHERE name LIKE 'Pre%'), but will this use the
> index mentioned above to optimize the search?
for instance:
test=*# \d words
Tabelle »public.words«
Spalte | Typ | Attribute
--------+------+-----------
w | text |
Indexe:
»idx_words_w« btree (lower(w) text_pattern_ops)
test=*# explain analyse select * from words where lower(w) like lower('foo%');
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------
Bitmap Heap Scan on words (cost=40.65..1779.81 rows=1595 width=13) (actual time=0.021..0.021 rows=0 loops=1)
Filter: (lower(w) ~~ 'foo%'::text)
-> Bitmap Index Scan on idx_words_w (cost=0.00..40.25 rows=1595 width=0) (actual time=0.019..0.019 rows=0 loops=1)
Index Cond: ((lower(w) ~>=~ 'foo'::text) AND (lower(w) ~<~ 'fop'::text))
Total runtime: 0.047 ms
(5 Zeilen)
Andreas
--
Really, I'm not out to destroy Microsoft. That will just be a completely
unintentional side effect. (Linus Torvalds)
"If I was god, I would recompile penguin with --enable-fly." (unknown)
Kaufbach, Saxony, Germany, Europe. N 51.05082°, E 13.56889°
From | Date | Subject | |
---|---|---|---|
Next Message | Ivan Sergio Borgonovo | 2009-01-12 00:48:52 | Re: some howto/theory book/tutorial on practical problem solving in SQL |
Previous Message | Havasvölgyi Ottó | 2009-01-11 20:50:19 | Seeking for the fore-part of the key |