Skip to content

Commit

Permalink
executor: ignore non-found partitions in inner joins (#43763) (#43919)
Browse files Browse the repository at this point in the history
close #43686
  • Loading branch information
ti-chi-bot authored May 17, 2023
1 parent 9ac275e commit 53aa3fa
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
3 changes: 3 additions & 0 deletions executor/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3672,6 +3672,9 @@ func (builder *dataReaderBuilder) prunePartitionForInnerExecutor(tbl table.Table
locateKey[keyColOffsets[i]] = data
}
p, err := partitionTbl.GetPartitionByRow(builder.ctx, locateKey)
if table.ErrNoPartitionForGivenValue.Equal(err) {
continue
}
if err != nil {
return nil, false, nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion executor/partitiontest/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 = 4,
shard_count = 5,
deps = [
"//testkit",
"@com_github_pingcap_failpoint//:failpoint",
Expand Down
45 changes: 45 additions & 0 deletions executor/partitiontest/partition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,3 +447,48 @@ func TestPartitionedTableDelete(t *testing.T) {
tk.CheckExecResult(1, 0)
tk.MustExec(`drop table t1;`)
}

func TestPartitionOnMissing(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("create schema OnMissing")
tk.MustExec("use OnMissing")
tk.MustExec(`set global tidb_partition_prune_mode='dynamic'`)
tk.MustExec(`set session tidb_partition_prune_mode='dynamic'`)

tk.MustExec(`CREATE TABLE tt1 (
id INT NOT NULL,
listid INT,
name varchar(10)
)
PARTITION BY LIST (listid) (
PARTITION p1 VALUES IN (1),
PARTITION p2 VALUES IN (2),
PARTITION p3 VALUES IN (3),
PARTITION p4 VALUES IN (4)
)`)

tk.MustExec(`CREATE TABLE tt2 (
id INT NOT NULL,
listid INT
)`)

tk.MustExec(`create index idx_listid on tt1(id,listid)`)
tk.MustExec(`create index idx_listid on tt2(listid)`)

tk.MustExec(`insert into tt1 values(1,1,1)`)
tk.MustExec(`insert into tt1 values(2,2,2)`)
tk.MustExec(`insert into tt1 values(3,3,3)`)
tk.MustExec(`insert into tt1 values(4,4,4)`)
tk.MustExec(`insert into tt2 values(1,1)`)
tk.MustExec(`insert into tt2 values(2,2)`)
tk.MustExec(`insert into tt2 values(3,3)`)
tk.MustExec(`insert into tt2 values(4,4)`)
tk.MustExec(`insert into tt2 values(5,5)`)

tk.MustExec(`analyze table tt1`)
tk.MustExec(`analyze table tt2`)

tk.MustQuery(`select /*+ inl_join(tt1)*/ count(*) from tt2
left join tt1 on tt1.listid=tt2.listid and tt1.id=tt2.id`).Check(testkit.Rows("5"))
}

0 comments on commit 53aa3fa

Please sign in to comment.