Optimization outcome depends on the index order

From: Andrei Lepikhov <a(dot)lepikhov(at)postgrespro(dot)ru>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Alexander Korotkov <aekorotkov(at)gmail(dot)com>
Subject: Optimization outcome depends on the index order
Date: 2023-12-22 06:53:01
Message-ID: 10a1586e-f96e-41b1-abe9-6f93667bf6bc@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On 21/12/2023 12:10, Alexander Korotkov wrote:
> I took a closer look at the patch in [9]. I should drop my argument
> about breaking the model, because add_path() already considers other
> aspects than just costs. But I have two more note about that patch:
>
> 1) It seems that you're determining the fact that the index path
> should return strictly one row by checking path->rows <= 1.0 and
> indexinfo->unique. Is it really guaranteed that in this case quals
> are matching unique constraint? path->rows <= 1.0 could be just an
> estimation error. Or one row could be correctly estimated, but it's
> going to be selected by some quals matching unique constraint and
> other quals in recheck. So, it seems there is a risk to select
> suboptimal index due to this condition.

Operating inside the optimizer, we consider all estimations to be the
sooth. This patch modifies only one place: having two equal assumptions,
we just choose one that generally looks more stable.
Filtered tuples should be calculated and included in the cost of the
path. The decision on the equality of paths has been made in view of the
estimation of these filtered tuples.

> 2) Even for non-unique indexes this patch is putting new logic on top
> of the subsequent code. How we can prove it's going to be a win?
> That could lead, for instance, to dropping parallel-safe paths in
> cases we didn't do so before.
Because we must trust all predictions made by the planner, we just
choose the most trustworthy path. According to the planner logic, it is
a path with a smaller selectivity. We can make mistakes anyway just
because of the nature of estimation.

> Anyway, please start a separate thread if you're willing to put more
> work into this.

Done

> 9. https://www.postgresql.org/message-id/154f786a-06a0-4fb1-
> b8a4-16c66149731b%40postgrespro.ru

--
regards,
Andrei Lepikhov
Postgres Professional

Attachment Content-Type Size
v3-0001-Choose-an-index-path-with-the-best-selectivity-estim.patch text/plain 10.5 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Xiaoran Wang 2023-12-22 07:34:00 Re: [PATCH]: Not to invaldiate CatalogSnapshot for local invalidation messages
Previous Message Kyotaro Horiguchi 2023-12-22 06:49:39 A typo in a messsage?