pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: brian <brian@zijn-digital.com>
To: pgsql-general@postgresql.org
Subject: Re: String handling function, substring vs. substr
Date: Sun, 01 Oct 2006 16:47:33 -0400
Message-ID: <45202965.3000000@zijn-digital.com> (raw)
In-Reply-To: <Pine.LNX.4.62.0610011453050.22102@aranzo.netg.se>
References: <6992E470F12A444BB787B5C937B9D4DF060E5C9B@ca-mail1.cis.local>
	<Pine.LNX.4.62.0610011453050.22102@aranzo.netg.se>

arsi@aranzo.netg.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



view thread (4+ messages)  latest in thread

Message-ID: <45202965.3000000@zijn-digital.com>
Permalink:  ../45202965.3000000@zijn-digital.com/
Also on:    postgresql.org/message-id/45202965.3000000@zijn-digital.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-admin@postgresql.org
  Cc: brian@zijn-digital.com, pgsql-general@postgresql.org
  Subject: Re: String handling function, substring vs. substr
  In-Reply-To: <45202965.3000000@zijn-digital.com>
  References: <6992E470F12A444BB787B5C937B9D4DF060E5C9B@ca-mail1.cis.local> <Pine.LNX.4.62.0610011453050.22102@aranzo.netg.se> <45202965.3000000@zijn-digital.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox