For the query below, it would be quite useful if Optiq could detect that the subquery in the HAVING clause is scalar and process it as a local filter on the outer 'nation' table instead of as a join.
For comparison, I have provided the Postgres plan for the same query. Is there any open enhancement bug for this ? In general, I am also curious to know if Optiq has functionality to detect if a subquery block is provably scalar or not.
select n.n_regionkey from nation n group by n.n_regionkey having n.n_regionkey > (select min(n2.n_regionkey) from nation n2);
Optiq logical plan: (I have removed the cost information since that is not relevant):
ProjectRel(n_regionkey=[$0]):
FilterRel(condition=[>($0, $1)])
JoinRel(condition=[true], joinType=[left]):
AggregateRel(group=[{0}]):
ProjectRel(n_regionkey=[$1]):
EnumerableTableAccessRel(table=[[cp, tpch/nation.parquet]]):
AggregateRel(group=[{}], EXPR$0=[MIN($0)]):
ProjectRel(n_regionkey=[$1]):
EnumerableTableAccessRel(table=[[cp, tpch/nation.parquet]]):
Postgres plan:
QUERY PLAN
--------------------------------------------------------------------------
HashAggregate (cost=24.92..25.55 rows=63 width=4)
InitPlan 1 (returns $0)
-> Aggregate (cost=12.38..12.39 rows=1 width=4)
-> Seq Scan on nation n2 (cost=0.00..11.90 rows=190 width=4)
-> Seq Scan on nation n (cost=0.00..12.38 rows=63 width=4)
Filter: (n_regionkey > $0)
(6 rows)
Thanks !
Aman