Skip to content

Commit c6dedb3

Browse files
craig[bot]jeffswenson
andcommitted
Merge #148014
148014: sql: skip inverted indexes in show fingerprints r=jeffswenson a=jeffswenson SHOW EXPERIMENTAL_FINGERPRINTS is used by the DR team to validate tables replicated via logical replication. It validates indexes by crafting a SQL query that forces the use of the index via hints. This doesn't work for inverted indexes, since each row can have multiple entries in the inverted index. This PR changes the fingerprinting logic so that it ignores the incompatible indexes instead of failing to execute. Release note: none Informs: CRDB-44094 Co-authored-by: Jeff Swenson <[email protected]>
2 parents 1f4888a + 7809684 commit c6dedb3

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

pkg/sql/show_fingerprints.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
"github.com/cockroachdb/cockroach/pkg/sql/privilege"
2626
"github.com/cockroachdb/cockroach/pkg/sql/sem/asof"
2727
"github.com/cockroachdb/cockroach/pkg/sql/sem/eval"
28+
"github.com/cockroachdb/cockroach/pkg/sql/sem/idxtype"
2829
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
2930
"github.com/cockroachdb/cockroach/pkg/sql/sessiondata"
3031
"github.com/cockroachdb/cockroach/pkg/sql/sessionprotectedts"
@@ -313,6 +314,14 @@ func (n *showFingerprintsNode) Next(params runParams) (bool, error) {
313314
return false, nil
314315
}
315316
index := n.indexes[n.run.rowIdx]
317+
318+
// Skip inverted indexes. Experimental fingerprint uses a query that forces
319+
// the use of an index and that is incompatible with inverted indexes.
320+
if index.GetType() == idxtype.INVERTED {
321+
n.run.rowIdx++
322+
return n.Next(params)
323+
}
324+
316325
excludedColumns := []string{}
317326
if n.options != nil && len(n.options.excludedUserColumns) > 0 {
318327
excludedColumns = append(excludedColumns, n.options.excludedUserColumns...)

pkg/sql/show_fingerprints_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,37 @@ func TestShowFingerprintsColumnNames(t *testing.T) {
9595
}
9696
}
9797

98+
func TestShowFingerprintInvertedIndex(t *testing.T) {
99+
defer leaktest.AfterTest(t)()
100+
defer log.Scope(t).Close(t)
101+
102+
ctx := context.Background()
103+
tc := serverutils.StartCluster(t, 1, base.TestClusterArgs{})
104+
defer tc.Stopper().Stop(ctx)
105+
106+
sqlDB := sqlutils.MakeSQLRunner(tc.ServerConn(0))
107+
sqlDB.Exec(t, `CREATE DATABASE d`)
108+
sqlDB.Exec(t, `CREATE TABLE d.t (
109+
a INT PRIMARY KEY,
110+
b INT,
111+
c INT,
112+
d JSONB,
113+
INDEX b_idx (b),
114+
INDEX c_partial_idx (c) WHERE c > 0,
115+
INVERTED INDEX d_inverted_idx (d)
116+
)`)
117+
118+
sqlDB.Exec(t, `INSERT INTO d.t VALUES (1, 2, 3, '{"a": 4}'), (2, 3, 0, '{"a": 5}')`)
119+
120+
// Get fingerprints for the table.
121+
rows := sqlDB.QueryStr(t, `SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE d.t`)
122+
require.Len(t, rows, 3, "expected only primary, b_idx, c_partial_idx to be fingerprinted")
123+
require.Equal(t, rows[0][0], "t_pkey")
124+
require.Equal(t, rows[1][0], "b_idx")
125+
require.Equal(t, rows[2][0], "c_partial_idx")
126+
// NOTE: no d_inverted_idx
127+
}
128+
98129
// TestShowFingerprintsDuringSchemaChange is a regression test that asserts that
99130
// fingerprinting does not fail when done in the middle of a schema change using
100131
// an AOST query. In the middle of a schema change such as `ADD COLUMN ...

0 commit comments

Comments
 (0)