Skip to content

Commit

Permalink
cli,sql: fix reported result columns for EXPLAIN ANALYZE
Browse files Browse the repository at this point in the history
This fixes an issue where EXPLAIN ANALYZE would report a RowDescription
for both the EXPLAIN and for the statement being explained. If the
statement had a different number of result columns, this would confuse
the CLI.

No release note, since this bug was not released.

Release note: None
  • Loading branch information
rafiss committed Jun 7, 2022
1 parent 729b075 commit f548996
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
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

0 comments on commit f548996

Please sign in to comment.