@@ -33,6 +33,7 @@ import (
33
33
"github.com/pingcap/failpoint"
34
34
"github.com/pingcap/tidb/pkg/config"
35
35
"github.com/pingcap/tidb/pkg/domain"
36
+ "github.com/pingcap/tidb/pkg/domain/infosync"
36
37
"github.com/pingcap/tidb/pkg/errno"
37
38
"github.com/pingcap/tidb/pkg/expression"
38
39
"github.com/pingcap/tidb/pkg/kv"
@@ -61,6 +62,101 @@ import (
61
62
"github.com/tikv/client-go/v2/oracle"
62
63
)
63
64
65
+ func TestVectorLong (t * testing.T ) {
66
+ store := testkit .CreateMockStoreWithSchemaLease (t , 1 * time .Second , mockstore .WithMockTiFlash (2 ))
67
+
68
+ tk := testkit .NewTestKit (t , store )
69
+
70
+ tiflash := infosync .NewMockTiFlash ()
71
+ infosync .SetMockTiFlash (tiflash )
72
+ defer func () {
73
+ tiflash .Lock ()
74
+ tiflash .StatusServer .Close ()
75
+ tiflash .Unlock ()
76
+ }()
77
+
78
+ genVec := func (d int , startValue int ) string {
79
+ vb := strings.Builder {}
80
+ vb .WriteString ("[" )
81
+ value := startValue
82
+ for i := 0 ; i < d ; i ++ {
83
+ if i > 0 {
84
+ vb .WriteString ("," )
85
+ }
86
+ vb .WriteString (strconv .FormatInt (int64 (value ), 10 ))
87
+ value += 100
88
+ }
89
+ vb .WriteString ("]" )
90
+ return vb .String ()
91
+ }
92
+
93
+ failpoint .Enable ("github.com/pingcap/tidb/pkg/ddl/MockCheckVectorIndexProcess" , `return(1)` )
94
+ defer func () {
95
+ require .NoError (t , failpoint .Disable ("github.com/pingcap/tidb/pkg/ddl/MockCheckVectorIndexProcess" ))
96
+ }()
97
+
98
+ runWorkload := func () {
99
+ tk .MustExec (fmt .Sprintf (`insert into t1 values (1, '%s')` , genVec (16383 , 100 )))
100
+ tk .MustQuery (`select * from t1 order by id` ).Check (testkit .Rows ("1 " + genVec (16383 , 100 )))
101
+ tk .MustExec (fmt .Sprintf (`delete from t1 where vec > '%s'` , genVec (16383 , 200 )))
102
+ tk .MustQuery (`select * from t1 order by id` ).Check (testkit .Rows ("1 " + genVec (16383 , 100 )))
103
+ tk .MustExec (fmt .Sprintf (`delete from t1 where vec > '%s'` , genVec (16383 , 50 )))
104
+ tk .MustQuery (`select * from t1 order by id` ).Check (testkit .Rows ())
105
+ tk .MustExec (fmt .Sprintf (`insert into t1 values (1, '%s')` , genVec (16383 , 100 )))
106
+ tk .MustExec (fmt .Sprintf (`insert into t1 values (2, '%s')` , genVec (16383 , 200 )))
107
+ tk .MustExec (fmt .Sprintf (`insert into t1 values (3, '%s')` , genVec (16383 , 300 )))
108
+ tk .MustQuery (fmt .Sprintf (`select id from t1 order by vec_l2_distance(vec, '%s') limit 2` , genVec (16383 , 180 ))).Check (testkit .Rows (
109
+ "2" ,
110
+ "1" ,
111
+ ))
112
+ tk .MustExec (fmt .Sprintf (`update t1 set vec = '%s' where id = 1` , genVec (16383 , 500 )))
113
+ tk .MustQuery (`select * from t1 order by id` ).Check (testkit .Rows (
114
+ "1 " + genVec (16383 , 500 ),
115
+ "2 " + genVec (16383 , 200 ),
116
+ "3 " + genVec (16383 , 300 ),
117
+ ))
118
+ tk .MustQuery (fmt .Sprintf (`select id from t1 order by vec_l2_distance(vec, '%s') limit 2` , genVec (16383 , 180 ))).Check (testkit .Rows (
119
+ "2" ,
120
+ "3" ,
121
+ ))
122
+ }
123
+
124
+ tk .MustExec ("use test" )
125
+ tk .MustExec (`
126
+ create table t1 (
127
+ id int primary key,
128
+ vec vector(16383)
129
+ )
130
+ ` )
131
+ runWorkload ()
132
+ tk .MustExec ("drop table t1" )
133
+
134
+ tk .MustExec (`
135
+ create table t1 (
136
+ id int primary key,
137
+ vec vector(16383),
138
+ VECTOR INDEX ((vec_cosine_distance(vec)))
139
+ )
140
+ ` )
141
+ runWorkload ()
142
+ tk .MustExec ("drop table if exists t1" )
143
+ tk .MustExec (`
144
+ create table t1 (
145
+ id int primary key,
146
+ vec vector(16383)
147
+ )
148
+ ` )
149
+ tk .MustExec (`alter table t1 set tiflash replica 1` )
150
+ tbl , _ := domain .GetDomain (tk .Session ()).InfoSchema ().TableByName (context .Background (), ast .NewCIStr ("test" ), ast .NewCIStr ("t1" ))
151
+ tbl .Meta ().TiFlashReplica = & model.TiFlashReplicaInfo {
152
+ Count : 1 ,
153
+ Available : true ,
154
+ }
155
+ tk .MustExec (`alter table t1 add VECTOR INDEX ((vec_cosine_distance(vec)))` )
156
+ runWorkload ()
157
+ tk .MustExec ("drop table if exists t1" )
158
+ }
159
+
64
160
func TestVectorDefaultValue (t * testing.T ) {
65
161
store := testkit .CreateMockStore (t )
66
162
tk := testkit .NewTestKit (t , store )
0 commit comments