Skip to content

Commit

Permalink
tree: fix walkStmt for SHOW EXPERIMENTAL_FINGERPRINTS
Browse files Browse the repository at this point in the history
If SHOW EXPERIMENTAL_FINGERPRINTS FROM TABLE appeared in certain kinds
of subqueries, the CRDB node could panic while walking the statement due
to a missing nil check.

No release note since this only affected an experimental feature.

Release note: None
  • Loading branch information
rafiss committed Sep 17, 2024
1 parent 7de9aca commit e248fcc
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
12 changes: 7 additions & 5 deletions pkg/sql/sem/tree/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -1152,12 +1152,14 @@ func (n *ShowFingerprints) copyNode() *ShowFingerprints {
// walkStmt is part of the walkableStmt interface.
func (n *ShowFingerprints) walkStmt(v Visitor) Statement {
ret := n
ts, changed := walkTenantSpec(v, n.TenantSpec)
if changed {
if ret == n {
ret = n.copyNode()
if n.TenantSpec != nil {
ts, changed := walkTenantSpec(v, n.TenantSpec)
if changed {
if ret == n {
ret = n.copyNode()
}
ret.TenantSpec = ts
}
ret.TenantSpec = ts
}
if n.Options.StartTimestamp != nil {
e, changed := WalkExpr(v, n.Options.StartTimestamp)
Expand Down
9 changes: 9 additions & 0 deletions pkg/testutils/sqlutils/pretty.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ func VerifyStatementPrettyRoundtrip(t *testing.T, sql string) {
for i := range stmts {
origStmt := stmts[i].AST
verifyStatementPrettyRoundTrip(t, sql, origStmt, false /* plpgsql */)

// Verify that the AST can be walked.
if _, err := tree.SimpleStmtVisit(
origStmt,
func(expr tree.Expr) (recurse bool, newExpr tree.Expr, err error) { return },
); err != nil {
t.Fatalf("cannot walk stmt %s %v", stmts[i].SQL, err)
}

}
}

Expand Down

0 comments on commit e248fcc

Please sign in to comment.