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

*: refine mysql.tidb_mdl_view #48728

Merged
merged 10 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions pkg/infoschema/test/clustertablestest/cluster_tables_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import (
"github.com/pingcap/tidb/pkg/parser"
"github.com/pingcap/tidb/pkg/parser/auth"
"github.com/pingcap/tidb/pkg/parser/mysql"
"github.com/pingcap/tidb/pkg/privilege/privileges"
"github.com/pingcap/tidb/pkg/server"
"github.com/pingcap/tidb/pkg/store/helper"
"github.com/pingcap/tidb/pkg/store/mockstore"
Expand Down Expand Up @@ -842,6 +843,11 @@ func TestMDLView(t *testing.T) {
{"add column", "create table t(a int)", "alter table test.t add column b int", []string{"select 1", "select * from t"}, "[\"begin\",\"select ?\",\"select * from `t`\"]"},
{"change column in 1 step", "create table t(a int)", "alter table test.t change column a b int", []string{"select 1", "select * from t"}, "[\"begin\",\"select ?\",\"select * from `t`\"]"},
}
save := privileges.SkipWithGrant
privileges.SkipWithGrant = true
defer func() {
privileges.SkipWithGrant = save
}()
for _, c := range testCases {
t.Run(c.name, func(t *testing.T) {
// setup suite
Expand Down
29 changes: 20 additions & 9 deletions pkg/session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -459,19 +459,18 @@ const (
);`
// CreateMDLView is a view about metadata locks.
CreateMDLView = `CREATE OR REPLACE VIEW mysql.tidb_mdl_view as (
SELECT job_id,
SELECT ddl_jobs.job_id,
db_name,
table_name,
query,
session_id,
txnstart,
cluster_tidb_trx.start_time,
tidb_decode_sql_digests(all_sql_digests, 4096) AS SQL_DIGESTS
FROM information_schema.ddl_jobs,
information_schema.cluster_tidb_trx,
information_schema.cluster_processlist
WHERE (ddl_jobs.state != 'synced' and ddl_jobs.state != 'cancelled')
AND Find_in_set(ddl_jobs.table_id, cluster_tidb_trx.related_table_ids)
AND cluster_tidb_trx.session_id = cluster_processlist.id
mysql.tidb_mdl_info,
information_schema.cluster_tidb_trx
WHERE ddl_jobs.job_id = tidb_mdl_info.job_id
AND CONCAT(',', tidb_mdl_info.table_ids, ',') REGEXP CONCAT(',', REPLACE(cluster_tidb_trx.related_table_ids, ',', '|'), ',') != 0
);`

// CreatePlanReplayerStatusTable is a table about plan replayer status
Expand Down Expand Up @@ -1022,14 +1021,18 @@ const (
// write mDDLTableVersion into `mysql.tidb` table
version178 = 178

// vresion 179
// version 179
// enlarge `VARIABLE_VALUE` of `mysql.global_variables` from `varchar(1024)` to `varchar(16383)`.
version179 = 179

// version 180
// replace `mysql.tidb_mdl_view` table
version180 = 180
)

// currentBootstrapVersion is defined as a variable, so we can modify its value for testing.
// please make sure this is the largest version
var currentBootstrapVersion int64 = version179
var currentBootstrapVersion int64 = version180

// DDL owner key's expired time is ManagerSessionTTL seconds, we should wait the time and give more time to have a chance to finish it.
var internalSQLTimeout = owner.ManagerSessionTTL + 15
Expand Down Expand Up @@ -1184,6 +1187,7 @@ var (
upgradeToVer177,
upgradeToVer178,
upgradeToVer179,
upgradeToVer180,
}
)

Expand Down Expand Up @@ -2892,6 +2896,13 @@ func upgradeToVer179(s Session, ver int64) {
doReentrantDDL(s, "ALTER TABLE mysql.global_variables MODIFY COLUMN `VARIABLE_VALUE` varchar(16383)")
}

func upgradeToVer180(s Session, ver int64) {
if ver >= version180 {
return
}
doReentrantDDL(s, CreateMDLView)
}

func writeOOMAction(s Session) {
comment := "oom-action is `log` by default in v3.0.x, `cancel` by default in v4.0.11+"
mustExecute(s, `INSERT HIGH_PRIORITY INTO %n.%n VALUES (%?, %?, %?) ON DUPLICATE KEY UPDATE VARIABLE_VALUE= %?`,
Expand Down
1 change: 1 addition & 0 deletions pkg/sessionctx/variable/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -2084,6 +2084,7 @@ func NewSessionVars(hctx HookContext) *SessionVars {
if EnableRowLevelChecksum.Load() {
vars.EnableRowLevelChecksum = true
}
vars.systems[MaxAllowedPacket] = strconv.Itoa(int(DefMaxAllowedPacket))
Copy link
Contributor

Choose a reason for hiding this comment

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

Why change this?

Copy link
Member Author

Choose a reason for hiding this comment

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

So that we can use concat in UT

vars.systems[CharacterSetConnection], vars.systems[CollationConnection] = charset.GetDefaultCharsetAndCollate()
return vars
}
Expand Down