1
0
mirror of https://github.com/postgres/postgres.git synced 2025-04-24 10:47:04 +03:00

Fix alter_table.sql test case to test what it claims to.

The stanza "SET STORAGE may need to add a TOAST table" does not
test what it's supposed to, and hasn't done so since we added
the ability to store constant column default values as metadata.
We need to use a non-constant default to get the expected table
rewrite to actually happen.

Fix that, and add the missing checks that would have exposed the
problem to begin with.

Noted while reviewing a patch that made changes in this test case.
Back-patch to v11 where the problem came in.
This commit is contained in:
Tom Lane 2022-11-10 17:24:26 -05:00
parent 36e545cd05
commit b158e0b1b1
2 changed files with 32 additions and 15 deletions

View File

@ -2245,12 +2245,26 @@ alter table recur1 alter column f2 type recur2; -- fails
ERROR: composite type recur1 cannot be made a member of itself ERROR: composite type recur1 cannot be made a member of itself
-- SET STORAGE may need to add a TOAST table -- SET STORAGE may need to add a TOAST table
create table test_storage (a text, c text storage plain); create table test_storage (a text, c text storage plain);
select reltoastrelid <> 0 as has_toast_table
from pg_class where oid = 'test_storage'::regclass;
has_toast_table
-----------------
t
(1 row)
alter table test_storage alter a set storage plain; alter table test_storage alter a set storage plain;
alter table test_storage add b int default 0; -- rewrite table to remove its TOAST table -- rewrite table to remove its TOAST table; need a non-constant column default
alter table test_storage add b int default random()::int;
select reltoastrelid <> 0 as has_toast_table
from pg_class where oid = 'test_storage'::regclass;
has_toast_table
-----------------
f
(1 row)
alter table test_storage alter a set storage extended; -- re-add TOAST table alter table test_storage alter a set storage extended; -- re-add TOAST table
select reltoastrelid <> 0 as has_toast_table select reltoastrelid <> 0 as has_toast_table
from pg_class from pg_class where oid = 'test_storage'::regclass;
where oid = 'test_storage'::regclass;
has_toast_table has_toast_table
----------------- -----------------
t t
@ -2263,12 +2277,12 @@ ERROR: column data type integer can only have storage PLAIN
create index test_storage_idx on test_storage (b, a); create index test_storage_idx on test_storage (b, a);
alter table test_storage alter column a set storage external; alter table test_storage alter column a set storage external;
\d+ test_storage \d+ test_storage
Table "public.test_storage" Table "public.test_storage"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+------------- --------+---------+-----------+----------+-------------------+----------+--------------+-------------
a | text | | | | external | | a | text | | | | external | |
c | text | | | | plain | | c | text | | | | plain | |
b | integer | | | 0 | plain | | b | integer | | | random()::integer | plain | |
Indexes: Indexes:
"test_storage_idx" btree (b, a) "test_storage_idx" btree (b, a)

View File

@ -1528,13 +1528,16 @@ alter table recur1 alter column f2 type recur2; -- fails
-- SET STORAGE may need to add a TOAST table -- SET STORAGE may need to add a TOAST table
create table test_storage (a text, c text storage plain); create table test_storage (a text, c text storage plain);
alter table test_storage alter a set storage plain;
alter table test_storage add b int default 0; -- rewrite table to remove its TOAST table
alter table test_storage alter a set storage extended; -- re-add TOAST table
select reltoastrelid <> 0 as has_toast_table select reltoastrelid <> 0 as has_toast_table
from pg_class from pg_class where oid = 'test_storage'::regclass;
where oid = 'test_storage'::regclass; alter table test_storage alter a set storage plain;
-- rewrite table to remove its TOAST table; need a non-constant column default
alter table test_storage add b int default random()::int;
select reltoastrelid <> 0 as has_toast_table
from pg_class where oid = 'test_storage'::regclass;
alter table test_storage alter a set storage extended; -- re-add TOAST table
select reltoastrelid <> 0 as has_toast_table
from pg_class where oid = 'test_storage'::regclass;
-- check STORAGE correctness -- check STORAGE correctness
create table test_storage_failed (a text, b int storage extended); create table test_storage_failed (a text, b int storage extended);