Skip to content

Commit 43c7806

Browse files
authored
session: fix initGlobalVariableIfNotExists function forget call rs.close (#61890)
close #61884
1 parent e5e4306 commit 43c7806

File tree

2 files changed

+17
-6
lines changed

2 files changed

+17
-6
lines changed

pkg/session/bootstrap.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ import (
4949
"github.com/pingcap/tidb/pkg/util/intest"
5050
"github.com/pingcap/tidb/pkg/util/logutil"
5151
"github.com/pingcap/tidb/pkg/util/sqlescape"
52+
"github.com/pingcap/tidb/pkg/util/sqlexec"
5253
"go.uber.org/zap"
5354
)
5455

@@ -1042,13 +1043,9 @@ func upgrade(s sessiontypes.Session) {
10421043
// initGlobalVariableIfNotExists initialize a global variable with specific val if it does not exist.
10431044
func initGlobalVariableIfNotExists(s sessiontypes.Session, name string, val any) {
10441045
ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnBootstrap)
1045-
rs, err := s.ExecuteInternal(ctx, "SELECT VARIABLE_VALUE FROM %n.%n WHERE VARIABLE_NAME=%?;",
1046-
mysql.SystemDB, mysql.GlobalVariablesTable, name)
1046+
rows, err := sqlexec.ExecSQL(ctx, s, "SELECT VARIABLE_VALUE FROM %n.%n WHERE VARIABLE_NAME=%?;", mysql.SystemDB, mysql.GlobalVariablesTable, name)
10471047
terror.MustNil(err)
1048-
req := rs.NewChunk(nil)
1049-
err = rs.Next(ctx, req)
1050-
terror.MustNil(err)
1051-
if req.NumRows() != 0 {
1048+
if len(rows) != 0 {
10521049
return
10531050
}
10541051

pkg/session/bootstrap_test.go

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

2326+
func TestIssue61890(t *testing.T) {
2327+
store, dom := CreateStoreAndBootstrap(t)
2328+
defer func() { require.NoError(t, store.Close()) }()
2329+
2330+
s1 := CreateSessionAndSetID(t, store)
2331+
MustExec(t, s1, "drop table mysql.global_variables")
2332+
MustExec(t, s1, "create table mysql.global_variables(`VARIABLE_NAME` varchar(64) NOT NULL PRIMARY KEY clustered, `VARIABLE_VALUE` varchar(16383) DEFAULT NULL)")
2333+
2334+
s2 := CreateSessionAndSetID(t, store)
2335+
initGlobalVariableIfNotExists(s2, vardef.TiDBEnableINLJoinInnerMultiPattern, vardef.Off)
2336+
2337+
dom.Close()
2338+
}
2339+
23262340
func TestIndexJoinMultiPatternByUpgrade650To840(t *testing.T) {
23272341
ctx := context.Background()
23282342
store, dom := CreateStoreAndBootstrap(t)

0 commit comments

Comments
 (0)