Skip to content

Commit

Permalink
transaction_mode variable to return flag default if unset (#15032)
Browse files Browse the repository at this point in the history
Signed-off-by: Harshit Gangal <[email protected]>
  • Loading branch information
harshit-gangal authored Jan 31, 2024
1 parent ebf0106 commit 3147240
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
33 changes: 33 additions & 0 deletions go/test/endtoend/vtgate/queries/misc/misc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,36 @@ func TestAnalyze(t *testing.T) {
})
}
}

// TestTransactionModeVar executes SELECT on `transaction_mode` variable
func TestTransactionModeVar(t *testing.T) {
utils.SkipIfBinaryIsBelowVersion(t, 19, "vtgate")

mcmp, closer := start(t)
defer closer()

tcases := []struct {
setStmt string
expRes string
}{{
expRes: `[[VARCHAR("MULTI")]]`,
}, {
setStmt: `set transaction_mode = single`,
expRes: `[[VARCHAR("SINGLE")]]`,
}, {
setStmt: `set transaction_mode = multi`,
expRes: `[[VARCHAR("MULTI")]]`,
}, {
setStmt: `set transaction_mode = twopc`,
expRes: `[[VARCHAR("TWOPC")]]`,
}}

for _, tcase := range tcases {
t.Run(tcase.setStmt, func(t *testing.T) {
if tcase.setStmt != "" {
utils.Exec(t, mcmp.VtConn, tcase.setStmt)
}
utils.AssertMatches(t, mcmp.VtConn, "select @@transaction_mode", tcase.expRes)
})
}
}
6 changes: 5 additions & 1 deletion go/vt/vtgate/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,11 @@ func (e *Executor) addNeededBindVars(vcursor *vcursorImpl, bindVarNeeds *sqlpars
})
bindVars[key] = sqltypes.Int64BindVariable(v)
case sysvars.TransactionMode.Name:
bindVars[key] = sqltypes.StringBindVariable(session.TransactionMode.String())
txMode := session.TransactionMode
if txMode == vtgatepb.TransactionMode_UNSPECIFIED {
txMode = getTxMode()
}
bindVars[key] = sqltypes.StringBindVariable(txMode.String())
case sysvars.Workload.Name:
var v string
ifOptionsExist(session, func(options *querypb.ExecuteOptions) {
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/executor_select_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,7 @@ func TestSelectSystemVariables(t *testing.T) {
sqltypes.NewInt64(0),
sqltypes.NewInt64(0),
sqltypes.NewInt64(0),
sqltypes.NewVarChar("UNSPECIFIED"),
sqltypes.NewVarChar("MULTI"),
sqltypes.NewVarChar(""),
// these have been set at the beginning of the test
sqltypes.NewVarChar("a fine gtid"),
Expand Down

0 comments on commit 3147240

Please sign in to comment.