@@ -11,6 +11,7 @@ import (
11
11
"fmt"
12
12
"strings"
13
13
14
+ "github.com/cockroachdb/cockroach/pkg/keys"
14
15
"github.com/cockroachdb/cockroach/pkg/roachpb"
15
16
"github.com/cockroachdb/cockroach/pkg/security/username"
16
17
"github.com/cockroachdb/cockroach/pkg/sql/catalog"
@@ -30,13 +31,28 @@ import (
30
31
"github.com/cockroachdb/redact"
31
32
)
32
33
33
- // indexConsistencyCheck verifies consistency between a table’s primary index
34
+ // indexConsistencyCheckApplicability is a lightweight version that only implements applicability logic.
35
+ type indexConsistencyCheckApplicability struct {
36
+ tableID descpb.ID
37
+ }
38
+
39
+ var _ inspectCheckApplicability = (* indexConsistencyCheckApplicability )(nil )
40
+
41
+ // AppliesTo implements the inspectCheckApplicability interface.
42
+ func (c * indexConsistencyCheckApplicability ) AppliesTo (
43
+ codec keys.SQLCodec , span roachpb.Span ,
44
+ ) (bool , error ) {
45
+ return spanContainsTable (c .tableID , codec , span )
46
+ }
47
+
48
+ // indexConsistencyCheck verifies consistency between a table's primary index
34
49
// and a specified secondary index by streaming rows from both sides of a
35
50
// query. It reports an issue if a key exists in the primary but not the
36
51
// secondary, or vice versa.
37
52
type indexConsistencyCheck struct {
53
+ indexConsistencyCheckApplicability
54
+
38
55
flowCtx * execinfra.FlowCtx
39
- tableID descpb.ID
40
56
indexID descpb.IndexID
41
57
asOf hlc.Timestamp
42
58
@@ -57,6 +73,7 @@ type indexConsistencyCheck struct {
57
73
}
58
74
59
75
var _ inspectCheck = (* indexConsistencyCheck )(nil )
76
+ var _ inspectCheckApplicability = (* indexConsistencyCheck )(nil )
60
77
61
78
// Started implements the inspectCheck interface.
62
79
func (c * indexConsistencyCheck ) Started () bool {
@@ -67,14 +84,9 @@ func (c *indexConsistencyCheck) Started() bool {
67
84
func (c * indexConsistencyCheck ) Start (
68
85
ctx context.Context , cfg * execinfra.ServerConfig , span roachpb.Span , workerIndex int ,
69
86
) error {
70
- // Early out for spans that don't apply to the table we are running the check on.
71
- _ , tableID , err := cfg .Codec .DecodeTablePrefix (span .Key )
72
- if err != nil {
87
+ if err := assertCheckApplies (c , cfg .Codec , span ); err != nil {
73
88
return err
74
89
}
75
- if descpb .ID (tableID ) != c .tableID {
76
- return nil
77
- }
78
90
79
91
// Load up the index and table descriptors.
80
92
if err := c .loadCatalogInfo (ctx ); err != nil {
0 commit comments