From 7c7139cf29b56d1b24cecf09a04ffd7e75c31737 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Wed, 28 May 2003 23:06:16 +0000 Subject: [PATCH] Knock down a couple more lappend() hotspots for large WHERE clauses. --- src/backend/commands/explain.c | 11 +++-- src/backend/optimizer/plan/createplan.c | 61 +++++++++++++------------ 2 files changed, 40 insertions(+), 32 deletions(-) diff --git a/src/backend/commands/explain.c b/src/backend/commands/explain.c index 879a7e6d68..3ce00d4ad0 100644 --- a/src/backend/commands/explain.c +++ b/src/backend/commands/explain.c @@ -7,7 +7,7 @@ * Portions Copyright (c) 1994-5, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.109 2003/05/08 18:16:36 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/commands/explain.c,v 1.110 2003/05/28 23:06:16 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -1033,12 +1033,15 @@ make_ors_ands_explicit(List *orclauses) return (Node *) make_ands_explicit(lfirst(orclauses)); else { - List *args = NIL; + FastList args; List *orptr; + FastListInit(&args); foreach(orptr, orclauses) - args = lappend(args, make_ands_explicit(lfirst(orptr))); + { + FastAppend(&args, make_ands_explicit(lfirst(orptr))); + } - return (Node *) make_orclause(args); + return (Node *) make_orclause(FastListValue(&args)); } } diff --git a/src/backend/optimizer/plan/createplan.c b/src/backend/optimizer/plan/createplan.c index 0d55dd7f8c..08b5944a1d 100644 --- a/src/backend/optimizer/plan/createplan.c +++ b/src/backend/optimizer/plan/createplan.c @@ -10,7 +10,7 @@ * * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.143 2003/05/28 16:03:56 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/plan/createplan.c,v 1.144 2003/05/28 23:06:16 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -681,7 +681,7 @@ create_indexscan_plan(Query *root, Expr *indxqual_or_expr = NULL; List *fixed_indxqual; List *recheck_indxqual; - List *indexids; + FastList indexids; List *ixinfo; IndexScan *scan_plan; @@ -692,12 +692,12 @@ create_indexscan_plan(Query *root, /* * Build list of index OIDs. */ - indexids = NIL; + FastListInit(&indexids); foreach(ixinfo, best_path->indexinfo) { IndexOptInfo *index = (IndexOptInfo *) lfirst(ixinfo); - indexids = lappendo(indexids, index->indexoid); + FastAppendo(&indexids, index->indexoid); } /* @@ -719,15 +719,15 @@ create_indexscan_plan(Query *root, * the implicit OR and AND semantics of the first- and * second-level lists. */ - List *orclauses = NIL; + FastList orclauses; List *orclause; + FastListInit(&orclauses); foreach(orclause, indxqual) { - orclauses = lappend(orclauses, - make_ands_explicit(lfirst(orclause))); + FastAppend(&orclauses, make_ands_explicit(lfirst(orclause))); } - indxqual_or_expr = make_orclause(orclauses); + indxqual_or_expr = make_orclause(FastListValue(&orclauses)); qpqual = set_difference(scan_clauses, makeList1(indxqual_or_expr)); } @@ -778,7 +778,7 @@ create_indexscan_plan(Query *root, scan_plan = make_indexscan(tlist, qpqual, baserelid, - indexids, + FastListValue(&indexids), fixed_indxqual, indxqual, best_path->indexscandir); @@ -1091,13 +1091,15 @@ static void fix_indxqual_references(List *indexquals, IndexPath *index_path, List **fixed_indexquals, List **recheck_indexquals) { - List *fixed_quals = NIL; - List *recheck_quals = NIL; + FastList fixed_quals; + FastList recheck_quals; Relids baserelids = index_path->path.parent->relids; int baserelid = index_path->path.parent->relid; List *ixinfo = index_path->indexinfo; List *i; + FastListInit(&fixed_quals); + FastListInit(&recheck_quals); foreach(i, indexquals) { List *indexqual = lfirst(i); @@ -1107,15 +1109,15 @@ fix_indxqual_references(List *indexquals, IndexPath *index_path, fix_indxqual_sublist(indexqual, baserelids, baserelid, index, &fixed_qual, &recheck_qual); - fixed_quals = lappend(fixed_quals, fixed_qual); + FastAppend(&fixed_quals, fixed_qual); if (recheck_qual != NIL) - recheck_quals = lappend(recheck_quals, recheck_qual); + FastAppend(&recheck_quals, recheck_qual); ixinfo = lnext(ixinfo); } - *fixed_indexquals = fixed_quals; - *recheck_indexquals = recheck_quals; + *fixed_indexquals = FastListValue(&fixed_quals); + *recheck_indexquals = FastListValue(&recheck_quals); } /* @@ -1136,10 +1138,12 @@ fix_indxqual_sublist(List *indexqual, IndexOptInfo *index, List **fixed_quals, List **recheck_quals) { - List *fixed_qual = NIL; - List *recheck_qual = NIL; + FastList fixed_qual; + FastList recheck_qual; List *i; + FastListInit(&fixed_qual); + FastListInit(&recheck_qual); foreach(i, indexqual) { OpExpr *clause = (OpExpr *) lfirst(i); @@ -1178,19 +1182,18 @@ fix_indxqual_sublist(List *indexqual, index, &opclass); - fixed_qual = lappend(fixed_qual, newclause); + FastAppend(&fixed_qual, newclause); /* * Finally, check to see if index is lossy for this operator. If * so, add (a copy of) original form of clause to recheck list. */ if (op_requires_recheck(newclause->opno, opclass)) - recheck_qual = lappend(recheck_qual, - copyObject((Node *) clause)); + FastAppend(&recheck_qual, copyObject((Node *) clause)); } - *fixed_quals = fixed_qual; - *recheck_quals = recheck_qual; + *fixed_quals = FastListValue(&fixed_qual); + *recheck_quals = FastListValue(&recheck_qual); } static Node * @@ -1327,26 +1330,28 @@ get_switched_clauses(List *clauses, Relids outerrelids) static List * order_qual_clauses(Query *root, List *clauses) { - List *nosubplans; - List *withsubplans; + FastList nosubplans; + FastList withsubplans; List *l; /* No need to work hard if the query is subselect-free */ if (!root->hasSubLinks) return clauses; - nosubplans = withsubplans = NIL; + FastListInit(&nosubplans); + FastListInit(&withsubplans); foreach(l, clauses) { Node *clause = lfirst(l); if (contain_subplans(clause)) - withsubplans = lappend(withsubplans, clause); + FastAppend(&withsubplans, clause); else - nosubplans = lappend(nosubplans, clause); + FastAppend(&nosubplans, clause); } - return nconc(nosubplans, withsubplans); + FastConcFast(&nosubplans, &withsubplans); + return FastListValue(&nosubplans); } /*