Re: BUG #16993: Query Planner does not use index for EXISTS-query on a large table with all equal foreign key values

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #16993: Query Planner does not use index for EXISTS-query on a large table with all equal foreign key values
Дата
Msg-id 4113744.1620271715@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: BUG #16993: Query Planner does not use index for EXISTS-query on a large table with all equal foreign key values  (David Rowley <dgrowleyml@gmail.com>)
Ответы Re: BUG #16993: Query Planner does not use index for EXISTS-query on a large table with all equal foreign key values  (David Rowley <dgrowleyml@gmail.com>)
Список pgsql-bugs
David Rowley <dgrowleyml@gmail.com> writes:
> On Thu, 6 May 2021 at 05:47, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> A narrower fix would be to hack var_eq_non_const so that it doesn't
>> assume that the comparison value must be one of the entries in the
>> column.  But it seems like whatever change we made in that line would
>> be a very unprincipled hack, because what are you going to assume
>> instead?

> Yeah, this is the same problem as I was mentioning in [1]
> My solution was to go for that "unprincipled hack" in var_eq_non_const().
> I'm not sure I 100% agree that it's a complete hack, you don't really
> have to change the n_distinct by much to get the good plan.  It's a
> massive risk to assume that the given value will *always* be the
> single distinct value that's indexed.

Yeah, I agree that it doesn't seem great to let var_eq_non_const return
1.0 when it has no idea what the comparison value is.  However, that
doesn't translate to having much confidence in any other value either.
The actual number-of-rows-fetched, given that we know the column
contents are all the same value, is either zero or the whole table.
It's hard to do much with that; and biasing it towards believing the
optimistic value over the pessimistic value seems dangerous.

In any case, I think the real issue here is that we know that *in use*,
the indexscan will fetch either zero or one row, and be pretty quick
either way.  The problem is that that knowledge is being applied
at the join level, which is too late to save the path from losing.
How could we move that knowledge down to the scan path costs?

            regards, tom lane



В списке pgsql-bugs по дате отправления:

Предыдущее
От: David Rowley
Дата:
Сообщение: Re: BUG #16993: Query Planner does not use index for EXISTS-query on a large table with all equal foreign key values
Следующее
От: David Rowley
Дата:
Сообщение: Re: BUG #16993: Query Planner does not use index for EXISTS-query on a large table with all equal foreign key values