@@ -418,6 +418,24 @@ func TestVectorColumnInfo(t *testing.T) {
418
418
tk .MustGetErrMsg ("create table t(embedding VECTOR(16384))" , "vector cannot have more than 16383 dimensions" )
419
419
}
420
420
421
+ func TestVectorExplainTruncate (t * testing.T ) {
422
+ store := testkit .CreateMockStore (t )
423
+ tk := testkit .NewTestKit (t , store )
424
+ tk .MustExec ("use test" )
425
+ tk .MustExec ("CREATE TABLE t(c VECTOR);" )
426
+
427
+ // TODO: The output can be improved.
428
+ tk .MustQuery (`EXPLAIN format='brief' SELECT
429
+ VEC_COSINE_DISTANCE(c, '[3,100,12345,10000]'),
430
+ VEC_COSINE_DISTANCE(c, '[11111111111,11111111111.23456789,3.1,5.12456]'),
431
+ VEC_COSINE_DISTANCE(c, '[-11111111111,-11111111111.23456789,-3.1,-5.12456]')
432
+ FROM t;` ).Check (testkit .Rows (
433
+ `Projection 10000.00 root vec_cosine_distance(test.t.c, [3,1e+02,1.2e+04,1e+04])->Column#3, vec_cosine_distance(test.t.c, [1.1e+10,1.1e+10,3.1,5.1])->Column#4, vec_cosine_distance(test.t.c, [-1.1e+10,-1.1e+10,-3.1,-5.1])->Column#5` ,
434
+ `└─TableReader 10000.00 root data:TableFullScan` ,
435
+ ` └─TableFullScan 10000.00 cop[tikv] table:t keep order:false, stats:pseudo` ,
436
+ ))
437
+ }
438
+
421
439
func TestVectorConstantExplain (t * testing.T ) {
422
440
store := testkit .CreateMockStore (t )
423
441
tk := testkit .NewTestKit (t , store )
@@ -475,6 +493,59 @@ func TestVectorConstantExplain(t *testing.T) {
475
493
tk .ResultSetToResult (rs , fmt .Sprintf ("%v" , rs ))
476
494
}
477
495
496
+ func TestVectorIndexExplain (t * testing.T ) {
497
+ store := testkit .CreateMockStoreWithSchemaLease (t , 1 * time .Second , mockstore .WithMockTiFlash (2 ))
498
+
499
+ tk := testkit .NewTestKit (t , store )
500
+
501
+ tiflash := infosync .NewMockTiFlash ()
502
+ infosync .SetMockTiFlash (tiflash )
503
+ defer func () {
504
+ tiflash .Lock ()
505
+ tiflash .StatusServer .Close ()
506
+ tiflash .Unlock ()
507
+ }()
508
+
509
+ failpoint .Enable ("github.com/pingcap/tidb/pkg/ddl/MockCheckVectorIndexProcess" , `return(1)` )
510
+ defer func () {
511
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/ddl/MockCheckVectorIndexProcess" ))
512
+ }()
513
+
514
+ tk .MustExec ("use test" )
515
+ tk .MustExec ("drop table if exists t1" )
516
+ tk .MustExec (`
517
+ create table t1 (
518
+ vec vector(100)
519
+ )
520
+ ` )
521
+ tk .MustExec ("alter table t1 set tiflash replica 1;" )
522
+ tk .MustExec ("alter table t1 add vector index ((vec_cosine_distance(vec))) USING HNSW;" )
523
+ tbl , _ := domain .GetDomain (tk .Session ()).InfoSchema ().TableByName (context .Background (), ast .NewCIStr ("test" ), ast .NewCIStr ("t1" ))
524
+ tbl .Meta ().TiFlashReplica = & model.TiFlashReplicaInfo {
525
+ Count : 1 ,
526
+ Available : true ,
527
+ }
528
+
529
+ vb := strings.Builder {}
530
+ vb .WriteString ("[" )
531
+ for i := 0 ; i < 100 ; i ++ {
532
+ if i > 0 {
533
+ vb .WriteString ("," )
534
+ }
535
+ vb .WriteString ("100" )
536
+ }
537
+ vb .WriteString ("]" )
538
+
539
+ tk .MustQuery (fmt .Sprintf ("explain format = 'brief' select * from t1 order by vec_cosine_distance(vec, '%s') limit 1" , vb .String ())).Check (testkit .Rows (
540
+ `TopN 1.00 root Column#5, offset:0, count:1` ,
541
+ `└─TableReader 1.00 root MppVersion: 2, data:ExchangeSender` ,
542
+ ` └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough` ,
543
+ ` └─TopN 1.00 mpp[tiflash] Column#5, offset:0, count:1` ,
544
+ ` └─Projection 1.00 mpp[tiflash] test.t1.vec, vec_cosine_distance(test.t1.vec, [1e+02,1e+02,1e+02,1e+02,1e+02,(95 more)...])->Column#5` ,
545
+ ` └─TableFullScan 1.00 mpp[tiflash] table:t1, index:vector_index(vec) keep order:false, stats:pseudo, annIndex:COSINE(vec..[1e+02,1e+02,1e+02,1e+02,1e+02,(95 more)...], limit:1)` ,
546
+ ))
547
+ }
548
+
478
549
func TestFixedVector (t * testing.T ) {
479
550
store := testkit .CreateMockStore (t )
480
551
tk := testkit .NewTestKit (t , store )
0 commit comments