|
25 | 25 | *
|
26 | 26 | *
|
27 | 27 | * 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 $ |
29 | 29 | *
|
30 | 30 | *-------------------------------------------------------------------------
|
31 | 31 | */
|
@@ -212,11 +212,40 @@ push_nots(Expr *qual)
|
212 | 212 | Oidnegator=get_negator(opexpr->opno);
|
213 | 213 |
|
214 | 214 | if (negator)
|
215 |
| -returnmake_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 | +returnmake_notclause(qual); |
| 227 | +} |
| 228 | +elseif (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 | +Oidnegator=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 | +} |
220 | 249 | else
|
221 | 250 | returnmake_notclause(qual);
|
222 | 251 | }
|
|