Skip to content

Commit 8ffc5bf

Browse files
committed
sql: add sql grammar for inspect command
The `INSPECT` commands are being added to support data consistency validation. These new statements require new SQL grammar. The grammar is added in this change and the implementations will be added in future PRs. Epic: CRDB-30356 Part of: #148272 Release note (sql change): Introduces the `INSPECT TABLE` and `INSPECT DATABASE` statements that are unimplemented. The new `enable_inspect_command` cluster setting feature flag configures access to the new features as they're implemented.
1 parent d8d00d8 commit 8ffc5bf

27 files changed

+542
-12
lines changed

docs/generated/sql/bnf/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ FILES = [
174174
"index_def",
175175
"insert_rest",
176176
"insert_stmt",
177+
"inspect_stmt",
178+
"inspect_database_stmt",
179+
"inspect_table_stmt",
177180
"iso_level",
178181
"joined_table",
179182
"legacy_begin_stmt",
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
inspect_database_stmt ::=
2+
'INSPECT' 'DATABASE' db_name opt_as_of_clause opt_inspect_options_clause
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
inspect_stmt ::=
2+
inspect_table_stmt
3+
| inspect_database_stmt
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
inspect_table_stmt ::=
2+
'INSPECT' 'TABLE' table_name opt_as_of_clause opt_inspect_options_clause

docs/generated/sql/bnf/preparable_stmt.bnf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ preparable_stmt ::=
99
| explain_stmt
1010
| import_stmt
1111
| insert_stmt
12+
| inspect_stmt
1213
| pause_stmt
1314
| reset_stmt
1415
| restore_stmt

docs/generated/sql/bnf/stmt_block.bnf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ preparable_stmt ::=
4949
| explain_stmt
5050
| import_stmt
5151
| insert_stmt
52+
| inspect_stmt
5253
| pause_stmt
5354
| reset_stmt
5455
| restore_stmt
@@ -246,6 +247,10 @@ insert_stmt ::=
246247
opt_with_clause 'INSERT' 'INTO' insert_target insert_rest returning_clause
247248
| opt_with_clause 'INSERT' 'INTO' insert_target insert_rest on_conflict returning_clause
248249

250+
inspect_stmt ::=
251+
inspect_table_stmt
252+
| inspect_database_stmt
253+
249254
pause_stmt ::=
250255
pause_jobs_stmt
251256
| pause_schedules_stmt
@@ -753,6 +758,12 @@ on_conflict ::=
753758
| 'ON' 'CONFLICT' 'ON' 'CONSTRAINT' constraint_name 'DO' 'NOTHING'
754759
| 'ON' 'CONFLICT' 'ON' 'CONSTRAINT' constraint_name 'DO' 'UPDATE' 'SET' set_clause_list opt_where_clause
755760

761+
inspect_table_stmt ::=
762+
'INSPECT' 'TABLE' table_name opt_as_of_clause opt_inspect_options_clause
763+
764+
inspect_database_stmt ::=
765+
'INSPECT' 'DATABASE' db_name opt_as_of_clause opt_inspect_options_clause
766+
756767
pause_jobs_stmt ::=
757768
'PAUSE' 'JOB' a_expr
758769
| 'PAUSE' 'JOB' a_expr 'WITH' 'REASON' '=' string_or_placeholder
@@ -1260,6 +1271,7 @@ unreserved_keyword ::=
12601271
| 'INJECT'
12611272
| 'INPUT'
12621273
| 'INSERT'
1274+
| 'INSPECT'
12631275
| 'INSTEAD'
12641276
| 'INTO_DB'
12651277
| 'INVERTED'
@@ -2044,6 +2056,13 @@ insert_column_item ::=
20442056
kv_option_list ::=
20452057
( kv_option ) ( ( ',' kv_option ) )*
20462058

2059+
opt_inspect_options_clause ::=
2060+
'WITH' 'OPTIONS' inspect_option_list
2061+
|
2062+
2063+
db_name ::=
2064+
db_object_name
2065+
20472066
session_var ::=
20482067
'identifier'
20492068
| 'identifier' session_var_parts
@@ -2940,6 +2959,9 @@ kv_option ::=
29402959
| 'SCONST' '=' string_or_placeholder
29412960
| 'SCONST'
29422961

2962+
inspect_option_list ::=
2963+
( inspect_option ) ( ( ',' inspect_option ) )*
2964+
29432965
session_var_parts ::=
29442966
( '.' 'identifier' ) ( ( '.' 'identifier' ) )*
29452967

@@ -3579,6 +3601,10 @@ only_signed_fconst ::=
35793601
db_object_name_list ::=
35803602
( db_object_name ) ( ( ',' db_object_name ) )*
35813603

3604+
inspect_option ::=
3605+
'INDEX' 'ALL'
3606+
| 'INDEX' '(' table_index_name_list ')'
3607+
35823608
virtual_cluster_name ::=
35833609
'VIRTUAL_CLUSTER_NAME'
35843610

@@ -4163,6 +4189,7 @@ bare_label_keywords ::=
41634189
| 'INPUT'
41644190
| 'INSENSITIVE'
41654191
| 'INSERT'
4192+
| 'INSPECT'
41664193
| 'INSTEAD'
41674194
| 'INT'
41684195
| 'INTEGER'

pkg/gen/bnf.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ BNF_SRCS = [
174174
"//docs/generated/sql/bnf:index_def.bnf",
175175
"//docs/generated/sql/bnf:insert_rest.bnf",
176176
"//docs/generated/sql/bnf:insert_stmt.bnf",
177+
"//docs/generated/sql/bnf:inspect_database_stmt.bnf",
178+
"//docs/generated/sql/bnf:inspect_stmt.bnf",
179+
"//docs/generated/sql/bnf:inspect_table_stmt.bnf",
177180
"//docs/generated/sql/bnf:iso_level.bnf",
178181
"//docs/generated/sql/bnf:joined_table.bnf",
179182
"//docs/generated/sql/bnf:legacy_begin_stmt.bnf",

pkg/gen/diagrams.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,9 @@ DIAGRAMS_SRCS = [
174174
"//docs/generated/sql/bnf:index_def.html",
175175
"//docs/generated/sql/bnf:insert.html",
176176
"//docs/generated/sql/bnf:insert_rest.html",
177+
"//docs/generated/sql/bnf:inspect.html",
178+
"//docs/generated/sql/bnf:inspect_database.html",
179+
"//docs/generated/sql/bnf:inspect_table.html",
177180
"//docs/generated/sql/bnf:iso_level.html",
178181
"//docs/generated/sql/bnf:joined_table.html",
179182
"//docs/generated/sql/bnf:legacy_begin.html",

pkg/gen/docs.bzl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ DOCS_SRCS = [
184184
"//docs/generated/sql/bnf:index_def.bnf",
185185
"//docs/generated/sql/bnf:insert_rest.bnf",
186186
"//docs/generated/sql/bnf:insert_stmt.bnf",
187+
"//docs/generated/sql/bnf:inspect_database_stmt.bnf",
188+
"//docs/generated/sql/bnf:inspect_stmt.bnf",
189+
"//docs/generated/sql/bnf:inspect_table_stmt.bnf",
187190
"//docs/generated/sql/bnf:iso_level.bnf",
188191
"//docs/generated/sql/bnf:joined_table.bnf",
189192
"//docs/generated/sql/bnf:legacy_begin_stmt.bnf",

pkg/sql/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ go_library(
141141
"information_schema.go",
142142
"insert.go",
143143
"insert_fast_path.go",
144+
"inspect_node.go",
144145
"instrumentation.go",
145146
"internal.go",
146147
"internal_result_channel.go",

0 commit comments

Comments
 (0)