@@ -30,6 +30,7 @@ import (
30
30
"time"
31
31
32
32
"github.com/pingcap/tidb/pkg/config"
33
+ "github.com/pingcap/tidb/pkg/domain"
33
34
"github.com/pingcap/tidb/pkg/errno"
34
35
"github.com/pingcap/tidb/pkg/kv"
35
36
"github.com/pingcap/tidb/pkg/parser/auth"
@@ -2134,6 +2135,7 @@ func TestEnsureActiveUserCoverage(t *testing.T) {
2134
2135
{"set password for test = 'test2'" , false },
2135
2136
{"show create user test" , false },
2136
2137
{"create user test1" , false },
2138
+ {"grant select on test.* to test1" , false },
2137
2139
{"show grants" , true },
2138
2140
{"show grants for 'test'@'%'" , true },
2139
2141
}
@@ -2151,3 +2153,43 @@ func TestEnsureActiveUserCoverage(t *testing.T) {
2151
2153
require .Equal (t , c .visited , visited , comment )
2152
2154
}
2153
2155
}
2156
+
2157
+ func TestSQLVariableAccelerateUserCreationUpdate (t * testing.T ) {
2158
+ store := createStoreAndPrepareDB (t )
2159
+ tk := testkit .NewTestKit (t , store )
2160
+ dom := domain .GetDomain (tk .Session ())
2161
+ // 1. check the default variable value
2162
+ tk .MustQuery ("select @@global.tidb_accelerate_user_creation_update" ).Check (testkit .Rows ("0" ))
2163
+ // trigger priv reload
2164
+ tk .MustExec ("create user aaa" )
2165
+ handle := dom .PrivilegeHandle ()
2166
+ handle .CheckFullData (t , true )
2167
+ priv := handle .Get ()
2168
+ require .False (t , priv .RequestVerification (nil , "bbb" , "%" , "test" , "" , "" , mysql .SelectPriv ))
2169
+
2170
+ // 2. change the variable and check
2171
+ tk .MustExec ("set @@global.tidb_accelerate_user_creation_update = on" )
2172
+ tk .MustQuery ("select @@global.tidb_accelerate_user_creation_update" ).Check (testkit .Rows ("1" ))
2173
+ require .True (t , vardef .AccelerateUserCreationUpdate .Load ())
2174
+ tk .MustExec ("create user bbb" )
2175
+ handle .CheckFullData (t , false )
2176
+ // trigger priv reload, but data for bbb is not really loaded
2177
+ tk .MustExec ("grant select on test.* to bbb" )
2178
+ priv = handle .Get ()
2179
+ // data for bbb is not loaded, because that user is not active
2180
+ // So this is **counterintuitive**, but it's still the expected behavior.
2181
+ require .False (t , priv .RequestVerification (nil , "bbb" , "%" , "test" , "" , "" , mysql .SelectPriv ))
2182
+ tk1 := testkit .NewTestKit (t , store )
2183
+ // if user bbb login, everything works as expected
2184
+ require .NoError (t , tk1 .Session ().Auth (& auth.UserIdentity {Username : "bbb" , Hostname : "localhost" }, nil , nil , nil ))
2185
+ priv = handle .Get ()
2186
+ require .True (t , priv .RequestVerification (nil , "bbb" , "%" , "test" , "" , "" , mysql .SelectPriv ))
2187
+
2188
+ // 3. change the variable and check again
2189
+ tk .MustExec ("set @@global.tidb_accelerate_user_creation_update = off" )
2190
+ tk .MustQuery ("select @@global.tidb_accelerate_user_creation_update" ).Check (testkit .Rows ("0" ))
2191
+ tk .MustExec ("drop user aaa" )
2192
+ handle .CheckFullData (t , true )
2193
+ priv = handle .Get ()
2194
+ require .True (t , priv .RequestVerification (nil , "bbb" , "%" , "test" , "" , "" , mysql .SelectPriv ))
2195
+ }
0 commit comments