Optimization of NestLoop join in the case of guaranteed empty inner subtree

From: Andrey Lepikhov <a(dot)lepikhov(at)postgrespro(dot)ru>
To: PostgreSQL-Dev <pgsql-hackers(at)postgresql(dot)org>
Subject: Optimization of NestLoop join in the case of guaranteed empty inner subtree
Date: 2019-12-11 13:08:40
Message-ID: a373827a-260c-2b05-e7e6-32f4135ec093@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

During NestLoop execution we have bad corner case: if outer subtree
contains tuples the join node will scan inner subtree even if it does
not return any tuples.

To reproduce the problem see 'problem.sql' in attachment:
Out of explain analyze see in 'problem_explain.txt'

As you can see, executor scan each of 1e5 outer tuples despite the fact
that inner can't return any tuples.

Teodor Sigaev and I developed a patch to solve this problem. Result of
explain analyze procedure can be found in the 'optimized_execution.txt'.

--
Andrey Lepikhov
Postgres Professional
https://postgrespro.com
The Russian Postgres Company

Attachment Content-Type Size
problem.sql application/sql 554 bytes
problem_explain.txt text/plain 1.1 KB
0001-Skip-scan-of-outer-subtree-if-inner-of-the-NestedLoo.patch text/x-patch 4.7 KB
optimized_execution.txt text/plain 768 bytes

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Julien Rouhaud 2019-12-11 13:44:52 Re: Collation versioning
Previous Message Ranier Vilela 2019-12-11 12:52:38 RE: [Proposal] Level4 Warnings show many shadow vars