Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tree: make SET TRANSACTION a walkable statement #113689

Merged
merged 1 commit into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 39 additions & 0 deletions pkg/sql/pgwire/testdata/pgtest/set_transaction
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This test relies on a CoockroachDB-specific feature, so everything
# is marked as crdb_only.

only crdb
----

send
Query {"String": "BEGIN"}
----

until
ReadyForQuery
----
{"Type":"CommandComplete","CommandTag":"BEGIN"}
{"Type":"ReadyForQuery","TxStatus":"T"}

send
Parse {"Query": "SET TRANSACTION AS OF SYSTEM TIME $1::timestamp"}
Bind {"Parameters": [{"text":"2019-01-01 00:00:00"}]}
Execute
Sync
Query {"String": "SELECT now()"}
Query {"String": "COMMIT"}
----

until ignore=RowDescription
ReadyForQuery
ReadyForQuery
ReadyForQuery
----
{"Type":"ParseComplete"}
{"Type":"BindComplete"}
{"Type":"CommandComplete","CommandTag":"SET TRANSACTION"}
{"Type":"ReadyForQuery","TxStatus":"T"}
{"Type":"DataRow","Values":[{"text":"2019-01-01 00:00:00+00"}]}
{"Type":"CommandComplete","CommandTag":"SELECT 1"}
{"Type":"ReadyForQuery","TxStatus":"T"}
{"Type":"CommandComplete","CommandTag":"COMMIT"}
{"Type":"ReadyForQuery","TxStatus":"I"}
19 changes: 19 additions & 0 deletions pkg/sql/sem/tree/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,25 @@ func (node *SetTransaction) Format(ctx *FmtCtx) {
ctx.FormatNode(&node.Modes)
}

// copyNode makes a copy of this Statement.
func (stmt *SetTransaction) copyNode() *SetTransaction {
stmtCopy := *stmt
return &stmtCopy
}

// walkStmt is part of the walkableStmt interface.
func (stmt *SetTransaction) walkStmt(v Visitor) Statement {
ret := stmt
if stmt.Modes.AsOf.Expr != nil {
e, changed := WalkExpr(v, stmt.Modes.AsOf.Expr)
if changed {
ret = stmt.copyNode()
ret.Modes.AsOf.Expr = e
}
}
return ret
}

// SetSessionAuthorizationDefault represents a SET SESSION AUTHORIZATION DEFAULT
// statement. This can be extended (and renamed) if we ever support names in the
// last position.
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/sem/tree/walk.go
Original file line number Diff line number Diff line change
Expand Up @@ -2039,6 +2039,7 @@ var _ walkableStmt = &Restore{}
var _ walkableStmt = &SelectClause{}
var _ walkableStmt = &Select{}
var _ walkableStmt = &SetClusterSetting{}
var _ walkableStmt = &SetTransaction{}
var _ walkableStmt = &SetVar{}
var _ walkableStmt = &ShowFingerprints{}
var _ walkableStmt = &ShowTenantClusterSetting{}
Expand Down