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: fix reported result columns for EXPLAIN ANALYZE #82520

Merged
merged 1 commit into from
Jun 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions pkg/cli/interactive_tests/test_explain_analyze.tcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#! /usr/bin/env expect -f

source [file join [file dirname $argv0] common.tcl]

start_server $argv

start_test "Ensure that EXPLAIN ANALYZE works as expected in the sql shell"

# Spawn a sql shell.
spawn $argv sql
set client_spawn_id $spawn_id
eexpect root@

# Check for a regression where the CLI would get confused when the statement
# had a different number of result columns.
send "EXPLAIN ANALYZE SELECT 1,2;\r"
eexpect "info"
eexpect "planning time"
eexpect "actual row count"

send_eof
eexpect eof

end_test

stop_server $argv
5 changes: 4 additions & 1 deletion pkg/sql/conn_executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -3004,7 +3004,10 @@ func (ex *connExecutor) initStatementResult(
return err
}
}
if ast.StatementReturnType() == tree.Rows {
// If the output mode has been modified by instrumentation (e.g. EXPLAIN
// ANALYZE), then the columns will be set later.
if ex.planner.instrumentation.outputMode == unmodifiedOutput &&
ast.StatementReturnType() == tree.Rows {
// Note that this call is necessary even if cols is nil.
res.SetColumns(ctx, cols)
}
Expand Down