diff --git a/src/backend/executor/execScan.c b/src/backend/executor/execScan.c index a96e826..635054e 100644 --- a/src/backend/executor/execScan.c +++ b/src/backend/executor/execScan.c @@ -275,17 +275,20 @@ tlist_matches_tupdesc(PlanState *ps, List *tlist, Index varno, TupleDesc tupdesc int numattrs = tupdesc->natts; int attrno; bool hasoid; - ListCell *tlist_item = list_head(tlist); + ListCell *l; + /* if lengths don't match then there's no point in checking items */ + if (numattrs != list_length(tlist)) + return false; + + attrno = 0; /* Check the tlist attributes */ - for (attrno = 1; attrno <= numattrs; attrno++) + foreach(l, tlist) { - Form_pg_attribute att_tup = tupdesc->attrs[attrno - 1]; + Form_pg_attribute att_tup = tupdesc->attrs[attrno]; Var *var; - if (tlist_item == NULL) - return false; /* tlist too short */ - var = (Var *) ((TargetEntry *) lfirst(tlist_item))->expr; + var = (Var *) ((TargetEntry *) lfirst(l))->expr; if (!var || !IsA(var, Var)) return false; /* tlist item not a Var */ /* if these Asserts fail, planner messed up */ @@ -311,12 +314,9 @@ tlist_matches_tupdesc(PlanState *ps, List *tlist, Index varno, TupleDesc tupdesc var->vartypmod != -1)) return false; /* type mismatch */ - tlist_item = lnext(tlist_item); + attrno++; } - if (tlist_item) - return false; /* tlist too long */ - /* * If the plan context requires a particular hasoid setting, then that has * to match, too.