|
| 1 | +setup |
| 2 | +SET CLUSTER SETTING feature.vector_index.enabled = true; |
| 3 | +SET CLUSTER SETTING sql.vecindex.deterministic_fixups.enabled = true; |
| 4 | +CREATE TABLE t (i INT PRIMARY KEY, j INT NOT NULL, embedding VECTOR(3), metadata TEXT); |
| 5 | +INSERT INTO t(i, j, embedding, metadata) VALUES (-4, -4, '[1,2,3]', 'data1'), (-2, -2, '[4,5,6]', 'data2'), (-3, -3, NULL, 'null_data'); |
| 6 | +CREATE VECTOR INDEX vec_idx ON t(embedding); |
| 7 | +---- |
| 8 | + |
| 9 | +# Test DML operations during primary key alteration with vector indexes |
| 10 | +# Vector indexes should be recreated with proper partial predicates |
| 11 | +stage-exec phase=PostCommitPhase stage=: |
| 12 | +INSERT INTO t VALUES($stageKey, $stageKey, '[7,8,9]', 'stage_data'); |
| 13 | +INSERT INTO t VALUES($stageKey + 1, $stageKey + 1, NULL, 'stage_null'); |
| 14 | +UPDATE t SET embedding = '[10,11,12]' WHERE i = $stageKey; |
| 15 | +UPDATE t SET metadata = 'updated_stage' WHERE i = $stageKey + 1; |
| 16 | +DELETE FROM t WHERE i=-4; |
| 17 | +DELETE FROM t WHERE i=$stageKey; |
| 18 | +INSERT INTO t VALUES($stageKey, $stageKey, '[13,14,15]', 'stage_reinsert'); |
| 19 | +INSERT INTO t VALUES(-4, -4, '[1,2,3]', 'data1'); |
| 20 | +---- |
| 21 | + |
| 22 | +# Verify vector data is correctly indexed during recreation |
| 23 | +stage-query phase=PostCommitPhase stage=: |
| 24 | +SELECT count(*)=$successfulStageCount FROM ( |
| 25 | + SELECT metadata FROM t@vec_idx ORDER BY embedding <-> '[13, 14, 15]' LIMIT 20) |
| 26 | +WHERE metadata = 'stage_reinsert'; |
| 27 | +---- |
| 28 | +true |
| 29 | + |
| 30 | +stage-exec phase=PostCommitNonRevertiblePhase stage=: |
| 31 | +INSERT INTO t VALUES($stageKey + 100, $stageKey + 100, '[16,17,18]', 'final_data'); |
| 32 | +INSERT INTO t VALUES($stageKey + 101, $stageKey + 101, NULL, 'final_null'); |
| 33 | +UPDATE t SET embedding = '[19,20,21]' WHERE i = $stageKey + 100; |
| 34 | +UPDATE t SET metadata = 'updated_final' WHERE embedding IS NULL; |
| 35 | +DELETE FROM t WHERE i=-4; |
| 36 | +DELETE FROM t WHERE i=$stageKey + 100; |
| 37 | +INSERT INTO t VALUES($stageKey + 100, $stageKey + 100, '[22,23,24]', 'final_reinsert'); |
| 38 | +INSERT INTO t VALUES(-4, -4, '[1,2,3]', 'data1'); |
| 39 | +---- |
| 40 | + |
| 41 | +# Verify final state after primary key change |
| 42 | +stage-query phase=PostCommitNonRevertiblePhase stage=: |
| 43 | +SELECT count(*)=$successfulStageCount FROM ( |
| 44 | + SELECT metadata FROM t@vec_idx ORDER BY embedding <-> '[22,23,24]' LIMIT 20) |
| 45 | +WHERE metadata = 'final_reinsert'; |
| 46 | +---- |
| 47 | +true |
| 48 | + |
| 49 | +test |
| 50 | +ALTER TABLE t ALTER PRIMARY KEY USING COLUMNS (j) |
| 51 | +---- |
0 commit comments