Re: Improving worst-case merge join performance with often-null foreign key

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Improving worst-case merge join performance with often-null foreign key
Дата
Msg-id 3677442.1682176872@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Improving worst-case merge join performance with often-null foreign key  (Steinar Kaldager <steinar.kaldager@oda.com>)
Ответы Re: Improving worst-case merge join performance with often-null foreign key  (Richard Guo <guofenglinux@gmail.com>)
Список pgsql-hackers
Steinar Kaldager <steinar.kaldager@oda.com> writes:
> First-time potential contributor here. We recently had an incident due
> to a sudden 1000x slowdown of a Postgres query (from ~10ms to ~10s)
> due to a join with a foreign key that was often null. We found that it
> was caused by a merge join with an index scan on one join path --
> whenever the non-null data happened to be such that the merge join
> couldn't be terminated early, the index would proceed to scan all of
> the null rows and filter each one out individually. Since this was an
> inner join, this was pointless; the nulls would never have matched the
> join clause anyway.

Hmm.  I don't entirely understand why the existing stop-at-nulls logic
in nodeMergejoin.c didn't fix this for you.  Maybe somebody has broken
that?  See the commentary for MJEvalOuterValues/MJEvalInnerValues.

Pushing down an IS NOT NULL restriction could possibly be of value
if the join is being done in the nulls-first direction, but that's
an extreme minority use-case.  I'm dubious that it'd be worth the
overhead in general.  It'd probably be more useful to make sure that
the planner's cost model is aware of this effect, so that it's prodded
to use nulls-last not nulls-first sort order when there are enough
nulls to make a difference.

            regards, tom lane



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

Предыдущее
От: Gurjeet Singh
Дата:
Сообщение: Re: [PATCH] Infinite loop while acquiring new TOAST Oid
Следующее
От: Tom Lane
Дата:
Сообщение: Re: run pgindent on a regular basis / scripted manner