Skip to content

Commit 3383cf0

Browse files
committed
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 06dca17 commit 3383cf0

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
@@ -2247,12 +2247,26 @@ alter table recur1 alter column f2 type recur2; -- fails
22472247
ERROR: composite type recur1 cannot be made a member of itself
22482248
-- SET STORAGE may need to add a TOAST table
22492249
create table test_storage (a text);
2250+
select reltoastrelid <> 0 as has_toast_table
2251+
from pg_class where oid = 'test_storage'::regclass;
2252+
has_toast_table
2253+
-----------------
2254+
t
2255+
(1 row)
2256+
22502257
alter table test_storage alter a set storage plain;
2251-
alter table test_storage add b int default 0; -- rewrite table to remove its TOAST table
2258+
-- rewrite table to remove its TOAST table; need a non-constant column default
2259+
alter table test_storage add b int default random()::int;
2260+
select reltoastrelid <> 0 as has_toast_table
2261+
from pg_class where oid = 'test_storage'::regclass;
2262+
has_toast_table
2263+
-----------------
2264+
f
2265+
(1 row)
2266+
22522267
alter table test_storage alter a set storage extended; -- re-add TOAST table
22532268
select reltoastrelid <> 0 as has_toast_table
2254-
from pg_class
2255-
where oid = 'test_storage'::regclass;
2269+
from pg_class where oid = 'test_storage'::regclass;
22562270
has_toast_table
22572271
-----------------
22582272
t
@@ -2262,11 +2276,11 @@ where oid = 'test_storage'::regclass;
22622276
create index test_storage_idx on test_storage (b, a);
22632277
alter table test_storage alter column a set storage external;
22642278
\d+ test_storage
2265-
Table "public.test_storage"
2266-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
2267-
--------+---------+-----------+----------+---------+----------+--------------+-------------
2268-
a | text | | | | external | |
2269-
b | integer | | | 0 | plain | |
2279+
Table "public.test_storage"
2280+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
2281+
--------+---------+-----------+----------+-------------------+----------+--------------+-------------
2282+
a | text | | | | external | |
2283+
b | integer | | | random()::integer | plain | |
22702284
Indexes:
22712285
"test_storage_idx" btree (b, a)
22722286

src/test/regress/sql/alter_table.sql

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

15331533
-- SET STORAGE may need to add a TOAST table
15341534
create table test_storage (a text);
1535+
select reltoastrelid <> 0 as has_toast_table
1536+
from pg_class where oid = 'test_storage'::regclass;
15351537
alter table test_storage alter a set storage plain;
1536-
alter table test_storage add b int default 0; -- rewrite table to remove its TOAST table
1538+
-- rewrite table to remove its TOAST table; need a non-constant column default
1539+
alter table test_storage add b int default random()::int;
1540+
select reltoastrelid <> 0 as has_toast_table
1541+
from pg_class where oid = 'test_storage'::regclass;
15371542
alter table test_storage alter a set storage extended; -- re-add TOAST table
1538-
15391543
select reltoastrelid <> 0 as has_toast_table
1540-
from pg_class
1541-
where oid = 'test_storage'::regclass;
1544+
from pg_class where oid = 'test_storage'::regclass;
15421545

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

0 commit comments

Comments
 (0)