diff --git a/src/backend/optimizer/path/costsize.c b/src/backend/optimizer/path/costsize.c index 53bfd4b..2da841e 100644 --- a/src/backend/optimizer/path/costsize.c +++ b/src/backend/optimizer/path/costsize.c @@ -4512,7 +4512,7 @@ set_cte_size_estimates(PlannerInfo *root, RelOptInfo *rel, double cte_rows) void set_tuplestore_size_estimates(PlannerInfo *root, RelOptInfo *rel) { - RangeTblEntry *rte; + RangeTblEntry *rte PG_USED_FOR_ASSERTS_ONLY; /* Should only be applied to base relations that are tuplestore references */ Assert(rel->relid > 0); diff --git a/src/backend/parser/parse_relation.c b/src/backend/parser/parse_relation.c index 7c943c3..0b45139 100644 --- a/src/backend/parser/parse_relation.c +++ b/src/backend/parser/parse_relation.c @@ -1160,12 +1160,17 @@ parserOpenTable(ParseState *pstate, const RangeVar *relation, int lockmode) else { /* + * An unqualified name might be a tuplestore relation name. + */ + if (get_visible_tuplestore_metadata(pstate->p_tsrcache, relation->relname)) + rel = NULL; + /* * An unqualified name might have been meant as a reference to * some not-yet-in-scope CTE. The bare "does not exist" message * has proven remarkably unhelpful for figuring out such problems, * so we take pains to offer a specific hint. */ - if (isFutureCTE(pstate, relation->relname)) + else if (isFutureCTE(pstate, relation->relname)) ereport(ERROR, (errcode(ERRCODE_UNDEFINED_TABLE), errmsg("relation \"%s\" does not exist", diff --git a/src/include/parser/parse_node.h b/src/include/parser/parse_node.h index a9f5d6e..57906c0 100644 --- a/src/include/parser/parse_node.h +++ b/src/include/parser/parse_node.h @@ -158,7 +158,7 @@ struct ParseState bool p_locked_from_parent; Relation p_target_relation; RangeTblEntry *p_target_rangetblentry; - Tsrcache *p_tsrcache; /* visible named tuplestore relations */ + Tsrcache *p_tsrcache; /* visible named tuplestore relations */ /* * Optional hook functions for parser callbacks. These are null unless