Skip to content

Commit 3fa40cd

Browse files
committed
sql/inspect: exclude REFCURSOR[] from index consistency comparisons
The index consistency check previously filtered out REFCURSOR columns when constructing join predicates, but failed to do the same for REFCURSOR[] (arrays of cursors). Like REFCURSOR, these cannot be used in comparison operations. This change ensures that both REFCURSOR and REFCURSOR[] columns are properly excluded from such comparisons. Informs: #155483 Epic: CRDB-55075 Release note: none
1 parent b97d3b3 commit 3fa40cd

File tree

2 files changed

+27
-8
lines changed

2 files changed

+27
-8
lines changed

pkg/sql/inspect/index_consistency_check.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
2929
"github.com/cockroachdb/cockroach/pkg/sql/sessiondata"
3030
"github.com/cockroachdb/cockroach/pkg/sql/spanutils"
31-
"github.com/cockroachdb/cockroach/pkg/sql/types"
3231
"github.com/cockroachdb/cockroach/pkg/util/hlc"
3332
"github.com/cockroachdb/cockroach/pkg/util/log"
3433
"github.com/cockroachdb/errors"
@@ -149,9 +148,8 @@ func (c *indexConsistencyCheck) Start(
149148
}
150149
col := c.tableDesc.PublicColumns()[pos]
151150
otherColumns = append(otherColumns, col)
152-
if col.GetType().Family() == types.RefCursorFamily {
153-
// Refcursor values do not support equality comparison, so we cannot use
154-
// them in the join predicates that detect inconsistencies.
151+
if !tree.EqCmpAllowedForEquivalentTypes(col.GetType(), col.GetType()) {
152+
// We cannot use types in join predicates that don't allow for equality comparisons.
155153
return
156154
}
157155
joinColumns = append(joinColumns, col)

pkg/sql/logictest/testdata/logic_test/inspect

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -514,26 +514,47 @@ subtest end
514514
subtest refcursor_stored_column
515515

516516
statement ok
517-
CREATE TABLE refcursor_tbl (id INT PRIMARY KEY, a INT, c REFCURSOR);
517+
CREATE TABLE refcursor_tbl (id INT PRIMARY KEY, a INT, c REFCURSOR, d REFCURSOR[]);
518518

519519
statement ok
520-
INSERT INTO refcursor_tbl VALUES (1, 10, 'cursor1'), (2, 20, 'cursor2');
520+
INSERT INTO refcursor_tbl VALUES
521+
(1, 10, 'cursor1', ARRAY['c1a', 'c1b']::REFCURSOR[]),
522+
(2, 20, 'cursor2', ARRAY['c2a', 'c2b']::REFCURSOR[]);
521523

522524
# Verify that we cannot index the refcursor. They can only be included
523525
# in an index as stored columns.
524526
statement error pq: unimplemented: column c has type refcursor, which is not indexable
525527
CREATE INDEX idx_refcursor ON refcursor_tbl (c);
526528

527529
statement ok
528-
CREATE INDEX idx_refcursor ON refcursor_tbl (a) STORING (c);
530+
CREATE INDEX idx_a_c ON refcursor_tbl (a) STORING (c);
531+
532+
statement ok
533+
CREATE INDEX idx_a_d ON refcursor_tbl (a) STORING (d);
529534

530535
statement ok
531536
INSPECT TABLE refcursor_tbl WITH OPTIONS INDEX ALL;
532537

533538
query TI
534539
SELECT * FROM last_inspect_job;
535540
----
536-
succeeded 1
541+
succeeded 2
542+
543+
# Test with hash optimization disabled to ensure JOIN-based consistency check works.
544+
statement ok
545+
SET CLUSTER SETTING sql.inspect.index_consistency_hash.enabled = false;
546+
547+
statement ok
548+
INSPECT TABLE refcursor_tbl WITH OPTIONS INDEX ALL;
549+
550+
query TI
551+
SELECT * FROM last_inspect_job;
552+
----
553+
succeeded 2
554+
555+
# Re-enable hash optimization.
556+
statement ok
557+
SET CLUSTER SETTING sql.inspect.index_consistency_hash.enabled = true;
537558

538559
statement ok
539560
DROP TABLE refcursor_tbl;

0 commit comments

Comments
 (0)