Adjust overly strict Assert
authorDavid Rowley <drowley@postgresql.org>
Sun, 21 Jul 2019 22:29:41 +0000 (10:29 +1200)
committerDavid Rowley <drowley@postgresql.org>
Sun, 21 Jul 2019 22:29:41 +0000 (10:29 +1200)
3373c7155 changed how we determine EquivalenceClasses for relations and
added an Assert to ensure all relations mentioned in each EC's ec_relids
was a RELOPT_BASEREL.  However, the join removal code may remove a LEFT
JOIN and since it does not clean up EC members belonging to the removed
relations it can leave RELOPT_DEADREL rels in ec_relids.

Fix this by adjusting the Assert to allow RELOPT_DEADREL rels too.

Reported-by: sqlsmith via Andreas Seltenreich
Discussion: https://postgr.es/m/87y30r8sls.fsf@ansel.ydns.eu

src/backend/optimizer/path/equivclass.c

index 2c595dfb08c77ffcba61719a54322b90ca6c0b7a..ccc07ba9f0de752821f823a7641b41796081a6b6 100644 (file)
@@ -761,7 +761,8 @@ get_eclass_for_sort_expr(PlannerInfo *root,
                {
                        RelOptInfo *rel = root->simple_rel_array[i];
 
-                       Assert(rel->reloptkind == RELOPT_BASEREL);
+                       Assert(rel->reloptkind == RELOPT_BASEREL ||
+                                  rel->reloptkind == RELOPT_DEADREL);
 
                        rel->eclass_indexes = bms_add_member(rel->eclass_indexes,
                                                                                                 ec_index);