Skip to content

Commit 34ce11a

Browse files
craig[bot]DrewKimball
andcommitted
Merge #153475
153475: sql: add system table for external statement hints r=michae2 a=DrewKimball #### sql: add hints package This commit adds a new `sql/hints` package along with a `StatementHints` protobuf struct and some utility functions for working with it. Epic: None Release note: None #### sql: add system.statement_hints table This patch adds a new table, `system.statement_hints`, which can be used to associate "external" hints with a statement without having to modify the statement itself. A following PR will add a per-node cache for this table, similar to the way table stats are handled. Informs #148160 Release note: None Co-authored-by: Drew Kimball <[email protected]>
2 parents efbdc43 + 32c5577 commit 34ce11a

File tree

106 files changed

+861
-309
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+861
-309
lines changed

docs/generated/settings/settings-for-tenants.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,4 +421,4 @@ trace.zipkin.collector string the address of a Zipkin instance to receive trace
421421
ui.database_locality_metadata.enabled boolean true if enabled shows extended locality data about databases and tables in DB Console which can be expensive to compute application
422422
ui.default_timezone string the default timezone used to format timestamps in the ui application
423423
ui.display_timezone enumeration etc/utc the timezone used to format timestamps in the ui. This setting is deprecatedand will be removed in a future version. Use the 'ui.default_timezone' setting instead. 'ui.default_timezone' takes precedence over this setting. [etc/utc = 0, america/new_york = 1] application
424-
version version 1000025.3-upgrading-to-1000025.4-step-012 set the active cluster version in the format '<major>.<minor>' application
424+
version version 1000025.3-upgrading-to-1000025.4-step-014 set the active cluster version in the format '<major>.<minor>' application

docs/generated/settings/settings.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,6 @@
379379
<tr><td><div id="setting-ui-database-locality-metadata-enabled" class="anchored"><code>ui.database_locality_metadata.enabled</code></div></td><td>boolean</td><td><code>true</code></td><td>if enabled shows extended locality data about databases and tables in DB Console which can be expensive to compute</td><td>Basic/Standard/Advanced/Self-Hosted</td></tr>
380380
<tr><td><div id="setting-ui-default-timezone" class="anchored"><code>ui.default_timezone</code></div></td><td>string</td><td><code></code></td><td>the default timezone used to format timestamps in the ui</td><td>Basic/Standard/Advanced/Self-Hosted</td></tr>
381381
<tr><td><div id="setting-ui-display-timezone" class="anchored"><code>ui.display_timezone</code></div></td><td>enumeration</td><td><code>etc/utc</code></td><td>the timezone used to format timestamps in the ui. This setting is deprecatedand will be removed in a future version. Use the &#39;ui.default_timezone&#39; setting instead. &#39;ui.default_timezone&#39; takes precedence over this setting. [etc/utc = 0, america/new_york = 1]</td><td>Basic/Standard/Advanced/Self-Hosted</td></tr>
382-
<tr><td><div id="setting-version" class="anchored"><code>version</code></div></td><td>version</td><td><code>1000025.3-upgrading-to-1000025.4-step-012</code></td><td>set the active cluster version in the format &#39;&lt;major&gt;.&lt;minor&gt;&#39;</td><td>Basic/Standard/Advanced/Self-Hosted</td></tr>
382+
<tr><td><div id="setting-version" class="anchored"><code>version</code></div></td><td>version</td><td><code>1000025.3-upgrading-to-1000025.4-step-014</code></td><td>set the active cluster version in the format &#39;&lt;major&gt;.&lt;minor&gt;&#39;</td><td>Basic/Standard/Advanced/Self-Hosted</td></tr>
383383
</tbody>
384384
</table>

pkg/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,6 +2062,7 @@ GO_TARGETS = [
20622062
"//pkg/sql/gcjob:gcjob",
20632063
"//pkg/sql/gcjob:gcjob_test",
20642064
"//pkg/sql/gcjob_test:gcjob_test_test",
2065+
"//pkg/sql/hints:hints",
20652066
"//pkg/sql/idxrecommendations:idxrecommendations",
20662067
"//pkg/sql/idxrecommendations:idxrecommendations_test",
20672068
"//pkg/sql/idxusage:idxusage",

pkg/backup/full_cluster_backup_restore_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,9 @@ CREATE TABLE data2.foo (a int);
192192
sqlDB.Exec(t, `CREATE SCHEDULE FOR BACKUP data.bank INTO $1 RECURRING '@hourly' FULL BACKUP ALWAYS WITH SCHEDULE OPTIONS first_run = $2`, localFoo, firstRun)
193193
sqlDB.Exec(t, `PAUSE SCHEDULES SELECT id FROM [SHOW SCHEDULES FOR BACKUP]`)
194194

195+
// Populate system.statement_hints with a dummy row.
196+
sqlDB.Exec(t, `INSERT INTO system.statement_hints (fingerprint, hint) VALUES ('FOO BAR _', '0xDEADBEEF'::BYTES)`)
197+
195198
injectStats(t, sqlDB, "data.bank", "id")
196199
sqlDB.Exec(t, `BACKUP INTO $1`, localFoo)
197200

@@ -294,6 +297,7 @@ CREATE TABLE data2.foo (a int);
294297
systemschema.UITable.GetName(),
295298
systemschema.UsersTable.GetName(),
296299
systemschema.ScheduledJobsTable.GetName(),
300+
systemschema.StatementHintsTable.GetName(),
297301
}
298302

299303
verificationQueries := make([]string, len(systemTablesToVerify))
@@ -713,6 +717,7 @@ func TestClusterRestoreFailCleanup(t *testing.T) {
713717
{"role_options"},
714718
{"scheduled_jobs"},
715719
{"settings"},
720+
{"statement_hints"},
716721
{"tenant_settings"},
717722
{"ui"},
718723
{"users"},
@@ -807,6 +812,7 @@ func TestClusterRestoreFailCleanup(t *testing.T) {
807812
{"role_options"},
808813
{"scheduled_jobs"},
809814
{"settings"},
815+
{"statement_hints"},
810816
{"tenant_settings"},
811817
{"ui"},
812818
{"users"},

pkg/backup/system_schema.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -872,6 +872,9 @@ var systemTableBackupConfiguration = map[string]systemBackupConfiguration{
872872
systemschema.TransactionDiagnosticsTable.GetName(): {
873873
shouldIncludeInClusterBackup: optOutOfClusterBackup,
874874
},
875+
systemschema.StatementHintsTable.GetName(): {
876+
shouldIncludeInClusterBackup: optInToClusterBackup, // No desc ID columns.
877+
},
875878
}
876879

877880
func rekeySystemTable(

pkg/backup/testdata/backup-restore/external-connections-nodelocal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ role_options table full
5151
scheduled_jobs table full
5252
schema schema full
5353
settings table full
54+
statement_hints table full
5455
system database full
5556
ui table full
5657
users table full

pkg/backup/testdata/backup-restore/external-connections-userfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ role_options table full
5151
scheduled_jobs table full
5252
schema schema full
5353
settings table full
54+
statement_hints table full
5455
system database full
5556
ui table full
5657
userfiles_root_upload_files table full

pkg/ccl/logictestccl/testdata/logic_test/crdb_internal_tenant

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,12 @@ txn_id txn_fingerprint_id query implicit_txn session_id start_time end_tim
251251
query ITTI
252252
SELECT range_id, start_pretty, end_pretty, lease_holder FROM crdb_internal.ranges
253253
----
254-
78 /Tenant/10 /Tenant/11 1
254+
79 /Tenant/10 /Tenant/11 1
255255

256256
query ITT
257257
SELECT range_id, start_pretty, end_pretty FROM crdb_internal.ranges_no_leases
258258
----
259-
78 /Tenant/10 /Tenant/11
259+
79 /Tenant/10 /Tenant/11
260260

261261
query IT
262262
SELECT zone_id, target FROM crdb_internal.zones ORDER BY 1

pkg/ccl/logictestccl/testdata/logic_test/multi_region_remote_access_error

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ skipif config multiregion-9node-3region-3azs-vec-off
471471
query I retry
472472
SELECT DISTINCT range_id FROM [SHOW RANGES FROM TABLE messages_rbr]
473473
----
474-
83
474+
84
475475

476476
# Update does not fail when accessing all rows in messages_rbr because lookup
477477
# join does not error out the lookup table in phase 1.

pkg/ccl/logictestccl/testdata/logic_test/regional_by_row_insert_fast_path

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ query T rowsort
200200
SELECT message FROM [SHOW KV TRACE FOR SESSION]
201201
WHERE message LIKE '%batch%' AND message LIKE '%Scan%'
202202
----
203-
r77: sending batch 4 Scan to (n1,s1):1
203+
r78: sending batch 4 Scan to (n1,s1):1
204204

205205
# Regression test for #115377.
206206
statement ok

0 commit comments

Comments
 (0)