Re: Postgres picks suboptimal index after building of an extended statistics

2023-12-21 Thread Alexander Korotkov
On Thu, Dec 21, 2023 at 10:41 AM Andrei Lepikhov wrote: > > On 18/12/2023 15:29, Alexander Korotkov wrote: > > Also, there is a set of patches [7], [8], and [9], which makes the > > optimizer consider path selectivity as long as path costs during the > > path selection. I've rechecked that none

Re: Postgres picks suboptimal index after building of an extended statistics

2023-12-21 Thread Andrei Lepikhov
On 18/12/2023 15:29, Alexander Korotkov wrote: Also, there is a set of patches [7], [8], and [9], which makes the optimizer consider path selectivity as long as path costs during the path selection.  I've rechecked that none of these patches could resolve the original problem described in [1].

Re: Postgres picks suboptimal index after building of an extended statistics

2023-12-18 Thread Alexander Korotkov
Hi! I'd like to get this subject off the ground. The problem originally described in [1] obviously comes from wrong selectivity estimation. "Dependencies" extended statistics lead to significant selectivity miss 24/1000 instead of 1/1000. When the estimation is correct, the PostgreSQL

Re: Postgres picks suboptimal index after building of an extended statistics

2023-11-26 Thread Andrei Lepikhov
Second version of the patch - resolve non-symmetrical decision, thanks to Teodor Sigaev's review. -- regards, Andrei Lepikhov Postgres Professional From 604899b6afe70eccbbdbf69ce254f37808c598db Mon Sep 17 00:00:00 2001 From: "Andrey V. Lepikhov" Date: Mon, 27 Nov 2023 11:23:48 +0700 Subject:

Re: Postgres picks suboptimal index after building of an extended statistics

2023-11-21 Thread Andrei Lepikhov
Thanks for detaied answer, On 3/11/2023 00:37, Tomas Vondra wrote: On 9/25/23 06:30, Andrey Lepikhov wrote: ... I can't stop thinking about this issue. It is bizarre when Postgres chooses a non-unique index if a unique index gives us proof of minimum scan. That's true, but no one implemented

Re: Postgres picks suboptimal index after building of an extended statistics

2023-11-02 Thread Tomas Vondra
On 9/25/23 06:30, Andrey Lepikhov wrote: > ... > I can't stop thinking about this issue. It is bizarre when Postgres > chooses a non-unique index if a unique index gives us proof of minimum > scan. That's true, but no one implemented this heuristics. So the "proof of minimum scan" is merely

Re: Postgres picks suboptimal index after building of an extended statistics

2023-09-24 Thread Andrey Lepikhov
On 12/8/2021 06:26, Tomas Vondra wrote: On 8/11/21 2:48 AM, Peter Geoghegan wrote: On Wed, Jun 23, 2021 at 7:19 AM Andrey V. Lepikhov wrote: Ivan Frolkov reported a problem with choosing a non-optimal index during a query optimization. This problem appeared after building of an extended

Re: Postgres picks suboptimal index after building of an extended statistics

2022-11-22 Thread Andres Freund
Hi, On 2022-07-11 12:57:36 +0500, Andrey Lepikhov wrote: > On 7/8/22 03:07, Tom Lane wrote: > > Andrey Lepikhov writes: > > > On 12/8/21 04:26, Tomas Vondra wrote: > > > > I wonder if we should teach clauselist_selectivity about UNIQUE indexes, > > > > and improve the cardinality estimates

Re: Postgres picks suboptimal index after building of an extended statistics

2022-07-11 Thread Andrey Lepikhov
On 7/8/22 03:07, Tom Lane wrote: Andrey Lepikhov writes: On 12/8/21 04:26, Tomas Vondra wrote: I wonder if we should teach clauselist_selectivity about UNIQUE indexes, and improve the cardinality estimates directly, not just costing for index scans. I tried to implement this in different

Re: Postgres picks suboptimal index after building of an extended statistics

2022-07-07 Thread Tom Lane
Andrey Lepikhov writes: > On 12/8/21 04:26, Tomas Vondra wrote: >> I wonder if we should teach clauselist_selectivity about UNIQUE indexes, >> and improve the cardinality estimates directly, not just costing for >> index scans. > I tried to implement this in different ways. But it causes

Re: Postgres picks suboptimal index after building of an extended statistics

2021-08-30 Thread Andrey Lepikhov
On 12/8/21 04:26, Tomas Vondra wrote: On 8/11/21 2:48 AM, Peter Geoghegan wrote: On Wed, Jun 23, 2021 at 7:19 AM Andrey V. Lepikhov I agree the current behavior is unfortunate, but I'm not convinced the proposed patch is fixing the right place - doesn't this mean the index costing won't match

Re: Postgres picks suboptimal index after building of an extended statistics

2021-08-13 Thread Andrey V. Lepikhov
On 8/12/21 4:26 AM, Tomas Vondra wrote: On 8/11/21 2:48 AM, Peter Geoghegan wrote: On Wed, Jun 23, 2021 at 7:19 AM Andrey V. Lepikhov wrote: Ivan Frolkov reported a problem with choosing a non-optimal index during a query optimization. This problem appeared after building of an extended

Re: Postgres picks suboptimal index after building of an extended statistics

2021-08-11 Thread Tomas Vondra
On 8/11/21 2:48 AM, Peter Geoghegan wrote: On Wed, Jun 23, 2021 at 7:19 AM Andrey V. Lepikhov wrote: Ivan Frolkov reported a problem with choosing a non-optimal index during a query optimization. This problem appeared after building of an extended statistics. Any thoughts on this, Tomas?

Re: Postgres picks suboptimal index after building of an extended statistics

2021-08-10 Thread Peter Geoghegan
On Wed, Jun 23, 2021 at 7:19 AM Andrey V. Lepikhov wrote: > Ivan Frolkov reported a problem with choosing a non-optimal index during > a query optimization. This problem appeared after building of an > extended statistics. Any thoughts on this, Tomas? -- Peter Geoghegan

Postgres picks suboptimal index after building of an extended statistics

2021-06-23 Thread Andrey V. Lepikhov
Hi, Ivan Frolkov reported a problem with choosing a non-optimal index during a query optimization. This problem appeared after building of an extended statistics. I prepared the test case (see t.sql in attachment). For reproduction of this case we need to have a composite primary key index