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

Commit0d1a7cd

Browse files
committed
Ensure we have a snapshot while dropping ON COMMIT DROP temp tables.
Dropping a temp table could entail TOAST table access to clean outtoasted catalog entries, such as large pg_constraint.conbin stringsfor complex CHECK constraints. If we did that via ON COMMIT DROP,we triggered the assertion in init_toast_snapshot(), becausethere was no provision for setting up a snapshot for the dropactions. Fix that.(I assume here that the adjacent truncation actions for ON COMMITDELETE ROWS don't have a similar problem: it doesn't seem likenontransactional truncations would need to touch any toasted fields.If that proves wrong, we could refactor a bit to have the samesnapshot acquisition cover that too.)The test case added here does not fail before v15, because thatassertion was added in2776922 which was not back-patched.However, the race condition the assertion warns of surelyexists further back, so back-patch to all supported branches.Per report from Richard Guo.Discussion:https://postgr.es/m/CAMbWs4-x26=_QxxgdJyNbiCDzvtr2WV5ZDso_v-CukKEe6cBZw@mail.gmail.com
1 parent882e522 commit0d1a7cd

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16900,13 +16900,21 @@ PreCommit_on_commit_actions(void)
1690016900
add_exact_object_address(&object, targetObjects);
1690116901
}
1690216902

16903+
/*
16904+
* Object deletion might involve toast table access (to clean up
16905+
* toasted catalog entries), so ensure we have a valid snapshot.
16906+
*/
16907+
PushActiveSnapshot(GetTransactionSnapshot());
16908+
1690316909
/*
1690416910
* Since this is an automatic drop, rather than one directly initiated
1690516911
* by the user, we pass the PERFORM_DELETION_INTERNAL flag.
1690616912
*/
1690716913
performMultipleDeletions(targetObjects, DROP_CASCADE,
1690816914
PERFORM_DELETION_INTERNAL | PERFORM_DELETION_QUIETLY);
1690916915

16916+
PopActiveSnapshot();
16917+
1691016918
#ifdef USE_ASSERT_CHECKING
1691116919

1691216920
/*

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,26 @@ SELECT * FROM temptest;
108108
1
109109
(1 row)
110110

111+
COMMIT;
112+
SELECT * FROM temptest;
113+
ERROR: relation "temptest" does not exist
114+
LINE 1: SELECT * FROM temptest;
115+
^
116+
-- Test it with a CHECK condition that produces a toasted pg_constraint entry
117+
BEGIN;
118+
do $$
119+
begin
120+
execute format($cmd$
121+
CREATE TEMP TABLE temptest (col text CHECK (col < %L)) ON COMMIT DROP
122+
$cmd$,
123+
(SELECT string_agg(g.i::text || ':' || random()::text, '|')
124+
FROM generate_series(1, 100) g(i)));
125+
end$$;
126+
SELECT * FROM temptest;
127+
col
128+
-----
129+
(0 rows)
130+
111131
COMMIT;
112132
SELECT * FROM temptest;
113133
ERROR: relation "temptest" does not exist

‎src/test/regress/sql/temp.sql

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ COMMIT;
101101

102102
SELECT*FROM temptest;
103103

104+
-- Test it with a CHECK condition that produces a toasted pg_constraint entry
105+
BEGIN;
106+
do $$
107+
begin
108+
execute format($cmd$
109+
CREATE TEMP TABLE temptest (coltextCHECK (col< %L))ONCOMMIT DROP
110+
$cmd$,
111+
(SELECT string_agg(g.i::text||':'|| random()::text,'|')
112+
FROM generate_series(1,100) g(i)));
113+
end$$;
114+
115+
SELECT*FROM temptest;
116+
COMMIT;
117+
118+
SELECT*FROM temptest;
119+
104120
-- ON COMMIT is only allowed for TEMP
105121

106122
CREATETABLEtemptest(colint)ONCOMMITDELETE ROWS;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp