Avoid depending on post-UPDATE row order in float4/float8 tests.
authorTom Lane <tgl@sss.pgh.pa.us>
Tue, 22 Apr 2025 18:24:21 +0000 (14:24 -0400)
committerTom Lane <tgl@sss.pgh.pa.us>
Tue, 22 Apr 2025 18:24:21 +0000 (14:24 -0400)
While heapam reproduces the insertion order of rows well, updates
can move rows to varying places depending on autovacuum activity.
In most regression tests we've guarded against getting variable
results due to that, but float4.sql and float8.sql had escaped
notice so far because they update tables that are too small for
autovacuum to pay attention to.

With increasing interest in non-heap table AMs, it seems worth
allowing for update behaviors that are not like heapam's.  Hence,
add ORDER BY to stabilize the results in case the updates put
the rows in a different order.  (We'll continue to assume that a
seqscan will reproduce original insertion order, though.  Removing
that assumption would require vastly-more-invasive test changes.)

Author: Pavel Borisov <pashkin.elfe@gmail.com>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CALT9ZEExHAnBoBVQzQuWPMKUbapF5-FBO3fdeYG3s2tuWQz1NQ@mail.gmail.com

src/test/regress/expected/float4-misrounded-input.out
src/test/regress/expected/float4.out
src/test/regress/expected/float8.out
src/test/regress/sql/float4.sql
src/test/regress/sql/float8.sql

index 20fd7139136e6d279080e2c5a18e2c032e4d4c5b..61c68a6c9fff5149453cd15f33cdb6f8736e87f6 100644 (file)
@@ -308,14 +308,14 @@ SELECT f.f1, @f.f1 AS abs_f1 FROM FLOAT4_TBL f;
 UPDATE FLOAT4_TBL
    SET f1 = FLOAT4_TBL.f1 * '-1'
    WHERE FLOAT4_TBL.f1 > '0.0';
-SELECT * FROM FLOAT4_TBL;
+SELECT * FROM FLOAT4_TBL ORDER BY 1;
        f1       
 ----------------
-              0
-         -34.84
-        -1004.3
  -1.2345679e+20
+        -1004.3
+         -34.84
  -1.2345679e-20
+              0
 (5 rows)
 
 -- test edge-case coercions to integer
index 1d21c4390ad71e793d7a59edc136adac48fa683a..eaed1f2bfe71dccaa64d6715da2be7da84967a70 100644 (file)
@@ -308,14 +308,14 @@ SELECT f.f1, @f.f1 AS abs_f1 FROM FLOAT4_TBL f;
 UPDATE FLOAT4_TBL
    SET f1 = FLOAT4_TBL.f1 * '-1'
    WHERE FLOAT4_TBL.f1 > '0.0';
-SELECT * FROM FLOAT4_TBL;
+SELECT * FROM FLOAT4_TBL ORDER BY 1;
        f1       
 ----------------
-              0
-         -34.84
-        -1004.3
  -1.2345679e+20
+        -1004.3
+         -34.84
  -1.2345679e-20
+              0
 (5 rows)
 
 -- test edge-case coercions to integer
index 10a5a6e1b65eb8e168f9b1f3d005fcbecc97b54d..9c519f1a1a1a5f4fed3e6ad1d827656d7a65ae72 100644 (file)
@@ -648,14 +648,14 @@ SELECT exp(f.f1) from FLOAT8_TBL f;
 ERROR:  value out of range: underflow
 SELECT f.f1 / '0.0' from FLOAT8_TBL f;
 ERROR:  division by zero
-SELECT * FROM FLOAT8_TBL;
+SELECT * FROM FLOAT8_TBL ORDER BY 1;
           f1           
 -----------------------
-                     0
-                -34.84
-               -1004.3
  -1.2345678901234e+200
+               -1004.3
+                -34.84
  -1.2345678901234e-200
+                     0
 (5 rows)
 
 -- hyperbolic functions
index 8fb12368c39b1ba0d492ae96f23cf06c5bacbbef..44418a64002ed8a75887d35f9cdcc066f43222f8 100644 (file)
@@ -98,7 +98,7 @@ UPDATE FLOAT4_TBL
    SET f1 = FLOAT4_TBL.f1 * '-1'
    WHERE FLOAT4_TBL.f1 > '0.0';
 
-SELECT * FROM FLOAT4_TBL;
+SELECT * FROM FLOAT4_TBL ORDER BY 1;
 
 -- test edge-case coercions to integer
 SELECT '32767.4'::float4::int2;
index db8d5724c25cef4b9a254d2e69d2da62644af4c9..0ef271f27020eb56338d71cf1b89b8bd260f9d7e 100644 (file)
@@ -197,7 +197,7 @@ SELECT exp(f.f1) from FLOAT8_TBL f;
 
 SELECT f.f1 / '0.0' from FLOAT8_TBL f;
 
-SELECT * FROM FLOAT8_TBL;
+SELECT * FROM FLOAT8_TBL ORDER BY 1;
 
 -- hyperbolic functions
 -- we run these with extra_float_digits = 0 too, since different platforms