Skip to content

Show query status and timings while waiting - #2278

Open
rolandwalker wants to merge 1 commit into
mainfrom
RW/show-query-status-in-foreground-with-rendering
Open

rolandwalker wants to merge 1 commit into
mainfrom
RW/show-query-status-in-foreground-with-rendering

Conversation

@rolandwalker

@rolandwalker rolandwalker commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Description

While a query is running, and while output is prepared, the current mycli UI is entirely blank. (Less than a lack of feedback: the prompt-toolkit toolbar even disappears.)

Better practice would be to tell the user what is happening. Here we run the MySQL query in a thread, and print the query status every half-second by default.

The status is accompanied by the elapsed time. A spinner from yaspinner was also considered. A spinner is more tidy; the timings give more information.

The query status string is derived from running SHOW PROCESSLIST in a separate monitoring connection, and a few pseudo-states are added beyond those listed in

including the important pseudo-state rendering, which we learned here can take a substantial amount of time for results on the order of 100K rows or above.

The MySQL thread states are very inconsistent on casing, which looked janky, so all are rendered as lowercase.

Care is taken to catch interrupts and cancel background threads correctly.

There is a new file query_runner.py, outside of which impact on non- test files is happily low.

Drawbacks:

  • only a few server states account for most of what is visible at a reasonable sampling resolution.

Suggestions for future work:

  • remember all of the states/timings for an extended textual timing summary at the end; a simpler SHOW PROFILES
  • show prompt-toolkit toolbar during query
  • show transforms as a separate state transforming
  • it is possible to see the executing state multiple times, and not clear if that is a good thing
  • it would be best to almost never see finding state, but it shows briefly at the start some times, in some configurations

Example: this video is from an early draft, but the idea is put across, including the amount of time spent on client-side rendering:

mycli_query_progress_rendering.mov

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 Sep 28, 2026
@rolandwalker
rolandwalker force-pushed the RW/show-query-status-in-foreground-with-rendering branch from 5dc3345 to e37fc4d Compare September 28, 2026 20:43
While a query is running, and while output is prepared, the current
mycli UI is entirely blank.  (Less than a lack of feedback:
the prompt-toolkit toolbar even disappears.)

Better practice would be to tell the user what is happening.  Here
we run the MySQL query in a thread, and print the query status every
half-second by default.

The status is accompanied by the elapsed time.  A spinner from
yaspinner was also considered.  A spinner is more tidy; the timings
give more information.

The query status string is derived from running SHOW PROCESSLIST in a
separate monitoring connection, and a few pseudo-states are added beyond
those listed in

 * https://dev.mysql.com/doc/refman/9.7/en/general-thread-states.html

including the important pseudo-state "rendering", which we learned here
can take a substantial amount of time for results on the order of 100K
rows or above.

The MySQL thread states are very inconsistent on casing, which looked
janky, so all are rendered as lowercase.

Care is taken to catch interrupts and cancel background threads
correctly.

There is a new file query_runner.py, outside of which impact on non-
test files is happily low.

Drawbacks:

 * only a few server states account for most of what is visible at a
   reasonable sampling resolution.

Suggestions for future work:

 * remember all of the states/timings for an extended textual timing
   summary at the end; a simpler SHOW PROFILES
 * show prompt-toolkit toolbar during query
 * show transforms as a separate state "transforming"
 * it is possible to see the "executing" state multiple times, and not
   clear if that is a good thing
 * it would be best to almost never see "finding state", but it shows
   briefly at the start some times, in some configurations
@rolandwalker
rolandwalker force-pushed the RW/show-query-status-in-foreground-with-rendering branch from e37fc4d to 0d4b1a1 Compare September 28, 2026 20:46

This branch has not been deployed

No deployments
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.

1 participant