@@ -414,7 +414,7 @@ func TestBindingSymbolList(t *testing.T) {
414
414
require .True (t , tk .MustUseIndex ("select a, b from t where a = 3 limit 1, 100" , "ib(b)" ))
415
415
416
416
// Normalize
417
- sql , hash := parser .NormalizeDigest ("select a, b from test . t where a = 1 limit 0, 1" )
417
+ sql , hash := parser .NormalizeDigestForBinding ("select a, b from test . t where a = 1 limit 0, 1" )
418
418
419
419
bindData := dom .BindHandle ().GetBindRecord (hash .String (), sql , "test" )
420
420
require .NotNil (t , bindData )
@@ -429,6 +429,50 @@ func TestBindingSymbolList(t *testing.T) {
429
429
require .NotNil (t , bind .UpdateTime )
430
430
}
431
431
432
+ // TestBindingInListWithSingleLiteral tests sql with "IN (Lit)", fixes #44298
433
+ func TestBindingInListWithSingleLiteral (t * testing.T ) {
434
+ store , dom := testkit .CreateMockStoreAndDomain (t )
435
+
436
+ tk := testkit .NewTestKit (t , store )
437
+ tk .MustExec ("use test" )
438
+ tk .MustExec ("drop table if exists t" )
439
+ tk .MustExec ("create table t(a int, b int, INDEX ia (a), INDEX ib (b));" )
440
+ tk .MustExec ("insert into t value(1, 1);" )
441
+
442
+ // GIVEN
443
+ sqlcmd := "select a, b from t where a in (1)"
444
+ binding := `create global binding for select a, b from t where a in (1, 2, 3) using select a, b from t use index (ib) where a in (1, 2, 3)`
445
+
446
+ // before binding
447
+ tk .MustQuery (sqlcmd )
448
+ require .Equal (t , "t:ia" , tk .Session ().GetSessionVars ().StmtCtx .IndexNames [0 ])
449
+ require .True (t , tk .MustUseIndex (sqlcmd , "ia(a)" ))
450
+
451
+ tk .MustExec (binding )
452
+
453
+ // after binding
454
+ tk .MustQuery (sqlcmd )
455
+ require .Equal (t , "t:ib" , tk .Session ().GetSessionVars ().StmtCtx .IndexNames [0 ])
456
+ require .True (t , tk .MustUseIndex (sqlcmd , "ib(b)" ))
457
+
458
+ tk .MustQuery ("select @@last_plan_from_binding" ).Check (testkit .Rows ("1" ))
459
+
460
+ // Normalize
461
+ sql , hash := parser .NormalizeDigestForBinding ("select a, b from test . t where a in (1)" )
462
+
463
+ bindData := dom .BindHandle ().GetBindRecord (hash .String (), sql , "test" )
464
+ require .NotNil (t , bindData )
465
+ require .Equal (t , "select `a` , `b` from `test` . `t` where `a` in ( ... )" , bindData .OriginalSQL )
466
+ bind := bindData .Bindings [0 ]
467
+ require .Equal (t , "SELECT `a`,`b` FROM `test`.`t` USE INDEX (`ib`) WHERE `a` IN (1,2,3)" , bind .BindSQL )
468
+ require .Equal (t , "test" , bindData .Db )
469
+ require .Equal (t , bindinfo .Enabled , bind .Status )
470
+ require .NotNil (t , bind .Charset )
471
+ require .NotNil (t , bind .Collation )
472
+ require .NotNil (t , bind .CreateTime )
473
+ require .NotNil (t , bind .UpdateTime )
474
+ }
475
+
432
476
func TestDMLSQLBind (t * testing.T ) {
433
477
store := testkit .CreateMockStore (t )
434
478
@@ -538,7 +582,7 @@ func TestErrorBind(t *testing.T) {
538
582
_ , err := tk .Exec ("create global binding for select * from t where i>100 using select * from t use index(index_t) where i>100" )
539
583
require .NoError (t , err , "err %v" , err )
540
584
541
- sql , hash := parser .NormalizeDigest ("select * from test . t where i > ?" )
585
+ sql , hash := parser .NormalizeDigestForBinding ("select * from test . t where i > ?" )
542
586
bindData := dom .BindHandle ().GetBindRecord (hash .String (), sql , "test" )
543
587
require .NotNil (t , bindData )
544
588
require .Equal (t , "select * from `test` . `t` where `i` > ?" , bindData .OriginalSQL )
@@ -1304,7 +1348,7 @@ func TestBindSQLDigest(t *testing.T) {
1304
1348
parser4binding := parser .New ()
1305
1349
originNode , err := parser4binding .ParseOneStmt (c .origin , "utf8mb4" , "utf8mb4_general_ci" )
1306
1350
require .NoError (t , err )
1307
- _ , sqlDigestWithDB := parser .NormalizeDigest (utilparser .RestoreWithDefaultDB (originNode , "test" , c .origin ))
1351
+ _ , sqlDigestWithDB := parser .NormalizeDigestForBinding (utilparser .RestoreWithDefaultDB (originNode , "test" , c .origin ))
1308
1352
require .Equal (t , res [0 ][9 ], sqlDigestWithDB .String ())
1309
1353
}
1310
1354
}
0 commit comments