Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit74a1d4f

Browse files
committed
Improve behavior of concurrent rename statements.
Previously, renaming a table, sequence, view, index, foreign table,column, or trigger checked permissions before locking the object, whichmeant that if permissions were revoked during the lock wait, we wouldstill allow the operation. Similarly, if the original object is droppedand a new one with the same name is created, the operation will be allowedif we had permissions on the old object; the permissions on the newobject don't matter. All this is now fixed.Along the way, attempting to rename a trigger on a foreign table now givesthe same error message as trying to create one there in the first place(i.e. that it's not a table or view) rather than simply stating that notrigger by that name exists.Patch by me; review by Noah Misch.
1 parentd039fd5 commit74a1d4f

File tree

7 files changed

+192
-141
lines changed

7 files changed

+192
-141
lines changed

‎src/backend/commands/alter.c

Lines changed: 9 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -105,62 +105,18 @@ ExecRenameStmt(RenameStmt *stmt)
105105
caseOBJECT_SEQUENCE:
106106
caseOBJECT_VIEW:
107107
caseOBJECT_INDEX:
108+
caseOBJECT_FOREIGN_TABLE:
109+
RenameRelation(stmt);
110+
break;
111+
108112
caseOBJECT_COLUMN:
109113
caseOBJECT_ATTRIBUTE:
114+
renameatt(stmt);
115+
break;
116+
110117
caseOBJECT_TRIGGER:
111-
caseOBJECT_FOREIGN_TABLE:
112-
{
113-
Oidrelid;
114-
115-
CheckRelationOwnership(stmt->relation, true);
116-
117-
/*
118-
* Lock level used here should match what will be taken later,
119-
* in RenameRelation, renameatt, or renametrig.
120-
*/
121-
relid=RangeVarGetRelid(stmt->relation,AccessExclusiveLock,
122-
false);
123-
124-
switch (stmt->renameType)
125-
{
126-
caseOBJECT_TABLE:
127-
caseOBJECT_SEQUENCE:
128-
caseOBJECT_VIEW:
129-
caseOBJECT_INDEX:
130-
caseOBJECT_FOREIGN_TABLE:
131-
{
132-
/*
133-
* RENAME TABLE requires that we (still) hold
134-
* CREATE rights on the containing namespace, as
135-
* well as ownership of the table.
136-
*/
137-
OidnamespaceId=get_rel_namespace(relid);
138-
AclResultaclresult;
139-
140-
aclresult=pg_namespace_aclcheck(namespaceId,
141-
GetUserId(),
142-
ACL_CREATE);
143-
if (aclresult!=ACLCHECK_OK)
144-
aclcheck_error(aclresult,ACL_KIND_NAMESPACE,
145-
get_namespace_name(namespaceId));
146-
147-
RenameRelation(relid,stmt->newname,stmt->renameType);
148-
break;
149-
}
150-
caseOBJECT_COLUMN:
151-
caseOBJECT_ATTRIBUTE:
152-
renameatt(relid,stmt);
153-
break;
154-
caseOBJECT_TRIGGER:
155-
renametrig(relid,
156-
stmt->subname,/* old att name */
157-
stmt->newname);/* new att name */
158-
break;
159-
default:
160-
/* can't happen */ ;
161-
}
162-
break;
163-
}
118+
renametrig(stmt);
119+
break;
164120

165121
caseOBJECT_TSPARSER:
166122
RenameTSParser(stmt->object,stmt->newname);

‎src/backend/commands/cluster.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1474,28 +1474,24 @@ finish_heap_swap(Oid OIDOldHeap, Oid OIDNewHeap,
14741474
{
14751475
Relationtoastrel;
14761476
Oidtoastidx;
1477-
Oidtoastnamespace;
14781477
charNewToastName[NAMEDATALEN];
14791478

14801479
toastrel=relation_open(newrel->rd_rel->reltoastrelid,
14811480
AccessShareLock);
14821481
toastidx=toastrel->rd_rel->reltoastidxid;
1483-
toastnamespace=toastrel->rd_rel->relnamespace;
14841482
relation_close(toastrel,AccessShareLock);
14851483

14861484
/* rename the toast table ... */
14871485
snprintf(NewToastName,NAMEDATALEN,"pg_toast_%u",
14881486
OIDOldHeap);
14891487
RenameRelationInternal(newrel->rd_rel->reltoastrelid,
1490-
NewToastName,
1491-
toastnamespace);
1488+
NewToastName);
14921489

14931490
/* ... and its index too */
14941491
snprintf(NewToastName,NAMEDATALEN,"pg_toast_%u_index",
14951492
OIDOldHeap);
14961493
RenameRelationInternal(toastidx,
1497-
NewToastName,
1498-
toastnamespace);
1494+
NewToastName);
14991495
}
15001496
relation_close(newrel,NoLock);
15011497
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp