pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG #14642: Excessive sorting node appears in the plan
3+ messages / 3 participants
[nested] [flat]
* BUG #14642: Excessive sorting node appears in the plan
@ 2017-05-04 12:29 bashtanov@imap.cc
0 siblings, 1 reply; 3+ messages in thread
From: bashtanov@imap.cc @ 2017-05-04 12:29 UTC (permalink / raw)
To: pgsql-bugs
The following bug has been logged on the website:
Bug reference: 14642
Logged by: Alexey Bashtanov
Email address: bashtanov@imap.cc
PostgreSQL version: 9.6.2
Operating system: Ubuntu Linux 14.04
Description:
Hello,
Under certain circumstances, an excessive sorting node appears in the
plan.
It happens when at the same time:
1) There is a merge join node with a join by two equality clauses (say,
`innr.p=outr.p AND innr.q=outr.q`);
2) One of the children, say the inner one, comes as a `SELECT p, q FROM ..
WHERE p = 0 GROUP BY p, q` or `GROUP BY q`, doesn't matter.
3) It uses sort+groupAgg, not hashAgg.
Then the result of the grouping, being already sorted by p (which is always
1), and q, gets sorted again for the merge join.
It looks like the grouping subplan is aware of p=1 and simplifies its
pathkeys from [(innr.p, 1), (innr.q)] to [(innr.q)]. However, looks like it
does not share this kind of knowledge with the code that plans the merge
join, so the merge join keeps requiring the data coming in [innr.p, innr.q]
order.
Do blackbox-style subplans, such as subqueries with grouping, share only the
resulting stream order info with the enclosing query, not the equivalence
classes?
This is the example:
---
set enable_hashjoin to off;
set enable_hashagg to off;
set enable_nestloop to off;
explain
select *
from (
select outr%2 o2,
outr%5 o5
from generate_series(1, 10) outr
order by o2,
o5
) o
join (
select innr%2 i2,
innr%5 i5
from generate_series(1, 10) innr
where innr%2 = 0
group by innr%2,
innr%5
) i on o.o2 = i.i2
and o.o5 = i.i5;
---
I tried 9.4.11, 9.6.2, and master versions.
Best regards,
Alexey Bashtanov
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #14642: Excessive sorting node appears in the plan
@ 2017-05-04 14:12 Tom Lane <tgl@sss.pgh.pa.us>
parent: bashtanov@imap.cc
0 siblings, 1 reply; 3+ messages in thread
From: Tom Lane @ 2017-05-04 14:12 UTC (permalink / raw)
To: bashtanov@imap.cc; +Cc: pgsql-bugs
bashtanov@imap.cc writes:
> Do blackbox-style subplans, such as subqueries with grouping, share only the
> resulting stream order info with the enclosing query, not the equivalence
> classes?
Yes, see convert_subquery_pathkeys().
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: BUG #14642: Excessive sorting node appears in the plan
@ 2017-05-04 14:34 David Rowley <david.rowley@2ndquadrant.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 3+ messages in thread
From: David Rowley @ 2017-05-04 14:34 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs
On 5 May 2017 at 02:12, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> bashtanov@imap.cc writes:
>> Do blackbox-style subplans, such as subqueries with grouping, share only the
>> resulting stream order info with the enclosing query, not the equivalence
>> classes?
>
> Yes, see convert_subquery_pathkeys().
Not as a back-patchable fix, but I wonder if we couldn't improve this
situation by having pathkey_is_redundant() not throw pathkeys with a
constant in their eclass away, but rather keep these around as "no-op
pathkeys".
It would make the logic in compare_pathkeys() a bit more tricky, but
maybe it could be manageable if we kept the no-op pathkeys in a
separate list, and only lookup the pathkey in that list when the
pathkeys being compared are not the same. If it's in the no-op list,
then we can skip to the next path key after the no-op one. Although
I'm not quite sure in what cases PATHKEYS_EQUAL would be returned.
--
David Rowley http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2017-05-04 14:34 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2017-05-04 12:29 BUG #14642: Excessive sorting node appears in the plan bashtanov@imap.cc
2017-05-04 14:12 ` Tom Lane <tgl@sss.pgh.pa.us>
2017-05-04 14:34 ` David Rowley <david.rowley@2ndquadrant.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