8
8
*
9
9
*
10
10
* IDENTIFICATION
11
- * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.163 2003/12/28 21:57:36 tgl Exp $
11
+ * $PostgreSQL: pgsql/src/backend/optimizer/plan/planner.c,v 1.164 2004/01/12 22:20:28 tgl Exp $
12
12
*
13
13
*-------------------------------------------------------------------------
14
14
*/
@@ -380,6 +380,10 @@ preprocess_expression(Query *parse, Node *expr, int kind)
380
380
* If it's a qual or havingQual, canonicalize it. It seems most useful
381
381
* to do this before applying eval_const_expressions, since the latter
382
382
* can optimize flattened AND/ORs better than unflattened ones.
383
+ *
384
+ * Note: all processing of a qual expression after this point must be
385
+ * careful to maintain AND/OR flatness --- that is, do not generate a
386
+ * tree with AND directly under AND, nor OR directly under OR.
383
387
*/
384
388
if (kind == EXPRKIND_QUAL )
385
389
{
@@ -396,14 +400,6 @@ preprocess_expression(Query *parse, Node *expr, int kind)
396
400
*/
397
401
expr = eval_const_expressions (expr );
398
402
399
- /*
400
- * If it's a qual or havingQual, convert it to implicit-AND format.
401
- * (We don't want to do this before eval_const_expressions, since the
402
- * latter would be unable to simplify a top-level AND correctly.)
403
- */
404
- if (kind == EXPRKIND_QUAL )
405
- expr = (Node * ) make_ands_implicit ((Expr * ) expr );
406
-
407
403
/* Expand SubLinks to SubPlans */
408
404
if (parse -> hasSubLinks )
409
405
expr = SS_process_sublinks (expr , (kind == EXPRKIND_QUAL ));
@@ -417,6 +413,15 @@ preprocess_expression(Query *parse, Node *expr, int kind)
417
413
if (PlannerQueryLevel > 1 )
418
414
expr = SS_replace_correlation_vars (expr );
419
415
416
+ /*
417
+ * If it's a qual or havingQual, convert it to implicit-AND format.
418
+ * (We don't want to do this before eval_const_expressions, since the
419
+ * latter would be unable to simplify a top-level AND correctly. Also,
420
+ * SS_process_sublinks expects explicit-AND format.)
421
+ */
422
+ if (kind == EXPRKIND_QUAL )
423
+ expr = (Node * ) make_ands_implicit ((Expr * ) expr );
424
+
420
425
return expr ;
421
426
}
422
427
0 commit comments