Skip to content

Commit 5094a32

Browse files
craig[bot]andy-kimball
andcommitted
Merge #144617
144617: vecindex: add deterministic for vector index tests r=drewkimball a=andy-kimball Vector indexes run non-deterministic background operations to perform maintenance tasks. These can change the results of tests. This commit adds the sql.vecindex.deterministic_fixups.enabled cluster setting, which makes these background operations deterministic when enabled. The background operations are synchronously run the index is searched or mutated. Epic: CRDB-42943 Release note: None Co-authored-by: Andrew Kimball <[email protected]>
2 parents 4b8bfa8 + 7b7018c commit 5094a32

File tree

10 files changed

+93
-50
lines changed

10 files changed

+93
-50
lines changed

pkg/sql/logictest/logic.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1862,6 +1862,14 @@ func (t *logicTest) newCluster(
18621862
); err != nil {
18631863
t.Fatal(err)
18641864
}
1865+
1866+
// Ensure that vector index background operations are deterministic, so
1867+
// that tests don't flake.
1868+
if _, err := conn.Exec(
1869+
"SET CLUSTER SETTING sql.vecindex.deterministic_fixups.enabled = true",
1870+
); err != nil {
1871+
t.Fatal(err)
1872+
}
18651873
}
18661874

18671875
if cfg.OverrideDistSQLMode != "" {

pkg/sql/logictest/testdata/logic_test/event_log

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,7 @@ ORDER BY "timestamp", info
485485
1 {"ApplicationName": "$ internal-optInToDiagnosticsStatReporting", "EventType": "set_cluster_setting", "SettingName": "diagnostics.reporting.enabled", "Statement": "SET CLUSTER SETTING \"diagnostics.reporting.enabled\" = true", "Tag": "SET CLUSTER SETTING", "User": "node", "Value": "true"}
486486
1 {"EventType": "set_cluster_setting", "SettingName": "sql.crdb_internal.table_row_statistics.as_of_time", "Statement": "SET CLUSTER SETTING \"sql.crdb_internal.table_row_statistics.as_of_time\" = e'-1\\u00B5s'", "Tag": "SET CLUSTER SETTING", "User": "root", "Value": "-00:00:00.000001"}
487487
1 {"EventType": "set_cluster_setting", "SettingName": "feature.vector_index.enabled", "Statement": "SET CLUSTER SETTING \"feature.vector_index.enabled\" = true", "Tag": "SET CLUSTER SETTING", "User": "root", "Value": "true"}
488+
1 {"EventType": "set_cluster_setting", "SettingName": "sql.vecindex.deterministic_fixups.enabled", "Statement": "SET CLUSTER SETTING \"sql.vecindex.deterministic_fixups.enabled\" = true", "Tag": "SET CLUSTER SETTING", "User": "root", "Value": "true"}
488489
1 {"EventType": "set_cluster_setting", "SettingName": "kv.allocator.load_based_lease_rebalancing.enabled", "Statement": "SET CLUSTER SETTING \"kv.allocator.load_based_lease_rebalancing.enabled\" = false", "Tag": "SET CLUSTER SETTING", "User": "root", "Value": "false"}
489490
1 {"EventType": "set_cluster_setting", "SettingName": "kv.allocator.load_based_lease_rebalancing.enabled", "Statement": "SET CLUSTER SETTING \"kv.allocator.load_based_lease_rebalancing.enabled\" = DEFAULT", "Tag": "SET CLUSTER SETTING", "User": "root", "Value": "DEFAULT"}
490491
1 {"EventType": "set_cluster_setting", "PlaceholderValues": ["'some string'"], "SettingName": "cluster.label", "Statement": "SET CLUSTER SETTING \"cluster.label\" = $1", "Tag": "SET CLUSTER SETTING", "User": "root", "Value": "'some string'"}
@@ -505,6 +506,7 @@ ORDER BY "timestamp", info
505506
1 {"ApplicationName": "$ internal-optInToDiagnosticsStatReporting", "EventType": "set_cluster_setting", "SettingName": "diagnostics.reporting.enabled", "Statement": "SET CLUSTER SETTING \"diagnostics.reporting.enabled\" = true", "Tag": "SET CLUSTER SETTING", "User": "node", "Value": "true"}
506507
1 {"EventType": "set_cluster_setting", "SettingName": "sql.crdb_internal.table_row_statistics.as_of_time", "Statement": "SET CLUSTER SETTING \"sql.crdb_internal.table_row_statistics.as_of_time\" = e'-1\\u00B5s'", "Tag": "SET CLUSTER SETTING", "User": "root", "Value": "-00:00:00.000001"}
507508
1 {"EventType": "set_cluster_setting", "SettingName": "feature.vector_index.enabled", "Statement": "SET CLUSTER SETTING \"feature.vector_index.enabled\" = true", "Tag": "SET CLUSTER SETTING", "User": "root", "Value": "true"}
509+
1 {"EventType": "set_cluster_setting", "SettingName": "sql.vecindex.deterministic_fixups.enabled", "Statement": "SET CLUSTER SETTING \"sql.vecindex.deterministic_fixups.enabled\" = true", "Tag": "SET CLUSTER SETTING", "User": "root", "Value": "true"}
508510
1 {"EventType": "set_cluster_setting", "PlaceholderValues": ["'some string'"], "SettingName": "cluster.label", "Statement": "SET CLUSTER SETTING \"cluster.label\" = $1", "Tag": "SET CLUSTER SETTING", "User": "root", "Value": "'some string'"}
509511

510512
# Set and unset zone configs

pkg/sql/logictest/testdata/logic_test/system

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,7 @@ cluster.secret
315315
diagnostics.reporting.enabled
316316
feature.vector_index.enabled
317317
sql.crdb_internal.table_row_statistics.as_of_time
318+
sql.vecindex.deterministic_fixups.enabled
318319
version
319320

320321
onlyif config 3node-tenant-default-configs
@@ -332,6 +333,7 @@ cluster.secret
332333
diagnostics.reporting.enabled
333334
feature.vector_index.enabled
334335
sql.crdb_internal.table_row_statistics.as_of_time
336+
sql.vecindex.deterministic_fixups.enabled
335337
version
336338

337339
statement ok
@@ -355,6 +357,7 @@ diagnostics.reporting.enabled true
355357
feature.vector_index.enabled true
356358
somesetting somevalue
357359
sql.crdb_internal.table_row_statistics.as_of_time -1µs
360+
sql.vecindex.deterministic_fixups.enabled true
358361

359362
onlyif config 3node-tenant-default-configs
360363
query TT
@@ -372,6 +375,7 @@ diagnostics.reporting.enabled true
372375
feature.vector_index.enabled true
373376
somesetting somevalue
374377
sql.crdb_internal.table_row_statistics.as_of_time -1µs
378+
sql.vecindex.deterministic_fixups.enabled true
375379

376380
user testuser
377381

pkg/sql/logictest/testdata/logic_test/vector_index

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -270,13 +270,13 @@ CREATE VECTOR INDEX ON vec_errors (d)
270270
statement error pq: column vec1 has type vector, which is not indexable in a non-vector index\nHINT: you may want to create a vector index instead
271271
CREATE INDEX ON vec_errors (b, vec1)
272272

273-
statement error vector indexes can't be unique
273+
statement error vector indexes can.t be unique
274274
CREATE UNIQUE VECTOR INDEX ON vec_errors (vec1)
275275

276-
statement error vector indexes don't support stored columns
276+
statement error vector indexes don.t support stored columns
277277
CREATE INDEX on vec_errors USING cspann (vec1) STORING (b);
278278

279-
statement error vector indexes don't support stored columns
279+
statement error vector indexes don.t support stored columns
280280
CREATE VECTOR INDEX on vec_errors (vec1) STORING (b);
281281

282282
# Try to use unsupported vector index type.
@@ -331,13 +331,14 @@ DROP TABLE alter_test
331331
# Execution tests.
332332
# ------------------------------------------------------------------------------
333333

334+
# Use small partition size so that index has more than one level.
334335
statement ok
335336
CREATE TABLE exec_test (
336337
a INT PRIMARY KEY,
337338
b INT,
338339
vec1 VECTOR(3),
339-
VECTOR INDEX idx1 (vec1),
340-
VECTOR INDEX idx2 (b, vec1)
340+
VECTOR INDEX idx1 (vec1) WITH (min_partition_size=1, max_partition_size=4),
341+
VECTOR INDEX idx2 (b, vec1) WITH (min_partition_size=1, max_partition_size=4)
341342
)
342343

343344
statement ok
@@ -350,37 +351,29 @@ INSERT INTO exec_test (a, b, vec1) VALUES
350351
(6, NULL, '[16, 17, 18]'),
351352
(7, NULL, '[1, 1, 1]');
352353

353-
# TODO(143209): write a full set of tests once we can make them deterministic.
354-
# For now, we can write tests that return every vector with a given prefix.
355-
query I rowsort
356-
SELECT a FROM exec_test@idx1 ORDER BY vec1 <-> '[1, 1, 2]' LIMIT 7;
354+
query IT rowsort
355+
SELECT a, vec1 FROM exec_test@idx1 ORDER BY vec1 <-> '[1, 1, 2]' LIMIT 3;
357356
----
358-
7
359-
1
360-
2
361-
3
362-
4
363-
5
364-
6
365-
366-
query I rowsort
367-
SELECT a FROM exec_test@idx2 WHERE b = 1 ORDER BY vec1 <-> '[1, 1, 2]' LIMIT 2;
357+
7 [1,1,1]
358+
1 [1,2,3]
359+
2 [4,5,6]
360+
361+
query IT rowsort
362+
SELECT a, vec1 FROM exec_test@idx2 WHERE b = 1 ORDER BY vec1 <-> '[1, 1, 2]' LIMIT 1;
368363
----
369-
1
370-
2
364+
1 [1,2,3]
371365

372-
query I rowsort
373-
SELECT a FROM exec_test@idx2 WHERE b = 2 ORDER BY vec1 <-> '[1, 1, 2]' LIMIT 3;
366+
query IT rowsort
367+
SELECT a, vec1 FROM exec_test@idx2 WHERE b = 2 ORDER BY vec1 <-> '[15, 15, 15]' LIMIT 2;
374368
----
375-
3
376-
4
377-
5
369+
5 [13,14,15]
370+
4 [10,11,12]
378371

379-
query I rowsort
380-
SELECT a FROM exec_test WHERE b IS NULL ORDER BY vec1 <-> '[1, 1, 2]' LIMIT 3;
372+
query IT rowsort
373+
SELECT a, vec1 FROM exec_test WHERE b IS NULL ORDER BY vec1 <-> '[1, 1, 2]' LIMIT 3;
381374
----
382-
7
383-
6
375+
7 [1,1,1]
376+
6 [16,17,18]
384377

385378
statement ok
386379
DROP TABLE exec_test
@@ -390,7 +383,7 @@ DROP TABLE exec_test
390383
#
391384
# The SELECT statements for these tests retrieve all the rows in the table
392385
# because the point is to test that backfill is happening correctly and that
393-
# we're still able to insert into and modify the index after the backfill is
386+
# we are still able to insert into and modify the index after the backfill is
394387
# done.
395388

396389
subtest backfill

0 commit comments

Comments
 (0)