本文总结了 ODP 无法正确解析SQL语句从而进行正确路由的几种场景。
适用版本
ODP V2.x 和 V3.x 版本。
ODP 无法正确路由的场景
场景一:SQL 语句长度大于 4K 可能无法解析出表名导致路由不准。
场景二:如果 insert 语句在分区字段上用了
nvl()函数,这个可能会导致路由偏差,需要 ODP V3.2.10 及以上版本才能修复该问题。场景三:如果 where 谓词条件中包含了分区键条件,但是分区键条件跟 where 关键字之间有很多复杂的谓词条件,会导致 ODP 解析分区失败,进而导致 ODP 随机路由。
-- 这边表的分区键为 client_id select init_date, curr_date, curr_milltime, op_branch_no, operator_no, op_entrust_way, op_station, branch_no, client_id, fund_account from xxx where position_str > '0' and ( 0 = 0 or entrust_no = 0 ) and ( 0 = 0 or branch_no = 0 ) and ( trim(' ') is null or exchange_type = ' ' ) and ( trim(' ') is null or stock_account = ' ' ) and ( trim(' ') is null or stock_code = ' ' ) and ( trim(' ') is null or entrust_type = ' ' ) and ( trim(' ') is null or entrust_bs = ' ' ) and ( trim(' ') is null or entrust_reference = ' ' ) and ( trim('0,1,2,3,4,5,6,7,8,9,V,U,C') is null or instr( ',' || '0,1,2,3,4,5,6,7,8,9,V,U,C' || ',', ',' || entrust_status || ',' ) > 0 ) and ( trim(',a,b,c,e,AFW,AFC,') is null or instr( ',' || ',a,b,c,e,AFW,AFC,' || ',', ',' || entrust_prop || ',' ) > 0 ) and ( trim(' ') is null or instr(',' || ' ' || ',', ',' || stock_type || ',') > 0 ) and ( trim(' ') is null or instr(',' || ' ' || ',', ',' || stock_type || ',') > 0 ) and ( trim(' ') is null or instr(',' || ' ' || ',', ',' || stock_type || ',') <= 0 ) and fund_account = '88580000027858' and client_id = '88580000027858' order by position_str;场景四:对于分区键上的范围条件的谓词,ODP 不能保证可以正确路由,ODP 可以保证等值条件的谓词能够正确路由。
-- 这边表的 一级分区方式为 range(init_date),二级分区方式为 hash(client_id) select a.stock_name, a.option_code from xxx a where a.client_id = 'XY0000403120' and a.init_date >= 20200102 and a.init_date <= 20200102 and a.position_str > '0';场景五:目前只要分区键位于嵌套子查询里面,ODP 就没法解析了。
-- 这边表的分区键为 client_id select * from ( select init_date, curr_date, curr_milltime, op_branch_no, operator_no, op_entrust_way, op_station, branch_no, client_id, fund_account from xxx where client_id = '88580000041367' and position_str > '0' order by position_str ) where rownum <= 50;