Re: Volatile Functions in Parallel Plans

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jesse Zhang <sbjesse(at)gmail(dot)com>
Cc: Zhenghua Lyu <zlyu(at)vmware(dot)com>, Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Volatile Functions in Parallel Plans
Date: 2020-07-16 15:18:57
Message-ID: 3358896.1594912737@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Jesse Zhang <sbjesse(at)gmail(dot)com> writes:
> You are right, no they are not consistent. But Neither plans is
> incorrect:

> 1. In the first query, it's semantically permissible to evaluate
> timeofday() for each pair of (c1, c2), and the plan reflects that.
> (Notice that the parallel nature of the plan is just noise here, the
> planner could have gone with a Nested Loop of which the inner side is
> _not_ materialized).

Yeah, exactly. The short answer here is that refusing to parallelize
the plan would not make things any more consistent.

In general, using a volatile function in a WHERE clause is problematic
because we make no guarantees about how often it will be evaluated.
It could be anywhere between "never" and "once per row of the
cross-product of the FROM tables". AFAIR, the only concession we've made
to make that less unpredictable is to avoid using volatile functions in
index quals. But even that will only make things noticeably more
predictable for single-table queries. As soon as you get into join cases,
you don't have much control over when the function will get evaluated.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bharath Rupireddy 2020-07-16 15:22:22 Re: [PATCH] Performance Improvement For Copy From Binary Files
Previous Message Robert Haas 2020-07-16 15:14:28 Re: Have SIGHUP instead of SIGTERM for config reload in logical replication launcher