8000 Fix alter_table.sql test case to test what it claims to. · postgres/postgres@421f336 · GitHub
[go: up one dir, main page]

Skip to content

Commit 421f336

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 fec80da commit 421f336

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
@@ -2277,12 +2277,26 @@ alter table recur1 alter column f2 type recur2; -- fails
22772277
ERROR: composite type recur1 cannot be made a member of itself
22782278
-- SET STORAGE may need to add a TOAST table
22792279
create table test_storage (a text);
2280+
select reltoastrelid <> 0 as has_toast_table
2281+
from pg_class where oid = 'test_storage'::regclass;
2282+
has_toast_table
2283+
-----------------
2284+
t
2285+
(1 row)
2286+
22802287
alter table test_storage alter a set storage plain;
2281-
alter table test_storage add b int default 0; -- rewrite table to remove its TOAST table
2288+
-- rewrite table to remove its TOAST table; need a non-constant column default
2289+
alter table test_storage add b int default random()::int;
2290+
select reltoastrelid <> 0 as has_toast_table
2291+
from pg_class where oid = 'test_storage'::regclass;
2292+
has_toast_table
2293+
-----------------
2294+
f
2295+
(1 row)
2296+
22822297
alter table test_storage alter a set storage extended; -- re-add TOAST table
22832298
select reltoastrelid <> 0 as has_toast_table
2284-
from pg_class
2285-
where oid = 'test_storage'::regclass;
2299+
from pg_class where oid = 'test_storage'::regclass;
22862300
has_toast_table
22872301
-----------------
22882302
t
@@ -2292,11 +2306,11 @@ where oid = 'test_storage'::regclass;
22922306
create index test_storage_idx on test_storage (b, a);
22932307
alter table test_storage alter column a set storage external;
22942308
\d+ test_storage
2295-
Table "public.test_storage"
2296-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
2297-
--------+---------+-----------+----------+---------+----------+--------------+-------------
2298-
a | text | | | | external | |
2299-
b | integer | | | 0 | plain | |
2309+
Table "public.test_storage"
2310+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
2311+
--------+---------+-----------+----------+---------------------+----------+--------------+-------------
2312+
a | text | | | | external | |
2313+
b | integer | | | (random())::integer | plain | |
23002314
Indexes:
23012315
"test_storage_idx" btree (b, a)
23022316

src/test/regress/sql/alter_table.sql

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

15291529
-- SET STORAGE may need to add a TOAST table
15301530
create table test_storage (a text);
1531+
select reltoastrelid <> 0 as has_toast_table
1532+
from pg_class where oid = 'test_storage'::regclass;
15311533
alter table test_storage alter a set storage plain;
1532-
alter table test_storage add b int default 0; -- rewrite table to remove its TOAST table
1534+
-- rewrite table to remove its TOAST table; need a non-constant column default
1535+
alter table test_storage add b int default random()::int;
1536+
select reltoastrelid <> 0 as has_toast_table
1537+
from pg_class where oid = 'test_storage'::regclass;
15331538
alter table test_storage alter a set storage extended; -- re-add TOAST table
1534-
15351539
select reltoastrelid <> 0 as has_toast_table
1536-
from pg_class
1537-
where oid = 'test_storage'::regclass;
1540+
from pg_class where oid = 'test_storage'::regclass;
15381541

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

0 commit comments

Comments
 (0)
0