Improve node type forward reference
authorPeter Eisentraut <[email protected]>
Thu, 17 Oct 2024 06:36:14 +0000 (08:36 +0200)
committerPeter Eisentraut <[email protected]>
Thu, 17 Oct 2024 06:36:48 +0000 (08:36 +0200)
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

src/backend/commands/createas.c
src/backend/parser/analyze.c
src/include/nodes/primnodes.h

index 0b629b1f79ca5820bd3fbbdbbc20e33981caf4c8..68ec122dbf9e66f7686bd16a83a8f6cea15a867c 100644 (file)
@@ -133,7 +133,7 @@ create_ctas_internal(List *attrList, IntoClause *into)
    if (is_matview)
    {
        /* StoreViewQuery scribbles on tree, so make a copy */
-       Query      *query = (Query *) copyObject(into->viewQuery);
+       Query      *query = copyObject(into->viewQuery);
 
        StoreViewQuery(intoRelationAddr.objectId, query, false);
        CommandCounterIncrement();
index 2d3d8fcf7699824fcadca11de4abed5160b64826..8a6ba1692e83b316be5e340c3ff9316aba749a3c 100644 (file)
@@ -3077,7 +3077,7 @@ transformCreateTableAsStmt(ParseState *pstate, CreateTableAsStmt *stmt)
         * in the IntoClause because that's where intorel_startup() can
         * conveniently get it from.
         */
-       stmt->into->viewQuery = (Node *) copyObject(query);
+       stmt->into->viewQuery = copyObject(query);
    }
 
    /* represent the command as a utility Query */
index ea47652adb871112d0652a7d4f5994609f563259..5b7b87dea542e03e711523905aa1c2bb63adb22b 100644 (file)
@@ -152,8 +152,8 @@ typedef struct TableFunc
  * For CREATE MATERIALIZED VIEW, viewQuery is the parsed-but-not-rewritten
  * SELECT Query for the view; otherwise it's NULL.  This is irrelevant in
  * the query jumbling as CreateTableAsStmt already includes a reference to
- * its own Query, so ignore it.  (Although it's actually Query*, we declare
- * it as Node* to avoid a forward reference.)
+ * its own Query, so ignore it.  (We declare it as struct Query* to avoid a
+ * forward reference.)
  */
 typedef struct IntoClause
 {
@@ -166,7 +166,7 @@ typedef struct IntoClause
    OnCommitAction onCommit;    /* what do we do at COMMIT? */
    char       *tableSpaceName; /* table space to use, or NULL */
    /* materialized view's SELECT query */
-   Node       *viewQuery pg_node_attr(query_jumble_ignore);
+   struct Query *viewQuery pg_node_attr(query_jumble_ignore);
    bool        skipData;       /* true for WITH NO DATA */
 } IntoClause;