dpns->appendrels = NULL; /* don't need it */
/*
- * Set up column name aliases. We will get rather bogus results for join
- * RTEs, but that doesn't matter because plan trees don't contain any join
- * alias Vars.
+ * Set up column name aliases, ignoring any join RTEs; they don't matter
+ * because plan trees don't contain any join alias Vars.
*/
set_simple_column_names(dpns);
*
* This handles EXPLAIN and cases where we only have relation RTEs. Without
* a join tree, we can't do anything smart about join RTEs, but we don't
- * need to (note that EXPLAIN should never see join alias Vars anyway).
- * If we do hit a join RTE we'll just process it like a non-table base RTE.
+ * need to, because EXPLAIN should never see join alias Vars anyway.
+ * If we find a join RTE we'll just skip it, leaving its deparse_columns
+ * struct all-zero. If somehow we try to deparse a join alias Var, we'll
+ * error out cleanly because the struct's num_cols will be zero.
*/
static void
set_simple_column_names(deparse_namespace *dpns)
dpns->rtable_columns = lappend(dpns->rtable_columns,
palloc0(sizeof(deparse_columns)));
- /* Assign unique column aliases within each RTE */
+ /* Assign unique column aliases within each non-join RTE */
forboth(lc, dpns->rtable, lc2, dpns->rtable_columns)
{
RangeTblEntry *rte = (RangeTblEntry *) lfirst(lc);
deparse_columns *colinfo = (deparse_columns *) lfirst(lc2);
- set_relation_column_names(dpns, rte, colinfo);
+ if (rte->rtekind != RTE_JOIN)
+ set_relation_column_names(dpns, rte, colinfo);
}
}