Skip to content
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
2 changes: 1 addition & 1 deletion pkg/domain/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ go_library(
"//pkg/util/sqlexec",
"//pkg/util/sqlkiller",
"//pkg/util/syncutil",
"//pkg/workloadbasedlearning",
"//pkg/workloadlearning",
"@com_github_burntsushi_toml//:toml",
"@com_github_ngaut_pools//:pools",
"@com_github_pingcap_errors//:errors",
Expand Down
8 changes: 4 additions & 4 deletions pkg/domain/domain.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ import (
"github.com/pingcap/tidb/pkg/util/size"
"github.com/pingcap/tidb/pkg/util/sqlkiller"
"github.com/pingcap/tidb/pkg/util/syncutil"
"github.com/pingcap/tidb/pkg/workloadbasedlearning"
"github.com/pingcap/tidb/pkg/workloadlearning"
"github.com/tikv/client-go/v2/tikv"
"github.com/tikv/client-go/v2/txnkv/transaction"
pd "github.com/tikv/pd/client"
Expand Down Expand Up @@ -3394,7 +3394,7 @@ func (do *Domain) planCacheEvictTrigger() {

// SetupWorkloadBasedLearningWorker sets up all of the workload based learning workers.
func (do *Domain) SetupWorkloadBasedLearningWorker() {
wbLearningHandle := workloadbasedlearning.NewWorkloadBasedLearningHandle()
wbLearningHandle := workloadlearning.NewWorkloadLearningHandle(do.sysSessionPool)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed to short the pkg name as wbl as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has been discuss in our group. We will use the workloadlearning uniform

// Start the workload based learning worker to analyze the read workload by statement_summary.
do.wg.Run(
func() {
Expand All @@ -3406,7 +3406,7 @@ func (do *Domain) SetupWorkloadBasedLearningWorker() {
}

// readTableCostWorker is a background worker that periodically analyze the read path table cost by statement_summary.
func (do *Domain) readTableCostWorker(wbLearningHandle *workloadbasedlearning.Handle) {
func (do *Domain) readTableCostWorker(wbLearningHandle *workloadlearning.Handle) {
// Recover the panic and log the error when worker exit.
defer util.Recover(metrics.LabelDomain, "readTableCostWorker", nil, false)
readTableCostTicker := time.NewTicker(vardef.WorkloadBasedLearningInterval.Load())
Expand All @@ -3418,7 +3418,7 @@ func (do *Domain) readTableCostWorker(wbLearningHandle *workloadbasedlearning.Ha
select {
case <-readTableCostTicker.C:
if vardef.EnableWorkloadBasedLearning.Load() && do.statsOwner.IsOwner() {
wbLearningHandle.HandleReadTableCost()
wbLearningHandle.HandleReadTableCost(do.InfoSchema())
}
case <-do.exit:
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/importer/importer_testkit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ func TestProcessChunkWith(t *testing.T) {
require.NoError(t, err)
checksumMap := checksum.GetInnerChecksums()
require.Len(t, checksumMap, 1)
require.Equal(t, verify.MakeKVChecksum(111, 3, 14585065391351463171), *checksumMap[verify.DataKVGroupID])
require.Equal(t, verify.MakeKVChecksum(111, 3, 17951921359894607752), *checksumMap[verify.DataKVGroupID])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why this is changed

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as following

})
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/executor/infoschema_cluster_table_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,7 @@ func TestTableStorageStats(t *testing.T) {
"test 2",
))
rows := tk.MustQuery("select TABLE_NAME from information_schema.TABLE_STORAGE_STATS where TABLE_SCHEMA = 'mysql';").Rows()
result := 58
result := 59
require.Len(t, rows, result)

// More tests about the privileges.
Expand Down
30 changes: 15 additions & 15 deletions pkg/executor/infoschema_reader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,22 +920,22 @@ func TestInfoSchemaDDLJobs(t *testing.T) {
tk2 := testkit.NewTestKit(t, store)
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE table_name = "t1";`).Check(testkit.RowsWithSep("|",
"131|add index|public|124|129|t1|synced",
"130|create table|public|124|129|t1|synced",
"117|add index|public|110|115|t1|synced",
"116|create table|public|110|115|t1|synced",
"133|add index|public|126|131|t1|synced",
"132|create table|public|126|131|t1|synced",
"119|add index|public|112|117|t1|synced",
"118|create table|public|112|117|t1|synced",
))
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE db_name = "d1" and JOB_TYPE LIKE "add index%%";`).Check(testkit.RowsWithSep("|",
"137|add index|public|124|135|t3|synced",
"134|add index|public|124|132|t2|synced",
"131|add index|public|124|129|t1|synced",
"128|add index|public|124|126|t0|synced",
"139|add index|public|126|137|t3|synced",
"136|add index|public|126|134|t2|synced",
"133|add index|public|126|131|t1|synced",
"130|add index|public|126|128|t0|synced",
))
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE db_name = "d0" and table_name = "t3";`).Check(testkit.RowsWithSep("|",
"123|add index|public|110|121|t3|synced",
"122|create table|public|110|121|t3|synced",
"125|add index|public|112|123|t3|synced",
"124|create table|public|112|123|t3|synced",
))
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE state = "running";`).Check(testkit.Rows())
Expand All @@ -946,15 +946,15 @@ func TestInfoSchemaDDLJobs(t *testing.T) {
if job.SchemaState == model.StateWriteOnly && loaded.CompareAndSwap(false, true) {
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE table_name = "t0" and state = "running";`).Check(testkit.RowsWithSep("|",
"138 add index write only 110 112 t0 running",
"140 add index write only 112 114 t0 running",
))
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE db_name = "d0" and state = "running";`).Check(testkit.RowsWithSep("|",
"138 add index write only 110 112 t0 running",
"140 add index write only 112 114 t0 running",
))
tk2.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE state = "running";`).Check(testkit.RowsWithSep("|",
"138 add index write only 110 112 t0 running",
"140 add index write only 112 114 t0 running",
))
}
})
Expand All @@ -970,8 +970,8 @@ func TestInfoSchemaDDLJobs(t *testing.T) {
tk.MustExec("create table test2.t1(id int)")
tk.MustQuery(`SELECT JOB_ID, JOB_TYPE, SCHEMA_STATE, SCHEMA_ID, TABLE_ID, table_name, STATE
FROM information_schema.ddl_jobs WHERE db_name = "test2" and table_name = "t1"`).Check(testkit.RowsWithSep("|",
"147|create table|public|144|146|t1|synced",
"142|create table|public|139|141|t1|synced",
"149|create table|public|146|148|t1|synced",
"144|create table|public|141|143|t1|synced",
))

// Test explain output, since the output may change in future.
Expand Down
12 changes: 6 additions & 6 deletions pkg/expression/integration_test/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1752,18 +1752,18 @@ func TestTiDBEncodeKey(t *testing.T) {
err := tk.QueryToErr("select tidb_encode_record_key('test', 't1', 0);")
require.ErrorContains(t, err, "doesn't exist")
tk.MustQuery("select tidb_encode_record_key('test', 't', 1);").
Check(testkit.Rows("74800000000000006e5f728000000000000001"))
Check(testkit.Rows("7480000000000000705f728000000000000001"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why EncodeKeyTest is changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because I added a new system table.


tk.MustExec("alter table t add index i(b);")
err = tk.QueryToErr("select tidb_encode_index_key('test', 't', 'i1', 1);")
require.ErrorContains(t, err, "index not found")
tk.MustQuery("select tidb_encode_index_key('test', 't', 'i', 1, 1);").
Check(testkit.Rows("74800000000000006e5f698000000000000001038000000000000001038000000000000001"))
Check(testkit.Rows("7480000000000000705f698000000000000001038000000000000001038000000000000001"))

tk.MustExec("create table t1 (a int primary key, b int) partition by hash(a) partitions 4;")
tk.MustExec("insert into t1 values (1, 1);")
tk.MustQuery("select tidb_encode_record_key('test', 't1(p1)', 1);").Check(testkit.Rows("7480000000000000735f728000000000000001"))
rs := tk.MustQuery("select tidb_mvcc_info('74800000000000006f5f728000000000000001');")
tk.MustQuery("select tidb_encode_record_key('test', 't1(p1)', 1);").Check(testkit.Rows("7480000000000000755f728000000000000001"))
rs := tk.MustQuery("select tidb_mvcc_info('74800000000000007f5f728000000000000001');")
mvccInfo := rs.Rows()[0][0].(string)
require.NotEqual(t, mvccInfo, `{"info":{}}`)

Expand All @@ -1772,14 +1772,14 @@ func TestTiDBEncodeKey(t *testing.T) {
tk2 := testkit.NewTestKit(t, store)
err = tk2.Session().Auth(&auth.UserIdentity{Username: "alice", Hostname: "localhost"}, nil, nil, nil)
require.NoError(t, err)
err = tk2.QueryToErr("select tidb_mvcc_info('74800000000000006f5f728000000000000001');")
err = tk2.QueryToErr("select tidb_mvcc_info('74800000000000007f5f728000000000000001');")
require.ErrorContains(t, err, "Access denied")
err = tk2.QueryToErr("select tidb_encode_record_key('test', 't1(p1)', 1);")
require.ErrorContains(t, err, "SELECT command denied")
err = tk2.QueryToErr("select tidb_encode_index_key('test', 't', 'i1', 1);")
require.ErrorContains(t, err, "SELECT command denied")
tk.MustExec("grant select on test.t1 to 'alice'@'%';")
tk2.MustQuery("select tidb_encode_record_key('test', 't1(p1)', 1);").Check(testkit.Rows("7480000000000000735f728000000000000001"))
tk2.MustQuery("select tidb_encode_record_key('test', 't1(p1)', 1);").Check(testkit.Rows("7480000000000000755f728000000000000001"))
}

func TestIssue9710(t *testing.T) {
Expand Down
2 changes: 2 additions & 0 deletions pkg/kv/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ const (
InternalTxnStats = "stats"
// InternalTxnBindInfo is the type of bind info txn.
InternalTxnBindInfo = InternalTxnOthers
// InternalTxnWorkloadLearning is the type of workload-based learning txn.
InternalTxnWorkloadLearning = "WorkloadLearning"
// InternalTxnSysVar is the type of sys var txn.
InternalTxnSysVar = InternalTxnOthers
// InternalTxnAdmin is the type of admin operations.
Expand Down
20 changes: 17 additions & 3 deletions pkg/session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -759,7 +759,7 @@ const (
extra json, -- for the cloud env to save more info like RU, cost_saving, ...
index idx_create(created_at),
index idx_update(updated_at),
unique index idx(schema_name, table_name, index_columns))`
unique index idx(schema_name, table_name, index_columns));`

// CreateKernelOptionsTable is a table to store kernel options for tidb.
CreateKernelOptionsTable = `CREATE TABLE IF NOT EXISTS mysql.tidb_kernel_options (
Expand All @@ -769,7 +769,18 @@ const (
updated_at datetime,
status varchar(128),
description text,
primary key(module, name))`
primary key(module, name));`

// CreateTiDBWorkloadValuesTable is a table to store workload-based learning values for tidb.
CreateTiDBWorkloadValuesTable = `CREATE TABLE IF NOT EXISTS mysql.tidb_workload_values (
id bigint(20) NOT NULL AUTO_INCREMENT PRIMARY KEY,
version bigint(20) NOT NULL,
category varchar(64) NOT NULL,
type varchar(64) NOT NULL,
table_id bigint(20) NOT NULL,
value json NOT NULL,
index idx_version_category_type (version, category, type),
index idx_table_id (table_id));`
)

// CreateTimers is a table to store all timers for tidb
Expand Down Expand Up @@ -1247,6 +1258,7 @@ const (

// version 242
// insert `cluster_id` into the `mysql.tidb` table.
// Add workload-based learning system tables
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

v242 is introduced by #59511 recently, better to add a temporary comment which will be reduced when WBL is ready to go. In case of the author will curious about the change

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid unnecessary version growth, I will share this version before releasing it.

version242 = 242
)

Expand Down Expand Up @@ -3345,8 +3357,8 @@ func upgradeToVer242(s sessiontypes.Session, ver int64) {
if ver >= version242 {
return
}

writeClusterID(s)
mustExecute(s, CreateTiDBWorkloadValuesTable)
}

// initGlobalVariableIfNotExists initialize a global variable with specific val if it does not exist.
Expand Down Expand Up @@ -3503,6 +3515,8 @@ func doDDLWorks(s sessiontypes.Session) {
mustExecute(s, CreateIndexAdvisorTable)
// create mysql.tidb_kernel_options
mustExecute(s, CreateKernelOptionsTable)
// create mysql.tidb_workload_values
mustExecute(s, CreateTiDBWorkloadValuesTable)
}

// doBootstrapSQLFile executes SQL commands in a file as the last stage of bootstrap.
Expand Down
2 changes: 2 additions & 0 deletions pkg/session/bootstrap_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ func TestBootstrapWithError(t *testing.T) {

// Check tidb_ttl_table_status table
MustExec(t, se, "SELECT * from mysql.tidb_ttl_table_status")
// Check mysql.tidb_workload_values table
MustExec(t, se, "SELECT * from mysql.tidb_workload_values")
}

func TestDDLTableCreateBackfillTable(t *testing.T) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,14 @@ func TestValidateAndPrepareForDynamicPartitionedTable(t *testing.T) {
tk.MustExec("create table example_table (a int, b int, index idx(a)) partition by range (a) (partition p0 values less than (2), partition p1 values less than (4))")
tableInfo, err := dom.InfoSchema().TableByName(context.Background(), ast.NewCIStr("example_schema"), ast.NewCIStr("example_table"))
require.NoError(t, err)
partitionInfo := tableInfo.Meta().GetPartitionInfo()
require.NotNil(t, partitionInfo)
job := &priorityqueue.DynamicPartitionedTableAnalysisJob{
SchemaName: "example_schema",
GlobalTableID: tableInfo.Meta().ID,
PartitionIDs: map[int64]struct{}{
113: {},
114: {},
partitionInfo.Definitions[0].ID: {},
partitionInfo.Definitions[1].ID: {},
},
Weight: 2,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func testConcurrentlyInitStats(t *testing.T) {
require.False(t, col.IsAllEvicted())
}
}
require.Equal(t, int64(126), handle.GetMaxTidRecordForTest())
require.Equal(t, int64(128), handle.GetMaxTidRecordForTest())
}

func TestDropTableBeforeConcurrentlyInitStats(t *testing.T) {
Expand Down
11 changes: 0 additions & 11 deletions pkg/workloadbasedlearning/BUILD.bazel

This file was deleted.

91 changes: 0 additions & 91 deletions pkg/workloadbasedlearning/handle.go

This file was deleted.

Loading