Skip to content

Commit

Permalink
sql: override StmtTimeout to 0 for background jobs
Browse files Browse the repository at this point in the history
For background jobs and schema changes, our Internal
Executor inherits from cluster settings. If a statement
timeout is set cluster-wide, then background jobs will
respect this -- which does not make much sense; thus,
this patch overrides the StmtTimeout to 0s for background
jobs.

Fixes: cockroachdb#126261
Release note (bug fix): Background jobs no longer respect
a statement timeout.
  • Loading branch information
annrpom committed Jun 27, 2024
1 parent 1c3b6a6 commit e157215
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/sql/internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func NewInternalSessionData(
sd.SearchPath = sessiondata.DefaultSearchPathForUser(username.NodeUserName())
sd.SequenceState = sessiondata.NewSequenceState()
sd.Location = time.UTC
sd.StmtTimeout = 0
return sd
}

Expand Down
34 changes: 34 additions & 0 deletions pkg/sql/opt/exec/execbuilder/testdata/execute_internally_builtin
Original file line number Diff line number Diff line change
Expand Up @@ -215,3 +215,37 @@ root

statement ok
SELECT crdb_internal.execute_internally('EXPLAIN ANALYZE SELECT 1;');

# Ensure that StmtTimeout for a session-independent IE cannot be overriden.
subtest stmt_timeout

statement ok
SET CLUSTER SETTING sql.defaults.statement_timeout = '36000000ms';

statement ok
SET statement_timeout = '39600000ms';

query T
SELECT crdb_internal.execute_internally('SHOW statement_timeout;');
----
0

# Ensure that a session-bound IE still inherits from session vars, if available;
# otherwise, it inherits from the cluster setting.
query T
SELECT crdb_internal.execute_internally('SHOW statement_timeout;', true);
----
39600000

statement ok
RESET statement_timeout;

query T
SELECT crdb_internal.execute_internally('SHOW statement_timeout;', true);
----
36000000

statement ok
RESET CLUSTER SETTING sql.defaults.statement_timeout;

subtest end

0 comments on commit e157215

Please sign in to comment.