Re: Redundant Result node

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: Richard Guo <guofenglinux(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: Redundant Result node
Date: 2024-08-26 12:58:29
Message-ID: dd8328a6-4602-48ca-88c8-4d7d5d16880f@eisentraut.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 23.08.24 10:27, Richard Guo wrote:
> On Fri, Aug 23, 2024 at 11:56 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Richard Guo <guofenglinux(at)gmail(dot)com> writes:
>>> I agree that it’s always desirable to postpone work from path-creation
>>> time to plan-creation time. In this case, however, it’s a little
>>> different. The projection step could actually be avoided from the
>>> start if we perform the correct check in create_ordered_paths.
>>
>> Well, the question is how expensive is the "correct check" compared
>> to what we're doing now. It might be cheaper than creating an extra
>> level of path node, or it might not. An important factor here is
>> that we'd pay the extra cost of a more complex check every time,
>> whether it avoids creation of an extra path node or not.
>
> Fair point. After looking at the code for a while, I believe it is
> sufficient to compare PathTarget.exprs after we've checked that the
> two targets have different pointers.

- if (sorted_path->pathtarget != target)
+ if (sorted_path->pathtarget != target &&
+ !equal(sorted_path->pathtarget->exprs, target->exprs))
sorted_path = apply_projection_to_path(root, ordered_rel,

equal() already checks whether both pointers are equal, so I think this
could be simplified to just

if (!equal(sorted_path->pathtarget->exprs, target->exprs))

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Wetmore, Matthew (CTR) 2024-08-26 12:58:38 Re: Non-trivial condition is only propagated to one side of JOIN
Previous Message Robert Haas 2024-08-26 12:40:17 Re: Add new protocol message to change GUCs for usage with future protocol-only GUCs