From: | Joe Conway <mail(at)joeconway(dot)com> |
---|---|
To: | David Olbersen <DOlbersen(at)stbernard(dot)com> |
Cc: | pgsql-novice <pgsql-novice(at)postgresql(dot)org> |
Subject: | Re: String manipulation |
Date: | 2003-07-28 23:17:30 |
Message-ID: | 3F25AF0A.3090009@joeconway.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-novice |
David Olbersen wrote:
>> SELECT substring(path from position(' ' in path) + 1) FROM (SELECT
>> split_part( path, ':', 2 ) AS path FROM paths) AS ss;
>
> That's cool enough except for the sub-select which would really slow
> down the query on a million+ row table. My solution is just
> reformatting data and doesn't add much if any over head to "SELECT
> path FROM paths".
>
> ...but that's all speculation, am I right? I'd like to revise my
> thinking if I'm wrong.
>
I could be wrong but I was thinking it would be more efficient to only
calculate the function once. I get these explain analyze results:
regression=# explain analyze SELECT substring(path from position(' ' in
path) + 1) FROM (SELECT split_part( path, ':', 2 ) AS path FROM paths)
AS ss;
QUERY PLAN
-----------------------------------------------------------------------
Seq Scan on paths (cost=0.00..1.09 rows=4 width=33) (actual
time=0.06..0.09 rows=4 loops=1)
Total runtime: 0.19 msec
(2 rows)
regression=# explain analyze SELECT substring(split_part( path, ':', 2 )
from position( ' ' in split_part( path, ':', 2 ) ) + 1) FROM paths;
QUERY PLAN
-------------------------------------------------------------------------
Seq Scan on paths (cost=0.00..1.09 rows=4 width=33) (actual
time=0.09..0.13 rows=4 loops=1)
Total runtime: 0.22 msec
(2 rows)
In either case each row is hit once.
Joe
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2003-07-29 01:21:13 | Re: String manipulation |
Previous Message | David Olbersen | 2003-07-28 23:08:42 | Re: String manipulation |