你好,oceanbase基于代价的查询改写,会将OR表达式改写为union all以方便使用不同字段的索引,但是,我们这个场景不需要进行查询改写,感觉是oceanbase在评估改写与不改写的时候cost出现了一些偏差。
执行计划上显示,不改写的代价更高,但是实际的情况是不改写快很多。
|ID|OPERATOR |NAME |EST.ROWS|EST.TIME(us)|
|0 |SCALAR GROUP BY | |1 |136707800 |
|1 |└─SUBPLAN FILTER | |6432495 |136591217 |
|2 | ├─HASH JOIN | |6432495 |3992410 |
|3 | │ ├─TABLE FULL SCAN |infraSzsm(idx_ftsp_infra_szsm_1)|1255 |22 |
|4 | │ └─HASH JOIN | |6112177 |1796236 |
|5 | │ ├─MERGE OUTER JOIN | |495511 |222119 |
|6 | │ │ ├─NESTED-LOOP OUTER JOIN | |202327 |78397 |
|7 | │ │ │ ├─NESTED-LOOP OUTER JOIN | |937 |58886 |
|8 | │ │ │ │ ├─NESTED-LOOP OUTER JOIN | |571 |47005 |
|9 | │ │ │ │ │ ├─NESTED-LOOP JOIN | |441 |37825 |
|10| │ │ │ │ │ │ ├─NESTED-LOOP OUTER JOIN | |428 |28910 |
|11| │ │ │ │ │ │ │ ├─NESTED-LOOP OUTER JOIN | |428 |16242 |
|12| │ │ │ │ │ │ │ │ ├─NESTED-LOOP OUTER JOIN | |384 |8243 |
|13| │ │ │ │ │ │ │ │ │ ├─NESTED-LOOP JOIN CARTESIAN | |384 |241 |
|14| │ │ │ │ │ │ │ │ │ │ ├─MERGE JOIN | |384 |226 |
|15| │ │ │ │ │ │ │ │ │ │ │ ├─SUBPLAN SCAN |VIEW1 |384 |59 |
|16| │ │ │ │ │ │ │ │ │ │ │ │ └─MERGE DISTINCT | |384 |58 |
|17| │ │ │ │ │ │ │ │ │ │ │ │ └─NESTED-LOOP JOIN CARTESIAN | |385 |54 |
|18| │ │ │ │ │ │ │ │ │ │ │ │ ├─TABLE RANGE SCAN |pg_(idx_ftsp_kh_pg_3) |384 |15 |
|19| │ │ │ │ │ │ │ │ │ │ │ │ └─MATERIAL | |2 |28 |
|20| │ │ │ │ │ │ │ │ │ │ │ │ └─HASH JOIN | |2 |28 |
|21| │ │ │ │ │ │ │ │ │ │ │ │ ├─TABLE RANGE SCAN |yh_(idx_ftsp_zj_bmyh_2) |1 |9 |
|22| │ │ │ │ │ │ │ │ │ │ │ │ └─TABLE RANGE SCAN |bm_(idx_ftsp_zj_bmxx_1) |52 |6 |
|23| │ │ │ │ │ │ │ │ │ │ │ └─TABLE RANGE SCAN |kh(idx_ftsp_kh_khxx_13) |1131 |118 |
|24| │ │ │ │ │ │ │ │ │ │ └─MATERIAL | |1 |5 |
|25| │ │ │ │ │ │ │ │ │ │ └─TABLE GET |zjxx |1 |5 |
|26| │ │ │ │ │ │ │ │ │ └─DISTRIBUTED TABLE RANGE SCAN |gsSjqr(uk_ftsp_sb_sbxx_status_1)|1 |21 |
|27| │ │ │ │ │ │ │ │ └─DISTRIBUTED TABLE RANGE SCAN |gs(uk_ftsp_sb_khxx_gs_1) |1 |21 |
|28| │ │ │ │ │ │ │ └─DISTRIBUTED TABLE RANGE SCAN |cj(ftsp_kh_cjxx_index) |1 |29 |
|29| │ │ │ │ │ │ └─DISTRIBUTED TABLE RANGE SCAN |zt(idx_ftsp_zt_ztxx_1) |1 |21 |
|30| │ │ │ │ │ └─DISTRIBUTED TABLE RANGE SCAN |xtzh(idx_ftsp_kh_dsf_xtzh_1) |1 |21 |
|31| │ │ │ │ └─DISTRIBUTED TABLE RANGE SCAN |sb(uk_ftsp_sb_sbxx) |1 |21 |
|32| │ │ │ └─DISTRIBUTED TABLE RANGE SCAN |lzd(uk_ftsp_dj_lzd_1) |1 |21 |
|33| │ │ └─TABLE FULL SCAN |jcxx(idx_kh_khxx_id__) |1924625 |83671 |
|34| │ └─TABLE FULL SCAN |szsm |1242058 |650776 |
|35| └─DISTRIBUTED TABLE RANGE SCAN |ht(idx_ftsp_ht_htxx_14) |1 |21 |
=======================================================================================================================
Outputs & filters:
0 - output([T_FUN_COUNT(distinct kh.id_)]), filter(nil), rowset=256
group(nil), agg_func([T_FUN_COUNT(distinct kh.id_)])
1 - output([kh.id_]), filter([cast(zjxx.approval_account_, DECIMAL(4, 0)) = cast(‘0’, DECIMAL(1, -1)) OR (T_OP_EXISTS, subquery(1))]), rowset=256
exec_params_([kh.id_(:0)]), onetime_exprs_(nil), init_plan_idxs_(nil), use_batch=false
2 - output([kh.id_], [zjxx.approval_account_]), filter(nil), rowset=256
equal_conds([infraSzsm.smbh_ = szsm.infra_szsm_smbh_]), other_conds([IFNULL(cast(jcxx.swzxh_, VARCHAR(4)), '0') = '0' OR IFNULL(cj.ycqj_, '210001')
> '202403'])
3 - output([infraSzsm.smbh_]), filter(nil), rowset=256
access([infraSzsm.smbh_]), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([infraSzsm.smbh_], [infraSzsm.id_]), range(MIN,MIN ; MAX,MAX)always true
4 - output([kh.id_], [zjxx.approval_account_], [cj.ycqj_], [jcxx.swzxh_], [szsm.infra_szsm_smbh_]), filter(nil), rowset=256
equal_conds([szsm.kh_khxx_id_ = kh.id_]), other_conds(nil)
5 - output([kh.id_], [zjxx.approval_account_], [cj.ycqj_], [jcxx.swzxh_]), filter(nil), rowset=256
equal_conds([jcxx.kh_khxx_id_ = kh.id_]), other_conds(nil)
merge_directions([ASC])
6 - output([kh.id_], [zjxx.approval_account_], [cj.ycqj_]), filter(nil), rowset=256
conds(nil), nl_params_([kh.id_(:12)]), use_batch=false
7 - output([kh.id_], [zjxx.approval_account_], [cj.ycqj_]), filter(nil), rowset=256
conds(nil), nl_params_([kh.id_(:8)]), use_batch=false
8 - output([kh.id_], [zjxx.approval_account_], [cj.ycqj_]), filter(nil), rowset=256
conds(nil), nl_params_([kh.id_(:13)]), use_batch=false
9 - output([kh.id_], [zjxx.approval_account_], [cj.ycqj_]), filter(nil), rowset=256
conds(nil), nl_params_([kh.id_(:3)]), use_batch=false
10 - output([kh.id_], [zjxx.approval_account_], [cj.ycqj_]), filter(nil), rowset=256
conds(nil), nl_params_([kh.id_(:10)]), use_batch=false
11 - output([kh.id_], [zjxx.approval_account_]), filter(nil), rowset=256
conds(nil), nl_params_([kh.id_(:7)]), use_batch=false
12 - output([kh.id_], [zjxx.approval_account_]), filter(nil), rowset=256
conds(nil), nl_params_([kh.id_(:11)]), use_batch=false
13 - output([kh.id_], [zjxx.approval_account_]), filter(nil), rowset=256
conds(nil), nl_params_(nil), use_batch=false
14 - output([kh.id_]), filter(nil), rowset=256
equal_conds([kh.id_ = VIEW1.kh_khxx_id_]), other_conds(nil)
merge_directions([ASC])
15 - output([VIEW1.kh_khxx_id_]), filter(nil), rowset=256
access([VIEW1.kh_khxx_id_])
16 - output([pg_.kh_khxx_id_]), filter(nil), rowset=256
distinct([pg_.kh_khxx_id_])
17 - output([pg_.kh_khxx_id_]), filter(nil), rowset=256
conds(nil), nl_params_(nil), use_batch=false
18 - output([pg_.kh_khxx_id_]), filter(nil), rowset=256
access([pg_.kh_khxx_id_]), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([pg_.infra_user_id_], [pg_.kh_khxx_id_], [pg_.create_date_], [pg_.id_]), range(h0000000000000399057290070958080,MIN,MIN,MIN ; h0000000000000399057290070958080,
MAX,MAX,MAX),
range_cond([pg_.infra_user_id_ = 'h0000000000000399057290070958080'])
19 - output(nil), filter(nil), rowset=256
20 - output(nil), filter(nil), rowset=256
equal_conds([yh_.zj_bmxx_id_ = bm_.id_]), other_conds(nil)
21 - output([yh_.zj_bmxx_id_]), filter(nil), rowset=256
access([yh_.id_], [yh_.zj_bmxx_id_]), partitions(p0)
is_index_back=true, is_global_index=false,
range_key([yh_.infra_user_id_], [yh_.is_delete_], [yh_.is_active_], [yh_.id_]), range(h0000000000000399057290070958080,0,1,MIN ; h0000000000000399057290070958080,
0,1,MAX),
range_cond(['h0000000000000399057290070958080' = yh_.infra_user_id_], [yh_.is_active_ = 1], [yh_.is_delete_ = 0])
22 - output([bm_.id_]), filter(nil), rowset=256
access([bm_.id_]), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([bm_.zj_zjxx_id_], [bm_.dept_no_], [bm_.id_]), range(h0000000000000498723430515097600,MIN,MIN ; h0000000000000498723430515097600,MAX,MAX),
range_cond([bm_.zj_zjxx_id_ = 'h0000000000000498723430515097600'])
23 - output([kh.id_]), filter(nil), rowset=256
access([kh.id_]), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([kh.zj_zjxx_id_], [kh.is_delete_], [kh.fw_status_], [kh.ht_fw_zt_], [kh.id_]), range(h0000000000000498723430515097600,0,1,1,MIN ; h0000000000000498723430515097600,
0,1,1,MAX),
range_cond([cast(kh.fw_status_, DECIMAL(4, 0)) = cast('1', DECIMAL(1, -1))], [cast(kh.is_delete_, DECIMAL(4, 0)) = cast('0', DECIMAL(1, -1))], [cast(kh.ht_fw_zt_,
DECIMAL(4, 0)) = cast('1', DECIMAL(1, -1))], [kh.zj_zjxx_id_ = 'h0000000000000498723430515097600'])
24 - output([zjxx.approval_account_]), filter(nil), rowset=256
25 - output([zjxx.approval_account_]), filter(nil), rowset=256
access([zjxx.approval_account_]), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([zjxx.id_]), range[h0000000000000498723430515097600 ; h0000000000000498723430515097600],
range_cond([zjxx.id_ = 'h0000000000000498723430515097600'])
26 - output(nil), filter(nil), rowset=256
access(nil), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([gsSjqr.kh_khxx_id_], [gsSjqr.ss_qj_], [gsSjqr.bb_code_], [gsSjqr.hdlx_code_], [gsSjqr.shadow_pk_0]), range(MIN ; MAX),
range_cond([gsSjqr.ss_qj_ = '202403'], [gsSjqr.bb_code_ = '50003001'], [gsSjqr.kh_khxx_id_ = :11])
27 - output(nil), filter(nil), rowset=256
access(nil), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([gs.kh_khxx_id_], [gs.kj_qj_], [gs.shadow_pk_0]), range(MIN ; MAX),
range_cond([gs.kj_qj_ = '202403'], [gs.kh_khxx_id_ = :7])
28 - output([cj.ycqj_]), filter(nil), rowset=256
access([cj.id_], [cj.ycqj_]), partitions(p0)
is_index_back=true, is_global_index=false,
range_key([cj.kh_khxx_id_], [cj.shadow_pk_0]), range(MIN ; MAX),
range_cond([cj.kh_khxx_id_ = :10])
29 - output(nil), filter(nil), rowset=256
access(nil), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([zt.kh_khxx_id_], [zt.is_default_], [zt.id_]), range(MIN ; MAX),
range_cond([cast(zt.is_default_, DECIMAL(1, 0)) = cast('1', DECIMAL(1, -1))], [:3 = zt.kh_khxx_id_])
30 - output(nil), filter(nil), rowset=256
access(nil), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([xtzh.kh_khxx_id_], [xtzh.xtlx_code_], [xtzh.id_]), range(MIN ; MAX),
range_cond([xtzh.xtlx_code_ = '04'], [xtzh.kh_khxx_id_ = :13])
31 - output(nil), filter(nil), rowset=256
access(nil), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([sb.kh_khxx_id_], [sb.ss_qj_], [sb.bb_code_], [sb.shadow_pk_0]), range(MIN ; MAX),
range_cond([sb.ss_qj_ = '202403'], [sb.bb_code_ = '50003001'], [sb.kh_khxx_id_ = :8])
32 - output(nil), filter(nil), rowset=256
access(nil), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([lzd.kh_khxx_id_], [lzd.kj_qj_], [lzd.shadow_pk_0]), range(MIN ; MAX),
range_cond([lzd.kj_qj_ = '202403'], [lzd.kh_khxx_id_ = :12])
33 - output([jcxx.kh_khxx_id_], [jcxx.swzxh_]), filter(nil), rowset=256
access([jcxx.kh_khxx_id_], [jcxx.swzxh_]), partitions(p0)
is_index_back=false, is_global_index=false,
range_key([jcxx.kh_khxx_id_], [jcxx.swzxh_], [jcxx.id_]), range(MIN,MIN,MIN ; MAX,MAX,MAX)always true
34 - output([szsm.kh_khxx_id_], [szsm.infra_szsm_smbh_]), filter([szsm.szlx_code_ = ‘06’]), rowset=256
access([szsm.kh_khxx_id_], [szsm.szlx_code_], [szsm.infra_szsm_smbh_]), partitions(p0)
is_index_back=false, is_global_index=false, filter_before_indexback[false],
range_key([szsm.id_]), range(MIN ; MAX)always true
35 - output([1]), filter([ht.status_ = ‘4’], [‘202403’ >= ht.fwqx_q_]), rowset=256
access([ht.id_], [ht.status_], [ht.fwqx_q_]), partitions(p0)
limit(1), offset(nil), is_index_back=true, is_global_index=false, filter_before_indexback[true,false],
range_key([ht.kh_khxx_id_], [ht.fwqx_z_], [ht.status_], [ht.htlx_], [ht.id_]), range(MIN,MIN,MIN,MIN,MIN ; MAX,MAX,MAX,MAX,MAX)always true,
range_cond([ht.kh_khxx_id_ = :0], [ht.fwqx_z_ >= '202403'])