Skip to content

Commit dbbdba2

Browse files
committed
sql/inspect: skip indexes with virtual columns during INSPECT
INSPECT previously attempted to verify index consistency on indexes containing virtual columns, which would result in internal errors. This occurred because INSPECT relies on LEFT LOOKUP JOIN ... @{FORCE_INDEX=[...]} constructs, which require all participating columns to be stored. Virtual columns are not compatible with this constraint, leading to a parser rejection. This change modifies the behavior of INSPECT to skip any index that has a key column over a virtual column, thereby avoiding the internal error. A follow-up task has been opened to add proper support for virtual columns in INSPECT. Informs: #155676 Informs: #155483 Epic: CRDB-55075 Release note (bug fix): INSPECT no longer fails when checking index consistency on indexes with virtual key columns. Such indexes will now be skipped.
1 parent e1c7374 commit dbbdba2

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

pkg/sql/inspect_job.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,16 @@ func isUnsupportedIndexForIndexConsistencyCheck(
197197
return true
198198
}
199199

200+
// Check if any of the index key columns are virtual columns.
201+
// TODO(155841): add support for indexes on virtual columns.
202+
for i := 0; i < index.NumKeyColumns(); i++ {
203+
colID := index.GetKeyColumnID(i)
204+
col := catalog.FindColumnByID(table, colID)
205+
if col != nil && col.IsVirtual() {
206+
return true
207+
}
208+
}
209+
200210
switch t := index.GetType(); t {
201211
case idxtype.VECTOR:
202212
return true

pkg/sql/logictest/testdata/logic_test/inspect

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,81 @@ DROP TABLE t2;
297297

298298
subtest end
299299

300+
subtest inspect_virtual_column_indexes
301+
302+
user root
303+
304+
# Test that indexes on virtual columns are not supported for INSPECT.
305+
statement ok
306+
CREATE TABLE t_virtual (
307+
c1 INT,
308+
c2 INT AS (c1 + 1) VIRTUAL,
309+
c3 INT,
310+
INDEX idx_c2 (c2),
311+
INDEX idx_c3 (c3)
312+
);
313+
314+
statement ok
315+
INSERT INTO t_virtual (c1, c3) VALUES (1, 10), (2, 20), (3, 30);
316+
317+
# INSPECT TABLE should skip the virtual column index and only check the regular index.
318+
statement ok
319+
INSPECT TABLE t_virtual AS OF SYSTEM TIME '-1us';
320+
321+
# Verify only one check was created (for idx_c3, the regular index).
322+
query TI
323+
SELECT * FROM last_inspect_job;
324+
----
325+
succeeded 1
326+
327+
# Explicitly specifying the virtual column index should fail.
328+
statement error pq: index "idx_c2" on table "t_virtual" is not supported for index consistency checking
329+
INSPECT TABLE t_virtual WITH OPTIONS INDEX (idx_c2);
330+
331+
# Explicitly specifying the regular index should succeed.
332+
statement ok
333+
INSPECT TABLE t_virtual WITH OPTIONS INDEX (idx_c3);
334+
335+
query TI
336+
SELECT * FROM last_inspect_job;
337+
----
338+
succeeded 1
339+
340+
# Test with multiple virtual columns in the same index.
341+
statement ok
342+
CREATE TABLE t_multi_virtual (
343+
c1 INT,
344+
c2 INT AS (c1 + 1) VIRTUAL,
345+
c3 INT AS (c1 * 2) VIRTUAL,
346+
c4 INT,
347+
INDEX idx_virtual_combo (c2, c3),
348+
INDEX idx_regular (c4)
349+
);
350+
351+
statement ok
352+
INSERT INTO t_multi_virtual (c1, c4) VALUES (1, 100);
353+
354+
# Should skip the index with virtual columns and only check the regular index.
355+
statement ok
356+
INSPECT TABLE t_multi_virtual AS OF SYSTEM TIME '-1us';
357+
358+
query TI
359+
SELECT * FROM last_inspect_job;
360+
----
361+
succeeded 1
362+
363+
# Explicitly specifying the index with virtual columns should fail.
364+
statement error pq: index "idx_virtual_combo" on table "t_multi_virtual" is not supported for index consistency checking
365+
INSPECT TABLE t_multi_virtual WITH OPTIONS INDEX (idx_virtual_combo);
366+
367+
statement ok
368+
DROP TABLE t_virtual;
369+
370+
statement ok
371+
DROP TABLE t_multi_virtual;
372+
373+
subtest end
374+
300375
subtest database_resolve_indexes
301376

302377
statement ok

0 commit comments

Comments
 (0)