risinglight icon indicating copy to clipboard operation
risinglight copied to clipboard

sql: support subquery

Open MingjiHan99 opened this issue 3 years ago • 2 comments

Step 1: support subquery binding in binder.

Existing binder can only bind columns and tables in the catalog.

One possbile solution is to add new types of column and table bindings: SubqueryColumnRef and SubQueryTableRef.

Step 2: support uncorrlated subquery execution.

Step 3: support subquery execution plan for correlated subquery.

Reference: https://ericfu.me/subquery-optimization/

MingjiHan99 avatar Dec 27 '22 02:12 MingjiHan99

@skyzh @wangrunji0408

MingjiHan99 avatar Dec 27 '22 02:12 MingjiHan99

Step 1 is done in #756. Now we support subqueries in FROM clause which can pass TPC-H Q9 #761. However, TPC-H Q7 still fails because it has one table being joined with itself. The binder will generate the same ColumnRefId for both sides, which actually refer to different subqueries. A possible solution is to decouple ColumnRefId from physical tables, instead generate a temporary table ID for each occurrence.

wangrunji0408 avatar Jan 07 '23 17:01 wangrunji0408