Re: String handling function, substring vs. substr

From: brian <brian(at)zijn-digital(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: String handling function, substring vs. substr
Date: 2006-10-01 20:47:33
Message-ID: 45202965.3000000@zijn-digital.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-admin pgsql-general

arsi(at)aranzo(dot)netg(dot)se wrote:
>
> Hi all,
>
> I want to call one of the two functions above many times (in an
> aggregate function) and it says in the manual pages that substr is the
> same as substring.
>
> Does this mean that substr calls substring internally?? Or is it the
> other way around?? Or are they independent of each other??
>
> So in short, which is faster to use??
>
> Thanks,
>
> Archie
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: explain analyze is your friend

I normally trim the cruft from the end of emails i'm replying to but
this time it seemed like a good idea to leave it.

test=# EXPLAIN ANALYZE SELECT substring('foobar', 2);
QUERY PLAN
------------------------------------------------------------------------------------
Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.011..0.013
rows=1 loops=1)
Total runtime: 0.042 ms
(2 rows)

test=# EXPLAIN ANALYZE SELECT substr('foobar', 2);
QUERY PLAN
------------------------------------------------------------------------------------
Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.010..0.012
rows=1 loops=1)
Total runtime: 0.043 ms
(2 rows)

test=# EXPLAIN ANALYZE SELECT substring('foobar', 2);
QUERY PLAN
------------------------------------------------------------------------------------
Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.012..0.014
rows=1 loops=1)
Total runtime: 0.044 ms
(2 rows)

test=# EXPLAIN ANALYZE SELECT substr('foobar', 2);
QUERY PLAN
------------------------------------------------------------------------------------
Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.011..0.013
rows=1 loops=1)
Total runtime: 0.043 ms
(2 rows)

Looks like they're pretty evenly matched. I'd try it with something a
bit more complex. You could also prepare a file with the same queries
repeated amny times, using different words and positions. Do a file for
each function. Have psql dump its results into 2 other files and grep
for all the running times for each. Average them out and compare both
averages.

b

In response to

Responses

Browse pgsql-admin by date

  From Date Subject
Next Message Tom Lane 2006-10-01 22:41:50 Re: String handling function, substring vs. substr
Previous Message arsi 2006-10-01 20:31:03 String handling function, substring vs. substr

Browse pgsql-general by date

  From Date Subject
Next Message Michelle Konzack 2006-10-01 20:48:01 Re: pg web hosting with tsearch2?
Previous Message arsi 2006-10-01 20:31:03 String handling function, substring vs. substr