Skip to content

Commit f5a1dc1

Browse files
committed
tree: add FmtHideHints flag
Add FmtHideHints flag which skips over hints when formatting an AST. This will be used by hint injection to validate that the donor statement matches the target statement. Informs: #153633 Release note: None
1 parent 300e81b commit f5a1dc1

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

pkg/sql/sem/tree/format.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,9 @@ const (
197197
// FmtSkipAsOfSystemTimeClauses prevents the formatter from printing AS OF
198198
// SYSTEM TIME clauses.
199199
FmtSkipAsOfSystemTimeClauses
200+
201+
// FmtHideHints skips over any hints.
202+
FmtHideHints
200203
)
201204

202205
const genericArityIndicator = "__more__"

pkg/sql/sem/tree/select.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ func (node *AliasedTableExpr) Format(ctx *FmtCtx) {
611611
ctx.WriteString("LATERAL ")
612612
}
613613
ctx.FormatNode(node.Expr)
614-
if node.IndexFlags != nil {
614+
if node.IndexFlags != nil && !ctx.HasFlags(FmtHideHints) {
615615
ctx.FormatNode(node.IndexFlags)
616616
}
617617
if node.Ordinality {
@@ -681,7 +681,7 @@ func (node *JoinTableExpr) Format(ctx *FmtCtx) {
681681
if node.JoinType != "" {
682682
ctx.WriteString(node.JoinType)
683683
ctx.WriteByte(' ')
684-
if node.Hint != "" {
684+
if node.Hint != "" && !ctx.HasFlags(FmtHideHints) {
685685
ctx.WriteString(node.Hint)
686686
ctx.WriteByte(' ')
687687
}
@@ -693,7 +693,7 @@ func (node *JoinTableExpr) Format(ctx *FmtCtx) {
693693
if node.JoinType != "" {
694694
ctx.WriteString(node.JoinType)
695695
ctx.WriteByte(' ')
696-
if node.Hint != "" {
696+
if node.Hint != "" && !ctx.HasFlags(FmtHideHints) {
697697
ctx.WriteString(node.Hint)
698698
ctx.WriteByte(' ')
699699
}

0 commit comments

Comments
 (0)