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 +}