[POC] Allow flattening of subquery with a link to upper query - Mailing list pgsql-hackers

From Andrey Lepikhov
Subject [POC] Allow flattening of subquery with a link to upper query
Date
Msg-id f26a8b9e-5b41-4013-9e95-7a056456e30c@postgrespro.ru
Whole thread Raw
Responses Re: [POC] Allow flattening of subquery with a link to upper query
List pgsql-hackers
Hi,

One of the most annoying things in the planner for me is unnesting of 
correlated queries [1]. A number papers on this subject were published 
starting 1980s, but only trivial optimizations exists in the Core. It 
means a lack of performance, especially when we use foreign tables in 
subquery.
In the patch I'm trying to propose a sort of sketch of solution.

Before flattening procedure we just look through the quals of subquery, 
pull to the upper level OpExpr's containing variables from the upper 
relation and replace their positions in the quals with true expression.
Further, the flattening machinery works as usual.

This patch is dedicated to simplest variant of correlated queries - 
without aggregate functions in the target list. It passes regression 
tests and contains some additional tests to demonstrate achievements.

I'd like to get critics on the approach.

[1]  Kim, Won. “On optimizing an SQL-like nested query.” ACM Trans. 
Database Syst. 7 (1982): 443-469.

-- 
Regards
Andrey Lepikhov
Postgres Professional
Attachment

pgsql-hackers by date:

Previous
From: Jeff Davis
Date:
Subject: Re: New strategies for freezing, advancing relfrozenxid early
Next
From: Amit Langote
Date:
Subject: Re: SQL/JSON features for v15