From 835bb975d8d11268582d9dbd26b0eeaa62b60632 Mon Sep 17 00:00:00 2001 From: Tom Lane Date: Sun, 29 Jun 2003 23:05:05 +0000 Subject: Restructure building of join relation targetlists so that a join plan node emits only those vars that are actually needed above it in the plan tree. (There were comments in the code suggesting that this was done at some point in the dim past, but for a long time we have just made join nodes emit everything that either input emitted.) Aside from being marginally more efficient, this fixes the problem noted by Peter Eisentraut where a join above an IN-implemented-as-join might fail, because the subplan targetlist constructed in the latter case didn't meet the expectation of including everything. Along the way, fix some places that were O(N^2) in the targetlist length. This is not all the trouble spots for wide queries by any means, but it's a step forward. --- src/backend/optimizer/path/pathkeys.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'src/backend/optimizer/path/pathkeys.c') diff --git a/src/backend/optimizer/path/pathkeys.c b/src/backend/optimizer/path/pathkeys.c index f8e4906c13b..d4d1179d545 100644 --- a/src/backend/optimizer/path/pathkeys.c +++ b/src/backend/optimizer/path/pathkeys.c @@ -11,7 +11,7 @@ * Portions Copyright (c) 1994, Regents of the University of California * * IDENTIFICATION - * $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.49 2003/05/28 16:03:56 tgl Exp $ + * $Header: /cvsroot/pgsql/src/backend/optimizer/path/pathkeys.c,v 1.50 2003/06/29 23:05:04 tgl Exp $ * *------------------------------------------------------------------------- */ @@ -703,20 +703,18 @@ find_indexkey_var(Query *root, RelOptInfo *rel, AttrNumber varattno) vartypeid; int32 type_mod; - foreach(temp, rel->targetlist) + foreach(temp, FastListValue(&rel->reltargetlist)) { - Var *tle_var = (Var *) ((TargetEntry *) lfirst(temp))->expr; + Var *var = (Var *) lfirst(temp); - if (IsA(tle_var, Var) && - tle_var->varattno == varattno) - return tle_var; + if (IsA(var, Var) && + var->varattno == varattno) + return var; } relid = rel->relid; - Assert(relid > 0); reloid = getrelid(relid, root->rtable); - vartypeid = get_atttype(reloid, varattno); - type_mod = get_atttypmod(reloid, varattno); + get_atttypetypmod(reloid, varattno, &vartypeid, &type_mod); return makeVar(relid, varattno, vartypeid, type_mod, 0); } -- cgit v1.2.3