| From: | hamann(dot)w(at)t-online(dot)de |
|---|---|
| To: | pgsql-general(at)postgresql(dot)org |
| Subject: | looking for a faster way to do that |
| Date: | 2011-09-21 15:59:49 |
| Message-ID: | wolfgang-1110921175949.A0114700@amadeus3.local |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
Hi,
I have one large table (about a million entries) with an indexed column containing codes
like ABC3561A, ABC3563X, 72-451-823 etc. (lots of order numbers from different
manufacturers)
When I ask for a specific item
select code .... where code = 'ABC3563X'
I get fast result. I also get fast result when doing a prefix match
select code .... where code ~ '^ABC3563'
If a am retrieving many items by joining with another table
select code ..... where code = wantcode
this is still fast.
If I try to get many items on a prefix match
select code .... where code ~ wantcode
things go very slow. Explain shows a nested loop, so seemingly the table is rescanned
for every wanted item in the other table. A test run (3000 wanted codes against a
shortened table of 10000 ones) took about 200 seconds to complete
What other queries could I use to get the requested selection?
Regards
Wolfgang
| From | Date | Subject | |
|---|---|---|---|
| Next Message | J.V. | 2011-09-21 18:36:02 | stored proc - how to format numbers? |
| Previous Message | jablonov | 2011-09-21 15:32:04 | Re: Trigger Procedure Error: NEW used in query that is not in a rule |