Skip to content

Commit 3a25007

Browse files
committed
sql: add setting to enable registering latch wait contention events
This commit adds a session setting (default off) that will cause contention events emitted by the latch table to be included in the `*_contention_events` virtual tables. This behavior is hidden behind a setting because latch wait events are more common than events emitted by the lock table. Tracking them in the virtual tables could increase system load and flood the statement insights with uninteresting events. For now, this setting does nothing, but the following commit will use it. Informs #103713 Release note: None
1 parent a66d2fb commit 3a25007

File tree

6 files changed

+31
-0
lines changed

6 files changed

+31
-0
lines changed

pkg/sql/exec_util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4097,6 +4097,10 @@ func (m *sessionDataMutator) SetOptimizerPlanLookupJoinsWithReverseScans(val boo
40974097
m.data.OptimizerPlanLookupJoinsWithReverseScans = val
40984098
}
40994099

4100+
func (m *sessionDataMutator) SetRegisterLatchWaitContentionEvents(val bool) {
4101+
m.data.RegisterLatchWaitContentionEvents = val
4102+
}
4103+
41004104
// Utility functions related to scrubbing sensitive information on SQL Stats.
41014105

41024106
// quantizeCounts ensures that the Count field in the

pkg/sql/logictest/testdata/logic_test/information_schema

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4049,6 +4049,7 @@ prefer_lookup_joins_for_fks off
40494049
prepared_statements_cache_size 0 B
40504050
propagate_input_ordering off
40514051
recursion_depth_limit 1000
4052+
register_latch_wait_contention_events off
40524053
reorder_joins_limit 8
40534054
require_explicit_primary_keys off
40544055
results_buffer_size 524288

pkg/sql/logictest/testdata/logic_test/pg_catalog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3060,6 +3060,7 @@ prefer_lookup_joins_for_fks off N
30603060
prepared_statements_cache_size 0 B NULL NULL NULL string
30613061
propagate_input_ordering off NULL NULL NULL string
30623062
recursion_depth_limit 1000 NULL NULL NULL string
3063+
register_latch_wait_contention_events off NULL NULL NULL string
30633064
reorder_joins_limit 8 NULL NULL NULL string
30643065
require_explicit_primary_keys off NULL NULL NULL string
30653066
results_buffer_size 524288 NULL NULL NULL string
@@ -3270,6 +3271,7 @@ prefer_lookup_joins_for_fks off N
32703271
prepared_statements_cache_size 0 B NULL user NULL 0 B 0 B
32713272
propagate_input_ordering off NULL user NULL off off
32723273
recursion_depth_limit 1000 NULL user NULL 1000 1000
3274+
register_latch_wait_contention_events off NULL user NULL off off
32733275
reorder_joins_limit 8 NULL user NULL 8 8
32743276
require_explicit_primary_keys off NULL user NULL off off
32753277
results_buffer_size 524288 NULL user NULL 524288 524288
@@ -3479,6 +3481,7 @@ prefer_lookup_joins_for_fks NULL NULL NULL
34793481
prepared_statements_cache_size NULL NULL NULL NULL NULL
34803482
propagate_input_ordering NULL NULL NULL NULL NULL
34813483
recursion_depth_limit NULL NULL NULL NULL NULL
3484+
register_latch_wait_contention_events NULL NULL NULL NULL NULL
34823485
reorder_joins_limit NULL NULL NULL NULL NULL
34833486
require_explicit_primary_keys NULL NULL NULL NULL NULL
34843487
results_buffer_size NULL NULL NULL NULL NULL

pkg/sql/logictest/testdata/logic_test/show_source

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ prefer_lookup_joins_for_fks off
176176
prepared_statements_cache_size 0 B
177177
propagate_input_ordering off
178178
recursion_depth_limit 1000
179+
register_latch_wait_contention_events off
179180
reorder_joins_limit 8
180181
require_explicit_primary_keys off
181182
results_buffer_size 524288

pkg/sql/sessiondatapb/local_only_session_data.proto

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,11 @@ message LocalOnlySessionData {
617617
// that use reverse scans to get results in reverse index order on each
618618
// lookup.
619619
bool optimizer_plan_lookup_joins_with_reverse_scans = 158;
620+
// RegisterLatchWaitContentionEvents, when true, causes latch wait contention
621+
// events to be registered with the *.contention_events virtual tables. It
622+
// defaults to false in order to avoid registering a large number of
623+
// uninformative latch wait events.
624+
bool register_latch_wait_contention_events = 159;
620625

621626
///////////////////////////////////////////////////////////////////////////
622627
// WARNING: consider whether a session parameter you're adding needs to //

pkg/sql/vars.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3840,6 +3840,23 @@ var varGen = map[string]sessionVar{
38403840
},
38413841
GlobalDefault: globalTrue,
38423842
},
3843+
3844+
// CockroachDB extension.
3845+
`register_latch_wait_contention_events`: {
3846+
GetStringVal: makePostgresBoolGetStringValFn(`register_latch_wait_contention_events`),
3847+
Set: func(_ context.Context, m sessionDataMutator, s string) error {
3848+
b, err := paramparse.ParseBoolVar("register_latch_wait_contention_events", s)
3849+
if err != nil {
3850+
return err
3851+
}
3852+
m.SetRegisterLatchWaitContentionEvents(b)
3853+
return nil
3854+
},
3855+
Get: func(evalCtx *extendedEvalContext, _ *kv.Txn) (string, error) {
3856+
return formatBoolAsPostgresSetting(evalCtx.SessionData().RegisterLatchWaitContentionEvents), nil
3857+
},
3858+
GlobalDefault: globalFalse,
3859+
},
38433860
}
38443861

38453862
func ReplicationModeFromString(s string) (sessiondatapb.ReplicationMode, error) {

0 commit comments

Comments
 (0)