Killing off removed rels properly
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: pgsql-hackers@lists.postgresql.org
Date: 2023-02-10T20:50:20Z
Lists: pgsql-hackers
Attachments
- really-remove-dead-rels-1.patch (text/x-diff) patch
Outer-join removal does this:
/*
* Mark the rel as "dead" to show it is no longer part of the join tree.
* (Removing it from the baserel array altogether seems too risky.)
*/
rel->reloptkind = RELOPT_DEADREL;
which apparently I thought was a good idea in 2010 (cf b78f6264e),
but looking at it now it just seems like an invitation to fail to
detect bugs. We've had a couple of recent reports of indxpath.c
failing like this:
Program terminated with signal SIGABRT, Aborted.
#0 __GI_raise (sig=sig(at)entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#1 0x00007f0b57bc6859 in __GI_abort () at abort.c:79
#2 0x0000555ec56d3ff3 in ExceptionalCondition (conditionName=0x555ec5887ff0
"outer_rel->rows > 0", fileName=0x555ec5887f2c "indxpath.c",
lineNumber=1909) at assert.c:66
#3 0x0000555ec538a67a in get_loop_count (root=0x555ec5f72680, cur_relid=3,
outer_relids=0x555ec5f93960) at indxpath.c:1909
#4 0x0000555ec5388b5e in build_index_paths (root=0x555ec5f72680,
rel=0x555ec5f8f648, index=0x555ec5f8ca90, clauses=0x7fffeea57480,
useful_predicate=false, scantype=ST_BITMAPSCAN, skip_nonnative_saop=0x0,
skip_lower_saop=0x0) at indxpath.c:957
This is pretty impenetrable at first glance, but what it boils
down to is something accessing a "dead" rel and taking its contents
at face value. Fortunately the contents triggered an assertion,
but that hardly seems like something to count on to detect bugs.
I think it's time to clean this up by removing the rel from the
planner data structures altogether. The attached passes check-world,
and if it does trigger any problems I would say that's a clear
sign of bugs elsewhere.
regards, tom lane
Commits
-
Prevent join removal from removing the query's result relation.
- f6db76c55509 16.0 landed
- e6d8639cf25c 15.3 landed
-
Remove gratuitous assumptions about what make_modifytable can see.
- c6c3b3bc3de1 16.0 landed
-
When removing a relation from the query, drop its RelOptInfo.
- e9a20e451f3a 16.0 landed
-
Allow left join removals and unique joins on partitioned tables
- 3c569049b7b5 16.0 cited