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

Commitb13fd34

Browse files
committed
Make constraint rename issue relcache invalidation on target relation
When a constraint gets renamed, it may have associated with it a targetrelation (for example domain constraints don't have one). Notinvalidating the target relation cache when issuing the renaming canresult in issues with subsequent commands that refer to the oldconstraint name using the relation cache, causing various failures. Onepattern spotted was using CREATE TABLE LIKE after a constraintrenaming.Reported-by: Stuart <sfbarbee@gmail.com>Author: Amit LangoteReviewed-by: Michael PaquierDiscussion:https://postgr.es/m/2047094.V130LYfLq4@station53.ousa.org
1 parenta73d083 commitb13fd34

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3019,8 +3019,15 @@ rename_constraint_internal(Oid myrelid,
30193019
ReleaseSysCache(tuple);
30203020

30213021
if (targetrelation)
3022+
{
30223023
relation_close(targetrelation,NoLock);/* close rel but keep lock */
30233024

3025+
/*
3026+
* Invalidate relcache so as others can see the new constraint name.
3027+
*/
3028+
CacheInvalidateRelcache(targetrelation);
3029+
}
3030+
30243031
returnaddress;
30253032
}
30263033

‎src/test/regress/expected/alter_table.out

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,28 @@ ALTER TABLE IF EXISTS constraint_not_exist RENAME CONSTRAINT con3 TO con3foo; --
393393
NOTICE: relation "constraint_not_exist" does not exist, skipping
394394
ALTER TABLE IF EXISTS constraint_rename_test ADD CONSTRAINT con4 UNIQUE (a);
395395
NOTICE: relation "constraint_rename_test" does not exist, skipping
396+
-- renaming constraints with cache reset of target relation
397+
CREATE TABLE constraint_rename_cache (a int,
398+
CONSTRAINT chk_a CHECK (a > 0),
399+
PRIMARY KEY (a));
400+
ALTER TABLE constraint_rename_cache
401+
RENAME CONSTRAINT chk_a TO chk_a_new;
402+
ALTER TABLE constraint_rename_cache
403+
RENAME CONSTRAINT constraint_rename_cache_pkey TO chk_a_gt_zero;
404+
CREATE TABLE like_constraint_rename_cache
405+
(LIKE constraint_rename_cache INCLUDING ALL);
406+
\d like_constraint_rename_cache
407+
Table "public.like_constraint_rename_cache"
408+
Column | Type | Collation | Nullable | Default
409+
--------+---------+-----------+----------+---------
410+
a | integer | | not null |
411+
Indexes:
412+
"like_constraint_rename_cache_pkey" PRIMARY KEY, btree (a)
413+
Check constraints:
414+
"chk_a_new" CHECK (a > 0)
415+
416+
DROP TABLE constraint_rename_cache;
417+
DROP TABLE like_constraint_rename_cache;
396418
-- FOREIGN KEY CONSTRAINT adding TEST
397419
CREATE TABLE attmp2 (a int primary key);
398420
CREATE TABLE attmp3 (a int, b int);

‎src/test/regress/sql/alter_table.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,20 @@ DROP TABLE constraint_rename_test;
289289
ALTERTABLE IF EXISTS constraint_not_exist RENAMECONSTRAINT con3 TO con3foo;-- ok
290290
ALTERTABLE IF EXISTS constraint_rename_test ADDCONSTRAINT con4 UNIQUE (a);
291291

292+
-- renaming constraints with cache reset of target relation
293+
CREATETABLEconstraint_rename_cache (aint,
294+
CONSTRAINT chk_aCHECK (a>0),
295+
PRIMARY KEY (a));
296+
ALTERTABLE constraint_rename_cache
297+
RENAMECONSTRAINT chk_a TO chk_a_new;
298+
ALTERTABLE constraint_rename_cache
299+
RENAMECONSTRAINT constraint_rename_cache_pkey TO chk_a_gt_zero;
300+
CREATETABLElike_constraint_rename_cache
301+
(LIKE constraint_rename_cache INCLUDING ALL);
302+
\d like_constraint_rename_cache
303+
DROPTABLE constraint_rename_cache;
304+
DROPTABLE like_constraint_rename_cache;
305+
292306
-- FOREIGN KEY CONSTRAINT adding TEST
293307

294308
CREATETABLEattmp2 (aintprimary key);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp