Skip to content

Commit ee308e7

Browse files
authored
session: fix initGlobalVariableIfNotExists function forget call rs.close (#61890) (#61905)
close #61884
1 parent 4578b4f commit ee308e7

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

pkg/session/bootstrap.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,13 +3266,9 @@ func upgradeToVer220(s sessiontypes.Session, ver int64) {
32663266
// initGlobalVariableIfNotExists initialize a global variable with specific val if it does not exist.
32673267
func initGlobalVariableIfNotExists(s sessiontypes.Session, name string, val any) {
32683268
ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnBootstrap)
3269-
rs, err := s.ExecuteInternal(ctx, "SELECT VARIABLE_VALUE FROM %n.%n WHERE VARIABLE_NAME=%?;",
3270-
mysql.SystemDB, mysql.GlobalVariablesTable, name)
3271-
terror.MustNil(err)
3272-
req := rs.NewChunk(nil)
3273-
err = rs.Next(ctx, req)
3269+
rows, err := sqlexec.ExecSQL(ctx, s, "SELECT VARIABLE_VALUE FROM %n.%n WHERE VARIABLE_NAME=%?;", mysql.SystemDB, mysql.GlobalVariablesTable, name)
32743270
terror.MustNil(err)
3275-
if req.NumRows() != 0 {
3271+
if len(rows) != 0 {
32763272
return
32773273
}
32783274

pkg/session/bootstrap_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2476,6 +2476,20 @@ func TestTiDBUpgradeToVer212(t *testing.T) {
24762476
MustExec(t, seCurVer, "select sample_sql, start_time, plan_digest from mysql.tidb_runaway_queries")
24772477
}
24782478

2479+
func TestIssue61890(t *testing.T) {
2480+
store, dom := CreateStoreAndBootstrap(t)
2481+
defer func() { require.NoError(t, store.Close()) }()
2482+
2483+
s1 := CreateSessionAndSetID(t, store)
2484+
MustExec(t, s1, "drop table mysql.global_variables")
2485+
MustExec(t, s1, "create table mysql.global_variables(`VARIABLE_NAME` varchar(64) NOT NULL PRIMARY KEY clustered, `VARIABLE_VALUE` varchar(16383) DEFAULT NULL)")
2486+
2487+
s2 := CreateSessionAndSetID(t, store)
2488+
initGlobalVariableIfNotExists(s2, variable.TiDBEnableINLJoinInnerMultiPattern, variable.Off)
2489+
2490+
dom.Close()
2491+
}
2492+
24792493
func TestIndexJoinMultiPatternByUpgrade650To840(t *testing.T) {
24802494
ctx := context.Background()
24812495
store, dom := CreateStoreAndBootstrap(t)

0 commit comments

Comments
 (0)