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
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
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
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
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;
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