Skip to content

Conversation

@spilchen
Copy link
Contributor

@spilchen spilchen commented Dec 3, 2025

Add a new SQL statement 'EXECUTE SCHEDULE <schedule_id>' to execute a scheduled job immediately. This reuses the existing logic from ALTER BACKUP SCHEDULE ... EXECUTE IMMEDIATELY, but generalizes it to support any scheduled job.

This functionality is particularly useful for TTL jobs, allowing users to trigger them on demand.

The <schedule_id> can be a literal or a subquery (e.g., from SHOW SCHEDULES). If multiple are provided, you must use EXECUTE SCHEDULES.

Resolves: #146723
Epic: none
Release note (sql change): Added support for EXECUTE SCHEDULE <schedule_id> to allow immediate execution of a scheduled job.

@spilchen spilchen self-assigned this Dec 3, 2025
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@spilchen spilchen force-pushed the gh-146723/251118/0958/run-ttl-job-immediately/pr-ready branch from 11fc91a to 00cb4ff Compare December 3, 2025 19:34
@spilchen spilchen changed the title sql: add support for RUN SCHEDULE statement sql: add support for EXECUTE SCHEDULE statement Dec 3, 2025
@spilchen spilchen force-pushed the gh-146723/251118/0958/run-ttl-job-immediately/pr-ready branch 2 times, most recently from 41d83fa to 6cb1c5e Compare December 3, 2025 19:41
@spilchen spilchen marked this pull request as ready for review December 3, 2025 21:12
@spilchen spilchen requested review from a team as code owners December 3, 2025 21:12
@spilchen spilchen requested review from a team, dt and mw5h and removed request for a team December 3, 2025 21:12
Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i only had minor comments, this lgtm!

could you post this PR in #db-jobinfra-eng on Slack as well to check if they have any feedback?

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt, @mw5h, and @spilchen)


pkg/sql/parser/testdata/control_job line 642 at r1 (raw file):


parse
EXECUTE SCHEDULES SELECT 123

can we also verify that EXECUTE SCHEDULE SELECT 123 (the non-plural variant) parses?


pkg/sql/parser/lexer.go line 330 at r1 (raw file):

				lval.id = FOR_JOB
			}
		case EXECUTE:

i think we need to add "execute" to the lookaheadKeywords slice:

// If you update these cases, update lexbase.lookaheadKeywords.

IIRC, this is needed to correctly handle objects that have the name "execute"

Add a new SQL statement 'EXECUTE SCHEDULE <schedule_id>' to execute a
scheduled job immediately. This reuses the existing logic from ALTER
BACKUP SCHEDULE ... EXECUTE IMMEDIATELY, but generalizes it to support
any scheduled job.

This functionality is particularly useful for TTL jobs, allowing users to
trigger them on demand.

The <schedule_id> can be a literal or a subquery (e.g., from SHOW
SCHEDULES). If multiple are provided, you must use EXECUTE SCHEDULES.

Resolves: cockroachdb#146723
Epic: none
Release note (sql change): Added support for EXECUTE SCHEDULE
<schedule_id> to allow immediate execution of a scheduled job.
@spilchen spilchen force-pushed the gh-146723/251118/0958/run-ttl-job-immediately/pr-ready branch from 6cb1c5e to 945b3ec Compare December 4, 2025 20:10
Copy link
Contributor Author

@spilchen spilchen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I posted it to #db-jobinfra-eng

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt, @mw5h, and @rafiss)


pkg/sql/parser/lexer.go line 330 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

i think we need to add "execute" to the lookaheadKeywords slice:

// If you update these cases, update lexbase.lookaheadKeywords.

IIRC, this is needed to correctly handle objects that have the name "execute"

Hmm, it was added already. See update to pkg/sql/lexbase/predicates.go


pkg/sql/parser/testdata/control_job line 642 at r1 (raw file):

Previously, rafiss (Rafi Shamim) wrote…

can we also verify that EXECUTE SCHEDULE SELECT 123 (the non-plural variant) parses?

Done.

Copy link
Collaborator

@rafiss rafiss left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained (waiting on @dt and @mw5h)


pkg/sql/parser/lexer.go line 330 at r1 (raw file):

Previously, spilchen wrote…

Hmm, it was added already. See update to pkg/sql/lexbase/predicates.go

Oops, I must have confused myself looking at my local diff

@msbutler msbutler self-requested a review December 5, 2025 22:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ttl: add mechanism to trigger TTL job immediately for testing

3 participants