Re: Incremental Sort Cost Estimation Instability

2025-05-14 Thread Andrei Lepikhov
On 9/12/24 16:57, Tomas Vondra wrote: On 9/12/24 12:12, David Rowley wrote: On Thu, 12 Sept 2024 at 21:51, Andrei Lepikhov wrote: Initial problem causes wrong cost_sort estimation. Right now I think about providing cost_sort() the sort clauses instead of (or in addition to) the pathkeys. I'm

Re: Incremental Sort Cost Estimation Instability

2024-11-11 Thread Andrei Lepikhov
Hi, Revising the patch I found out that it may make sense to teach estimate_num_groups to process a PathKey node inside the presortedExprs list. In this case it can pass through the EquivalenceClass members and choose correct number of distinct values. Here is a sketch of the solution (see in

Re: Incremental Sort Cost Estimation Instability

2024-11-07 Thread Andrei Lepikhov
On 11/7/24 18:06, Alena Rybakina wrote: On 07.11.2024 08:57, Andrei Lepikhov wrote: That happens because when estimating the number of groups, Postgres doesn't consider EquivalenceClass, which can let him correct group estimation at a low price. It may be done inside the make_pathkeys_for_sortc

Re: Incremental Sort Cost Estimation Instability

2024-11-07 Thread Alena Rybakina
Hi! On 07.11.2024 08:57, Andrei Lepikhov wrote: On 10/8/24 11:33, Andrei Lepikhov wrote: On 9/23/24 20:02, Andrei Lepikhov wrote: On 12/9/2024 12:12, David Rowley wrote: On Thu, 12 Sept 2024 at 21:51, Andrei Lepikhov Minor change to make compiler and cfbot happy Now, this thread looks conne

Re: Incremental Sort Cost Estimation Instability

2024-11-06 Thread Andrei Lepikhov
On 10/8/24 11:33, Andrei Lepikhov wrote: On 9/23/24 20:02, Andrei Lepikhov wrote: On 12/9/2024 12:12, David Rowley wrote: On Thu, 12 Sept 2024 at 21:51, Andrei Lepikhov Minor change to make compiler and cfbot happy Now, this thread looks connected to the [1]. However, it still has independen

Re: Incremental Sort Cost Estimation Instability

2024-10-07 Thread Andrei Lepikhov
On 9/23/24 20:02, Andrei Lepikhov wrote: On 12/9/2024 12:12, David Rowley wrote: On Thu, 12 Sept 2024 at 21:51, Andrei Lepikhov wrote: Initial problem causes wrong cost_sort estimation. Right now I think about providing cost_sort() the sort clauses instead of (or in addition to) the pathkeys.

Re: Incremental Sort Cost Estimation Instability

2024-09-23 Thread Andrei Lepikhov
On 12/9/2024 16:57, Tomas Vondra wrote: On 9/12/24 12:12, David Rowley wrote: On Thu, 12 Sept 2024 at 21:51, Andrei Lepikhov wrote: but doesn't estimate_num_groups() supposed to already do that? The comment says: * 3. If the list contains Vars of different relations that are known equal

Re: Incremental Sort Cost Estimation Instability

2024-09-23 Thread Andrei Lepikhov
On 12/9/2024 16:57, Tomas Vondra wrote: On 9/12/24 12:12, David Rowley wrote: On Thu, 12 Sept 2024 at 21:51, Andrei Lepikhov wrote: I'm not sure how to fix this, but it seems estimate_num_groups() needs to do things differently. And I agree looking for the minimum ndistinct seems like the righ

Re: Incremental Sort Cost Estimation Instability

2024-09-23 Thread Andrei Lepikhov
On 12/9/2024 12:12, David Rowley wrote: On Thu, 12 Sept 2024 at 21:51, Andrei Lepikhov wrote: Initial problem causes wrong cost_sort estimation. Right now I think about providing cost_sort() the sort clauses instead of (or in addition to) the pathkeys. I'm not quite sure why the sort clauses

Re: Incremental Sort Cost Estimation Instability

2024-09-19 Thread Andrei Lepikhov
On 12/9/2024 12:12, David Rowley wrote: On Thu, 12 Sept 2024 at 21:51, Andrei Lepikhov wrote: Initial problem causes wrong cost_sort estimation. Right now I think about providing cost_sort() the sort clauses instead of (or in addition to) the pathkeys. I'm not quite sure why the sort clauses

Re: Incremental Sort Cost Estimation Instability

2024-09-12 Thread Tomas Vondra
On 9/12/24 12:12, David Rowley wrote: > On Thu, 12 Sept 2024 at 21:51, Andrei Lepikhov wrote: >> Initial problem causes wrong cost_sort estimation. Right now I think >> about providing cost_sort() the sort clauses instead of (or in addition >> to) the pathkeys. > > I'm not quite sure why the sort

Re: Incremental Sort Cost Estimation Instability

2024-09-12 Thread David Rowley
On Thu, 12 Sept 2024 at 21:51, Andrei Lepikhov wrote: > Initial problem causes wrong cost_sort estimation. Right now I think > about providing cost_sort() the sort clauses instead of (or in addition > to) the pathkeys. I'm not quite sure why the sort clauses matter any more than the EquivalenceCl

Re: Incremental Sort Cost Estimation Instability

2024-09-12 Thread Andrei Lepikhov
On 12/9/2024 03:05, David Rowley wrote: On Thu, 27 Jun 2024 at 03:00, Andrei Lepikhov wrote: I tried to invent a simple solution to fight this minor case. But the most clear and straightforward way here is to save a reference to the expression that triggered the PathKey creation inside the Path

Re: Incremental Sort Cost Estimation Instability

2024-09-11 Thread David Rowley
On Thu, 27 Jun 2024 at 03:00, Andrei Lepikhov wrote: > I tried to invent a simple solution to fight this minor case. But the > most clear and straightforward way here is to save a reference to the > expression that triggered the PathKey creation inside the PathKey itself. > See the sketch of the p

Incremental Sort Cost Estimation Instability

2024-06-26 Thread Andrei Lepikhov
Hi, While designing an improvement for the cost sort model, I discovered that the query plan can vary if we slightly change the query text without pushing semantic differences. See the example below: CREATE TABLE test(x integer, y integer,z text); INSERT INTO test (x,y) SELECT x, 1 FROM gener