Re: BUG #17564: Planner bug in combination of generate_series(), unnest() and ORDER BY
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Tomas Vondra <tomas.vondra@enterprisedb.com>
Cc: Richard Guo <guofenglinux@gmail.com>,
Martijn van Oosterhout <kleptog@gmail.com>,
PostgreSQL mailing lists <pgsql-bugs@lists.postgresql.org>
Date: 2022-08-03T21:44:17Z
Lists: pgsql-bugs
I wrote:
>> FWIW, this reproduces the bug for me in v13 and v14, but not v15 or HEAD.
I decided I'd wasted entirely too much time trying to find a suitable
test case, so I pushed the bug fix with no new regression test.
Meanwhile, back at the question of whether db0d67db2 is buggy,
it looks like that reduces to whether it was intentional that that
made a large change in estimated sort costs. What I'm getting from
v15 and HEAD, as I said earlier, is:
Sort (cost=2946.79..3096.79 rows=60000 width=36)
Sort Key: (((unnest('{}'::jsonb[])) ->> 'timestamp'::text))
-> Result (cost=90.08..1446.79 rows=60000 width=36)
-> ProjectSet (cost=90.08..396.79 rows=60000 width=36)
-> Hash Join (cost=90.08..96.19 rows=60 width=0)
Hash Cond: (groups.group_id = results.group_id)
-> Seq Scan on groups (cost=0.00..5.66 rows=166 width=4)
-> Hash (cost=89.33..89.33 rows=60 width=4)
-> Index Only Scan using results_pkey on results (cost=0.28..89.33 rows=60 width=4)
Index Cond: (search_id = 3336)
After applying this patch, what I get from v13 and v14 is
Sort (cost=6208.59..6358.59 rows=60000 width=36)
Sort Key: (((unnest('{}'::jsonb[])) ->> 'timestamp'::text))
-> Result (cost=90.08..1446.79 rows=60000 width=36)
-> ProjectSet (cost=90.08..396.79 rows=60000 width=36)
-> Hash Join (cost=90.08..96.19 rows=60 width=0)
Hash Cond: (groups.group_id = results.group_id)
-> Seq Scan on groups (cost=0.00..5.66 rows=166 width=4)
-> Hash (cost=89.33..89.33 rows=60 width=4)
-> Index Only Scan using results_pkey on results (cost=0.28..89.33 rows=60 width=4)
Index Cond: (search_id = 3336)
So this plan is identical except for the sort costs, which seem to
be about half of what they were in the older branches. If that was
intentional, why didn't the commit message mention it? It's not
exactly a minor change, and enable_group_by_reordering doesn't
seem to have any effect on it.
regards, tom lane
Commits
-
Add proper regression test for the recent SRFs-in-pathkeys problem.
- cc116479917b 16.0 landed
- 8d38ccafca93 13.8 landed
- 1a9ac84923b8 14.5 landed
- 11e7d626cee4 15.0 landed
-
Fix incorrect tests for SRFs in relation_can_be_sorted_early().
- da4ed7588132 13.8 landed
- 445b9020c97f 14.5 landed
- 1aa8dad41ffa 16.0 landed
- 14168d57bb91 15.0 landed
-
Optimize order of GROUP BY keys
- db0d67db2401 15.0 cited