mirror of
https://github.com/postgres/postgres.git
synced 2025-05-03 22:24:49 +03:00
Ensure we have a snapshot while dropping ON COMMIT DROP temp tables.
Dropping a temp table could entail TOAST table access to clean out toasted catalog entries, such as large pg_constraint.conbin strings for complex CHECK constraints. If we did that via ON COMMIT DROP, we triggered the assertion in init_toast_snapshot(), because there was no provision for setting up a snapshot for the drop actions. Fix that. (I assume here that the adjacent truncation actions for ON COMMIT DELETE ROWS don't have a similar problem: it doesn't seem like nontransactional truncations would need to touch any toasted fields. If that proves wrong, we could refactor a bit to have the same snapshot acquisition cover that too.) The test case added here does not fail before v15, because that assertion was added in 277692220 which was not back-patched. However, the race condition the assertion warns of surely exists 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
This commit is contained in:
parent
81b3df0f1b
commit
f6e1ee3cfa
@ -16364,6 +16364,12 @@ PreCommit_on_commit_actions(void)
|
|||||||
add_exact_object_address(&object, targetObjects);
|
add_exact_object_address(&object, targetObjects);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Object deletion might involve toast table access (to clean up
|
||||||
|
* toasted catalog entries), so ensure we have a valid snapshot.
|
||||||
|
*/
|
||||||
|
PushActiveSnapshot(GetTransactionSnapshot());
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Since this is an automatic drop, rather than one directly initiated
|
* Since this is an automatic drop, rather than one directly initiated
|
||||||
* by the user, we pass the PERFORM_DELETION_INTERNAL flag.
|
* by the user, we pass the PERFORM_DELETION_INTERNAL flag.
|
||||||
@ -16371,6 +16377,8 @@ PreCommit_on_commit_actions(void)
|
|||||||
performMultipleDeletions(targetObjects, DROP_CASCADE,
|
performMultipleDeletions(targetObjects, DROP_CASCADE,
|
||||||
PERFORM_DELETION_INTERNAL | PERFORM_DELETION_QUIETLY);
|
PERFORM_DELETION_INTERNAL | PERFORM_DELETION_QUIETLY);
|
||||||
|
|
||||||
|
PopActiveSnapshot();
|
||||||
|
|
||||||
#ifdef USE_ASSERT_CHECKING
|
#ifdef USE_ASSERT_CHECKING
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -108,6 +108,26 @@ SELECT * FROM temptest;
|
|||||||
1
|
1
|
||||||
(1 row)
|
(1 row)
|
||||||
|
|
||||||
|
COMMIT;
|
||||||
|
SELECT * FROM temptest;
|
||||||
|
ERROR: relation "temptest" does not exist
|
||||||
|
LINE 1: SELECT * FROM temptest;
|
||||||
|
^
|
||||||
|
-- Test it with a CHECK condition that produces a toasted pg_constraint entry
|
||||||
|
BEGIN;
|
||||||
|
do $$
|
||||||
|
begin
|
||||||
|
execute format($cmd$
|
||||||
|
CREATE TEMP TABLE temptest (col text CHECK (col < %L)) ON COMMIT DROP
|
||||||
|
$cmd$,
|
||||||
|
(SELECT string_agg(g.i::text || ':' || random()::text, '|')
|
||||||
|
FROM generate_series(1, 100) g(i)));
|
||||||
|
end$$;
|
||||||
|
SELECT * FROM temptest;
|
||||||
|
col
|
||||||
|
-----
|
||||||
|
(0 rows)
|
||||||
|
|
||||||
COMMIT;
|
COMMIT;
|
||||||
SELECT * FROM temptest;
|
SELECT * FROM temptest;
|
||||||
ERROR: relation "temptest" does not exist
|
ERROR: relation "temptest" does not exist
|
||||||
|
@ -101,6 +101,22 @@ COMMIT;
|
|||||||
|
|
||||||
SELECT * FROM temptest;
|
SELECT * FROM temptest;
|
||||||
|
|
||||||
|
-- Test it with a CHECK condition that produces a toasted pg_constraint entry
|
||||||
|
BEGIN;
|
||||||
|
do $$
|
||||||
|
begin
|
||||||
|
execute format($cmd$
|
||||||
|
CREATE TEMP TABLE temptest (col text CHECK (col < %L)) ON COMMIT DROP
|
||||||
|
$cmd$,
|
||||||
|
(SELECT string_agg(g.i::text || ':' || random()::text, '|')
|
||||||
|
FROM generate_series(1, 100) g(i)));
|
||||||
|
end$$;
|
||||||
|
|
||||||
|
SELECT * FROM temptest;
|
||||||
|
COMMIT;
|
||||||
|
|
||||||
|
SELECT * FROM temptest;
|
||||||
|
|
||||||
-- ON COMMIT is only allowed for TEMP
|
-- ON COMMIT is only allowed for TEMP
|
||||||
|
|
||||||
CREATE TABLE temptest(col int) ON COMMIT DELETE ROWS;
|
CREATE TABLE temptest(col int) ON COMMIT DELETE ROWS;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user