Re: Redundant Result node

2024-08-27 Thread Ranier Vilela
Em ter., 27 de ago. de 2024 às 00:43, Richard Guo escreveu: > On Thu, Aug 22, 2024 at 9:02 PM Ranier Vilela wrote: > > Em qui., 22 de ago. de 2024 às 04:34, Richard Guo < > guofengli...@gmail.com> escreveu: > >> This does not seem right to me, as PathTargets are not canonical, so > >> we cannot

Re: Redundant Result node

2024-08-26 Thread Richard Guo
On Thu, Aug 22, 2024 at 9:02 PM Ranier Vilela wrote: > Em qui., 22 de ago. de 2024 às 04:34, Richard Guo > escreveu: >> This does not seem right to me, as PathTargets are not canonical, so >> we cannot guarantee that two identical PathTargets will have the same >> pointer. Actually, for the que

Re: Redundant Result node

2024-08-26 Thread Richard Guo
On Mon, Aug 26, 2024 at 8:58 PM Peter Eisentraut wrote: > On 23.08.24 10:27, Richard Guo wrote: > > 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. > > -

Re: Redundant Result node

2024-08-26 Thread Peter Eisentraut
On 23.08.24 10:27, Richard Guo wrote: On Fri, Aug 23, 2024 at 11:56 AM Tom Lane wrote: Richard Guo 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

Re: Redundant Result node

2024-08-23 Thread Ranier Vilela
Hi Rafia. Em qui., 22 de ago. de 2024 às 17:17, Rafia Sabih escreveu: > > > On Thu, 22 Aug 2024 at 15:02, Ranier Vilela wrote: > >> Hi. >> >> Em qui., 22 de ago. de 2024 às 04:34, Richard Guo >> escreveu: >> >>> I ran into a query plan where the Result node seems redundant to me: >>> >>> creat

Re: Redundant Result node

2024-08-23 Thread Richard Guo
On Fri, Aug 23, 2024 at 11:56 AM Tom Lane wrote: > Richard Guo 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

Re: Redundant Result node

2024-08-22 Thread Tom Lane
Richard Guo writes: > On Fri, Aug 23, 2024 at 11:19 AM Tom Lane wrote: >> I'm not sure you're considering "efficiency" in the right light. > 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. Th

Re: Redundant Result node

2024-08-22 Thread Richard Guo
On Fri, Aug 23, 2024 at 11:19 AM Tom Lane wrote: > Richard Guo writes: > > ... we'll always make a separate ProjectionPath on top of the SortPath > > in create_ordered_paths. It’s only when we create the plan node for > > the projection step in createplan.c that we realize a separate Result > >

Re: Redundant Result node

2024-08-22 Thread Tom Lane
Richard Guo writes: > ... we'll always make a separate ProjectionPath on top of the SortPath > in create_ordered_paths. It’s only when we create the plan node for > the projection step in createplan.c that we realize a separate Result > is unnecessary. This is not efficient. I'm not sure you're

Re: Redundant Result node

2024-08-22 Thread Richard Guo
On Thu, Aug 22, 2024 at 3:34 PM Richard Guo wrote: > /* Add projection step if needed */ > if (sorted_path->pathtarget != target) > sorted_path = apply_projection_to_path(root, ordered_rel, >sorted_path, target); > > This does not see

Re: Redundant Result node

2024-08-22 Thread Richard Guo
On Thu, Aug 22, 2024 at 8:03 PM David Rowley wrote: > On Thu, 22 Aug 2024 at 23:33, Peter Eisentraut wrote: > > > I wonder if we need to invent a function to compare two PathTargets. > > > > Wouldn't the normal node equal() work? > > It might. I think has_volatile_expr might be missing a > pg_nod

Re: Redundant Result node

2024-08-22 Thread Rafia Sabih
On Thu, 22 Aug 2024 at 15:02, Ranier Vilela wrote: > Hi. > > Em qui., 22 de ago. de 2024 às 04:34, Richard Guo > escreveu: > >> I ran into a query plan where the Result node seems redundant to me: >> >> create table t (a int, b int, c int); >> insert into t select i%10, i%10, i%10 from generate_

Re: Redundant Result node

2024-08-22 Thread Ranier Vilela
Hi. Em qui., 22 de ago. de 2024 às 04:34, Richard Guo escreveu: > I ran into a query plan where the Result node seems redundant to me: > > create table t (a int, b int, c int); > insert into t select i%10, i%10, i%10 from generate_series(1,100)i; > create index on t (a, b); > analyze t; > > set

Re: Redundant Result node

2024-08-22 Thread David Rowley
On Thu, 22 Aug 2024 at 23:33, Peter Eisentraut wrote: > > I wonder if we need to invent a function to compare two PathTargets. > > Wouldn't the normal node equal() work? It might. I think has_volatile_expr might be missing a pg_node_attr(equal_ignore). David

Re: Redundant Result node

2024-08-22 Thread Peter Eisentraut
On 22.08.24 09:34, Richard Guo wrote: I looked into this a little bit and found that in function create_ordered_paths, we decide whether a projection step is needed based on a simple pointer comparison between sorted_path->pathtarget and final_target. /* Add projection step if needed */

Re: Redundant Result node

2024-08-22 Thread David Rowley
On Thu, 22 Aug 2024 at 19:34, Richard Guo wrote: > /* Add projection step if needed */ > if (sorted_path->pathtarget != target) > sorted_path = apply_projection_to_path(root, ordered_rel, >sorted_path, target); > > This does not seem