]> git.ipfire.org Git - thirdparty/postgresql.git/commitdiff
Fix alter_table.sql test case to test what it claims to.
authorTom Lane <tgl@sss.pgh.pa.us>
Thu, 10 Nov 2022 22:24:26 +0000 (17:24 -0500)
committerTom Lane <tgl@sss.pgh.pa.us>
Thu, 10 Nov 2022 22:24:26 +0000 (17:24 -0500)
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.

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

index ba2e80a3b94926296e1d7863705915d2178d8730..68a06a61c33af0643843d1e1f7452c5e1e802f3c 100644 (file)
@@ -2277,12 +2277,26 @@ alter table recur1 alter column f2 type recur2; -- fails
 ERROR:  composite type recur1 cannot be made a member of itself
 -- SET STORAGE may need to add a TOAST table
 create table test_storage (a text);
+select reltoastrelid <> 0 as has_toast_table
+  from pg_class where oid = 'test_storage'::regclass;
+ has_toast_table 
+-----------------
+ t
+(1 row)
+
 alter table test_storage alter a set storage plain;
-alter table test_storage add b int default 0; -- rewrite table to remove its TOAST table
+-- rewrite table to remove its TOAST table; need a non-constant column default
+alter table test_storage add b int default random()::int;
+select reltoastrelid <> 0 as has_toast_table
+  from pg_class where oid = 'test_storage'::regclass;
+ has_toast_table 
+-----------------
+ f
+(1 row)
+
 alter table test_storage alter a set storage extended; -- re-add TOAST table
 select reltoastrelid <> 0 as has_toast_table
-from pg_class
-where oid = 'test_storage'::regclass;
+  from pg_class where oid = 'test_storage'::regclass;
  has_toast_table 
 -----------------
  t
@@ -2292,11 +2306,11 @@ where oid = 'test_storage'::regclass;
 create index test_storage_idx on test_storage (b, a);
 alter table test_storage alter column a set storage external;
 \d+ test_storage
-                                Table "public.test_storage"
- Column |  Type   | Collation | Nullable | Default | Storage  | Stats target | Description 
---------+---------+-----------+----------+---------+----------+--------------+-------------
- a      | text    |           |          |         | external |              | 
- b      | integer |           |          | 0       | plain    |              | 
+                                      Table "public.test_storage"
+ Column |  Type   | Collation | Nullable |       Default       | Storage  | Stats target | Description 
+--------+---------+-----------+----------+---------------------+----------+--------------+-------------
+ a      | text    |           |          |                     | external |              | 
+ b      | integer |           |          | (random())::integer | plain    |              | 
 Indexes:
     "test_storage_idx" btree (b, a)
 
index 6b3f7d88baed44f74482a77eb9577a159ba900c3..b9c44b5b3167367e780e0c014d898970851547b1 100644 (file)
@@ -1528,13 +1528,16 @@ alter table recur1 alter column f2 type recur2; -- fails
 
 -- SET STORAGE may need to add a TOAST table
 create table test_storage (a text);
+select reltoastrelid <> 0 as has_toast_table
+  from pg_class where oid = 'test_storage'::regclass;
 alter table test_storage alter a set storage plain;
-alter table test_storage add b int default 0; -- rewrite table to remove its TOAST table
+-- rewrite table to remove its TOAST table; need a non-constant column default
+alter table test_storage add b int default random()::int;
+select reltoastrelid <> 0 as has_toast_table
+  from pg_class where oid = 'test_storage'::regclass;
 alter table test_storage alter a set storage extended; -- re-add TOAST table
-
 select reltoastrelid <> 0 as has_toast_table
-from pg_class
-where oid = 'test_storage'::regclass;
+  from pg_class where oid = 'test_storage'::regclass;
 
 -- test that SET STORAGE propagates to index correctly
 create index test_storage_idx on test_storage (b, a);