From: Tom Lane <tgl@sss.pgh.pa.us>
To: xinwen@stu.scu.edu.cn
Cc: pgsql-bugs@lists.postgresql.org, David Rowley <dgrowleyml@gmail.com>
Subject: Re: BUG #17826: An assert failed in /src/backend/optimizer/util/var.c
Date: Thu, 09 Mar 2023 11:09:13 -0500
Message-ID: <402866.1678378153@sss.pgh.pa.us> (raw)
In-Reply-To: <17826-7d8750952f19a5f5@postgresql.org>
References: <17826-7d8750952f19a5f5@postgresql.org>
PG Bug reporting form <noreply@postgresql.org> writes:
> When executing the following query:
> WITH table1 AS ( SELECT 1 ) SELECT 1 FROM ( SELECT RANK ( ) OVER ( ) column0
> FROM table1 JOIN table1 AS alias0 ON TRUE ) AS alias1 WHERE ( CASE WHEN ( 1
> IN ( SELECT 1 ) ) THEN 1 END = column0 ) ;
> I get a failed assertion with the following stacktrace:
The assertion is complaining about a SubPlan that has gotten pushed down
into the subquery, where it should not have been. Tracing through it,
the blame appears to fall on commit 9d9c02ccd, which added this rather
astonishing bit of coding:
if (!rinfo->pseudoconstant &&
qual_is_pushdown_safe(subquery, rti, rinfo, &safetyInfo))
{
/* Push it down */
subquery_push_qual(subquery, rte, rti, clause);
}
else
{
+ /*
+ * Since we can't push the qual down into the subquery, check
+ * if it happens to reference a window function. If so then
+ * it might be useful to use for the WindowAgg's runCondition.
+ */
+ if (!subquery->hasWindowFuncs ||
+ check_and_push_window_quals(subquery, rte, rti, clause,
+ &run_cond_attrs))
In other words, after qual_is_pushdown_safe has rejected a qual as being
unsafe to push down, check_and_push_window_quals merrily does it anyway,
apparently on the theory that window functions are exempt from all rules.
How is this even a little bit sane?
We could fix the given problem by adding a duplicative contain_subplans
check in check_and_push_window_quals, but first I want to see an argument
why it's okay to ignore any of the other things qual_is_pushdown_safe is
checking for, because I think this is dangerously broken on every single
count. My druthers would be to remove check_and_push_window_quals
altogether.
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, xinwen@stu.scu.edu.cn, dgrowleyml@gmail.com
Subject: Re: BUG #17826: An assert failed in /src/backend/optimizer/util/var.c
In-Reply-To: <402866.1678378153@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