Show query state and timings while waiting - #2278
Merged
rolandwalker merged 1 commit intoSep 29, 2026
Merged
Conversation
rolandwalker
force-pushed
the
RW/show-query-status-in-foreground-with-rendering
branch
3 times, most recently
from
September 29, 2026 09:55
0d4b1a1 to
748a8bd
Compare
rolandwalker
force-pushed
the
RW/show-query-status-in-foreground-with-rendering
branch
4 times, most recently
from
September 29, 2026 10:26
a6e0b6c to
4ee1ca7
Compare
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 state every half-second by default. Nothing is displayed until the half-second interval is reached. The state 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-state 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 official 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. The second monitoring connection is reused between queries. 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 (difficult) * 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 * test on exotic servers such as TiDB
rolandwalker
force-pushed
the
RW/show-query-status-in-foreground-with-rendering
branch
from
September 29, 2026 10:30
4ee1ca7 to
d1f07c1
Compare
rolandwalker
deleted the
RW/show-query-status-in-foreground-with-rendering
branch
September 29, 2026 14:22
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 state every half-second by default. Nothing is displayed until the half-second interval is reached.
The state is accompanied by the elapsed time. A spinner from
yaspinnerwas also considered. A spinner is more tidy; the timings give more information.The query-state string is derived from running
SHOW PROCESSLISTin a separate monitoring connection, and a few pseudo-states are added beyond those listed inincluding 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 official 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.
The second monitoring connection is reused between queries.
There is a new file
query_runner.py, outside of which impact on non-test files is happily low.Drawbacks:
Suggestions for future work:
SHOW PROFILES.Show transforms as a separate statedone and force-pushedtransforming.executingstate multiple times, and not clear if that is a good thing.finding state, but it shows briefly at the start some times, in some configurations.SHOW PROCESSLISTwhich should be all that is needed.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
changelog.mdfile.AUTHORSfile (or it's already there).