tristaZero edited a comment on issue #8284: URL: https://github.com/apache/shardingsphere/issues/8284#issuecomment-743767420
Hi @guimingyue , I gave a look at your repo, and basically, it is on the right way to do query optimization. : ) Here are some of my thought about how to leverage Calcite to do query optimization and SQL federation for ShardingSphere. @junwen12221 @guimingyue What's your thinking about the process below? Welcome your any comments. --- ### Process #### Preparation - Create SQL Parser using configuration - Create Calcite schema factory using `sharding rules` (TODO) - Put the reference of ` Calcite schema` and `Calcite context` in `SchemaContexts` for the following SQL optimization and SQL federation (TODO) #### Parse (DONE) - ShardingSphere parser parses SQLs as an AST or SQLStatement [SQLStatement](https://github.com/apache/shardingsphere/blob/master/shardingsphere-sql-parser/shardingsphere-sql-parser-statement/src/main/java/org/apache/shardingsphere/sql/parser/sql/common/statement/SQLStatement.java) is a concise object of a String SQL and generated by Antlr visitor. #### Optimize (TODO) @guimingyue - ShardingSphere optimizer transforms `SQLStatement` to `SqlNode` of `Calcite` - ShardingSphere optimizer applies some of the rules (e.g., CoreRules or EnumerableRules) to perform logical transformations on relational expressions - ShardingSphere optimize returns a optimized `RelNode` (BestPlan) #### Execute (TODO) - Create Calcite raw executor - Execute SQL by `InterpretableConverter` of `Calcite` - Packaging `Enumerable<Object[]>` and `ResultSetMetaData` as `QueryResult` of `ShardingSphere` - Pass the execution result, i.e., `QueryResult` to `executeEngine` of `ShardingSphere` --- Plus, @guimingyue, It looks you need at least a `ShardingSphereCalciteSchema` to do SQL optimization. I will first try to finish the **preparation** part next week. After that, you can use the Calcite Context for the optimation module (Ready to raize a PR, I guess). BTW, my task seems not a blocker for your work. Just pretend you have a `ShardingSphereCalciteSchema` and continue Sqlnode transformation work. : ) @junwen12221 I am unsure whether you have time programming? If not, could you help review the succeeding PRs? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
