Re: Remove useless GROUP BY columns considering unique index

2024-12-11 Thread Andrei Lepikhov
On 12/12/24 10:09, David Rowley wrote: On Mon, 2 Dec 2024 at 17:18, Andrei Lepikhov wrote: Patch 0002 looks helpful and performant. I propose to check 'relid > 0' to avoid diving into 'foreach(lc, parse->rtable)' at all if nothing has been found. I did end up adding another fast path there, b

Re: Remove useless GROUP BY columns considering unique index

2024-12-11 Thread David Rowley
On Mon, 2 Dec 2024 at 17:18, Andrei Lepikhov wrote: > Patch 0002 looks helpful and performant. I propose to check 'relid > 0' > to avoid diving into 'foreach(lc, parse->rtable)' at all if nothing has > been found. I did end up adding another fast path there, but I felt like checking relid > 0 was

Re: Remove useless GROUP BY columns considering unique index

2024-12-11 Thread David Rowley
On Mon, 2 Dec 2024 at 17:22, jian he wrote: > regarding v10. > you placed remove_useless_groupby_columns right after add_base_rels_to_query > makes so much sense. > so we can be safely use cached RelOptInfo->indexlist, > RelOptInfo->notnullattnums > overall it didn't find any issue. Thanks for l

Re: Remove useless GROUP BY columns considering unique index

2024-12-01 Thread jian he
On Fri, Nov 29, 2024 at 5:20 PM David Rowley wrote: > > The reason I don't think is possible is that we have no infrastructure > that allows us to tag functions or operators so that non-null input(s) > mean non-null outputs. We only have strict, which means null input > means null output. That's

Re: Remove useless GROUP BY columns considering unique index

2024-12-01 Thread Andrei Lepikhov
On 29/11/2024 14:28, David Rowley wrote: On Fri, 29 Nov 2024 at 19:36, Andrei Lepikhov wrote: 1. Thread reference in the patch comment doesn't work. 2. May it be possible to move remove_useless_groupby_columns in the second commit? It would be easier to review the differences. For #1, I rewro

Re: Remove useless GROUP BY columns considering unique index

2024-11-29 Thread David Rowley
On Fri, 29 Nov 2024 at 20:04, jian he wrote: > I found that unique expression index can also be used for groupby > column removal. > so I implemented it, aslo added two tests on it. > what do you think? I think it's likely just not common enough to be worthwhile, plus, unfortunately, I don't thi

Re: Remove useless GROUP BY columns considering unique index

2024-11-28 Thread David Rowley
On Fri, 29 Nov 2024 at 19:36, Andrei Lepikhov wrote: > 1. Thread reference in the patch comment doesn't work. > 2. May it be possible to move remove_useless_groupby_columns in the > second commit? It would be easier to review the differences. For #1, I rewrote the commit message. I've split into

Re: Remove useless GROUP BY columns considering unique index

2024-11-28 Thread jian he
On Fri, Nov 29, 2024 at 2:36 PM Andrei Lepikhov wrote: > > > I forgot to do a local commit before sending v8. Fixed in the attached v9. > 1. Thread reference in the patch comment doesn't work. fixed. I found that unique expression index can also be used for groupby column removal. so I implemente

Re: Remove useless GROUP BY columns considering unique index

2024-11-28 Thread Andrei Lepikhov
On 11/29/24 09:39, David Rowley wrote: On Fri, 29 Nov 2024 at 15:02, David Rowley wrote: I've attached an updated patch that gets rid of the get_unique_not_null_attnos() function completely and uses the RelOptInfo.indexlist and RelOptInfo.notnullattnums. I forgot to do a local commit before s

Re: Remove useless GROUP BY columns considering unique index

2024-11-28 Thread David Rowley
On Fri, 29 Nov 2024 at 15:02, David Rowley wrote: > I've attached an updated patch that gets rid of the > get_unique_not_null_attnos() function completely and uses the > RelOptInfo.indexlist and RelOptInfo.notnullattnums. I forgot to do a local commit before sending v8. Fixed in the attached v9.

Re: Remove useless GROUP BY columns considering unique index

2024-11-28 Thread David Rowley
On Fri, 29 Nov 2024 at 01:33, jian he wrote: > > On Thu, Nov 28, 2024 at 2:11 PM David Rowley wrote: > > I think it'll make more sense to adjust some of the > > existing tests to use a unique constraint instead of a PK and then > > adjust a column's NOT NULL property to check that part of the cod

Re: Remove useless GROUP BY columns considering unique index

2024-11-28 Thread jian he
minor changes in get_unique_not_null_attnos: * cosmetic changes * if the returned list length is less than 2, no need sort. From 58094504364d8a9eb51cbc77a75626aef39b17f0 Mon Sep 17 00:00:00 2001 From: jian he Date: Fri, 29 Nov 2024 09:23:27 +0800 Subject: [PATCH v7 1/1] remove useless group by co

Re: Remove useless GROUP BY columns considering unique index

2024-11-28 Thread jian he
On Thu, Nov 28, 2024 at 2:11 PM David Rowley wrote: > > I think it'll make more sense to adjust some of the > existing tests to use a unique constraint instead of a PK and then > adjust a column's NOT NULL property to check that part of the code is > working correctly. > looking around, i insert

Re: Remove useless GROUP BY columns considering unique index

2024-11-27 Thread David Rowley
On Thu, 28 Nov 2024 at 17:39, jian he wrote: > v4 logic is to choose one with the least number of columns. > if there is more than one with the least number of columns, simply > choose the first one > in the matched list. The new code inside remove_useless_groupby_columns() is still more complex

Re: Remove useless GROUP BY columns considering unique index

2024-11-27 Thread jian he
On Wed, Nov 27, 2024 at 5:30 PM David Rowley wrote: > > On Wed, 27 Nov 2024 at 19:51, jian he wrote: > > v3 attached. in v3: > > 1. I find the following quite strange: > > postgres=# create table abcd (a int primary key, b int not null, c int > not null, d int not null, unique(b)); > CREATE TABLE

Re: Remove useless GROUP BY columns considering unique index

2024-11-27 Thread David Rowley
On Wed, 27 Nov 2024 at 19:51, jian he wrote: > v3 attached. in v3: 1. I find the following quite strange: postgres=# create table abcd (a int primary key, b int not null, c int not null, d int not null, unique(b)); CREATE TABLE postgres=# explain select b,c from abcd group by b,c;

Re: Remove useless GROUP BY columns considering unique index

2024-11-26 Thread jian he
On Fri, Nov 22, 2024 at 9:24 PM jian he wrote: > > overall i come up with the attached patch. in v2: create table t1 (a int, b int not null, c int, unique(b, c)); explain(costs off) select count(*) from t1 group by b,c,a; QUERY PLAN -- HashAggregate Group Key: b -

Re: Remove useless GROUP BY columns considering unique index

2024-11-22 Thread jian he
On Thu, Sep 12, 2024 at 9:44 AM David Rowley wrote: > > On Sat, 30 Dec 2023 at 04:05, Zhang Mingli wrote: > > So my patch make it easy: check unique index’s columns, it’s a valid > > candidate if all of that have NOT NULL constraint. > > And we choose a best one who has the least column numbers

Re: Remove useless GROUP BY columns considering unique index

2024-09-23 Thread Zhang Mingli
Hi, all I haven't paid attention to this topic in a long time, thanks all for the advices, I will study them then update. Thanks again. Zhang Mingli www.hashdata.xyz On Sep 18, 2024 at 15:50 +0800, David Rowley , wrote: > On Wed, 18 Sept 2024 at 19:28, Peter Eisentraut wrote: > > > > On 12.0

Re: Remove useless GROUP BY columns considering unique index

2024-09-18 Thread David Rowley
On Wed, 18 Sept 2024 at 19:28, Peter Eisentraut wrote: > > On 12.09.24 03:43, David Rowley wrote: > > (Likely it could just look at pg_attribute.attnotnull instead) > > That won't work because you can't record dependencies on that. (This is > one of the reasons for cataloging not-null constraints

Re: Remove useless GROUP BY columns considering unique index

2024-09-18 Thread Peter Eisentraut
On 12.09.24 03:43, David Rowley wrote: On Sat, 30 Dec 2023 at 04:05, Zhang Mingli wrote: So my patch make it easy: check unique index’s columns, it’s a valid candidate if all of that have NOT NULL constraint. And we choose a best one who has the least column numbers in get_min_unique_not_null

Re: Remove useless GROUP BY columns considering unique index

2024-09-11 Thread David Rowley
On Sat, 30 Dec 2023 at 04:05, Zhang Mingli wrote: > So my patch make it easy: check unique index’s columns, it’s a valid > candidate if all of that have NOT NULL constraint. > And we choose a best one who has the least column numbers in > get_min_unique_not_null_attnos(), as the reason: less col

Re: Remove useless GROUP BY columns considering unique index

2023-12-31 Thread jian he
On Fri, Dec 29, 2023 at 11:05 PM Zhang Mingli wrote: > > Hi, > > This idea first came from remove_useless_groupby_columns does not need to > record constraint dependencie[0] which points out that > unique index whose columns all have NOT NULL constraints could also take the > work with primary

Remove useless GROUP BY columns considering unique index

2023-12-29 Thread Zhang Mingli
Hi, This idea first came from remove_useless_groupby_columns does not need to record constraint dependencie[0] which points out that unique index whose columns all have NOT NULL constraints  could also take the work with primary key when removing useless GROUP BY columns. I study it and implemen