Skip to content

Commit eafda78

Browse files
committed
Improve node type forward reference
Instead of using Node *, we can use an incomplete struct. That way, everything has the correct type and fewer casts are required. This technique is already used elsewhere in node type definitions. Reviewed-by: Nathan Bossart <[email protected]> Reviewed-by: Tender Wang <[email protected]> Discussion: https://www.postgresql.org/message-id/flat/637eeea8-5663-460b-a114-39572c0f6c6e%40eisentraut.org
1 parent 41b0239 commit eafda78

File tree

3 files changed

+5
-5
lines changed

3 files changed

+5
-5
lines changed

src/backend/commands/createas.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ create_ctas_internal(List *attrList, IntoClause *into)
133133
if (is_matview)
134134
{
135135
/* StoreViewQuery scribbles on tree, so make a copy */
136-
Query *query = (Query *) copyObject(into->viewQuery);
136+
Query *query = copyObject(into->viewQuery);
137137

138138
StoreViewQuery(intoRelationAddr.objectId, query, false);
139139
CommandCounterIncrement();

src/backend/parser/analyze.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -3077,7 +3077,7 @@ transformCreateTableAsStmt(ParseState *pstate, CreateTableAsStmt *stmt)
30773077
* in the IntoClause because that's where intorel_startup() can
30783078
* conveniently get it from.
30793079
*/
3080-
stmt->into->viewQuery = (Node *) copyObject(query);
3080+
stmt->into->viewQuery = copyObject(query);
30813081
}
30823082

30833083
/* represent the command as a utility Query */

src/include/nodes/primnodes.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,8 @@ typedef struct TableFunc
152152
* For CREATE MATERIALIZED VIEW, viewQuery is the parsed-but-not-rewritten
153153
* SELECT Query for the view; otherwise it's NULL. This is irrelevant in
154154
* the query jumbling as CreateTableAsStmt already includes a reference to
155-
* its own Query, so ignore it. (Although it's actually Query*, we declare
156-
* it as Node* to avoid a forward reference.)
155+
* its own Query, so ignore it. (We declare it as struct Query* to avoid a
156+
* forward reference.)
157157
*/
158158
typedef struct IntoClause
159159
{
@@ -166,7 +166,7 @@ typedef struct IntoClause
166166
OnCommitAction onCommit; /* what do we do at COMMIT? */
167167
char *tableSpaceName; /* table space to use, or NULL */
168168
/* materialized view's SELECT query */
169-
Node *viewQuery pg_node_attr(query_jumble_ignore);
169+
struct Query *viewQuery pg_node_attr(query_jumble_ignore);
170170
bool skipData; /* true for WITH NO DATA */
171171
} IntoClause;
172172

0 commit comments

Comments
 (0)