是否可以在真正全面解析sql之前,只解析sql有哪几个表名,然后判断是否有路由规则
相应的源码我也阅读了,是否可以在真正全面解析sql之前,只解析sql有哪几个表名,然后判断是否有路由规则,如果没有,则跳过后面的解析,如果有再走正常流程,这样,则抛出异常的情况就会大大减少,针对只分表不分库的场景就会更加的友好。
引用: Sorry, we can not do on this way.
We must use parse engine to adjust table in SQL is in default datasource or not. If some syntax cannot support, we will throw an exception and terminate parse. So you said if in default datasource, then skip verify... is impassable.
Actually, we don'y have SQL verify phase, we just throw an exception when meet unsupported SQL.
Some scene is more complicated. For example:
select distinct * from xxx
we need to parse distinct first, and then can know table. but we don't want parse sql any more because distinct is unsupported. SQL parsing cannot reversal.
Please discuss further in English, thank you.
@terrymanu My English is a bit poor, if there are problems caused you express, please point out, thank you (^ - ^)
I think of two scenarios:
-
Adjust the parsing order, give priority to the from keyword, analyze the table, and determine whether there is a routing rule, and whether it is a non-sharding rule.
-
Add a new module, before the start of the all process, first began to parse the from keyword (relative freedom, because is a new module, parsing rules should be recursive interception and parse the from keyword), and then judge the routing rules. Depending on the judge result, to decide to continue with the rules that follow the lead, or skip that and direct execute the original SQL.
Hi, I just prepare to read the Sharding-JDBC source code. Below is just my own opinion. We should use SQL parsing engine to do the analyzing, and during the parsing procedure, we already know if the SQL syntax is supported I think. So we can't get the tables as simple as you think about it.
you can try to read it , and i think it is possible after i do . we can discuss further after you have read it. @JayceeQ
I don't agree to do it, because use hint to do will be better
Parse twice will cause performance issue. And I don't think parse table name only is necessary. We can improve parse module for long-term plan, but should not add any temporary design.
个人见解 这东西应该做,因为可以降低老项目接入成本; 用hint又不是一个全局的方案; 而只要实现了,内部实现的代码质量啥的,临时设计啥的,开发组后面可以逐步消化,性能啥的,因为有缓存所以应该其实还好; 对使用者的无感接入是一个很棒的用户体验
软件不像硬件,不需要没做到完美就不开发布会,可以先拿出来再优化的

说真的,如果不解析SQL,就用字符串包含来判断,会不会在正确性上其实是没有问题的
如果以扩展的身份,用一个别的SQL解析器多解析一遍,是不是就说得过去了呢
Excuse me, let me lock this conversation.
We had never consider about using string search or parse more than 1 times to refactor sharding-sphere.
We prefer standard way to do middleware.