Re: looking for a faster way to do that

From: hamann(dot)w(at)t-online(dot)de
To: pgsql-general(at)postgresql(dot)org
Subject: Re: looking for a faster way to do that
Date: 2011-09-23 12:12:32
Message-ID: 4E7C77B0.mailH4R116K97@amadeus3.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Eduardo Morras wrote:

>> You can try these, i doubt they will use any index but its a
>> different approach:
>>
>> select * from items where length(items.code)<>length(rtrim(items.code,'ABC'));
>>
>> select * from items where strpos(items.code,'ABC')=0 or
>> strpos(items.code,'any_substring')=0;

Hi,

if I understand this right, it does not mean "check if the string appears at position 0"
which could translate into an index query, but rather "check if the string appears anywhere
and then check if that is position 0", so the entire table is checked.

explain analyze select items.num, wantcode from items, n where strpos(code, wantcode) = 0;
Nested Loop (cost=167.14..196066.54 rows=39178 width=36) (actual time=0.074..36639.312 rows=7832539 loops=1)
Join Filter: (strpos(("inner".code)::text, "outer".wantcode) = 0)
-> Seq Scan on n (cost=0.00..14.15 rows=815 width=32) (actual time=0.005..2.212 rows=815 loops=1)
-> Materialize (cost=167.14..263.28 rows=9614 width=42) (actual time=0.007..13.970 rows=9614 loops=815)
-> Seq Scan on items (cost=0.00..167.14 rows=9614 width=42) (actual time=0.044..14.855 rows=9614 loops=1)
Total runtime: 46229.836 ms

The query ran much faster than the pattern query, however. This seems to be the performance
of just searching for a plain string vs. initializing the regex engine every time (for 815
queries in a test set)

Regards
Wolfgang Hamann

Responses

Browse pgsql-general by date

  From Date Subject
Next Message hamann.w 2011-09-23 12:29:19 Re: looking for a faster way to do that
Previous Message c k 2011-09-23 11:42:43 Re: [GENERAL] Date time value error in Ms Access using pass through queries