Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

executor: Fix index join hash produces redundant rows for left outer anti semi join type #52908

Merged
merged 1 commit into from
Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions pkg/executor/index_lookup_hash_join.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/pkg/executor/internal/exec"
"github.com/pingcap/tidb/pkg/expression"
plannercore "github.com/pingcap/tidb/pkg/planner/core"
"github.com/pingcap/tidb/pkg/types"
"github.com/pingcap/tidb/pkg/util"
"github.com/pingcap/tidb/pkg/util/channel"
Expand Down Expand Up @@ -736,7 +735,7 @@ func (iw *indexHashJoinInnerWorker) getMatchedOuterRows(innerRow chunk.Row, task
return nil, nil, nil
}
joinType := JoinerType(iw.joiner)
isSemiJoin := joinType == plannercore.SemiJoin || joinType == plannercore.LeftOuterSemiJoin
isSemiJoin := joinType.IsSemiJoin()
for ; matchedOuterEntry != nil; matchedOuterEntry = matchedOuterEntry.next {
ptr := matchedOuterEntry.ptr
outerRow := task.outerResult.GetRow(ptr)
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/test/jointest/hashjoin/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ go_test(
],
flaky = True,
race = "on",
shard_count = 10,
shard_count = 11,
deps = [
"//pkg/config",
"//pkg/meta/autoid",
Expand Down
25 changes: 25 additions & 0 deletions pkg/executor/test/jointest/hashjoin/hash_join_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,31 @@ func TestIndexNestedLoopHashJoin(t *testing.T) {
tk.MustExec("drop table orders")
}

func TestIssue52902(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
// index hash join with semi join
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/pkg/planner/core/MockOnlyEnableIndexHashJoin", "return(true)"))
defer func() {
require.NoError(t, failpoint.Disable("github.com/pingcap/tidb/pkg/planner/core/MockOnlyEnableIndexHashJoin"))
}()
tk.MustExec("use test")
tk.MustExec("drop table if exists t0")
tk.MustExec("drop table if exists t1")
tk.MustExec("create table t1 (x int, y int)")
tk.MustExec("create table t0 (a int, b int, key (`b`))")
tk.MustExec("insert into t1 values(103, 600)")
tk.MustExec("insert into t1 values(100, 200)")
tk.MustExec("insert into t0 values( 105, 400)")
tk.MustExec("insert into t0 values( 104, 300)")
tk.MustExec("insert into t0 values( 103, 300)")
tk.MustExec("insert into t0 values( 102, 200)")
tk.MustExec("insert into t0 values( 101, 200)")
tk.MustExec("insert into t0 values( 100, 200)")
tk.MustQuery("select * from t1 where 1 = 1 and case when t1.x < 1000 then 1 = 1 " +
"when t1.x < 2000 then not exists (select 1 from t0 where t0.b = t1.y) else 1 = 1 end").Check(testkit.Rows("100 200", "103 600"))
}

func TestHashJoin(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
Expand Down