The following bug has been logged on the website:
Bug reference: 17150
Logged by: Yu Liang
Email address: luy70@psu.edu
PostgreSQL version: 14beta3
Operating system: Ubuntu 20.04 LTS
Description:
For query
```SQL
CREATE TABLE v0 ( v1 INT );
CREATE VIEW v2 AS SELECT * FROM v0 WHERE v1 = 0;
SELECT SUM(result) FROM ( SELECT ALL( true )::INT as result FROM v2 ORDER BY
( SELECT COUNT ( v1 ) ) ) as res;
-- Expected sum = "0", returns sum = "1"
```
Detailed outputs:
```
1: sum (typeid = 20, len = 8, typmod = -1, byval = t)
----
1: sum = "1" (typeid = 20, len = 8, typmod = -1, byval = t)
----
```
In the query above, given TABLE v0 has no data inserted, and v2 is a view
that observes on v0, we expect the SELECT statement that tries to sum up the
entries of v2 would output sum = "0". However, sum = "1" is returned. This
unexpected return can be fixed by removing "ORDER BY ( SELECT COUNT ( v1 )
)", then the query returns sum="0" as expected.
This behavior can be reproduced with an empty database, using Postgres
single mode. Postgres version = "PostgreSQL 14beta3 on x86_64-pc-linux-gnu,
compiled by gcc (Ubuntu 9.3.0-17ubuntu1~20.04) 9.3.0, 64-bit".