diff options
author | Jeff Davis <jdavis@postgresql.org> | 2024-08-02 11:49:03 -0700 |
---|---|---|
committer | Jeff Davis <jdavis@postgresql.org> | 2024-08-02 12:52:56 -0700 |
commit | 7926a9a80f6daf0fcc1feb1bee5c51fd001bc173 (patch) | |
tree | e64bb6833d8f5f2159fbd91bf9b47e3489ecccef /src/backend/commands/createas.c | |
parent | 3cffe7946c268be91a340ec9a27081cb93d67d35 (diff) | |
download | postgresql-7926a9a80f6daf0fcc1feb1bee5c51fd001bc173.tar.gz postgresql-7926a9a80f6daf0fcc1feb1bee5c51fd001bc173.zip |
Small refactoring around ExecCreateTableAs().
Since commit 4b74ebf726, the refresh logic is used to populate
materialized views, so we can simplify the error message in
ExecCreateTableAs().
Also, RefreshMatViewByOid() is moved to just after
create_ctas_nodata() call to improve code readability.
Author: Yugo Nagata
Discussion: https://postgr.es/m/20240802161301.d975daca9ba7a706fa05ecd7@sraoss.co.jp
Diffstat (limited to 'src/backend/commands/createas.c')
-rw-r--r-- | src/backend/commands/createas.c | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 36e192b79b2..c71ff801888 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -228,9 +228,6 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt, bool do_refresh = false; DestReceiver *dest; ObjectAddress address; - List *rewritten; - PlannedStmt *plan; - QueryDesc *queryDesc; /* Check if the relation exists or not */ if (CreateTableAsRelExists(stmt)) @@ -279,9 +276,25 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt, * from running the planner before all dependencies are set up. */ address = create_ctas_nodata(query->targetList, into); + + /* + * For materialized views, reuse the REFRESH logic, which locks down + * security-restricted operations and restricts the search_path. This + * reduces the chance that a subsequent refresh will fail. + */ + if (do_refresh) + RefreshMatViewByOid(address.objectId, true, false, false, + pstate->p_sourcetext, qc); + } else { + List *rewritten; + PlannedStmt *plan; + QueryDesc *queryDesc; + + Assert(!is_matview); + /* * Parse analysis was done already, but we still have to run the rule * rewriter. We do not do AcquireRewriteLocks: we assume the query @@ -292,9 +305,7 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt, /* SELECT should never rewrite to more or less than one SELECT query */ if (list_length(rewritten) != 1) - elog(ERROR, "unexpected rewrite result for %s", - is_matview ? "CREATE MATERIALIZED VIEW" : - "CREATE TABLE AS SELECT"); + elog(ERROR, "unexpected rewrite result for CREATE TABLE AS SELECT"); query = linitial_node(Query, rewritten); Assert(query->commandType == CMD_SELECT); @@ -339,17 +350,6 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt, PopActiveSnapshot(); } - /* - * For materialized views, reuse the REFRESH logic, which locks down - * security-restricted operations and restricts the search_path. This - * reduces the chance that a subsequent refresh will fail. - */ - if (do_refresh) - { - RefreshMatViewByOid(address.objectId, true, false, false, - pstate->p_sourcetext, qc); - } - return address; } |