pingcap / pingcap/tidb

there is an 'other cond' in hash join When using TiFlash

Open
#47,828 0 comments 0 reactions 0 assignees View on GitHub
sig/planner type/feature-request
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## Bug Report

Please answer these questions before submitting your issue. Thanks!

### 1. Minimal reproduce step (Required)
``` sql
CREATE TABLE `cfat_ledger_journal_bocs_zj_pl` (
`temp_rcrd_dt` char(8) NOT NULL COMMENT '记录日期',
`temp_acc_mdf_dt` char(8) NOT NULL COMMENT '临时_账户变更日期',
`temp_sys_time` char(9) NOT NULL COMMENT '临时_账户变更时间',
`core_sys_chnl_tp` char(1) NOT NULL COMMENT '核心系统渠道类型',
`core_sys_sn` char(9) NOT NULL COMMENT '核心系统流水号',
`jrne_with_sn` smallint(6) NOT NULL COMMENT '分录内序号',
`bocgp_inst_no` char(3) NOT NULL COMMENT '中银集团银行号',
`temp_txn_hpn_org_refno` char(5) DEFAULT NULL COMMENT '临时_交易发生机构编号',
`gnlld_code` char(25) NOT NULL COMMENT '总账代码',
`temp_txn_dt` char(8) DEFAULT NULL COMMENT '临时_交易日期',
`temp_txn_time` char(9) DEFAULT NULL COMMENT '临时_交易时间',
`temp_dep_accno` varchar(16) DEFAULT NULL COMMENT '临时_存款账号',
`temp_rvrs_flag` char(1) DEFAULT NULL COMMENT '临时_冲正标志',
`temp_mnplt_empe_refno` char(7) DEFAULT NULL COMMENT '临时_操作员工编号',
`temp_hmcy_amt` decimal(20,3) NOT NULL COMMENT '临时_本币金额',
`temp_frncy_amt` decimal(20,3) NOT NULL COMMENT '临时_外币金额',
`summ_des` varchar(300) DEFAULT NULL COMMENT '摘要描述',
`temp_ol_batch_idr` varchar(2) DEFAULT NULL COMMENT '临时_批量联机标志',
`promp` varchar(2) DEFAULT NULL COMMENT '提示码',
`last_mnt_dttm` datetime(3) DEFAULT NULL COMMENT '最后维护日期时间',
`last_mnt_sts_code` char(1) DEFAULT NULL COMMENT '最后维护状态代码',
PRIMARY KEY (`core_sys_sn`,`temp_rcrd_dt`,`temp_acc_mdf_dt`,`temp_sys_time`,`core_sys_chnl_tp`,`jrne_with_sn`,`bocgp_inst_no`) /*T![clustered_index] NONCLUSTERED */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T! SHARD_ROW_ID_BITS=5 PRE_SPLIT_REGIONS=5 */ COMMENT='核心会计传票信息表';

CREATE TABLE `cfat_ledger_journal_bocs_zj_sc` (
`temp_rcrd_dt` char(8) NOT NULL COMMENT '记录日期',
`temp_acc_mdf_dt` char(8) NOT NULL COMMENT '临时_账户变更日期',
`temp_sys_time` char(9) NOT NULL COMMENT '临时_账户变更时间',
`core_sys_chnl_tp` char(1) NOT NULL COMMENT '核心系统渠道类型',
`core_sys_sn` char(9) NOT NULL COMMENT '核心系统流水号',
`jrne_with_sn` smallint(6) NOT NULL COMMENT '分录内序号',
`bocgp_inst_no` char(3) NOT NULL COMMENT '中银集团银行号',
`temp_txn_hpn_org_refno` char(5) DEFAULT NULL COMMENT '临时_交易发生机构编号',
`gnlld_code` char(25) NOT NULL COMMENT '总账代码',
`temp_txn_dt` char(8) DEFAULT NULL COMMENT '临时_交易日期',
`temp_txn_time` char(9) DEFAULT NULL COMMENT '临时_交易时间',
`temp_dep_accno` varchar(16) DEFAULT NULL COMMENT '临时_存款账号',
`temp_rvrs_flag` char(1) DEFAULT NULL COMMENT '临时_冲正标志',
`temp_mnplt_empe_refno` char(7) DEFAULT NULL COMMENT '临时_操作员工编号',
`temp_hmcy_amt` decimal(20,3) NOT NULL COMMENT '临时_本币金额',
`temp_frncy_amt` decimal(20,3) NOT NULL COMMENT '临时_外币金额',
`summ_des` varchar(300) DEFAULT NULL COMMENT '摘要描述',
`temp_ol_batch_idr` varchar(2) DEFAULT NULL COMMENT '临时_批量联机标志',
`promp` varchar(2) DEFAULT NULL COMMENT '提示码',
`last_mnt_dttm` datetime(3) DEFAULT NULL COMMENT '最后维护日期时间',
`last_mnt_sts_code` char(1) DEFAULT NULL COMMENT '最后维护状态代码',
PRIMARY KEY (`core_sys_sn`,`temp_rcrd_dt`,`temp_acc_mdf_dt`,`temp_sys_time`,`core_sys_chnl_tp`,`jrne_with_sn`,`bocgp_inst_no`) /*T![clustered_index] NONCLUSTERED */,
KEY `idx_gnlld_code` (`gnlld_code`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin /*T! SHARD_ROW_ID_BITS=5 PRE_SPLIT_REGIONS=5 */ COMMENT='核心会计传票信息表'

alter table cfat_ledger_journal_bocs_zj_pl set tiflash replica 1;
alter table cfat_ledger_journal_bocs_zj_sc set tiflash replica 1;

SELECT
/*+ read_from_storage(tiflash[a]) */
SUBSTRING(a.gnlld_code, 13, 4) AS accd ,
COUNT(1) AS COUNT
FROM
`cfat_ledger_journal_bocs_zj_pl` AS a
WHERE
EXISTS (
SELECT
/*+ read_from_storage(tiflash[b]) */
1
FROM
cfat_ledger_journal_bocs_zj_sc b
WHERE
b.`bocgp_inst_no` = '003'
AND a.`gnlld_code` = b.`gnlld_code`
AND IF(SUBSTRING(a.gnlld_code, 6, 3) = 'CNY' ,
a.temp_hmcy_amt ,
a.temp_frncy_amt) = IF(SUBSTRING(b.gnlld_code, 6, 3) = 'CNY' ,
b.temp_hmcy_amt ,
b.temp_frncy_amt)
AND b.`temp_rcrd_dt` = '20230920' )
AND a.bocgp_inst_no = '003'
AND a.`temp_ol_batch_idr` = 'OL'
AND a.`temp_rcrd_dt` = '20230920'
GROUP BY
accd
ORDER BY
COUNT DESC
```

### 2. What did you expect to see? (Required)
there is no `other cond` in HashJoin, it should be `equal:`

### 3. What did you see instead (Required)
there is `other cond` in HashJoin, relevant oncall: ONCALL-6513
``` sql
Projection_14 1.00 root substring(cact_db_uat.cfat_ledger_journal_bocs_zj_pl.gnlld_code, 13, 4)->Column#47, Column#46
└─TopN_17 1.00 root Column#46:desc, offset:0, count:200
└─TableReader_60 1.00 root data:ExchangeSender_59
└─ExchangeSender_59 1.00 mpp[tiflash] ExchangeType: PassThrough
└─Projection_55 1.00 mpp[tiflash] Column#46, cact_db_uat.cfat_ledger_journal_bocs_zj_pl.gnlld_code
└─HashAgg_56 1.00 mpp[tiflash] group by:Column#53, funcs:sum(Column#54)->Column#46, funcs:firstrow(Column#55)->cact_db_uat.cfat_ledger_journal_bocs_zj_pl.gnlld_code
└─ExchangeReceiver_58 1.00 mpp[tiflash]
└─ExchangeSender_57 1.00 mpp[tiflash] ExchangeType: HashPartition, Hash Cols: [name: Column#53, collate: utf8mb4_bin]
└─HashAgg_25 1.00 mpp[tiflash] group by:Column#63, funcs:count(1)->Column#54, funcs:firstrow(Column#62)->Column#55
└─Projection_72 7.66 mpp[tiflash] cact_db_uat.cfat_ledger_journal_bocs_zj_pl.gnlld_code, substring(cact_db_uat.cfat_ledger_journal_bocs_zj_pl.gnlld_code, 13, 4)->Column#63
└─HashJoin_54 7.66 mpp[tiflash] semi join, equal:[eq(cact_db_uat.cfat_ledger_journal_bocs_zj_pl.gnlld_code, cact_db_uat.cfat_ledger_journal_bocs_zj_sc.gnlld_code) eq(Column#49, Column#50)], other cond:eq(if(eq(substring(cact_db_uat.cfat_ledger_journal_bocs_zj_pl.gnlld_code, 6, 3), "CNY"), cact_db_uat.cfat_ledger_journal_bocs_zj_pl.temp_hmcy_amt, cact_db_uat.cfat_ledger_journal_bocs_zj_pl.temp_frncy_amt), if(eq(substring(cact_db_uat.cfat_ledger_journal_bocs_zj_pl.gnlld_code, 6, 3), "CNY"), cact_db_uat.cfat_ledger_journal_bocs_zj_sc.temp_hmcy_amt, cact_db_uat.cfat_ledger_journal_bocs_zj_sc.temp_frncy_amt)), eq(if(eq(substring(cact_db_uat.cfat_ledger_journal_bocs_zj_sc.gnlld_code, 6, 3), "CNY"), cact_db_uat.cfat_ledger_journal_bocs_zj_pl.temp_hmcy_amt, cact_db_uat.cfat_ledger_journal_bocs_zj_pl.temp_frncy_amt), if(eq(substring(cact_db_uat.cfat_ledger_journal_bocs_zj_sc.gnlld_code, 6, 3), "CNY"), cact_db_uat.cfat_ledger_journal_bocs_zj_sc.temp_hmcy_amt, cact_db_uat.cfat_ledger_journal_bocs_zj_sc.temp_frncy_amt))
├─ExchangeReceiver_37(Build) 92.70 mpp[tiflash]
│ └─ExchangeSender_36 92.70 mpp[tiflash] ExchangeType: Broadcast
│ └─Projection_33 92.70 mpp[tiflash] cact_db_uat.cfat_ledger_journal_bocs_zj_sc.gnlld_code, cact_db_uat.cfat_ledger_journal_bocs_zj_sc.temp_hmcy_amt, cact_db_uat.cfat_ledger_journal_bocs_zj_sc.temp_frncy_amt, if(eq(substring(cact_db_uat.cfat_ledger_journal_bocs_zj_sc.gnlld_code, 6, 3), CNY), cact_db_uat.cfat_ledger_journal_bocs_zj_sc.temp_hmcy_amt, cact_db_uat.cfat_ledger_journal_bocs_zj_sc.temp_frncy_amt)->Column#50
│ └─Selection_35 92.70 mpp[tiflash] eq(cact_db_uat.cfat_ledger_journal_bocs_zj_sc.bocgp_inst_no, "003"), eq(cact_db_uat.cfat_ledger_journal_bocs_zj_sc.temp_rcrd_dt, "20230920")
│ └─TableFullScan_34 92699781.00 mpp[tiflash] table:b keep order:false
└─Projection_29(Probe) 9.58 mpp[tiflash] cact_db_uat.cfat_ledger_journal_bocs_zj_pl.gnlld_code, cact_db_uat.cfat_ledger_journal_bocs_zj_pl.temp_hmcy_amt, cact_db_uat.cfat_ledger_journal_bocs_zj_pl.temp_frncy_amt, if(eq(substring(cact_db_uat.cfat_ledger_journal_bocs_zj_pl.gnlld_code, 6, 3), CNY), cact_db_uat.cfat_ledger_journal_bocs_zj_pl.temp_hmcy_amt, cact_db_uat.cfat_ledger_journal_bocs_zj_pl.temp_frncy_amt)->Column#49
└─Selection_31 9.58 mpp[tiflash] eq(cact_db_uat.cfat_ledger_journal_bocs_zj_pl.bocgp_inst_no, "003"), eq(cact_db_uat.cfat_ledger_journal_bocs_zj_pl.temp_ol_batch_idr, "OL"), eq(cact_db_uat.cfat_ledger_journal_bocs_zj_pl.temp_rcrd_dt, "20230920")
└─TableFullScan_30 42915759.00 mpp[tiflash] table:a keep order:false
```

### 4. What is your TiDB version? (Required)
v6.5.2

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.