Order of execution

From: luis(dot)roberto(at)siscobra(dot)com(dot)br
To: pgsql-performance(at)postgresql(dot)org
Subject: Order of execution
Date: 2021-04-27 18:52:37
Message-ID: 1849398212.2153796.1619549557535.JavaMail.zimbra@siscobra.com.br
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Hi!

My question is: is it possible to optimize function order execution?

Here's explanation:

I have a bunch of queries that have volatile quals, some more than one. For example:

SELECT *
FROM clients
WHERE some_func(client_id)
AND some_other_func(client_id)

Now, I know that having volatile function quals is not a good practice, but alas, it is what it is.

In this contrived example, some_func filters about 50% of clients, whereas some_other_func around 5%.

If PostgreSQL would execute them "serially", some_other_func would only run for 50% of the clients, cutting execution time. What I've seen is that volatile functions execute always.

Is the reason this happen because the function can modify the result from the outer query?

Luis R. Weck

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Jean-Christophe Boggio 2021-04-27 19:49:59 Re: Order of execution
Previous Message Marc Millas 2021-04-26 16:30:43 Re: Does btrfs on Linux have a negative performance impact for PostgreSQL 13?