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

Commit1e67817

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 parent67060be commit1e67817

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
@@ -15859,13 +15859,21 @@ PreCommit_on_commit_actions(void)
1585915859
add_exact_object_address(&object, targetObjects);
1586015860
}
1586115861

15862+
/*
15863+
* Object deletion might involve toast table access (to clean up
15864+
* toasted catalog entries), so ensure we have a valid snapshot.
15865+
*/
15866+
PushActiveSnapshot(GetTransactionSnapshot());
15867+
1586215868
/*
1586315869
* Since this is an automatic drop, rather than one directly initiated
1586415870
* by the user, we pass the PERFORM_DELETION_INTERNAL flag.
1586515871
*/
1586615872
performMultipleDeletions(targetObjects, DROP_CASCADE,
1586715873
PERFORM_DELETION_INTERNAL | PERFORM_DELETION_QUIETLY);
1586815874

15875+
PopActiveSnapshot();
15876+
1586915877
#ifdef USE_ASSERT_CHECKING
1587015878

1587115879
/*

‎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