Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cli/sql: support query cancellation in the SQL shell #76433

Closed
knz opened this issue Feb 11, 2022 · 0 comments · Fixed by #76437
Closed

cli/sql: support query cancellation in the SQL shell #76433

knz opened this issue Feb 11, 2022 · 0 comments · Fixed by #76437
Labels
A-cli-client CLI commands that pertain to using SQL features A-sql-execution Relating to SQL execution. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-server-and-security DB Server & Security

Comments

@knz
Copy link
Contributor

knz commented Feb 11, 2022

We want Ctrl+C to interrupt queries when running interactively.

This will also address #46988.

@knz knz added C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) A-sql-execution Relating to SQL execution. A-cli-client CLI commands that pertain to using SQL features labels Feb 11, 2022
@blathers-crl blathers-crl bot added the T-server-and-security DB Server & Security label Feb 11, 2022
craig bot pushed a commit that referenced this issue Feb 11, 2022
76427: cli,sql: do not exit interactive shells with Ctrl+C r=rafiss a=knz

First commit from #76434.
Needed for #76433.

This change is a preface to making the interactive shell support
Ctrl+C to cancel a currently executing query.

When that happens, we need to ensure that Ctrl+C *only* cancels the
current query, and not the entire shell. This is because there is no
deterministic boundary in time for a user to decide whether the key
press will cancel only the query, or stop the shell. If they care
about keeping their shell alive, they would never "dare" to press
Ctrl+C while a query is executing.

Incidentally, this is also what `psql` does, for pretty much the same
reason.

Note that the new behavior is restricted to *interactive* shells, when
stdin is a terminal. The behavior for non-interactive shells remains
unchanged, where Ctrl+C will terminate everything. This is also what
other SQL shells do.

Release note (cli change): `cockroach sql` (and `demo`) now continue
to accept user input when Ctrl+C is pressed at the interactive prompt
and the current input line is empty. Previously, it would terminate
the shell.  To terminate the shell, the client-side command `\q` is
still supported. The user can also terminate the input altogether via
EOF (Ctrl+D).
The behavior in non-interactive use remains unchanged.

Co-authored-by: Raphael 'kena' Poss <[email protected]>
@craig craig bot closed this as completed in 0aacc53 Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-cli-client CLI commands that pertain to using SQL features A-sql-execution Relating to SQL execution. C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) T-server-and-security DB Server & Security
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant