Skip to content

Commit dbc8fba

Browse files
committed
sql: format all statements in test builds
This commit improves our testing coverage somewhat so that in test builds we now format each executed query unconditionally. Release note: None
1 parent b99dcdb commit dbc8fba

File tree

2 files changed

+17
-5
lines changed

2 files changed

+17
-5
lines changed

pkg/sql/conn_executor_exec.go

+12
Original file line numberDiff line numberDiff line change
@@ -676,6 +676,12 @@ func (ex *connExecutor) execStmtInOpenState(
676676
p.semaCtx.Placeholders.Assign(pinfo, stmt.NumPlaceholders)
677677
p.extendedEvalCtx.Placeholders = &p.semaCtx.Placeholders
678678

679+
if buildutil.CrdbTestBuild {
680+
// Ensure that each statement is formatted regardless of logging
681+
// settings.
682+
_ = p.FormatAstAsRedactableString(stmt.AST, p.extendedEvalCtx.Annotations)
683+
}
684+
679685
// This flag informs logging decisions.
680686
// Some statements are not dispatched to the execution engine and need
681687
// some special plan initialization for logging.
@@ -1673,6 +1679,12 @@ func (ex *connExecutor) execStmtInOpenStateWithPausablePortal(
16731679
p.semaCtx.Placeholders.Assign(pinfo, vars.stmt.NumPlaceholders)
16741680
p.extendedEvalCtx.Placeholders = &p.semaCtx.Placeholders
16751681

1682+
if buildutil.CrdbTestBuild {
1683+
// Ensure that each statement is formatted regardless of logging
1684+
// settings.
1685+
_ = p.FormatAstAsRedactableString(vars.stmt.AST, p.extendedEvalCtx.Annotations)
1686+
}
1687+
16761688
// This flag informs logging decisions.
16771689
// Some statements are not dispatched to the execution engine and need
16781690
// some special plan initialization for logging.

pkg/sql/sem/tree/format.go

+5-5
Original file line numberDiff line numberDiff line change
@@ -675,7 +675,7 @@ func (ctx *FmtCtx) FormatNode(n NodeFormatter) {
675675
// number of characters to be printed.
676676
func (ctx *FmtCtx) formatLimitLength(n NodeFormatter, maxLength int) {
677677
temp := NewFmtCtx(ctx.flags)
678-
temp.FormatNodeSummary(n)
678+
temp.formatNodeSummary(n)
679679
s := temp.CloseAndGetString()
680680
if len(s) > maxLength {
681681
truncated := s[:maxLength] + "..."
@@ -731,7 +731,7 @@ func (ctx *FmtCtx) formatSummaryInsert(node *Insert) {
731731
expr := rows.Select
732732
if _, ok := expr.(*SelectClause); ok {
733733
ctx.WriteByte(' ')
734-
ctx.FormatNodeSummary(rows)
734+
ctx.formatNodeSummary(rows)
735735
} else if node.Columns != nil {
736736
ctx.WriteByte('(')
737737
ctx.formatLimitLength(&node.Columns, ColumnLimit)
@@ -754,8 +754,8 @@ func (ctx *FmtCtx) formatSummaryUpdate(node *Update) {
754754
}
755755
}
756756

757-
// FormatNodeSummary recurses into a node for pretty-printing a summarized version.
758-
func (ctx *FmtCtx) FormatNodeSummary(n NodeFormatter) {
757+
// formatNodeSummary recurses into a node for pretty-printing a summarized version.
758+
func (ctx *FmtCtx) formatNodeSummary(n NodeFormatter) {
759759
switch node := n.(type) {
760760
case *Insert:
761761
ctx.formatSummaryInsert(node)
@@ -775,7 +775,7 @@ func (ctx *FmtCtx) FormatNodeSummary(n NodeFormatter) {
775775
func AsStringWithFlags(n NodeFormatter, fl FmtFlags, opts ...FmtCtxOption) string {
776776
ctx := NewFmtCtx(fl, opts...)
777777
if fl.HasFlags(FmtSummary) {
778-
ctx.FormatNodeSummary(n)
778+
ctx.formatNodeSummary(n)
779779
} else {
780780
ctx.FormatNode(n)
781781
}

0 commit comments

Comments
 (0)