@@ -18,6 +18,11 @@ pub(crate) async fn new() -> TestCase {
1818 timeout,
1919 simple_create_drop_index,
2020 )
21+ . with_test (
22+ "simple_create_drop_multiple_indexes" ,
23+ timeout,
24+ simple_create_drop_multiple_indexes,
25+ )
2126}
2227
2328async fn simple_create_drop_index ( actors : TestActors ) {
@@ -74,3 +79,170 @@ async fn simple_create_drop_index(actors: TestActors) {
7479
7580 info ! ( "finished" ) ;
7681}
82+
83+ async fn simple_create_drop_multiple_indexes ( actors : TestActors ) {
84+ info ! ( "started" ) ;
85+
86+ let ( session, client) = prepare_connection ( actors) . await ;
87+
88+ // Create keyspace
89+ // Different keyspace name have to be used until the issue VECTOR-213 is fixed.
90+ // When fixed please remove the comment and change the keyspace back to "ks"
91+ session. query_unpaged (
92+ "CREATE KEYSPACE ks2 WITH replication = {'class': 'SimpleStrategy', 'replication_factor': 1}" ,
93+ ( ) ,
94+ ) . await . expect ( "failed to create a keyspace" ) ;
95+
96+ // Use keyspace
97+ session
98+ . use_keyspace ( "ks2" , false )
99+ . await
100+ . expect ( "failed to use a keyspace" ) ;
101+
102+ // Create table
103+ session
104+ . query_unpaged (
105+ "
106+ CREATE TABLE tbl (pk INT PRIMARY KEY, v1 VECTOR<FLOAT, 3>, v2 VECTOR<FLOAT, 3>)
107+ " ,
108+ ( ) ,
109+ )
110+ . await
111+ . expect ( "failed to create a table" ) ;
112+
113+ // Create index on column v1
114+ session
115+ . query_unpaged ( "CREATE INDEX idx1 ON tbl(v1) USING 'vector_index'" , ( ) )
116+ . await
117+ . expect ( "failed to create an index" ) ;
118+
119+ // Wait for the index to be created
120+ wait_for (
121+ || async { client. indexes ( ) . await . len ( ) == 1 } ,
122+ "Waiting for the first index to be created" ,
123+ Duration :: from_secs ( 5 ) ,
124+ )
125+ . await ;
126+
127+ // Wait for the full scan to complete and check if ANN query succeeds on v1
128+ wait_for (
129+ || async {
130+ session
131+ . query_unpaged (
132+ "SELECT * FROM tbl ORDER BY v1 ANN OF [1.0, 2.0, 3.0] LIMIT 5" ,
133+ ( ) ,
134+ )
135+ . await
136+ . is_ok ( )
137+ } ,
138+ "Waiting for full scan to complete. ANN query should succeed" ,
139+ Duration :: from_secs ( 5 ) ,
140+ )
141+ . await ;
142+
143+ // ANN query on v2 should not succeed without the index
144+ session
145+ . query_unpaged (
146+ "SELECT * FROM tbl ORDER BY v2 ANN OF [1.0, 2.0, 3.0] LIMIT 5" ,
147+ ( ) ,
148+ )
149+ . await
150+ . expect_err ( "ANN query should fail when index does not exist" ) ;
151+
152+ // Create index on column v2
153+ session
154+ . query_unpaged ( "CREATE INDEX idx2 ON tbl(v2) USING 'vector_index'" , ( ) )
155+ . await
156+ . expect ( "failed to create an index" ) ;
157+
158+ info ! ( "waiting for the second index to be created" ) ;
159+
160+ // Wait for the second index to be created
161+ wait_for (
162+ || async { client. indexes ( ) . await . len ( ) == 2 } ,
163+ "Waiting for 2 indexes to be created" ,
164+ Duration :: from_secs ( 5 ) ,
165+ )
166+ . await ;
167+
168+ // Check if ANN query on v1 still succeeds
169+ session
170+ . query_unpaged (
171+ "SELECT * FROM tbl ORDER BY v1 ANN OF [1.0, 2.0, 3.0] LIMIT 5" ,
172+ ( ) ,
173+ )
174+ . await
175+ . expect ( "failed to run ANN query" ) ;
176+
177+ // Wait for the full scan to complete and check if ANN query succeeds on v2
178+ wait_for (
179+ || async {
180+ session
181+ . query_unpaged (
182+ "SELECT * FROM tbl ORDER BY v2 ANN OF [1.0, 2.0, 3.0] LIMIT 5" ,
183+ ( ) ,
184+ )
185+ . await
186+ . is_ok ( )
187+ } ,
188+ "Waiting for full scan to complete. ANN query should succeed" ,
189+ Duration :: from_secs ( 5 ) ,
190+ )
191+ . await ;
192+
193+ // Drop index on column v1
194+ session
195+ . query_unpaged ( "DROP INDEX idx1" , ( ) )
196+ . await
197+ . expect ( "failed to drop an index" ) ;
198+
199+ info ! ( "waiting for the first index to be dropped" ) ;
200+
201+ // Wait for the first index to be dropped
202+ wait_for (
203+ || async { client. indexes ( ) . await . len ( ) == 1 } ,
204+ "Waiting for the first index to be dropped" ,
205+ Duration :: from_secs ( 5 ) ,
206+ )
207+ . await ;
208+
209+ // ANN query on v1 should not succeed after dropping the index
210+ session
211+ . query_unpaged (
212+ "SELECT * FROM tbl ORDER BY v1 ANN OF [1.0, 2.0, 3.0] LIMIT 5" ,
213+ ( ) ,
214+ )
215+ . await
216+ . expect_err ( "ANN query should fail when index does not exist" ) ;
217+
218+ // Check if ANN query on v2 still succeeds
219+ session
220+ . query_unpaged (
221+ "SELECT * FROM tbl ORDER BY v2 ANN OF [1.0, 2.0, 3.0] LIMIT 5" ,
222+ ( ) ,
223+ )
224+ . await
225+ . expect ( "failed to run ANN query" ) ;
226+
227+ // Drop index on column v2
228+ session
229+ . query_unpaged ( "DROP INDEX idx2" , ( ) )
230+ . await
231+ . expect ( "failed to drop an index" ) ;
232+
233+ // Wait for the second index to be dropped
234+ wait_for (
235+ || async { client. indexes ( ) . await . is_empty ( ) } ,
236+ "Waiting for all indexes to be dropped" ,
237+ Duration :: from_secs ( 5 ) ,
238+ )
239+ . await ;
240+
241+ // Drop keyspace
242+ session
243+ . query_unpaged ( "DROP KEYSPACE ks2" , ( ) )
244+ . await
245+ . expect ( "failed to drop a keyspace" ) ;
246+
247+ info ! ( "finished" ) ;
248+ }
0 commit comments