diff --git a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go index 19af2cdc4d2..74a32bd083c 100644 --- a/go/test/endtoend/vtgate/reservedconn/sysvar_test.go +++ b/go/test/endtoend/vtgate/reservedconn/sysvar_test.go @@ -319,3 +319,38 @@ func TestSetSystemVarInTxWithConnError(t *testing.T) { // subsequent queries on 80- will pass assertMatches(t, conn, "select id, @@sql_safe_updates from test where id = 4", "[[INT64(4) INT64(1)]]") } + +func TestEnableSystemSettings(t *testing.T) { + vtParams := mysql.ConnParams{ + Host: "localhost", + Port: clusterInstance.VtgateMySQLPort, + } + conn, err := mysql.Connect(context.Background(), &vtParams) + require.NoError(t, err) + defer conn.Close() + + // Insert a single row to correctly select @@enable_system_settings. + // See: https://github.com/vitessio/vitess/issues/7301 + checkedExec(t, conn, "delete from test") + checkedExec(t, conn, "insert into test (id, val1, val2, val3) values (1, null, 0, 0)") + + // test set @@enable_system_settings to false and true + checkedExec(t, conn, "set enable_system_settings = false") + assertMatches(t, conn, `select @@enable_system_settings from test`, `[[INT64(0)]]`) + checkedExec(t, conn, "set enable_system_settings = true") + assertMatches(t, conn, `select @@enable_system_settings from test`, `[[INT64(1)]]`) + + // prepare the @@sql_mode variable + checkedExec(t, conn, "set sql_mode = 'NO_ZERO_DATE'") + assertMatches(t, conn, "select @@sql_mode", `[[VARCHAR("NO_ZERO_DATE")]]`) + + // check disabling @@enable_system_settings + checkedExec(t, conn, "set enable_system_settings = false") + checkedExec(t, conn, "set sql_mode = ''") // attempting to set @@sql_mode to an empty string + assertMatches(t, conn, "select @@sql_mode", `[[VARCHAR("NO_ZERO_DATE")]]`) // @@sql_mode did not change + + // check enabling @@enable_system_settings + checkedExec(t, conn, "set enable_system_settings = true") + checkedExec(t, conn, "set sql_mode = ''") // changing @@sql_mode to empty string + assertMatches(t, conn, "select @@sql_mode", `[[VARCHAR("")]]`) // @@sql_mode did change +} diff --git a/go/vt/proto/vtgate/vtgate.pb.go b/go/vt/proto/vtgate/vtgate.pb.go index e5deffdfd18..ef6d6a75fd6 100644 --- a/go/vt/proto/vtgate/vtgate.pb.go +++ b/go/vt/proto/vtgate/vtgate.pb.go @@ -156,7 +156,9 @@ type Session struct { // DDL strategy DDLStrategy string `protobuf:"bytes,21,opt,name=DDLStrategy,proto3" json:"DDLStrategy,omitempty"` // Session UUID - SessionUUID string `protobuf:"bytes,22,opt,name=SessionUUID,proto3" json:"SessionUUID,omitempty"` + SessionUUID string `protobuf:"bytes,22,opt,name=SessionUUID,proto3" json:"SessionUUID,omitempty"` + // enable_system_settings defines if we can use reserved connections. + EnableSystemSettings bool `protobuf:"varint,23,opt,name=enable_system_settings,json=enableSystemSettings,proto3" json:"enable_system_settings,omitempty"` XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_unrecognized []byte `json:"-"` XXX_sizecache int32 `json:"-"` @@ -334,6 +336,13 @@ func (m *Session) GetSessionUUID() string { return "" } +func (m *Session) GetEnableSystemSettings() bool { + if m != nil { + return m.EnableSystemSettings + } + return false +} + type Session_ShardSession struct { Target *query.Target `protobuf:"bytes,1,opt,name=target,proto3" json:"target,omitempty"` TransactionId int64 `protobuf:"varint,2,opt,name=transaction_id,json=transactionId,proto3" json:"transaction_id,omitempty"` @@ -1101,90 +1110,92 @@ func init() { func init() { proto.RegisterFile("vtgate.proto", fileDescriptor_aab96496ceaf1ebb) } var fileDescriptor_aab96496ceaf1ebb = []byte{ - // 1357 bytes of a gzipped FileDescriptorProto - 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0x6d, 0x6f, 0x1b, 0xc5, - 0x13, 0xef, 0xf9, 0xd9, 0xe3, 0xa7, 0xcb, 0xe6, 0xe1, 0x7f, 0xcd, 0xbf, 0x80, 0xe5, 0xb6, 0xaa, - 0x5b, 0x50, 0x02, 0x41, 0x40, 0x85, 0x40, 0x90, 0xd8, 0x6e, 0x71, 0x95, 0xd4,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x25, 0xed, 0xd0, 0xc3, 0x65, - 0x87, 0x8e, 0x04, 0xe1, 0x4d, 0xa3, 0x7c, 0x1c, 0xe9, 0xb6, 0x02, 0xc9, 0xa7, 0x78, 0x6d, 0x7c, - 0x0d, 0x84, 0x3a, 0x60, 0x8b, 0xa9, 0x90, 0xe4, 0x32, 0x66, 0xba, 0xac, 0x4d, 0xdf, 0x7b, 0x29, - 0x56, 0xad, 0xb7, 0x64, 0xb5, 0x22, 0x16, 0xa5, 0xe8, 0xff, 0x90, 0xe7, 0xec, 0xca, 0xed, 0xb3, - 0x71, 0x20, 0x9d, 0x4a, 0xd5, 0xaa, 0x27, 0x71, 0x8e, 0xb3, 0xab, 0x86, 0x5a, 0xab, 0x12, 0x14, - 0xde, 0x84, 0x8c, 0x18, 0x0d, 0xa4, 0x70, 0xec, 0x6a, 0xb2, 0x9e, 0xc7, 0x31, 0x09, 0xaa, 0x83, - 0x4d, 0x03, 0x97, 0x13, 0x41, 0xf8, 0x84, 0xf8, 0x6e, 0x9f, 0x05, 0x81, 0xb3, 0xa2, 0x0b, 0xb5, - 0x4c, 0x03, 0x1c, 0x8a, 0x1b, 0x2c, 0x08, 0x14, 0xc3, 0x43, 0xd6, 0xbf, 0x88, 0x08, 0x72, 0x90, - 0x2e, 0xc6, 0x57, 0x30, 0xac, 0x76, 0x44, 0x9d, 0xb7, 0x05, 0xab, 0x9a, 0x1e, 0x6d, 0xe5, 0x9c, - 0x78, 0x5c, 0x9e, 0x12, 0x4f, 0x3a, 0xab, 0xda, 0xe3, 0x15, 0x05, 0xed, 0xb3, 0xfe, 0xc5, 0x77, - 0x11, 0x80, 0xbe, 0x05, 0x9b, 0x13, 0xcf, 0x77, 0xbd, 0x33, 0x49, 0xb8, 0x7b, 0xc5, 0xa9, 0x24, - 0xce, 0x9a, 0x3e, 0x74, 0x23, 0x3a, 0x14, 0x13, 0xcf, 0xdf, 0x55, 0xf0, 0x89, 0x42, 0x71, 0x99, - 0x2f, 0xac, 0x51, 0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d, 0x70, 0x45, 0xd9, 0xb6, 0xf9, 0xda, - 0x1e, 0xb0, 0xed, 0x89, 0xdc, 0xd6, 0xe8, 0xb6, 0x29, 0xcd, 0xd3, 0x8c, 0x5e, 0x7d, 0xfa, 0x4f, - 0x00, 0x00, 0x00, 0xff, 0xff, 0x90, 0xad, 0x39, 0x45, 0x08, 0x0e, 0x00, 0x00, + // 1382 bytes of a gzipped FileDescriptorProto + 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xb4, 0x57, 0xdd, 0x6e, 0x1b, 0xb7, + 0x12, 0xce, 0xea, 0x5f, 0xa3, 0xbf, 0x35, 0x2d, 0x3b, 0x1b, 0x9f, 0x9c, 0x73, 0x04, 0x25, 0x41, + 0x94, 0x9c, 0x03, 0xbb, 0x75, 0xff, 0x82, 0xa2, 0x45, 0x6b, 0xcb, 0x4a, 0xaa, 0xc0, 0x8e, 0x5c, + 0x4a, 0xb6, 0x81, 0xa2, 0xc5, 0x62, 0xad, 0xa5, 0x65, 0xc2, 0xf2, 0x52, 0x21, 0x29, 0xb9, 0x7a, + 0x8a, 0xde, 0xf7, 0x05, 0x7a, 0xd3, 0xfb, 0xbe, 0x43, 0xef, 0xf2, 0x46, 0x05, 0xc9, 0x5d, 0x69, + 0xa5, 0xb8, 0x8d, 0x93, 0x20, 0x37, 0xc2, 0x72, 0xbe, 0xe1, 0x70, 0x38, 0xdf, 0xfc, 0x50, 0x50, + 0x9c, 0xc8, 0x81, 0x27, 0xc9, 0xe6, 0x88, 0x33, 0xc9, 0x50, 0xc6, 0xac, 0x36, 0xec, 0x53, 0x1a, + 0x0c, 0xd9, 0xc0, 0xf7, 0xa4, 0x67, 0x90, 0x8d, 0xc2, 0xcb, 0x31, 0xe1, 0xd3, 0x70, 0x51, 0x96, + 0x6c, 0xc4, 0xe2, 0xe0, 0x44, 0xf2, 0x51, 0xdf, 0x2c, 0xea, 0xaf, 0x0a, 0x90, 0xed, 0x12, 0x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, 0xd9, 0x34, 0x63, 0xab, 0xa9, 0xe5, + 0xed, 0x3d, 0x9c, 0x33, 0x1a, 0x6d, 0x1f, 0x3d, 0x82, 0x6c, 0x54, 0x79, 0x89, 0x99, 0x6e, 0xbc, + 0xf2, 0x70, 0x84, 0xa3, 0x87, 0x90, 0xd6, 0x2c, 0x84, 0x69, 0xb1, 0x12, 0x71, 0xa2, 0x7a, 0x9c, + 0x6e, 0xdf, 0xd8, 0xe0, 0xe8, 0x33, 0x08, 0x73, 0xc3, 0x95, 0xd3, 0x11, 0xd1, 0xc9, 0x50, 0xde, + 0xae, 0x2e, 0x67, 0x51, 0x6f, 0x3a, 0x22, 0x18, 0xe4, 0xec, 0x5b, 0x25, 0xe9, 0x05, 0x99, 0x8a, + 0x91, 0xd7, 0x27, 0xae, 0x1e, 0x78, 0x7a, 0x30, 0xe5, 0x71, 0x29, 0x92, 0xea, 0xcc, 0x8f, 0x0f, + 0xae, 0xec, 0x4d, 0x06, 0xd7, 0xf3, 0x54, 0x2e, 0x6d, 0x67, 0xea, 0xbf, 0x58, 0x50, 0x99, 0x45, + 0x4a, 0x8c, 0x58, 0x20, 0xd4, 0x89, 0x69, 0xc2, 0x39, 0xe3, 0x4b, 0x61, 0xc2, 0x87, 0xcd, 0x96, + 0x12, 0x63, 0x83, 0xbe, 0x4d, 0x8c, 0x1e, 0x43, 0x86, 0x13, 0x31, 0x1e, 0xca, 0x30, 0x48, 0x28, + 0x3e, 0xde, 0xb0, 0x46, 0x70, 0xa8, 0x51, 0x7f, 0x95, 0x80, 0xd5, 0xd0, 0xa3, 0x5d, 0x4f, 0xf6, + 0xcf, 0x3f, 0x38, 0x81, 0xff, 0x83, 0xac, 0xf2, 0x86, 0x12, 0x95, 0x50, 0xc9, 0xeb, 0x29, 0x8c, + 0x34, 0xde, 0x83, 0x44, 0x4f, 0x2c, 0xbc, 0x83, 0xd2, 0xe6, 0x1d, 0xe4, 0x89, 0xf8, 0x3b, 0xe8, + 0x03, 0x71, 0x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0xfa, 0x67, 0x80, 0x2a, 0x50, 0x38, 0x7a, 0xd1, + 0x3d, 0x6c, 0x35, 0xdb, 0x4f, 0xdb, 0xad, 0x3d, 0xfb, 0x16, 0x02, 0xc8, 0x74, 0xdb, 0x2f, 0x9e, + 0xed, 0xb7, 0x6c, 0x0b, 0xe5, 0x21, 0x7d, 0x70, 0xb4, 0xdf, 0x6b, 0xdb, 0x09, 0xf5, 0xd9, 0x3b, + 0xe9, 0x1c, 0x36, 0xed, 0xe4, 0xe3, 0xaf, 0xa0, 0xd0, 0xd4, 0xff, 0x6f, 0x3a, 0xdc, 0x27, 0x5c, + 0x6d, 0x78, 0xd1, 0xc1, 0x07, 0x3b, 0xfb, 0xf6, 0x2d, 0x94, 0x85, 0xe4, 0x21, 0x56, 0x3b, 0x73, + 0x90, 0x3a, 0xec, 0x74, 0x7b, 0x76, 0x02, 0x95, 0x01, 0x76, 0x8e, 0x7a, 0x9d, 0x66, 0xe7, 0xe0, + 0xa0, 0xdd, 0xb3, 0x93, 0xbb, 0x9f, 0x43, 0x85, 0xb2, 0xcd, 0x09, 0x95, 0x44, 0x08, 0xf3, 0xf7, + 0xed, 0x87, 0x7b, 0xe1, 0x8a, 0xb2, 0x2d, 0xf3, 0xb5, 0x35, 0x60, 0x5b, 0x13, 0xb9, 0xa5, 0xd1, + 0x2d, 0x93, 0x9a, 0xa7, 0x19, 0xbd, 0xfa, 0xe4, 0xaf, 0x00, 0x00, 0x00, 0xff, 0xff, 0x86, 0x85, + 0xad, 0x4f, 0x3e, 0x0e, 0x00, 0x00, } diff --git a/go/vt/sqlparser/ast_rewriting.go b/go/vt/sqlparser/ast_rewriting.go index bc0e8653ae3..151fc4291f7 100644 --- a/go/vt/sqlparser/ast_rewriting.go +++ b/go/vt/sqlparser/ast_rewriting.go @@ -235,6 +235,7 @@ func (er *expressionRewriter) sysVarRewrite(cursor *Cursor, node *ColName) { sysvars.Workload.Name, sysvars.DDLStrategy.Name, sysvars.SessionUUID.Name, + sysvars.SessionEnableSystemSettings.Name, sysvars.ReadAfterWriteGTID.Name, sysvars.ReadAfterWriteTimeOut.Name, sysvars.VitessVersion.Name, diff --git a/go/vt/sqlparser/ast_rewriting_test.go b/go/vt/sqlparser/ast_rewriting_test.go index 64f185c42da..15b25d068ac 100644 --- a/go/vt/sqlparser/ast_rewriting_test.go +++ b/go/vt/sqlparser/ast_rewriting_test.go @@ -29,7 +29,7 @@ import ( type myTestCase struct { in, expected string liid, db, foundRows, rowCount, rawGTID, rawTimeout, sessTrackGTID bool - ddlStrategy, sessionUUID bool + ddlStrategy, sessionUUID, sessionEnableSystemSettings bool udv int autocommit, clientFoundRows, skipQueryPlanCache bool sqlSelectLimit, transactionMode, workload, vitessVersion bool @@ -44,6 +44,10 @@ func TestRewrites(in *testing.T) { in: "SELECT @@vitess_version", expected: "SELECT :__vtvitess_version as `@@vitess_version`", vitessVersion: true, + }, { + in: "SELECT @@enable_system_settings", + expected: "SELECT :__vtenable_system_settings as `@@enable_system_settings`", + sessionEnableSystemSettings: true, }, { in: "SELECT last_insert_id()", expected: "SELECT :__lastInsertId as `last_insert_id()`", @@ -199,6 +203,7 @@ func TestRewrites(in *testing.T) { assert.Equal(tc.workload, result.NeedsSysVar(sysvars.Workload.Name), "should need :__vtworkload") assert.Equal(tc.ddlStrategy, result.NeedsSysVar(sysvars.DDLStrategy.Name), "should need ddlStrategy") assert.Equal(tc.sessionUUID, result.NeedsSysVar(sysvars.SessionUUID.Name), "should need sessionUUID") + assert.Equal(tc.sessionEnableSystemSettings, result.NeedsSysVar(sysvars.SessionEnableSystemSettings.Name), "should need sessionEnableSystemSettings") assert.Equal(tc.rawGTID, result.NeedsSysVar(sysvars.ReadAfterWriteGTID.Name), "should need rawGTID") assert.Equal(tc.rawTimeout, result.NeedsSysVar(sysvars.ReadAfterWriteTimeOut.Name), "should need rawTimeout") assert.Equal(tc.sessTrackGTID, result.NeedsSysVar(sysvars.SessionTrackGTIDs.Name), "should need sessTrackGTID") diff --git a/go/vt/sysvars/sysvars.go b/go/vt/sysvars/sysvars.go index 2c6515ca28e..ecbffa94775 100644 --- a/go/vt/sysvars/sysvars.go +++ b/go/vt/sysvars/sysvars.go @@ -43,17 +43,18 @@ var ( off = "0" utf8 = "'utf8'" - Autocommit = SystemVariable{Name: "autocommit", IsBoolean: true, Default: on} - ClientFoundRows = SystemVariable{Name: "client_found_rows", IsBoolean: true, Default: off} - SkipQueryPlanCache = SystemVariable{Name: "skip_query_plan_cache", IsBoolean: true, Default: off} - TxReadOnly = SystemVariable{Name: "tx_read_only", IsBoolean: true, Default: off} - TransactionReadOnly = SystemVariable{Name: "transaction_read_only", IsBoolean: true, Default: off} - SQLSelectLimit = SystemVariable{Name: "sql_select_limit", Default: off} - TransactionMode = SystemVariable{Name: "transaction_mode", IdentifierAsString: true} - Workload = SystemVariable{Name: "workload", IdentifierAsString: true} - Charset = SystemVariable{Name: "charset", Default: utf8, IdentifierAsString: true} - Names = SystemVariable{Name: "names", Default: utf8, IdentifierAsString: true} - SessionUUID = SystemVariable{Name: "session_uuid", IdentifierAsString: true} + Autocommit = SystemVariable{Name: "autocommit", IsBoolean: true, Default: on} + ClientFoundRows = SystemVariable{Name: "client_found_rows", IsBoolean: true, Default: off} + SkipQueryPlanCache = SystemVariable{Name: "skip_query_plan_cache", IsBoolean: true, Default: off} + TxReadOnly = SystemVariable{Name: "tx_read_only", IsBoolean: true, Default: off} + TransactionReadOnly = SystemVariable{Name: "transaction_read_only", IsBoolean: true, Default: off} + SQLSelectLimit = SystemVariable{Name: "sql_select_limit", Default: off} + TransactionMode = SystemVariable{Name: "transaction_mode", IdentifierAsString: true} + Workload = SystemVariable{Name: "workload", IdentifierAsString: true} + Charset = SystemVariable{Name: "charset", Default: utf8, IdentifierAsString: true} + Names = SystemVariable{Name: "names", Default: utf8, IdentifierAsString: true} + SessionUUID = SystemVariable{Name: "session_uuid", IdentifierAsString: true} + SessionEnableSystemSettings = SystemVariable{Name: "enable_system_settings", IsBoolean: true, Default: on} // Online DDL DDLStrategy = SystemVariable{Name: "ddl_strategy", IdentifierAsString: true} VitessVersion = SystemVariable{Name: "vitess_version", IdentifierAsString: true} @@ -76,6 +77,7 @@ var ( Charset, Names, SessionUUID, + SessionEnableSystemSettings, ReadAfterWriteGTID, ReadAfterWriteTimeOut, SessionTrackGTIDs, diff --git a/go/vt/vtgate/engine/fake_vcursor_test.go b/go/vt/vtgate/engine/fake_vcursor_test.go index 59a4eb82374..df27d1984e8 100644 --- a/go/vt/vtgate/engine/fake_vcursor_test.go +++ b/go/vt/vtgate/engine/fake_vcursor_test.go @@ -73,6 +73,14 @@ func (t noopVCursor) SetReadAfterWriteGTID(s string) { panic("implement me") } +func (t noopVCursor) SetSessionEnableSystemSettings(allow bool) error { + panic("implement me") +} + +func (t noopVCursor) GetSessionEnableSystemSettings() bool { + panic("implement me") +} + func (t noopVCursor) SetReadAfterWriteTimeout(f float64) { panic("implement me") } diff --git a/go/vt/vtgate/engine/primitive.go b/go/vt/vtgate/engine/primitive.go index b8562ba7175..6d347f3deb6 100644 --- a/go/vt/vtgate/engine/primitive.go +++ b/go/vt/vtgate/engine/primitive.go @@ -134,6 +134,9 @@ type ( GetSessionUUID() string + SetSessionEnableSystemSettings(bool) error + GetSessionEnableSystemSettings() bool + // SetReadAfterWriteGTID sets the GTID that the user expects a replica to have caught up with before answering a query SetReadAfterWriteGTID(string) SetReadAfterWriteTimeout(float64) diff --git a/go/vt/vtgate/engine/set.go b/go/vt/vtgate/engine/set.go index 43401cb8a25..24d0b9b8b4a 100644 --- a/go/vt/vtgate/engine/set.go +++ b/go/vt/vtgate/engine/set.go @@ -408,6 +408,8 @@ func (svss *SysVarSetAware) Execute(vcursor VCursor, env evalengine.ExpressionEn return vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "invalid DDL strategy: %s", str) } vcursor.Session().SetDDLStrategy(str) + case sysvars.SessionEnableSystemSettings.Name: + err = svss.setBoolSysVar(env, vcursor.Session().SetSessionEnableSystemSettings) case sysvars.Charset.Name, sysvars.Names.Name: str, err := svss.evalAsString(env) if err != nil { diff --git a/go/vt/vtgate/executor.go b/go/vt/vtgate/executor.go index 7dcd4aa73e2..f16e7122d90 100644 --- a/go/vt/vtgate/executor.go +++ b/go/vt/vtgate/executor.go @@ -297,6 +297,8 @@ func (e *Executor) addNeededBindVars(bindVarNeeds *sqlparser.BindVarNeeds, bindV bindVars[key] = sqltypes.StringBindVariable(session.DDLStrategy) case sysvars.SessionUUID.Name: bindVars[key] = sqltypes.StringBindVariable(session.SessionUUID) + case sysvars.SessionEnableSystemSettings.Name: + bindVars[key] = sqltypes.BoolBindVariable(session.EnableSystemSettings) case sysvars.ReadAfterWriteGTID.Name: var v string ifReadAfterWriteExist(session, func(raw *vtgatepb.ReadAfterWrite) { diff --git a/go/vt/vtgate/executor_select_test.go b/go/vt/vtgate/executor_select_test.go index d5783b070ce..48945d68c6f 100644 --- a/go/vt/vtgate/executor_select_test.go +++ b/go/vt/vtgate/executor_select_test.go @@ -327,7 +327,7 @@ func TestSelectSystemVariables(t *testing.T) { logChan := QueryLogger.Subscribe("Test") defer QueryLogger.Unsubscribe(logChan) - sql := "select @@autocommit, @@client_found_rows, @@skip_query_plan_cache, " + + sql := "select @@autocommit, @@client_found_rows, @@skip_query_plan_cache, @@enable_system_settings, " + "@@sql_select_limit, @@transaction_mode, @@workload, @@read_after_write_gtid, " + "@@read_after_write_timeout, @@session_track_gtids, @@ddl_strategy" @@ -337,6 +337,7 @@ func TestSelectSystemVariables(t *testing.T) { {Name: "@@autocommit", Type: sqltypes.Int32}, {Name: "@@client_found_rows", Type: sqltypes.Int32}, {Name: "@@skip_query_plan_cache", Type: sqltypes.Int32}, + {Name: "@@enable_system_settings", Type: sqltypes.Int32}, {Name: "@@sql_select_limit", Type: sqltypes.Int64}, {Name: "@@transaction_mode", Type: sqltypes.VarBinary}, {Name: "@@workload", Type: sqltypes.VarBinary}, @@ -351,6 +352,7 @@ func TestSelectSystemVariables(t *testing.T) { sqltypes.NULL, sqltypes.NULL, sqltypes.NULL, + sqltypes.NULL, sqltypes.NewInt64(0), sqltypes.NewVarBinary("UNSPECIFIED"), sqltypes.NewVarBinary(""), diff --git a/go/vt/vtgate/executor_set_test.go b/go/vt/vtgate/executor_set_test.go index 19e8d980600..3d6db4a755d 100644 --- a/go/vt/vtgate/executor_set_test.go +++ b/go/vt/vtgate/executor_set_test.go @@ -228,6 +228,24 @@ func TestExecutorSet(t *testing.T) { }, { in: "set session transaction read write", out: &vtgatepb.Session{Autocommit: true}, + }, { + in: "set @@enable_system_settings = on", + out: &vtgatepb.Session{Autocommit: true, EnableSystemSettings: true}, + }, { + in: "set @@enable_system_settings = off", + out: &vtgatepb.Session{Autocommit: true, EnableSystemSettings: false}, + }, { + in: "set @@enable_system_settings = 1", + out: &vtgatepb.Session{Autocommit: true, EnableSystemSettings: true}, + }, { + in: "set @@enable_system_settings = 0", + out: &vtgatepb.Session{Autocommit: true, EnableSystemSettings: false}, + }, { + in: "set @@enable_system_settings = true", + out: &vtgatepb.Session{Autocommit: true, EnableSystemSettings: true}, + }, { + in: "set @@enable_system_settings = false", + out: &vtgatepb.Session{Autocommit: true, EnableSystemSettings: false}, }} for i, tcase := range testcases { t.Run(fmt.Sprintf("%d-%s", i, tcase.in), func(t *testing.T) { @@ -247,76 +265,91 @@ func TestExecutorSetOp(t *testing.T) { executor, _, _, sbclookup := createLegacyExecutorEnv() *sysVarSetEnabled = true - sbclookup.SetResults([]*sqltypes.Result{ - sqltypes.MakeTestResult(sqltypes.MakeTestFields("sql_mode", "varchar"), "STRICT_ALL_TABLES,NO_AUTO_UPDATES"), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("sql_safe_updates", "int64"), "1"), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("tx_isolation", "varchar"), "read-committed"), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("sql_quote_show_create", "int64"), "0"), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("foreign_key_checks", "int64")), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("unique_checks", "int64"), "0"), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("net_write_timeout", "int64"), "600"), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("net_read_timeout", "int64"), "300"), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("character_set_client", "varchar"), "utf8"), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("character_set_results", "varchar")), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("character_set_results", "varchar")), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("character_set_results", "varchar")), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("character_set_results", "varchar")), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("character_set_results", "varchar")), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("character_set_results", "varchar")), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("client_found_rows", "int64")), - sqltypes.MakeTestResult(sqltypes.MakeTestFields("client_found_rows", "int64")), - }) + returnResult := func(columnName, typ, value string) *sqltypes.Result { + return sqltypes.MakeTestResult(sqltypes.MakeTestFields(columnName, typ), value) + } + returnNoResult := func(columnName, typ string) *sqltypes.Result { + return sqltypes.MakeTestResult(sqltypes.MakeTestFields(columnName, typ)) + } testcases := []struct { - in string - warning []*querypb.QueryWarning - sysVars map[string]string + in string + warning []*querypb.QueryWarning + sysVars map[string]string + disallowResConn bool + result *sqltypes.Result }{{ in: "set big_tables = 1", //ignore }, { in: "set sql_mode = 'STRICT_ALL_TABLES,NO_AUTO_UPDATES'", sysVars: map[string]string{"sql_mode": "'STRICT_ALL_TABLES,NO_AUTO_UPDATES'"}, + result: returnResult("sql_mode", "varchar", "STRICT_ALL_TABLES,NO_AUTO_UPDATES"), + }, { + // even though the tablet is saying that the value has changed, + // useReservedConn is false, so we won't allow this change + in: "set sql_mode = 'STRICT_ALL_TABLES,NO_AUTO_UPDATES'", + result: returnResult("sql_mode", "varchar", "STRICT_ALL_TABLES,NO_AUTO_UPDATES"), + sysVars: nil, + disallowResConn: true, }, { in: "set sql_safe_updates = 1", sysVars: map[string]string{"sql_safe_updates": "1"}, + result: returnResult("sql_safe_updates", "int64", "1"), }, { in: "set tx_isolation = 'read-committed'", sysVars: map[string]string{"tx_isolation": "'read-committed'"}, + result: returnResult("tx_isolation", "varchar", "read-committed"), }, { in: "set sql_quote_show_create = 0", sysVars: map[string]string{"sql_quote_show_create": "0"}, + result: returnResult("sql_quote_show_create", "int64", "0"), }, { - in: "set foreign_key_checks = 1", + in: "set foreign_key_checks = 1", + result: returnNoResult("foreign_key_checks", "int64"), }, { in: "set unique_checks = 0", sysVars: map[string]string{"unique_checks": "0"}, + result: returnResult("unique_checks", "int64", "0"), }, { - in: "set net_write_timeout = 600", + in: "set net_write_timeout = 600", + result: returnResult("net_write_timeout", "int64", "600"), }, { - in: "set net_read_timeout = 600", + in: "set net_read_timeout = 600", + result: returnResult("net_read_timeout", "int64", "300"), }, { - in: "set character_set_client = utf8", + in: "set character_set_client = utf8", + result: returnResult("character_set_client", "varchar", "utf8"), }, { - in: "set character_set_results=null", + in: "set character_set_results=null", + result: returnNoResult("character_set_results", "varchar"), }, { - in: "set character_set_results='binary'", + in: "set character_set_results='binary'", + result: returnNoResult("character_set_results", "varchar"), }, { - in: "set character_set_results='utf8'", + in: "set character_set_results='utf8'", + result: returnNoResult("character_set_results", "varchar"), }, { - in: "set character_set_results=utf8mb4", + in: "set character_set_results=utf8mb4", + result: returnNoResult("character_set_results", "varchar"), }, { - in: "set character_set_results='latin1'", + in: "set character_set_results='latin1'", + result: returnNoResult("character_set_results", "varchar"), }, { - in: "set character_set_results='abcd'", + in: "set character_set_results='abcd'", + result: returnNoResult("character_set_results", "varchar"), }, { - in: "set @@global.client_found_rows = 1", + in: "set @@global.client_found_rows = 1", + result: returnNoResult("client_found_rows", "int64"), }, { - in: "set global client_found_rows = 1", + in: "set global client_found_rows = 1", + result: returnNoResult("client_found_rows", "int64"), }} for _, tcase := range testcases { t.Run(tcase.in, func(t *testing.T) { session := NewAutocommitSession(masterSession) session.TargetString = KsTestUnsharded + session.EnableSystemSettings = !tcase.disallowResConn + sbclookup.SetResults([]*sqltypes.Result{tcase.result}) _, err := executor.Execute( context.Background(), "TestExecute", diff --git a/go/vt/vtgate/plugin_mysql_server.go b/go/vt/vtgate/plugin_mysql_server.go index 5ee65dd5c45..dce5e5f37e4 100644 --- a/go/vt/vtgate/plugin_mysql_server.go +++ b/go/vt/vtgate/plugin_mysql_server.go @@ -342,9 +342,10 @@ func (vh *vtgateHandler) session(c *mysql.Conn) *vtgatepb.Session { IncludedFields: querypb.ExecuteOptions_ALL, Workload: querypb.ExecuteOptions_Workload(mysqlDefaultWorkload), }, - Autocommit: true, - DDLStrategy: *defaultDDLStrategy, - SessionUUID: u.String(), + Autocommit: true, + DDLStrategy: *defaultDDLStrategy, + SessionUUID: u.String(), + EnableSystemSettings: *sysVarSetEnabled, } if c.Capabilities&mysql.CapabilityClientFoundRows != 0 { session.Options.ClientFoundRows = true diff --git a/go/vt/vtgate/safe_session.go b/go/vt/vtgate/safe_session.go index ead6619b4af..9691fd18662 100644 --- a/go/vt/vtgate/safe_session.go +++ b/go/vt/vtgate/safe_session.go @@ -478,6 +478,20 @@ func (session *SafeSession) GetSessionUUID() string { return session.SessionUUID } +// SetSessionEnableSystemSettings set the SessionEnableSystemSettings setting. +func (session *SafeSession) SetSessionEnableSystemSettings(allow bool) { + session.mu.Lock() + defer session.mu.Unlock() + session.EnableSystemSettings = allow +} + +// GetSessionEnableSystemSettings returns the SessionEnableSystemSettings value. +func (session *SafeSession) GetSessionEnableSystemSettings() bool { + session.mu.Lock() + defer session.mu.Unlock() + return session.EnableSystemSettings +} + // SetReadAfterWriteGTID set the ReadAfterWriteGtid setting. func (session *SafeSession) SetReadAfterWriteGTID(vtgtid string) { session.mu.Lock() diff --git a/go/vt/vtgate/vcursor_impl.go b/go/vt/vtgate/vcursor_impl.go index 6760994bfdc..1d9ac6ca76c 100644 --- a/go/vt/vtgate/vcursor_impl.go +++ b/go/vt/vtgate/vcursor_impl.go @@ -329,7 +329,7 @@ func (vc *vcursorImpl) FirstSortedKeyspace() (*vindexes.Keyspace, error) { // SysVarSetEnabled implements the ContextVSchema interface func (vc *vcursorImpl) SysVarSetEnabled() bool { - return *sysVarSetEnabled + return vc.GetSessionEnableSystemSettings() } // KeyspaceExists provides whether the keyspace exists or not. @@ -661,6 +661,17 @@ func (vc *vcursorImpl) GetSessionUUID() string { return vc.safeSession.GetSessionUUID() } +// SetSessionEnableSystemSettings implements the SessionActions interface +func (vc *vcursorImpl) SetSessionEnableSystemSettings(allow bool) error { + vc.safeSession.SetSessionEnableSystemSettings(allow) + return nil +} + +// GetSessionEnableSystemSettings implements the SessionActions interface +func (vc *vcursorImpl) GetSessionEnableSystemSettings() bool { + return vc.safeSession.GetSessionEnableSystemSettings() +} + // SetReadAfterWriteGTID implements the SessionActions interface func (vc *vcursorImpl) SetReadAfterWriteGTID(vtgtid string) { vc.safeSession.SetReadAfterWriteGTID(vtgtid) diff --git a/proto/vtgate.proto b/proto/vtgate.proto index 43723c5bcd5..61ec3d7211a 100644 --- a/proto/vtgate.proto +++ b/proto/vtgate.proto @@ -143,6 +143,9 @@ message Session { // Session UUID string SessionUUID = 22; + + // enable_system_settings defines if we can use reserved connections. + bool enable_system_settings = 23; } // ReadAfterWrite contains information regarding gtid set and timeout