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

tests/realtikvtest: add tests for adding index #37320

Merged
merged 7 commits into from
Aug 23, 2022
Merged
Show file tree
Hide file tree
Changes from 5 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
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -460,3 +460,7 @@ bazel_statisticstest: failpoint-enable bazel_ci_prepare
bazel_txntest: failpoint-enable bazel_ci_prepare
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv \
-- //tests/realtikvtest/txntest/...

bazel_addindextest: failpoint-enable bazel_ci_prepare
bazel $(BAZEL_GLOBAL_CONFIG) test $(BAZEL_CMD_CONFIG) --test_arg=-with-real-tikv \
-- //tests/realtikvtest/addindextest/...
2 changes: 1 addition & 1 deletion sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -794,7 +794,7 @@ const (
// when a single SQL statement exceeds the memory quota specified by the memory quota.
TiDBEnableTmpStorageOnOOM = "tidb_enable_tmp_storage_on_oom"
// TiDBDDLEnableFastReorg indicates whether to use lighting backfill process for adding index.
TiDBDDLEnableFastReorg = "tidb_ddl_fast_reorg"
TiDBDDLEnableFastReorg = "tidb_ddl_enable_fast_reorg"
// TiDBDDLDiskQuota used to set disk quota for lightning add index.
TiDBDDLDiskQuota = "tidb_ddl_disk_quota"
)
Expand Down
31 changes: 31 additions & 0 deletions tests/realtikvtest/addindextest/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "addindextest",
srcs = [
"common.go",
"workload.go",
],
importpath = "github.com/pingcap/tidb/tests/realtikvtest/addindextest",
visibility = ["//visibility:public"],
deps = [
"//kv",
"//testkit",
"//util/logutil",
"@com_github_stretchr_testify//require",
"@org_uber_go_zap//:zap",
],
)

go_test(
name = "addindextest_test",
srcs = [
"add_index_test.go",
"main_test.go",
],
embed = [":addindextest"],
deps = [
"//testkit",
"//tests/realtikvtest",
],
)
82 changes: 82 additions & 0 deletions tests/realtikvtest/addindextest/add_index_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2022 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package addindextest

import (
"testing"

"github.com/pingcap/tidb/testkit"
"github.com/pingcap/tidb/tests/realtikvtest"
)

func initTest(t *testing.T) *suiteContext {
store := realtikvtest.CreateMockStoreAndSetup(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec("drop database if exists addindex;")
tk.MustExec("create database addindex;")
tk.MustExec("use addindex;")
tk.MustExec(`set global tidb_ddl_enable_fast_reorg=on;`)

ctx := newSuiteContext(t, tk, store)
createTable(tk)
insertRows(tk)
initWorkloadParams(ctx)
return ctx
}

func TestCreateNonUniqueIndex(t *testing.T) {
var colIDs = [][]int{
{1, 4, 7, 10, 13, 16, 19, 22, 25},
{2, 5, 8, 11, 14, 17, 20, 23, 26},
{3, 6, 9, 12, 15, 18, 21, 24, 27},
}
ctx := initTest(t)
testOneColFrame(ctx, colIDs, addIndexNonUnique)
}

func TestCreateUniqueIndex(t *testing.T) {
var colIDs [][]int = [][]int{
{1, 6, 7, 8, 11, 13, 15, 16, 18, 19, 22, 26},
{2, 9, 11, 17},
{3, 12, 25},
}
ctx := initTest(t)
testOneColFrame(ctx, colIDs, addIndexUnique)
}

func TestCreatePrimaryKey(t *testing.T) {
ctx := initTest(t)
testOneIndexFrame(ctx, 0, addIndexPK)
}

func TestCreateGenColIndex(t *testing.T) {
ctx := initTest(t)
testOneIndexFrame(ctx, 29, addIndexGenCol)
}

func TestCreateMultiColsIndex(t *testing.T) {
var coliIDs = [][]int{
{1, 4, 7, 10, 13},
{2, 5, 8, 11},
{3, 6, 9, 12, 15},
}
var coljIDs = [][]int{
{16, 19, 22, 25},
{14, 17, 20, 23, 26},
{18, 21, 24, 27},
}
ctx := initTest(t)
testTwoColsFrame(ctx, coliIDs, coljIDs, addIndexMultiCols)
}
Loading