Skip to content

Commit 2f8a7bf

Browse files
committed
Fix make_restrictinfo_from_bitmapqual() to preserve AND/OR flatness of its
output, ie, no OR immediately below an OR. Otherwise we get Asserts or wrong answers for cases such as select * from tenk1 a, tenk1 b where (a.ten = b.ten and (a.unique1 = 100 or a.unique1 = 101)) or (a.hundred = b.hundred and a.unique1 = 42); Per report from Rafael Martinez Guerrero.
1 parent 0914ae1 commit 2f8a7bf

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

src/backend/optimizer/util/restrictinfo.c

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.46 2006/03/05 15:58:32 momjian Exp $
11+
* $PostgreSQL: pgsql/src/backend/optimizer/util/restrictinfo.c,v 1.47 2006/04/07 17:05:39 tgl Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -160,13 +160,44 @@ make_restrictinfo_from_bitmapqual(Path *bitmapqual,
160160
*/
161161
return NIL;
162162
}
163-
/* Create AND subclause with RestrictInfos */
164-
withris = lappend(withris,
165-
make_ands_explicit(sublist));
166-
/* And one without */
167-
sublist = get_actual_clauses(sublist);
168-
withoutris = lappend(withoutris,
169-
make_ands_explicit(sublist));
163+
/*
164+
* If the sublist contains multiple RestrictInfos, we create an
165+
* AND subclause. If there's just one, we have to check if it's
166+
* an OR clause, and if so flatten it to preserve AND/OR flatness
167+
* of our output.
168+
*
169+
* We construct lists with and without sub-RestrictInfos, so
170+
* as not to have to regenerate duplicate RestrictInfos below.
171+
*/
172+
if (list_length(sublist) > 1)
173+
{
174+
withris = lappend(withris, make_andclause(sublist));
175+
sublist = get_actual_clauses(sublist);
176+
withoutris = lappend(withoutris, make_andclause(sublist));
177+
}
178+
else
179+
{
180+
RestrictInfo *subri = (RestrictInfo *) linitial(sublist);
181+
182+
Assert(IsA(subri, RestrictInfo));
183+
if (restriction_is_or_clause(subri))
184+
{
185+
BoolExpr *subor = (BoolExpr *) subri->orclause;
186+
187+
Assert(or_clause((Node *) subor));
188+
withris = list_concat(withris,
189+
list_copy(subor->args));
190+
subor = (BoolExpr *) subri->clause;
191+
Assert(or_clause((Node *) subor));
192+
withoutris = list_concat(withoutris,
193+
list_copy(subor->args));
194+
}
195+
else
196+
{
197+
withris = lappend(withris, subri);
198+
withoutris = lappend(withoutris, subri->clause);
199+
}
200+
}
170201
}
171202

172203
/*

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy