From: Tom Lane <tgl@sss.pgh.pa.us>
To: poliv78@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18676: Execute function while selecting from table with partial index using this function.
Date: Mon, 28 Oct 2024 11:42:46 -0400
Message-ID: <3972734.1730130166@sss.pgh.pa.us> (raw)
In-Reply-To: <18676-383b0d2b6dc65bf6@postgresql.org>
References: <18676-383b0d2b6dc65bf6@postgresql.org>
PG Bug reporting form <noreply@postgresql.org> writes:
> Please run the script below. It creates sample table with partial index
> using IMMUTABLE function.
> I think when table is changing - index in changing and thus function used in
> WHERE cluse can be run.
> But it is not supposed to be run on just simple SELECT from table without
> even condition to use this index.
[ shrug... ] There is no bug here. The planner is entitled to
investigate the properties of indexes attached to a table it's
trying to plan for. Sure, this index is not relevant to this
query --- but how's the planner going to know that without
examining the index? And part of that examination involves
reducing any partial-index predicate to standard form, which
includes constant-folding. Since your function is marked
IMMUTABLE, that means it should be evaluated and reduced to
a constant.
Part of the contract for marking a function IMMUTABLE is that
it has no interesting side-effects. This example breaks that
in two ways: the RAISE NOTICE is a side-effect, and the
possibility of a permissions failure is another one.
regards, tom lane
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-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, poliv78@gmail.com, pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #18676: Execute function while selecting from table with partial index using this function.
In-Reply-To: <3972734.1730130166@sss.pgh.pa.us>
* 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