About
Sql Engine - Logical Plan (Query) in Calcite
A logical plan is a relational expression with only logical operator. Logical algebra has no implementation of the relational operator and therefore can't run.
The logical plan is the first plan created when transforming a Sql tree into relational algebra.
All logical operator starts with the prefix Logical
Articles Related
Management
Create
Every logical plan is created from a SQL tree (sqlNode)
The main entry point is the sqltorelconverter but you would generally use a tool to call it such as the planner
not the same that the planner optimizer)
Planner
Extract from the getting started page with the query processing tool
RelRoot relRoot = planner.rel(sqlNodeValidated);
sqlToRelConverter
With the sqlToRelConverter apache/calcite/blob/master/core/src/main/java/org/apache/calcite/prepare/Prepare.java
RelRoot root = sqlToRelConverter.convertQuery(sqlQuery, needsValidation, true);
As a logical plan is just a relational expression, you just need to print it (explain):
Example: All logical operator starts with the prefix Logical
4:LogicalProject(name=[$2])
3:LogicalFilter(condition=[=($0, 100)])
2:LogicalJoin(condition=[=($1, $5)], joinType=[inner])
0:LogicalTableScan(table=[[HR, emps]])
1:LogicalTableScan(table=[[HR, depts]])
This is equivalent to the below SQL:
select *
from emps inner join depts on deptno
where empid = 100