pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Surfing <onlinesurfing@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Efficiency Problem
Date: Sun, 17 Mar 2013 12:15:18 +0100
Message-ID: <5145A5C6.9000703@gmail.com> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

Hi all,
     I'm composing a query from a web application of type:

*SELECT * FROM table WHERE a_text_field LIKE replace_something 
('%**/a_given_string/**%');*

The function replace_something( ... ) is a stored procedure that 
replaces some particular characters with others.
The problem is that I noticed that this query is inefficient... and I 
think that the replace_something ( ... ) function is called for each row 
of the table.

This observation is motivated by the fact that it takes around 30 
seconds to execute on the table (of about 25,000 rows), whereas if I 
execute:
*SELECT * FROM table WHERE a_text_field LIKE 
'**/pre_processed_string/**//**';*

where/pre_processed_string///is the result of the application of 
replace_something ('%/a_given_string/%')  it just takes 164ms.

The execution of
*SELECT replace_something ('%**/a_given_string/**%')*
  takes only 14ms.

Summarizing,
- Replace function:     14ms
- SELECT query without replace function:     164ms
- SELECT query with replace function:      30.000ms

Morever, I cannot create a stored procedure that precalculate the 
/pre_processed_string /and executes the query, since I dinamically
compose other conditions in the WHERE clause.

Any suggestion?

Thank you.
//

view thread (3+ messages)  latest in thread

Message-ID: <5145A5C6.9000703@gmail.com>
Permalink:  ../5145A5C6.9000703@gmail.com/
Also on:    postgresql.org/message-id/5145A5C6.9000703@gmail.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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: onlinesurfing@gmail.com
  Subject: Re: Efficiency Problem
  In-Reply-To: <5145A5C6.9000703@gmail.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