Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Efficiency Problem

0 views
Skip to first unread message

Surfing

unread,
Mar 17, 2013, 7:15:18 AM3/17/13
to
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.

Misa Simic

unread,
Mar 17, 2013, 7:39:21 AM3/17/13
to
Hi,

1) Is function marked as immutable?

2) if immutable doesnt help... It should be possible execute it first, and use it in other dynamics things in where...

Cheers,

Misa

Sent from my Windows Phone

From: Surfing
Sent: 17/03/2013 12:16
To: pgsq...@postgresql.org
Subject: [SQL] Efficiency Problem

Surfing

unread,
Mar 17, 2013, 7:43:16 AM3/17/13
to
IMMUTABLE solved the problem.

Thank you!
0 new messages