diff --git a/pkg/cli/interactive_tests/test_explain_analyze.tcl b/pkg/cli/interactive_tests/test_explain_analyze.tcl new file mode 100644 index 000000000000..38a8a8bccdbf --- /dev/null +++ b/pkg/cli/interactive_tests/test_explain_analyze.tcl @@ -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 diff --git a/pkg/sql/conn_executor.go b/pkg/sql/conn_executor.go index 36e4df5da257..f6ed9f86c5cc 100644 --- a/pkg/sql/conn_executor.go +++ b/pkg/sql/conn_executor.go @@ -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) }