public inbox for [email protected]
help / color / mirror / Atom feedFrom: Ankit Kumar Pandey <[email protected]>
To: Vik Fearing <[email protected]>
To: David Rowley <[email protected]>
Cc: pghackers <[email protected]>
Subject: Re: Todo: Teach planner to evaluate multiple windows in the optimal order
Date: Sun, 8 Jan 2023 22:35:08 +0530
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>
<CAApHDvp=r1LnEKCmWCYaruMPL-jP4j_sdc8yeFYwaDT1ac5GsQ@mail.gmail.com>
<[email protected]>
<CAApHDvq=g2=ny59f1bvwRVvupsgPHK-KjLPBsSL25fVuGZ4idQ@mail.gmail.com>
<[email protected]>
<[email protected]>
<[email protected]>
<CAApHDvruS-3gG_KYXPb_=Um_TfUXi+G4o7VyBVbChTjThXF2yA@mail.gmail.com>
<[email protected]>
<[email protected]>
<CAApHDvpEYcQ7d-c6Lje26gLi4dXOM3qQ9nrTe1Z241tT8nBiCg@mail.gmail.com>
<[email protected]>
<CAApHDvp8BpUEo_kQdGHWNPCjcmRWCdiy5p26SoQA4R6rinkaLA@mail.gmail.com>
<[email protected]>
<[email protected]>
<[email protected]>
> On 08/01/23 21:36, Vik Fearing wrote:
> On 1/8/23 11:21, Ankit Kumar Pandey wrote:
>>
>> Please find attached patch with addressed issues mentioned before.
> I am curious about this plan:
> +-- ORDER BY's in multiple Window functions can be combined into one
> +-- if they are subset of QUERY's ORDER BY
> +EXPLAIN (COSTS OFF)
> +SELECT empno,
> + depname,
> + min(salary) OVER (PARTITION BY depname ORDER BY empno) depminsalary,
> + sum(salary) OVER (PARTITION BY depname) depsalary,
> + count(*) OVER (ORDER BY enroll_date DESC) c
> +FROM empsalary
> +ORDER BY depname, empno, enroll_date;
> + QUERY PLAN
> +------------------------------------------------------
> + WindowAgg
> + -> WindowAgg
> + -> Sort
> + Sort Key: depname, empno, enroll_date
> + -> WindowAgg
> + -> Sort
> + Sort Key: enroll_date DESC
> + -> Seq Scan on empsalary
> +(8 rows)
> +
> Why aren't min() and sum() calculated on the same WindowAgg run?
Isn't that exactly what is happening here? First count() with sort on
enroll_date is run and
then min() and sum()?
Only difference between this and plan generated by master(given below)
is a sort in the end.
QUERY PLAN
------------------------------------------------------------
Incremental Sort
Sort Key: depname, empno, enroll_date
Presorted Key: depname, empno
-> WindowAgg
-> WindowAgg
-> Sort
Sort Key: depname, empno
-> WindowAgg
-> Sort
Sort Key: enroll_date DESC
-> Seq Scan on empsalary
Let me know if I am missing anything. Thanks.
--
Regards,
Ankit Kumar Pandey
view thread (60+ messages) latest in thread
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected]
Subject: Re: Todo: Teach planner to evaluate multiple windows in the optimal order
In-Reply-To: <[email protected]>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox