From 5db2e83852cc3f25fdea48c4aa0da8696c88a826 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Mon, 28 Mar 2005 00:58:26 +0000 Subject: Rethink the order of expression preprocessing: eval_const_expressions really ought to run before canonicalize_qual, because it can now produce forms that canonicalize_qual knows how to improve (eg, NOT clauses). Also, because eval_const_expressions already knows about flattening nested ANDs and ORs into N-argument form, the initial flatten_andors pass in canonicalize_qual is now completely redundant and can be removed. This doesn't save a whole lot of code, but the time and palloc traffic eliminated is a useful gain on large expression trees. --- src/backend/utils/cache/relcache.c | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) (limited to 'src/backend/utils/cache/relcache.c') diff --git a/src/backend/utils/cache/relcache.c b/src/backend/utils/cache/relcache.c index d1143381d2d..a6660fc4d32 100644 --- a/src/backend/utils/cache/relcache.c +++ b/src/backend/utils/cache/relcache.c @@ -8,7 +8,7 @@ * * * IDENTIFICATION - * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.216 2005/03/07 04:42:16 tgl Exp $ + * $PostgreSQL: pgsql/src/backend/utils/cache/relcache.c,v 1.217 2005/03/28 00:58:26 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -2788,14 +2788,11 @@ RelationGetIndexExpressions(Relation relation) pfree(exprsString); /* - * Run the expressions through flatten_andors and - * eval_const_expressions. This is not just an optimization, but is - * necessary, because the planner will be comparing them to - * similarly-processed qual clauses, and may fail to detect valid - * matches without this. + * Run the expressions through eval_const_expressions. This is not just an + * optimization, but is necessary, because the planner will be comparing + * them to similarly-processed qual clauses, and may fail to detect valid + * matches without this. We don't bother with canonicalize_qual, however. */ - result = (List *) flatten_andors((Node *) result); - result = (List *) eval_const_expressions((Node *) result); /* @@ -2863,16 +2860,18 @@ RelationGetIndexPredicate(Relation relation) pfree(predString); /* - * Run the expression through canonicalize_qual and - * eval_const_expressions. This is not just an optimization, but is - * necessary, because the planner will be comparing it to - * similarly-processed qual clauses, and may fail to detect valid - * matches without this. + * Run the expression through const-simplification and canonicalization. + * This is not just an optimization, but is necessary, because the planner + * will be comparing it to similarly-processed qual clauses, and may fail + * to detect valid matches without this. This must match the processing + * done to qual clauses in preprocess_expression()! (We can skip the + * stuff involving subqueries, however, since we don't allow any in + * index predicates.) */ - result = (List *) canonicalize_qual((Expr *) result); - result = (List *) eval_const_expressions((Node *) result); + result = (List *) canonicalize_qual((Expr *) result); + /* * Also mark any coercion format fields as "don't care", so that the * planner can match to both explicit and implicit coercions. -- cgit v1.2.3