Commit 301fcf33 authored by Alvaro Herrera's avatar Alvaro Herrera

Have CREATE TABLE AS and REFRESH return an OID

Other DDL commands are already returning the OID, which is required for
future additional event trigger work.  This is merely making these
commands in line with the rest of utility command support.
parent d6d6020f
...@@ -55,6 +55,9 @@ typedef struct ...@@ -55,6 +55,9 @@ typedef struct
BulkInsertState bistate; /* bulk insert state */ BulkInsertState bistate; /* bulk insert state */
} DR_intorel; } DR_intorel;
/* the OID of the created table, for ExecCreateTableAs consumption */
static Oid CreateAsRelid = InvalidOid;
static void intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo); static void intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo);
static void intorel_receive(TupleTableSlot *slot, DestReceiver *self); static void intorel_receive(TupleTableSlot *slot, DestReceiver *self);
static void intorel_shutdown(DestReceiver *self); static void intorel_shutdown(DestReceiver *self);
...@@ -64,7 +67,7 @@ static void intorel_destroy(DestReceiver *self); ...@@ -64,7 +67,7 @@ static void intorel_destroy(DestReceiver *self);
/* /*
* ExecCreateTableAs -- execute a CREATE TABLE AS command * ExecCreateTableAs -- execute a CREATE TABLE AS command
*/ */
void Oid
ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
ParamListInfo params, char *completionTag) ParamListInfo params, char *completionTag)
{ {
...@@ -75,6 +78,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, ...@@ -75,6 +78,7 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
Oid save_userid = InvalidOid; Oid save_userid = InvalidOid;
int save_sec_context = 0; int save_sec_context = 0;
int save_nestlevel = 0; int save_nestlevel = 0;
Oid relOid;
List *rewritten; List *rewritten;
PlannedStmt *plan; PlannedStmt *plan;
QueryDesc *queryDesc; QueryDesc *queryDesc;
...@@ -98,7 +102,9 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, ...@@ -98,7 +102,9 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
Assert(!is_matview); /* excluded by syntax */ Assert(!is_matview); /* excluded by syntax */
ExecuteQuery(estmt, into, queryString, params, dest, completionTag); ExecuteQuery(estmt, into, queryString, params, dest, completionTag);
return; relOid = CreateAsRelid;
CreateAsRelid = InvalidOid;
return relOid;
} }
Assert(query->commandType == CMD_SELECT); Assert(query->commandType == CMD_SELECT);
...@@ -190,6 +196,11 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, ...@@ -190,6 +196,11 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
/* Restore userid and security context */ /* Restore userid and security context */
SetUserIdAndSecContext(save_userid, save_sec_context); SetUserIdAndSecContext(save_userid, save_sec_context);
} }
relOid = CreateAsRelid;
CreateAsRelid = InvalidOid;
return relOid;
} }
/* /*
...@@ -421,6 +432,9 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo) ...@@ -421,6 +432,9 @@ intorel_startup(DestReceiver *self, int operation, TupleDesc typeinfo)
myState->rel = intoRelationDesc; myState->rel = intoRelationDesc;
myState->output_cid = GetCurrentCommandId(true); myState->output_cid = GetCurrentCommandId(true);
/* and remember the new relation's OID for ExecCreateTableAs */
CreateAsRelid = RelationGetRelid(myState->rel);
/* /*
* We can skip WAL-logging the insertions, unless PITR or streaming * We can skip WAL-logging the insertions, unless PITR or streaming
* replication is in use. We can skip the FSM in any case. * replication is in use. We can skip the FSM in any case.
......
...@@ -132,7 +132,7 @@ SetMatViewPopulatedState(Relation relation, bool newstate) ...@@ -132,7 +132,7 @@ SetMatViewPopulatedState(Relation relation, bool newstate)
* The matview's "populated" state is changed based on whether the contents * The matview's "populated" state is changed based on whether the contents
* reflect the result set of the materialized view's query. * reflect the result set of the materialized view's query.
*/ */
void Oid
ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
ParamListInfo params, char *completionTag) ParamListInfo params, char *completionTag)
{ {
...@@ -281,6 +281,8 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, ...@@ -281,6 +281,8 @@ ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
} }
else else
refresh_by_heap_swap(matviewOid, OIDNewHeap); refresh_by_heap_swap(matviewOid, OIDNewHeap);
return matviewOid;
} }
/* /*
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "tcop/dest.h" #include "tcop/dest.h"
extern void ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, extern Oid ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString,
ParamListInfo params, char *completionTag); ParamListInfo params, char *completionTag);
extern int GetIntoRelEFlags(IntoClause *intoClause); extern int GetIntoRelEFlags(IntoClause *intoClause);
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
extern void SetMatViewPopulatedState(Relation relation, bool newstate); extern void SetMatViewPopulatedState(Relation relation, bool newstate);
extern void ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString, extern Oid ExecRefreshMatView(RefreshMatViewStmt *stmt, const char *queryString,
ParamListInfo params, char *completionTag); ParamListInfo params, char *completionTag);
extern DestReceiver *CreateTransientRelDestReceiver(Oid oid); extern DestReceiver *CreateTransientRelDestReceiver(Oid oid);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment