Re: BUG #18091: Unexpected Result by enable_material - Mailing list pgsql-bugs

From Richard Guo
Subject Re: BUG #18091: Unexpected Result by enable_material
Date
Msg-id CAMbWs49OsEPutOcYaWXUrph3Z-F0p_QsrF_P1kxGBPT5rc+vgA@mail.gmail.com
Whole thread Raw
In response to BUG #18091: Unexpected Result by enable_material  (PG Bug reporting form <noreply@postgresql.org>)
List pgsql-bugs

On Thu, Sep 7, 2023 at 3:10 PM PG Bug reporting form <noreply@postgresql.org> wrote:
Hello,

The same query returns different results when enable_material is changed:

CREATE TABLE t2(c1 DECIMAL, c2 serial);
CREATE TABLE t4(c0 TEXT);
INSERT INTO t2(c2) VALUES(1), (2);
INSERT INTO t2(c1) VALUES(0.1);
INSERT INTO t4(c0) VALUES('a'), ('b'), ('c');

SET enable_material=true;
SELECT DISTINCT ON (t2.c1) t2.c2 FROM t2, t4; -- {1}, {1}
SET enable_material=false;
SELECT DISTINCT ON (t2.c1) t2.c2 FROM t2, t4; -- {1}, {2}

With DISTINCT ON, only the first row of each set is kept, which is
unpredictable.  Usually you're supposed to use ORDER BY to get the
desired row.

Thanks
Richard

pgsql-bugs by date:

Previous
From: Francisco Olarte
Date:
Subject: Re: BUG #18092: Unexpected Result by enable_seqscan
Next
From: "Lepikhov Andrei"
Date:
Subject: Re: BUG #18077: PostgreSQL server subprocess crashed by a SELECT statement with WITH clause