Re: Draft LIMIT pushdown to Append and MergeAppend patch

2023-10-09 Thread Michał Kłeczek
> On 9 Oct 2023, at 15:04, Ashutosh Bapat wrote: > > On Mon, Oct 9, 2023 at 4:33 PM David Rowley > wrote: >> >> What are there benefits if the paths are already ordered? e.g if it's >> an index scan then we'll only pull the tuples we need from it. >> > >

Re: Draft LIMIT pushdown to Append and MergeAppend patch

2023-10-09 Thread Ashutosh Bapat
On Mon, Oct 9, 2023 at 4:33 PM David Rowley wrote: > > On Mon, 9 Oct 2023 at 23:35, Ashutosh Bapat > wrote: > > > > On Mon, Oct 9, 2023 at 6:25 AM David Rowley wrote: > > > > > > However, it may also be worth you reading over [3] and the ultimate > > > reason I changed my mind on that being a

Re: Draft LIMIT pushdown to Append and MergeAppend patch

2023-10-09 Thread David Rowley
On Mon, 9 Oct 2023 at 23:35, Ashutosh Bapat wrote: > > On Mon, Oct 9, 2023 at 6:25 AM David Rowley wrote: > > > > However, it may also be worth you reading over [3] and the ultimate > > reason I changed my mind on that being a good idea. Pushing LIMITs > > below an Append seems quite incomplete

Re: Draft LIMIT pushdown to Append and MergeAppend patch

2023-10-09 Thread Ashutosh Bapat
On Mon, Oct 9, 2023 at 6:25 AM David Rowley wrote: > > However, it may also be worth you reading over [3] and the ultimate > reason I changed my mind on that being a good idea. Pushing LIMITs > below an Append seems quite incomplete when we don't yet push sorts > below Appends, which is what that

Re: Draft LIMIT pushdown to Append and MergeAppend patch

2023-10-08 Thread Andy Fan
On Mon, Oct 9, 2023 at 8:52 AM David Rowley wrote: > On Sun, 8 Oct 2023 at 18:32, Michał Kłeczek wrote: > > On 8 Oct 2023, at 03:33, Andy Fan wrote: > >> For the patches for performance improvement, it is better to provide > >> an example to show how much benefits we can get. As for this

Re: Draft LIMIT pushdown to Append and MergeAppend patch

2023-10-08 Thread David Rowley
On Sun, 8 Oct 2023 at 18:32, Michał Kłeczek wrote: > On 8 Oct 2023, at 03:33, Andy Fan wrote: >> For the patches for performance improvement, it is better to provide >> an example to show how much benefits we can get. As for this case, >> I'm doubtful it can work as an improvement. > Could

Re: Draft LIMIT pushdown to Append and MergeAppend patch

2023-10-07 Thread Michał Kłeczek
Thanks for the feedback. > On 8 Oct 2023, at 03:33, Andy Fan wrote: > > > > On Sun, Oct 8, 2023 at 5:04 AM Michał Kłeczek > wrote: >> Hi All, >> >> Attached is a second version of the patch. >> >> The goal is to: >> 1. Apply LIMIT as early as possible -

Re: Draft LIMIT pushdown to Append and MergeAppend patch

2023-10-07 Thread Andy Fan
On Sun, Oct 8, 2023 at 5:04 AM Michał Kłeczek wrote: > Hi All, > > Attached is a second version of the patch. > > The goal is to: > 1. Apply LIMIT as early as possible - especially to apply LIMIT in > partition scans > For the patches for performance improvement, it is better to provide an

Re: Draft LIMIT pushdown to Append and MergeAppend patch

2023-10-07 Thread Michał Kłeczek
Hi All, Attached is a second version of the patch. The goal is to: 1. Apply LIMIT as early as possible - especially to apply LIMIT in partition scans 2. Enable LIMIT pushdown for FDW partitions. Main idea of the patch is: 1. Wrap children of Append and MergeAppend paths in LimitPaths. 2. Let

Draft LIMIT pushdown to Append and MergeAppend patch

2023-10-07 Thread Michał Kłeczek
Hi All, Attached is a draft patch implementing LIMIT pushdown to Append and MergeAppend nodes. This patch eliminates the need to resort to subqueries to optimise UNIONs. It also enables more aggressive partition pruning. Not sure if it causes LIMIT pushdown to foreign partitions though.