Re: BUG #18812: Conditional rule: inconsistent check for statement

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: drtr0jan(at)yandex(dot)ru
Cc: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #18812: Conditional rule: inconsistent check for statement
Date: 2025-02-14 22:55:14
Message-ID: 3914796.1739573714@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

PG Bug reporting form <noreply(at)postgresql(dot)org> writes:
> I've two rules for a view - unconditional INSTEAD (skip) and conditional
> INSTEAD (always FALSE). But if I trying to insert a type mismatched data to
> the view, I've got a type constraint error.

[ shrug... ] The WHERE FALSE condition is evaluated later than it
would need to be to prevent this error. If we use a value that
doesn't trigger the error:

=# explain verbose INSERT INTO v (c) VALUES ('testtest');
QUERY PLAN
------------------------------------------------------
Insert on public.t (cost=0.00..0.01 rows=0 width=0)
-> Result (cost=0.00..0.01 rows=1 width=14)
Output: 'testtest'::character varying(10)
One-Time Filter: false
(4 rows)

we can see that the "false" is actually applied at runtime, but the
value coercion happened during planner constant-folding. In general
the order of application of WHERE clauses is not guaranteed, so
there's not a good argument that this outcome is wrong.

We get variants of this complaint from time to time, but few of
them present use-cases that seem compelling enough to justify the
performance costs of not doing constant-folding.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message PG Bug reporting form 2025-02-16 15:49:55 BUG #18813: Materialized view creation regression when inlining recursive SQL function
Previous Message PG Bug reporting form 2025-02-14 21:00:09 BUG #18812: Conditional rule: inconsistent check for statement