为提高效率,提问时请尽量提供详细背景信息,问题描述清晰可优先响应。以下信息点请尽量提供:
- 【系统版本 & kernel 版本】
- 【TiDB 版本】
- 【磁盘型号】
- 【集群节点分布】
- 【数据量 & region 数量 & 副本数】
- 【问题描述(我做了什么)】
- 【关键词】更改了1秒的时间范围,无法查询出结果
sql:
select
ec.code as lots_code,
ec.name as lots_name,
sc.code as scenic_code,
sc.name as scenic_name,
od.pay_method as pay_method,
od.quantity as quantity,
od.already_check_num as already_check_num,
od.return_num as return_num,
od.order_type as order_type,
od.price as price,
od.close_price as close_price,
od.total_price as total_price,
od.close_total_price as close_total_price,
od.return_fee_category as return_fee_category,
od.return_fee_rate as return_fee_rate,
od.return_fee as return_fee,
od.corp_code as corp_code,
od.sale_corp_code as sale_corp_code,
od.goods_code as goods_code,
od.goods_name as goods_name,
od.pay_status as pay_status,
od.create_time as create_time,
od.create_by as create_by,
od.occ_date as occ_date,
od.check_time as check_time,
od.status as status,
od.is_vm as is_vm,
od.deleted as deleted,
oi.check_status as check_status,
oi.src as src,
oi.third_code as third_code,
oi.order_code as order_code,
oi.link_name as link_name,
oi.tel as tel,
oi.certificate_no as certificate_no,
p.provice as province,
p.city2 as city,
fx.name as corp_name,
gy.name as sale_corp_name,
fx.label_id as corp_label_id,
gy.label_id as sale_corp_label_id,
fx.corp_group_code as corp_group_code,
gy.corp_group_code as sale_corp_group_code,
fx.sys_area_code as corp_area_code,
gy.sys_area_code as sale_corp_area_code,
od.modify_time as modify_time
from zhiyoubao2_mq_dw.order_detail od
left join zhiyoubao2_mq_dw.order_info oi on od.order_info_id = oi.id
inner join zhiyoubao2_mq_dw.corp fx on od.corp_code = fx.code
inner join zhiyoubao2_mq_dw.corp gy on od.sale_corp_code = gy.code
inner JOIN zhiyoubao_zhiyoubao.ecological_company_corp ecc ON ecc.corp_id = gy.id
inner JOIN zhiyoubao_zhiyoubao.ecological_company ec ON ecc.ecological_company_id = ec.id
left JOIN zybpd_zyb_product.scenic_ticket_type sttm ON od.goods_code = sttm.code
left JOIN zhiyoubao2_mq_dw.scenic sc ON sttm.scenic_id = sc.id
left join zhiyoubao_zhiyoubao.phone_area_new p on substr(oi.tel, 1, 7) = p.code
WHERE
od.create_time >= ‘2019-10-31 15:50:33’
and
od.create_time <= ‘2019-10-31 16:05:00’
and ec.code = ‘guizhgszhlyyxgs’
执行计划:
id | count | task | operator info |
---|---|---|---|
Projection_25 | 246.71 | root | zhiyoubao_zhiyoubao.ec.code, zhiyoubao_zhiyoubao.ec.name, zhiyoubao2_mq_dw.sc.code, zhiyoubao2_mq_dw.sc.name, zhiyoubao2_mq_dw.od.pay_method, zhiyoubao2_mq_dw.od.quantity, zhiyoubao2_mq_dw.od.already_check_num, zhiyoubao2_mq_dw.od.return_num, zhiyoubao2_m |
└─IndexMergeJoin_34 | 246.71 | root | left outer join, inner:IndexLookUp_32, outer key:substr(zhiyoubao2_mq_dw.oi.tel, 1, 7), inner key:zhiyoubao_zhiyoubao.p.code |
├─Projection_36 | 241.40 | root | zhiyoubao2_mq_dw.od.order_info_id, zhiyoubao2_mq_dw.od.order_type, zhiyoubao2_mq_dw.od.sale_corp_code, zhiyoubao2_mq_dw.od.already_check_num, zhiyoubao2_mq_dw.od.check_time, zhiyoubao2_mq_dw.od.goods_name, zhiyoubao2_mq_dw.od.total_price, zhiyoubao2_mq_dw |
│ └─IndexMergeJoin_45 | 241.40 | root | left outer join, inner:IndexLookUp_43, outer key:zybpd_zyb_product.sttm.scenic_id, inner key:zhiyoubao2_mq_dw.sc.id |
│ ├─HashLeftJoin_47 | 238.74 | root | left outer join, inner:TableReader_165, equal:[eq(zhiyoubao2_mq_dw.od.goods_code, zybpd_zyb_product.sttm.code)] |
│ │ ├─IndexMergeJoin_59 | 237.01 | root | inner join, inner:IndexLookUp_57, outer key:zhiyoubao2_mq_dw.od.corp_code, inner key:zhiyoubao2_mq_dw.fx.code |
│ │ │ ├─HashRightJoin_65 | 234.20 | root | inner join, inner:IndexMergeJoin_84, equal:[eq(zhiyoubao2_mq_dw.gy.code, zhiyoubao2_mq_dw.od.sale_corp_code)] |
│ │ │ │ ├─IndexMergeJoin_84 | 0.09 | root | inner join, inner:IndexLookUp_82, outer key:zhiyoubao_zhiyoubao.ecc.corp_id, inner key:zhiyoubao2_mq_dw.gy.id |
│ │ │ │ │ ├─HashRightJoin_99 | 0.08 | root | inner join, inner:IndexLookUp_108, equal:[eq(zhiyoubao_zhiyoubao.ec.id, zhiyoubao_zhiyoubao.ecc.ecological_company_id)] |
│ │ │ │ │ │ ├─IndexLookUp_108 | 0.07 | root | |
│ │ │ │ │ │ │ ├─IndexScan_106 | 0.07 | cop | table:ec, index:CODE, range:[“guizhgszhlyyxgs”,“guizhgszhlyyxgs”], keep order:false, stats:pseudo |
│ │ │ │ │ │ │ └─TableScan_107 | 0.07 | cop | table:ec, keep order:false, stats:pseudo |
│ │ │ │ │ │ └─TableReader_102 | 70.86 | root | data:Selection_101 |
│ │ │ │ │ │ └─Selection_101 | 70.86 | cop | not(isnull(zhiyoubao_zhiyoubao.ecc.corp_id)), not(isnull(zhiyoubao_zhiyoubao.ecc.ecological_company_id)) |
│ │ │ │ │ │ └─TableScan_100 | 71.00 | cop | table:ecc, range:[-inf,+inf], keep order:false, stats:pseudo |
│ │ │ │ │ └─IndexLookUp_82 | 1.00 | root | |
│ │ │ │ │ ├─IndexScan_79 | 1.00 | cop | table:gy, index:ID, range: decided by [eq(zhiyoubao2_mq_dw.gy.id, zhiyoubao_zhiyoubao.ecc.corp_id)], keep order:true |
│ │ │ │ │ └─Selection_81 | 1.00 | cop | not(isnull(zhiyoubao2_mq_dw.gy.code)) |
│ │ │ │ │ └─TableScan_80 | 1.00 | cop | table:gy, keep order:false |
│ │ │ │ └─IndexMergeJoin_124 | 2707.04 | root | left outer join, inner:IndexLookUp_122, outer key:zhiyoubao2_mq_dw.od.order_info_id, inner key:zhiyoubao2_mq_dw.oi.id |
│ │ │ │ ├─IndexLookUp_141 | 2707.04 | root | |
│ │ │ │ │ ├─IndexScan_138 | 2707.04 | cop | table:od, index:CREATE_TIME, range:[2019-10-31 15:50:33,2019-10-31 16:05:00], keep order:false |
│ │ │ │ │ └─Selection_140 | 2707.04 | cop | not(isnull(zhiyoubao2_mq_dw.od.corp_code)), not(isnull(zhiyoubao2_mq_dw.od.sale_corp_code)) |
│ │ │ │ │ └─TableScan_139 | 2707.04 | cop | table:od, keep order:false |
│ │ │ │ └─IndexLookUp_122 | 0.96 | root | |
│ │ │ │ ├─IndexScan_120 | 0.96 | cop | table:oi, index:ID, range: decided by [eq(zhiyoubao2_mq_dw.oi.id, zhiyoubao2_mq_dw.od.order_info_id)], keep order:true |
│ │ │ │ └─TableScan_121 | 0.96 | cop | table:oi, keep order:false |
│ │ │ └─IndexLookUp_57 | 1.00 | root | |
│ │ │ ├─Selection_56 | 1.00 | cop | not(isnull(zhiyoubao2_mq_dw.fx.code)) |
│ │ │ │ └─IndexScan_54 | 1.00 | cop | table:fx, index:CODE, range: decided by [eq(zhiyoubao2_mq_dw.fx.code, zhiyoubao2_mq_dw.od.corp_code)], keep order:true |
│ │ │ └─TableScan_55 | 1.00 | cop | table:fx, keep order:false |
│ │ └─TableReader_165 | 188782.00 | root | data:Selection_164 |
│ │ └─Selection_164 | 188782.00 | cop | not(isnull(zybpd_zyb_product.sttm.code)) |
│ │ └─TableScan_163 | 188782.00 | cop | table:sttm, range:[-inf,+inf], keep order:false |
│ └─IndexLookUp_43 | 1.00 | root | |
│ ├─IndexScan_41 | 1.00 | cop | table:sc, index:ID, range: decided by [eq(zhiyoubao2_mq_dw.sc.id, zybpd_zyb_product.sttm.scenic_id)], keep order:true |
│ └─TableScan_42 | 1.00 | cop | table:sc, keep order:false |
└─IndexLookUp_32 | 1.00 | root |
├─IndexScan_30 |1.00 |cop |table:p, index:CODE, range: decided by [eq(zhiyoubao_zhiyoubao.p.code, substr(zhiyoubao2_mq_dw.oi.tel, 1, 7))], keep order:true |
└─TableScan_31 |1.00 |cop |table:p, keep order:false |
这样是可以出结果的,然而把时间范围的开始时间-1秒,就没有数据了,减1秒后的执行计划:
id | count | task | operator info |
---|---|---|---|
Projection_25 | 246.93 | root | zhiyoubao_zhiyoubao.ec.code, zhiyoubao_zhiyoubao.ec.name, zhiyoubao2_mq_dw.sc.code, zhiyoubao2_mq_dw.sc.name, zhiyoubao2_mq_dw.od.pay_method, zhiyoubao2_mq_dw.od.quantity, zhiyoubao2_mq_dw.od.already_check_num, zhiyoubao2_mq_dw.od.return_num, zhiyoubao2_m |
└─IndexMergeJoin_34 | 246.93 | root | left outer join, inner:IndexLookUp_32, outer key:substr(zhiyoubao2_mq_dw.oi.tel, 1, 7), inner key:zhiyoubao_zhiyoubao.p.code |
├─Projection_36 | 241.62 | root | zhiyoubao2_mq_dw.od.order_info_id, zhiyoubao2_mq_dw.od.order_type, zhiyoubao2_mq_dw.od.sale_corp_code, zhiyoubao2_mq_dw.od.already_check_num, zhiyoubao2_mq_dw.od.check_time, zhiyoubao2_mq_dw.od.goods_name, zhiyoubao2_mq_dw.od.total_price, zhiyoubao2_mq_dw |
│ └─IndexMergeJoin_45 | 241.62 | root | left outer join, inner:IndexLookUp_43, outer key:zybpd_zyb_product.sttm.scenic_id, inner key:zhiyoubao2_mq_dw.sc.id |
│ ├─HashLeftJoin_47 | 238.95 | root | left outer join, inner:TableReader_165, equal:[eq(zhiyoubao2_mq_dw.od.goods_code, zybpd_zyb_product.sttm.code)] |
│ │ ├─IndexMergeJoin_59 | 237.22 | root | inner join, inner:IndexLookUp_57, outer key:zhiyoubao2_mq_dw.od.corp_code, inner key:zhiyoubao2_mq_dw.fx.code |
│ │ │ ├─HashRightJoin_65 | 234.41 | root | inner join, inner:IndexMergeJoin_84, equal:[eq(zhiyoubao2_mq_dw.gy.code, zhiyoubao2_mq_dw.od.sale_corp_code)] |
│ │ │ │ ├─IndexMergeJoin_84 | 0.09 | root | inner join, inner:IndexLookUp_82, outer key:zhiyoubao_zhiyoubao.ecc.corp_id, inner key:zhiyoubao2_mq_dw.gy.id |
│ │ │ │ │ ├─HashRightJoin_99 | 0.08 | root | inner join, inner:IndexLookUp_108, equal:[eq(zhiyoubao_zhiyoubao.ec.id, zhiyoubao_zhiyoubao.ecc.ecological_company_id)] |
│ │ │ │ │ │ ├─IndexLookUp_108 | 0.07 | root | |
│ │ │ │ │ │ │ ├─IndexScan_106 | 0.07 | cop | table:ec, index:CODE, range:[“guizhgszhlyyxgs”,“guizhgszhlyyxgs”], keep order:false, stats:pseudo |
│ │ │ │ │ │ │ └─TableScan_107 | 0.07 | cop | table:ec, keep order:false, stats:pseudo |
│ │ │ │ │ │ └─TableReader_102 | 70.86 | root | data:Selection_101 |
│ │ │ │ │ │ └─Selection_101 | 70.86 | cop | not(isnull(zhiyoubao_zhiyoubao.ecc.corp_id)), not(isnull(zhiyoubao_zhiyoubao.ecc.ecological_company_id)) |
│ │ │ │ │ │ └─TableScan_100 | 71.00 | cop | table:ecc, range:[-inf,+inf], keep order:false, stats:pseudo |
│ │ │ │ │ └─IndexLookUp_82 | 1.00 | root | |
│ │ │ │ │ ├─IndexScan_79 | 1.00 | cop | table:gy, index:ID, range: decided by [eq(zhiyoubao2_mq_dw.gy.id, zhiyoubao_zhiyoubao.ecc.corp_id)], keep order:true |
│ │ │ │ │ └─Selection_81 | 1.00 | cop | not(isnull(zhiyoubao2_mq_dw.gy.code)) |
│ │ │ │ │ └─TableScan_80 | 1.00 | cop | table:gy, keep order:false |
│ │ │ │ └─IndexMergeJoin_124 | 2709.45 | root | left outer join, inner:IndexLookUp_122, outer key:zhiyoubao2_mq_dw.od.order_info_id, inner key:zhiyoubao2_mq_dw.oi.id |
│ │ │ │ ├─IndexLookUp_141 | 2709.45 | root | |
│ │ │ │ │ ├─IndexScan_138 | 3386.82 | cop | table:od, index:CREATE_TIME, range:[2019-10-31 15:50:32,2019-10-31 16:05:00], keep order:false |
│ │ │ │ │ └─Selection_140 | 2709.45 | cop | not(isnull(zhiyoubao2_mq_dw.od.corp_code)), not(isnull(zhiyoubao2_mq_dw.od.sale_corp_code)) |
│ │ │ │ │ └─TableScan_139 | 3386.82 | cop | table:od, keep order:false |
│ │ │ │ └─IndexLookUp_122 | 0.96 | root | |
│ │ │ │ ├─IndexScan_120 | 0.96 | cop | table:oi, index:ID, range: decided by [eq(zhiyoubao2_mq_dw.oi.id, zhiyoubao2_mq_dw.od.order_info_id)], keep order:true |
│ │ │ │ └─TableScan_121 | 0.96 | cop | table:oi, keep order:false |
│ │ │ └─IndexLookUp_57 | 1.00 | root | |
│ │ │ ├─Selection_56 | 1.00 | cop | not(isnull(zhiyoubao2_mq_dw.fx.code)) |
│ │ │ │ └─IndexScan_54 | 1.00 | cop | table:fx, index:CODE, range: decided by [eq(zhiyoubao2_mq_dw.fx.code, zhiyoubao2_mq_dw.od.corp_code)], keep order:true |
│ │ │ └─TableScan_55 | 1.00 | cop | table:fx, keep order:false |
│ │ └─TableReader_165 | 188782.00 | root | data:Selection_164 |
│ │ └─Selection_164 | 188782.00 | cop | not(isnull(zybpd_zyb_product.sttm.code)) |
│ │ └─TableScan_163 | 188782.00 | cop | table:sttm, range:[-inf,+inf], keep order:false |
│ └─IndexLookUp_43 | 1.00 | root | |
│ ├─IndexScan_41 | 1.00 | cop | table:sc, index:ID, range: decided by [eq(zhiyoubao2_mq_dw.sc.id, zybpd_zyb_product.sttm.scenic_id)], keep order:true |
│ └─TableScan_42 | 1.00 | cop | table:sc, keep order:false |
└─IndexLookUp_32 | 1.00 | root |
├─IndexScan_30 |1.00 |cop |table:p, index:CODE, range: decided by [eq(zhiyoubao_zhiyoubao.p.code, substr(zhiyoubao2_mq_dw.oi.tel, 1, 7))], keep order:true |
└─TableScan_31 |1.00 |cop |table:p, keep order:false |
两个执行计划除了count以外其他的是一模一样的
*查询出的结果用count(1)能看出是11条和12条,但是12条那个只要是查询具体字段,就没有任何值,好像是和join的方式有关,加上/*+ TIDB_HJ(oi,p) /使用hashjoin就都能出结果,但是sql会变得慢很多,有什么办法解决么0.0