Skip to content

Skip --checkpoint file statements with --resume#1853

Open
rolandwalker wants to merge 1 commit intomainfrom
RW/batch-replay-checkpoint-file
Open

Skip --checkpoint file statements with --resume#1853
rolandwalker wants to merge 1 commit intomainfrom
RW/batch-replay-checkpoint-file

Conversation

@rolandwalker
Copy link
Copy Markdown
Contributor

@rolandwalker rolandwalker commented Apr 18, 2026

Description

In --batch mode, when the batch input script is not STDIN, and when --checkpoint is also given, --resume causes mycli to replay the checkpoint file, looking for leading matching statements, and skip execution of batch statements already present in the checkpoint file.

Motivation: resumption of interrupted batch scripts.

The number of statements in the checkpoint file must be fewer than the number of statements in the batch script, and form a leading match, or mycli will exit without executing anything.

Once execution is picked up again from the midpoint of the --batch script, we continue to append new statements to the checkpoint file, after each statement is successfully executed. That behavior is unchanged. This allows the checkpoint file to be used again if the batch script is interrupted multiple times.

The --progress bar and included ETA calculation account for the statements replayed from the checkpoint file, and show corrected views.

Further work could include creating a [batch] section in myclirc and adding a default value for resumption, with a --no-resume option at the CLI.

Note: some SQL statements change server/session state or start transactions. But any successful statement will be checkpointed and then not executed upon resumption in --resume mode. It is incumbent on the user to account for such state when resuming from a checkpoint.

This PR represents a major goal in a series of PRs to strengthen batch execution, some of which are:

Checklist

  • I added this contribution to the changelog.md file.
  • I added my name to the AUTHORS file (or it's already there).
  • To lint and format the code, I ran
    uv run ruff check && uv run ruff format && uv run mypy --install-types .

@rolandwalker rolandwalker self-assigned this Apr 18, 2026
In --batch mode, when the batch input script is not STDIN, and when
--checkpoint is also given, --resume causes mycli to replay the
checkpoint file, looking for leading matching statements, and skip
execution of batch statements already present in the checkpoint file.

Motivation: resumption of interrupted batch scripts.

The number of statements in the checkpoint file must be fewer than the
number of statements in the batch script, and form a leading match, or
mycli will exit without executing anything.

Once execution is picked up again from the midpoint of the --batch
script, we continue to append _new_ statements to the checkpoint file,
after each statement is successfully executed.  That behavior is
unchanged.  This allows the checkpoint file to be used again if the
batch script is interrupted multiple times.

The --progress bar and included ETA calculation account for the
statements replayed from the checkpoint file, and show corrected
views.

Further work could include creating a [batch] section in myclirc and
adding a default value for resumption, with a --no-resume option.

Note: some SQL statements change server/session state or start
transactions.  But _any_ successful statement will be checkpointed and
then not executed upon resumption in --resume mode.  It is incumbent on
the user to account for such state when resuming from a checkpoint.
@rolandwalker rolandwalker force-pushed the RW/batch-replay-checkpoint-file branch from 90f4540 to 483bfbf Compare April 18, 2026 17:01
Comment thread mycli/main_modes/batch.py
click.secho('--progress is only compatible with a plain file.', err=True, fg='red')
return 1
try:
completed_statement_count = replay_checkpoint_file(cli_args.batch, cli_args.checkpoint, cli_args.resume)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks like currently the batch file is getting opened three times; one in this new replay_checkpoint_file function, again on line 122, and again on line 172. Would it be possible to combine those somehow? Maybe returning something from replay_checkpoint_file to re-use.

Comment thread mycli/main.py
if cli_args.password is None and os.environ.get("MYSQL_PWD") is not None:
cli_args.password = os.environ.get("MYSQL_PWD")

if cli_args.resume and not cli_args.checkpoint:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Should you also check if --batch mode is given with --resume? I.e. could use --execute and --resume currently.

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.

2 participants