@@ -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 )
@@ -479,6 +497,62 @@ func TestVectorConstantExplain(t *testing.T) {
479
497
tk .ResultSetToResult (rs , fmt .Sprintf ("%v" , rs ))
480
498
}
481
499
500
+ func TestVectorIndexExplain (t * testing.T ) {
501
+ store := testkit .CreateMockStoreWithSchemaLease (t , 1 * time .Second , mockstore .WithMockTiFlash (2 ))
502
+
503
+ tk := testkit .NewTestKit (t , store )
504
+
505
+ tiflash := infosync .NewMockTiFlash ()
506
+ infosync .SetMockTiFlash (tiflash )
507
+ defer func () {
508
+ tiflash .Lock ()
509
+ tiflash .StatusServer .Close ()
510
+ tiflash .Unlock ()
511
+ }()
512
+
513
+ failpoint .Enable ("github.com/pingcap/tidb/pkg/ddl/MockCheckVectorIndexProcess" , `return(1)` )
514
+ defer func () {
515
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/ddl/MockCheckVectorIndexProcess" ))
516
+ }()
517
+
518
+ tk .MustExec ("use test" )
519
+ tk .MustExec ("drop table if exists t1" )
520
+ tk .MustExec (`
521
+ create table t1 (
522
+ vec vector(100)
523
+ )
524
+ ` )
525
+ tk .MustExec ("alter table t1 set tiflash replica 1;" )
526
+ tk .MustExec ("alter table t1 add vector index ((vec_cosine_distance(vec))) USING HNSW;" )
527
+ tbl , _ := domain .GetDomain (tk .Session ()).InfoSchema ().TableByName (context .Background (), pmodel .NewCIStr ("test" ), pmodel .NewCIStr ("t1" ))
528
+ tbl .Meta ().TiFlashReplica = & model.TiFlashReplicaInfo {
529
+ Count : 1 ,
530
+ Available : true ,
531
+ }
532
+
533
+ vb := strings.Builder {}
534
+ vb .WriteString ("[" )
535
+ for i := 0 ; i < 100 ; i ++ {
536
+ if i > 0 {
537
+ vb .WriteString ("," )
538
+ }
539
+ vb .WriteString ("100" )
540
+ }
541
+ vb .WriteString ("]" )
542
+
543
+ tk .MustQuery (fmt .Sprintf ("explain format = 'brief' select * from t1 order by vec_cosine_distance(vec, '%s') limit 1" , vb .String ())).Check (testkit .Rows (
544
+ `Projection 1.00 root test.t1.vec` ,
545
+ `└─TopN 1.00 root Column#4, offset:0, count:1` ,
546
+ ` └─Projection 1.00 root test.t1.vec, vec_cosine_distance(test.t1.vec, [1e+02,1e+02,1e+02,1e+02,1e+02,(95 more)...])->Column#4` ,
547
+ ` └─TableReader 1.00 root MppVersion: 2, data:ExchangeSender` ,
548
+ ` └─ExchangeSender 1.00 mpp[tiflash] ExchangeType: PassThrough` ,
549
+ ` └─Projection 1.00 mpp[tiflash] test.t1.vec` ,
550
+ ` └─TopN 1.00 mpp[tiflash] Column#3, offset:0, count:1` ,
551
+ ` └─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#3` ,
552
+ ` └─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)` ,
553
+ ))
554
+ }
555
+
482
556
func TestFixedVector (t * testing.T ) {
483
557
store := testkit .CreateMockStore (t )
484
558
tk := testkit .NewTestKit (t , store )
0 commit comments