Skip to content

Commit 769e407

Browse files
committed
sql/inspect: run INSPECT against a single index
Previously, the INSPECT command was a no-op that performed no actual checking. This change implements the first consistency check for INSPECT: index consistency checking, currently supporting a single index at a time. The consistency checking uses a full outer join between the primary index and secondary index access paths to identify rows that exist in one index but not the other, detecting potential corruption or inconsistency issues. This new functionality is integrated into the INSPECT job and triggered through SCRUB when the enable_scrub_job setting is enabled. Future work will expose this through direct INSPECT SQL commands. Note for reviewers: - Some tests currently generate internal errors in the SQL query engine. These are not logged as INSPECT issues for now and will be resolved in subsequent work. - I include a crdb_internal.void_func() predicate in the query to prevent the optimizer from optimizing the join away. There were a couple of other options (add barrier option to CTE, materialize the CTE inline), but this was the preferred method. Release note: None Epic: CRDB-30356
1 parent 9e0ba6b commit 769e407

13 files changed

+1342
-59
lines changed

pkg/sql/exec_util.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,8 @@ type InspectTestingKnobs struct {
20982098
// OnInspectJobStart is called just before the inspect job begins execution.
20992099
// If it returns an error, the job fails immediately.
21002100
OnInspectJobStart func() error
2101+
// InspectIssueLogger is an override to the default issue logger.
2102+
InspectIssueLogger interface{}
21012103
}
21022104

21032105
// ModuleTestingKnobs implements the base.ModuleTestingKnobs interface.

pkg/sql/inspect/BUILD.bazel

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
33
go_library(
44
name = "inspect",
55
srcs = [
6+
"index_consistency_check.go",
67
"inspect_job.go",
78
"inspect_processor.go",
89
"issue.go",
@@ -16,20 +17,31 @@ go_library(
1617
"//pkg/jobs",
1718
"//pkg/jobs/jobspb",
1819
"//pkg/roachpb",
20+
"//pkg/security/username",
1921
"//pkg/settings",
2022
"//pkg/settings/cluster",
2123
"//pkg/sql",
24+
"//pkg/sql/catalog",
25+
"//pkg/sql/catalog/catenumpb",
2226
"//pkg/sql/catalog/descpb",
2327
"//pkg/sql/catalog/descs",
2428
"//pkg/sql/execinfra",
2529
"//pkg/sql/execinfrapb",
2630
"//pkg/sql/isql",
31+
"//pkg/sql/lexbase",
32+
"//pkg/sql/pgwire/pgcode",
33+
"//pkg/sql/pgwire/pgerror",
2734
"//pkg/sql/physicalplan",
2835
"//pkg/sql/rowexec",
36+
"//pkg/sql/sem/idxtype",
2937
"//pkg/sql/sem/tree",
38+
"//pkg/sql/sessiondata",
39+
"//pkg/sql/sessiondatapb",
40+
"//pkg/sql/spanutils",
3041
"//pkg/sql/types",
3142
"//pkg/util/ctxgroup",
3243
"//pkg/util/log",
44+
"//pkg/util/timeutil",
3345
"//pkg/util/tracing",
3446
"@com_github_cockroachdb_errors//:errors",
3547
"@com_github_cockroachdb_redact//:redact",
@@ -39,6 +51,7 @@ go_library(
3951
go_test(
4052
name = "inspect_test",
4153
srcs = [
54+
"index_consistency_check_test.go",
4255
"inspect_job_test.go",
4356
"inspect_processor_test.go",
4457
"issue_test.go",
@@ -48,14 +61,21 @@ go_test(
4861
embed = [":inspect"],
4962
deps = [
5063
"//pkg/base",
64+
"//pkg/keys",
65+
"//pkg/kv",
5166
"//pkg/roachpb",
5267
"//pkg/security/securityassets",
5368
"//pkg/security/securitytest",
5469
"//pkg/server",
5570
"//pkg/settings/cluster",
5671
"//pkg/sql",
72+
"//pkg/sql/catalog",
73+
"//pkg/sql/catalog/desctestutils",
5774
"//pkg/sql/execinfra",
5875
"//pkg/sql/execinfrapb",
76+
"//pkg/sql/rowenc",
77+
"//pkg/sql/sem/tree",
78+
"//pkg/sql/sessiondata",
5979
"//pkg/testutils",
6080
"//pkg/testutils/serverutils",
6181
"//pkg/testutils/sqlutils",

0 commit comments

Comments
 (0)