Skip to content

Commit a66e2c8

Browse files
committed
Teach push_nots() how to negate a ScalarArrayOpExpr. In passing, save
a palloc or two in the OpExpr case.
1 parent 4c4eb57 commit a66e2c8

File tree

1 file changed

+35
-6
lines changed

1 file changed

+35
-6
lines changed

src/backend/optimizer/prep/prepqual.c

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
*
2626
*
2727
* IDENTIFICATION
28-
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepqual.c,v 1.52 2005/11/22 18:17:14 momjian Exp $
28+
* $PostgreSQL: pgsql/src/backend/optimizer/prep/prepqual.c,v 1.53 2005/11/26 18:07:40 tgl Exp $
2929
*
3030
*-------------------------------------------------------------------------
3131
*/
@@ -212,11 +212,40 @@ push_nots(Expr *qual)
212212
Oid negator = get_negator(opexpr->opno);
213213

214214
if (negator)
215-
return make_opclause(negator,
216-
opexpr->opresulttype,
217-
opexpr->opretset,
218-
(Expr *) get_leftop(qual),
219-
(Expr *) get_rightop(qual));
215+
{
216+
OpExpr *newopexpr = makeNode(OpExpr);
217+
218+
newopexpr->opno = negator;
219+
newopexpr->opfuncid = InvalidOid;
220+
newopexpr->opresulttype = opexpr->opresulttype;
221+
newopexpr->opretset = opexpr->opretset;
222+
newopexpr->args = opexpr->args;
223+
return (Expr *) newopexpr;
224+
}
225+
else
226+
return make_notclause(qual);
227+
}
228+
else if (qual && IsA(qual, ScalarArrayOpExpr))
229+
{
230+
/*
231+
* Negate a ScalarArrayOpExpr if there is a negator for its operator;
232+
* for example x = ANY (list) becomes x <> ALL (list).
233+
* Otherwise, retain the clause as it is (the NOT can't be pushed down
234+
* any farther).
235+
*/
236+
ScalarArrayOpExpr *saopexpr = (ScalarArrayOpExpr *) qual;
237+
Oid negator = get_negator(saopexpr->opno);
238+
239+
if (negator)
240+
{
241+
ScalarArrayOpExpr *newopexpr = makeNode(ScalarArrayOpExpr);
242+
243+
newopexpr->opno = negator;
244+
newopexpr->opfuncid = InvalidOid;
245+
newopexpr->useOr = !saopexpr->useOr;
246+
newopexpr->args = saopexpr->args;
247+
return (Expr *) newopexpr;
248+
}
220249
else
221250
return make_notclause(qual);
222251
}

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