Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit b158e0b

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 36e545c commit b158e0b

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

src/test/regress/expected/alter_table.out

Lines changed: 23 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2245,12 +2245,26 @@ alter table recur1 alter column f2 type recur2; -- fails
22452245
ERROR: composite type recur1 cannot be made a member of itself
22462246
-- SET STORAGE may need to add a TOAST table
22472247
create table test_storage (a text, c text storage plain);
2248+
select reltoastrelid <> 0 as has_toast_table
2249+
from pg_class where oid = 'test_storage'::regclass;
2250+
has_toast_table
2251+
-----------------
2252+
t
2253+
(1 row)
2254+
22482255
alter table test_storage alter a set storage plain;
2249-
alter table test_storage add b int default 0; -- rewrite table to remove its TOAST table
2256+
-- rewrite table to remove its TOAST table; need a non-constant column default
2257+
alter table test_storage add b int default random()::int;
2258+
select reltoastrelid <> 0 as has_toast_table
2259+
from pg_class where oid = 'test_storage'::regclass;
2260+
has_toast_table
2261+
-----------------
2262+
f
2263+
(1 row)
2264+
22502265
alter table test_storage alter a set storage extended; -- re-add TOAST table
22512266
select reltoastrelid <> 0 as has_toast_table
2252-
from pg_class
2253-
where oid = 'test_storage'::regclass;
2267+
from pg_class where oid = 'test_storage'::regclass;
22542268
has_toast_table
22552269
-----------------
22562270
t
@@ -2263,12 +2277,12 @@ ERROR: column data type integer can only have storage PLAIN
22632277
create index test_storage_idx on test_storage (b, a);
22642278
alter table test_storage alter column a set storage external;
22652279
\d+ test_storage
2266-
Table "public.test_storage"
2267-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
2268-
--------+---------+-----------+----------+---------+----------+--------------+-------------
2269-
a | text | | | | external | |
2270-
c | text | | | | plain | |
2271-
b | integer | | | 0 | plain | |
2280+
Table "public.test_storage"
2281+
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
2282+
--------+---------+-----------+----------+-------------------+----------+--------------+-------------
2283+
a | text | | | | external | |
2284+
c | text | | | | plain | |
2285+
b | integer | | | random()::integer | plain | |
22722286
Indexes:
22732287
"test_storage_idx" btree (b, a)
22742288

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, c text storage plain);
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
-- check STORAGE correctness
15401543
create table test_storage_failed (a text, b int storage extended);

0 commit comments

Comments
 (0)