pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #18091: Unexpected Result by enable_material
3+ messages / 3 participants
[nested] [flat]
* BUG #18091: Unexpected Result by enable_material
@ 2023-09-07 05:26 PG Bug reporting form <noreply@postgresql.org>
0 siblings, 2 replies; 3+ messages in thread
From: PG Bug reporting form @ 2023-09-07 05:26 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org; +Cc: bajinsheng@u.nus.edu
The following bug has been logged on the website:
Bug reference: 18091
Logged by: Jinsheng Ba
Email address: bajinsheng@u.nus.edu
PostgreSQL version: 15.4
Operating system: Ubuntu
Description:
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}
Reproduction:
docker run -p 5432:5432 -e POSTGRES_PASSWORD=root -it postgres:latest
psql "postgresql://postgres:root@localhost:5432"
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #18091: Unexpected Result by enable_material
@ 2023-09-07 07:30 Francisco Olarte <folarte@peoplecall.com>
parent: PG Bug reporting form <noreply@postgresql.org>
1 sibling, 0 replies; 3+ messages in thread
From: Francisco Olarte @ 2023-09-07 07:30 UTC (permalink / raw)
To: bajinsheng@u.nus.edu; pgsql-bugs@lists.postgresql.org
On Thu, 7 Sept 2023 at 09:10, PG Bug reporting form
<noreply@postgresql.org> wrote:
> The same query returns different results when enable_material is changed:
I'm not too sure your query is guaranteed to return the same result
allways, let me see..
-- Zapping t4....
> CREATE TABLE t2(c1 DECIMAL, c2 serial);
> INSERT INTO t2(c2) VALUES(1), (2);
> INSERT INTO t2(c1) VALUES(0.1);
This seems to leave t2 as (null,1),(null,2),(0.1,1)
--
...
> SELECT DISTINCT ON (t2.c1) t2.c2 FROM t2, t4; -- {1}, {1}
> SELECT DISTINCT ON (t2.c1) t2.c2 FROM t2, t4; -- {1}, {2}
And this seems to ask for one row from
(null,1,{a,b,c})+(null,2,{a,b,c}), another from (0.1,1,{a,b,c})
So your result would be (1|2) + 1 ( in any order ), as the first set
can be scanned/selected in any order ( and the results returned in any
order )
Normally postgres would not bother on generating different outputs if
nothing is changed, but I think any response in {1,1},{1,2},{2,1} is
correct. Enable_material is probably just changing some access order
details.
You may be able to get better repeatable results using order by judiciously.
Francisco Olarte.
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #18091: Unexpected Result by enable_material
@ 2023-09-07 07:51 Richard Guo <guofenglinux@gmail.com>
parent: PG Bug reporting form <noreply@postgresql.org>
1 sibling, 0 replies; 3+ messages in thread
From: Richard Guo @ 2023-09-07 07:51 UTC (permalink / raw)
To: bajinsheng@u.nus.edu; pgsql-bugs@lists.postgresql.org
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
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2023-09-07 07:51 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2023-09-07 05:26 BUG #18091: Unexpected Result by enable_material PG Bug reporting form <noreply@postgresql.org>
2023-09-07 07:30 ` Francisco Olarte <folarte@peoplecall.com>
2023-09-07 07:51 ` Richard Guo <guofenglinux@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox