Re: Redundant Unique plan node for table with a unique index

2023-09-14 Thread Damir Belyalov
Thank you for feedback and thread [1]. Regards, Damir Belyalov Postgres Professional

Re: Redundant Unique plan node for table with a unique index

2023-09-13 Thread Andy Fan
> > > I don't think this is a good way to do this. The method you're using > only supports this optimisation when querying a table directly. If > there were subqueries, joins, etc then it wouldn't work as there are > no unique indexes. You should probably have a look at [1] to see > further

Re: Redundant Unique plan node for table with a unique index

2023-09-13 Thread David Rowley
On Thu, 14 Sept 2023 at 02:28, Damir Belyalov wrote: > create table a (n int); > insert into a (n) select x from generate_series(1, 14) as g(x); > create unique index on a (n); > explain select distinct n from a; > QUERY PLAN >

Re: Redundant Unique plan node for table with a unique index

2023-09-13 Thread Daniel Gustafsson
> On 13 Sep 2023, at 15:22, Damir Belyalov wrote: > There is a table with a unique index on it and we have a query that searching > DISTINCT values on this table on columns of unique index. > We can see that Unique node is redundant for this case. So I implemented a > simple patch that

Redundant Unique plan node for table with a unique index

2023-09-13 Thread Damir Belyalov
Hello! There is a table with a unique index on it and we have a query that searching DISTINCT values on this table on columns of unique index. Example: create table a (n int); insert into a (n) select x from generate_series(1, 14) as g(x); create unique index on a (n); explain select