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: add test for issue 45279 #45606

Closed
Closed
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
9 changes: 8 additions & 1 deletion executor/index_merge_reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ import (
)

var (
_ exec.Executor = &IndexMergeReaderExecutor{}
_ exec.Executor = &IndexMergeReaderExecutor{}
TestContextCancelFunc func()
)

const (
Expand Down Expand Up @@ -860,6 +861,9 @@ func (e *IndexMergeReaderExecutor) getResultTask(ctx context.Context) (*indexMer

func handleWorkerPanic(ctx context.Context, finished <-chan struct{}, ch chan<- *indexMergeTableTask, extraNotifyCh chan bool, worker string) func(r interface{}) {
return func(r interface{}) {
failpoint.Inject("testChangeProcessWorkerType", func() {
worker = ""
})
if worker == processWorkerType {
// There is only one processWorker, so it's safe to close here.
// No need to worry about "close on closed channel" error.
Expand Down Expand Up @@ -1206,6 +1210,9 @@ func (w *indexMergeProcessWorker) fetchLoopUnion(ctx context.Context, fetchCh <-
case <-finished:
return
case resultCh <- task:
failpoint.Inject("testCancelContext", func() {
TestContextCancelFunc()
})
}
}
}
Expand Down
28 changes: 28 additions & 0 deletions executor/test/indexmergereadtest/index_merge_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package indexmergereadtest

import (
"context"
"fmt"
"math/rand"
"regexp"
Expand All @@ -25,6 +26,8 @@ import (
"time"

"github.com/pingcap/failpoint"
"github.com/pingcap/tidb/executor"
"github.com/pingcap/tidb/session"
"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/testkit/testutil"
"github.com/pingcap/tidb/util"
Expand Down Expand Up @@ -1164,3 +1167,28 @@ func TestProcessInfoRaceWithIndexScan(t *testing.T) {
}
wg.Wait()
}

func TestIndexMergeReaderIssue45279(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("use test")

tk.MustExec("drop table if exists reproduce;")
tk.MustExec("CREATE TABLE reproduce (c1 int primary key, c2 int, c3 int, key ci2(c2), key ci3(c3));")
tk.MustExec("insert into reproduce values (1, 1, 1), (2, 2, 2), (3, 3, 3);")
tk.MustQuery("explain select * from reproduce where c1 in (0, 1, 2, 3) or c2 in (0, 1, 2);").Check(testkit.Rows(
"IndexMerge_11 33.99 root type: union",
"├─TableRangeScan_8(Build) 4.00 cop[tikv] table:reproduce range:[0,0], [1,1], [2,2], [3,3], keep order:false, stats:pseudo",
"├─IndexRangeScan_9(Build) 30.00 cop[tikv] table:reproduce, index:ci2(c2) range:[0,0], [1,1], [2,2], keep order:false, stats:pseudo",
"└─TableRowIDScan_10(Probe) 33.99 cop[tikv] table:reproduce keep order:false, stats:pseudo"))

// This function should return successfully
var ctx context.Context
ctx, executor.TestContextCancelFunc = context.WithCancel(context.Background())
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/executor/testCancelContext", "return()"))
require.NoError(t, failpoint.Enable("github.com/pingcap/tidb/executor/testChangeProcessWorkerType", "return()"))
rs, _ := tk.ExecWithContext(ctx, "select /*+ use_index_merge(reproduce) */ * from reproduce where (c1 < 10 or c2 < 10) and c3 < 10;")
session.ResultSetToStringSlice(ctx, tk.Session(), rs)
failpoint.Disable("github.com/pingcap/tidb/br/pkg/checksum/testChangeProcessWorkerType")
failpoint.Disable("github.com/pingcap/tidb/br/pkg/checksum/testCancelContext")
}