Skip to content

Commit 6a1396f

Browse files
committedNov 10, 2022
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.
1 parent cf0f465 commit 6a1396f

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed
 

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

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,12 +2234,26 @@ alter table recur1 alter column f2 type recur2; -- fails
22342234
ERROR: composite type recur1 cannot be made a member of itself
22352235
-- SET STORAGE may need to add a TOAST table
22362236
create table test_storage (a text);
2237+
select reltoastrelid <> 0 as has_toast_table
2238+
from pg_class where oid = 'test_storage'::regclass;
2239+
has_toast_table
2240+
-----------------
2241+
t
2242+
(1 row)
2243+
22372244
alter table test_storage alter a set storage plain;
2238-
alter table test_storage add b int default 0; -- rewrite table to remove its TOAST table
2245+
-- rewrite table to remove its TOAST table; need a non-constant column default
2246+
alter table test_storage add b int default random()::int;
2247+
select reltoastrelid <> 0 as has_toast_table
2248+
from pg_class where oid = 'test_storage'::regclass;
2249+
has_toast_table
2250+
-----------------
2251+
f
2252+
(1 row)
2253+
22392254
alter table test_storage alter a set storage extended; -- re-add TOAST table
22402255
select reltoastrelid <> 0 as has_toast_table
2241-
from pg_class
2242-
where oid = 'test_storage'::regclass;
2256+
from pg_class where oid = 'test_storage'::regclass;
22432257
has_toast_table
22442258
-----------------
22452259
t
@@ -2249,11 +2263,11 @@ where oid = 'test_storage'::regclass;
22492263
create index test_storage_idx on test_storage (b, a);
22502264
alter table test_storage alter column a set storage external;
22512265
\d+ test_storage
2252-
Table "public.test_storage"
2253-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
2254-
--------+---------+-----------+----------+---------+----------+--------------+-------------
2255-
a | text | | | | external | |
2256-
b | integer | | | 0 | plain | |
2266+
Table "public.test_storage"
2267+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
2268+
--------+---------+-----------+----------+-------------------+----------+--------------+-------------
2269+
a | text | | | | external | |
2270+
b | integer | | | random()::integer | plain | |
22572271
Indexes:
22582272
"test_storage_idx" btree (b, a)
22592273

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,13 +1519,16 @@ alter table recur1 alter column f2 type recur2; -- fails
15191519

15201520
-- SET STORAGE may need to add a TOAST table
15211521
create table test_storage (a text);
1522+
select reltoastrelid <> 0 as has_toast_table
1523+
from pg_class where oid = 'test_storage'::regclass;
15221524
alter table test_storage alter a set storage plain;
1523-
alter table test_storage add b int default 0; -- rewrite table to remove its TOAST table
1525+
-- rewrite table to remove its TOAST table; need a non-constant column default
1526+
alter table test_storage add b int default random()::int;
1527+
select reltoastrelid <> 0 as has_toast_table
1528+
from pg_class where oid = 'test_storage'::regclass;
15241529
alter table test_storage alter a set storage extended; -- re-add TOAST table
1525-
15261530
select reltoastrelid <> 0 as has_toast_table
1527-
from pg_class
1528-
where oid = 'test_storage'::regclass;
1531+
from pg_class where oid = 'test_storage'::regclass;
15291532

15301533
-- test that SET STORAGE propagates to index correctly
15311534
create index test_storage_idx on test_storage (b, a);

0 commit comments

Comments
 (0)