Skip to content

Commit cd92cfe

Browse files
Resolve conflicts in createas.h/createas.c
createas.h: Commit e665769 put the check for IF NOT EXISTS clause of CTAS command into the separate CreateTableAsRelExists(), while 598f4b0 had modified this file earlier. createas.c Commit e665769 used the CreateTableAsRelExists() at the begining of ExecCreateTableAs(), while GPDB team had cherry-picked more recent commit 782b169 fixing CREATE OR REPLACE vulnerability. Fix the confict in a way existing in upstream. Commit 846005e has modified intorel_shutdown when 598f4b0 has added the null check in the same place. Keep both variants.
1 parent 8e0bcb0 commit cd92cfe

2 files changed

Lines changed: 15 additions & 38 deletions

File tree

src/backend/commands/createas.c

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -310,40 +310,10 @@ ExecCreateTableAs(ParseState *pstate, CreateTableAsStmt *stmt,
310310

311311
Assert(Gp_role != GP_ROLE_EXECUTE);
312312

313-
<<<<<<< HEAD
314-
if (stmt->if_not_exists)
315-
{
316-
Oid nspid;
317-
Oid oldrelid;
318-
319-
nspid = RangeVarGetCreationNamespace(into->rel);
320-
321-
oldrelid = get_relname_relid(into->rel->relname, nspid);
322-
if (OidIsValid(oldrelid))
323-
{
324-
/*
325-
* The relation exists and IF NOT EXISTS has been specified.
326-
*
327-
* If we are in an extension script, insist that the pre-existing
328-
* object be a member of the extension, to avoid security risks.
329-
*/
330-
ObjectAddressSet(address, RelationRelationId, oldrelid);
331-
checkMembershipInCurrentExtension(&address);
332-
333-
/* OK to skip */
334-
ereport(NOTICE,
335-
(errcode(ERRCODE_DUPLICATE_TABLE),
336-
errmsg("relation \"%s\" already exists, skipping",
337-
into->rel->relname)));
338-
return InvalidObjectAddress;
339-
}
340-
}
341-
=======
342313
/* Check if the relation exists or not */
343314
if (CreateTableAsRelExists(stmt))
344315
return InvalidObjectAddress;
345316

346-
>>>>>>> f315205f3fafd6f6c7c479f480289fcf45700310
347317
/*
348318
* Create the tuple receiver object and insert info it will need
349319
*/
@@ -537,19 +507,31 @@ bool
537507
CreateTableAsRelExists(CreateTableAsStmt *ctas)
538508
{
539509
Oid nspid;
510+
Oid oldrelid;
511+
ObjectAddress address;
540512
IntoClause *into = ctas->into;
541513

542514
nspid = RangeVarGetCreationNamespace(into->rel);
543515

544-
if (get_relname_relid(into->rel->relname, nspid))
516+
oldrelid = get_relname_relid(into->rel->relname, nspid);
517+
if (OidIsValid(oldrelid))
545518
{
546519
if (!ctas->if_not_exists)
547520
ereport(ERROR,
548521
(errcode(ERRCODE_DUPLICATE_TABLE),
549522
errmsg("relation \"%s\" already exists",
550523
into->rel->relname)));
551524

552-
/* The relation exists and IF NOT EXISTS has been specified */
525+
/*
526+
* The relation exists and IF NOT EXISTS has been specified.
527+
*
528+
* If we are in an extension script, insist that the pre-existing
529+
* object be a member of the extension, to avoid security risks.
530+
*/
531+
ObjectAddressSet(address, RelationRelationId, oldrelid);
532+
checkMembershipInCurrentExtension(&address);
533+
534+
/* OK to skip */
553535
ereport(NOTICE,
554536
(errcode(ERRCODE_DUPLICATE_TABLE),
555537
errmsg("relation \"%s\" already exists, skipping",
@@ -777,14 +759,12 @@ static void
777759
intorel_shutdown(DestReceiver *self)
778760
{
779761
DR_intorel *myState = (DR_intorel *) self;
780-
<<<<<<< HEAD
781762
Relation into_rel = myState->rel;
782763

783764
if (into_rel == NULL)
784765
return;
785-
=======
766+
786767
IntoClause *into = myState->into;
787-
>>>>>>> f315205f3fafd6f6c7c479f480289fcf45700310
788768

789769
if (!into->skipData)
790770
{

src/include/commands/createas.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,8 @@ extern int GetIntoRelEFlags(IntoClause *intoClause);
2929

3030
extern DestReceiver *CreateIntoRelDestReceiver(IntoClause *intoClause);
3131

32-
<<<<<<< HEAD
3332
struct QueryDesc;
3433
extern void intorel_initplan(struct QueryDesc *queryDesc, int eflags);
35-
=======
3634
extern bool CreateTableAsRelExists(CreateTableAsStmt *ctas);
37-
>>>>>>> f315205f3fafd6f6c7c479f480289fcf45700310
3835

3936
#endif /* CREATEAS_H */

0 commit comments

Comments
 (0)