Re: Make the qual cost on index Filter slightly higher than qual cost on index Cond.

From: Ashutosh Bapat <ashutosh(dot)bapat(at)2ndquadrant(dot)com>
To: Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com>
Cc: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>, PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: Make the qual cost on index Filter slightly higher than qual cost on index Cond.
Date: 2020-05-27 12:00:55
Message-ID: CAG-ACPWjm1cKjSyU_kicBDMJ-LcWe=_0oGPKyodfygB6axD_4g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, 27 May 2020 at 04:43, Andy Fan <zhihui(dot)fan1213(at)gmail(dot)com> wrote:

> You can use the attached sql to reproduce this issue, but I'm not sure you
> can
> get the above result at the first time that is because when optimizer
> think the
> 2 index scan have the same cost, it will choose the first one it found,
> the order
> depends on RelationGetIndexList. If so, you may try drop and create
> j1_i_im5 index.
>
> The sense behind this patch is we still use the cost based optimizer, just
> when we
> we find out the 2 index scans have the same cost, we prefer to use the
> index which
> have more qual filter on Index Cond. This is implemented by adjust the
> qual cost
> on index filter slightly higher.
>

Thanks for the example and the explanation.

The execution time difference in your example is pretty high to account for
executing the filter on so many rows. My guess is this has to do with the
heap access. For applying the filter the entire row needs to be fetched
from the heap. So we should investigate this case from that angle. Another
guess I have is the statistics is not correct and hence the cost is wrong.

--
Best Wishes,
Ashutosh

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Ashutosh Bapat 2020-05-27 12:11:16 Re: Getting ERROR with FOR UPDATE/SHARE for partitioned table.
Previous Message Robert Haas 2020-05-27 11:57:38 Re: tablespace_map code cleanup