shardingsphere icon indicating copy to clipboard operation
shardingsphere copied to clipboard

是否可以在真正全面解析sql之前,只解析sql有哪几个表名,然后判断是否有路由规则

Open chncho opened this issue 8 years ago • 10 comments

相应的源码我也阅读了,是否可以在真正全面解析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.

chncho avatar Apr 30 '18 05:04 chncho

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 avatar May 02 '18 03:05 terrymanu

@terrymanu My English is a bit poor, if there are problems caused you express, please point out, thank you (^ - ^)

I think of two scenarios:

  1. 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.

  2. 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.

chncho avatar May 03 '18 04:05 chncho

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.

ghost avatar May 07 '18 13:05 ghost

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

chncho avatar May 08 '18 13:05 chncho

I don't agree to do it, because use hint to do will be better

maxiaoguang64 avatar May 11 '18 03:05 maxiaoguang64

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.

terrymanu avatar May 11 '18 03:05 terrymanu

个人见解 这东西应该做,因为可以降低老项目接入成本; 用hint又不是一个全局的方案; 而只要实现了,内部实现的代码质量啥的,临时设计啥的,开发组后面可以逐步消化,性能啥的,因为有缓存所以应该其实还好; 对使用者的无感接入是一个很棒的用户体验

软件不像硬件,不需要没做到完美就不开发布会,可以先拿出来再优化的

limingwei avatar May 11 '18 03:05 limingwei

qq 20180511222859

说真的,如果不解析SQL,就用字符串包含来判断,会不会在正确性上其实是没有问题的

wangdan0-0 avatar May 11 '18 14:05 wangdan0-0

如果以扩展的身份,用一个别的SQL解析器多解析一遍,是不是就说得过去了呢

limingwei avatar May 14 '18 01:05 limingwei

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.

terrymanu avatar May 14 '18 03:05 terrymanu