Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c1a4fc

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 nottest what it's supposed to, and hasn't done so since we addedthe ability to store constant column default values as metadata.We need to use a non-constant default to get the expected tablerewrite to actually happen.Fix that, and add the missing checks that would have exposed theproblem 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 parent5765063 commit9c1a4fc

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
@@ -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);
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
@@ -2260,11 +2274,11 @@ where oid = 'test_storage'::regclass;
22602274
create index test_storage_idx on test_storage (b, a);
22612275
alter table test_storage alter column a set storage external;
22622276
\d+ test_storage
2263-
Table "public.test_storage"
2264-
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
2265-
--------+---------+-----------+----------+---------+----------+--------------+-------------
2266-
a | text | | | | external | |
2267-
b | integer | | |0 | plain | |
2277+
Table "public.test_storage"
2278+
Column | Type | Collation | Nullable |Default | Storage | Stats target | Description
2279+
--------+---------+-----------+----------+-------------------+----------+--------------+-------------
2280+
a | text | | || external | |
2281+
b | integer | | |random()::integer | plain | |
22682282
Indexes:
22692283
"test_storage_idx" btree (b, a)
22702284

‎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
createtabletest_storage (atext);
1531+
select reltoastrelid<>0as has_toast_table
1532+
from pg_classwhereoid='test_storage'::regclass;
15311533
altertable test_storage alter aset storage plain;
1532-
altertable test_storage add bint default0;-- rewrite table to remove its TOAST table
1534+
-- rewrite table to remove its TOAST table; need a non-constant column default
1535+
altertable test_storage add bint default random()::int;
1536+
select reltoastrelid<>0as has_toast_table
1537+
from pg_classwhereoid='test_storage'::regclass;
15331538
altertable test_storage alter aset storage extended;-- re-add TOAST table
1534-
15351539
select reltoastrelid<>0as has_toast_table
1536-
from pg_class
1537-
whereoid='test_storage'::regclass;
1540+
from pg_classwhereoid='test_storage'::regclass;
15381541

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

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp