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

Set CheckAndIgnore to Log Warn than Error on failing the SysVar settings check #6099

Merged
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go/test/endtoend/vtgate/setstatement/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ func TestSetSysVar(t *testing.T) {
query: `set @@sql_mode = concat(@@sql_mode,"")`,
expectedRows: ``, rowsAffected: 0,
}, {
query: `set @@sql_mode = concat(@@sql_mode,"ALLOW_INVALID_DATES")`,
errMsg: "Modification not allowed using set construct for: sql_mode",
query: `set @@sql_mode = concat(@@sql_mode,"ALLOW_INVALID_DATES")`,
expectedWarning: "[[VARCHAR(\"Warning\") UINT16(1235) VARCHAR(\"Modification not allowed using set construct for: sql_mode\")]]",
}}

conn, err := mysql.Connect(ctx, &vtParams)
Expand Down
2 changes: 1 addition & 1 deletion go/test/endtoend/vtgate/setstatement/udv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestSetUDV(t *testing.T) {
expectedRows: "", rowsAffected: 0,
}, {
query: "select @foo, @bar, @baz",
expectedRows: `[[VARCHAR("abc") INT64(42) DECIMAL(30.5)]]`, rowsAffected: 1,
expectedRows: `[[VARBINARY("abc") INT64(42) FLOAT64(30.5)]]`, rowsAffected: 1,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand why this is changing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

set statement e2e test are not added in config.json. This should have changes when I modified varchar to be stored as varbinary in bindvars. As this is not part of regular run, this did not fail.

}, {
query: "insert into test(id, val1, val2, val3) values(1, @foo, null, null), (2, null, @bar, null), (3, null, null, @baz)",
expectedRows: ``, rowsAffected: 3,
Expand Down
13 changes: 9 additions & 4 deletions go/vt/vtgate/engine/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type (
Name string
Keyspace *vindexes.Keyspace
TargetDestination key.Destination
CheckSysVarQuery string
Expr string
}
)

Expand Down Expand Up @@ -196,12 +196,17 @@ func (svci *SysVarCheckAndIgnore) Execute(vcursor VCursor, bindVars map[string]*
if len(rss) != 1 {
return vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "Unexpected error, DestinationKeyspaceID mapping to multiple shards: %v", svci.TargetDestination)
}
result, err := execShard(vcursor, svci.CheckSysVarQuery, bindVars, rss[0], false /* rollbackOnError */, false /* canAutocommit */)
checkSysVarQuery := fmt.Sprintf("select 1 from dual where @@%s = %s", svci.Name, svci.Expr)
result, err := execShard(vcursor, checkSysVarQuery, bindVars, rss[0], false /* rollbackOnError */, false /* canAutocommit */)
if err != nil {
return err
}
if result.RowsAffected != 1 {
return vterrors.Errorf(vtrpcpb.Code_INVALID_ARGUMENT, "Modification not allowed using set construct for: %s", svci.Name)
var warning *querypb.QueryWarning
if result.RowsAffected == 0 {
warning = &querypb.QueryWarning{Code: mysql.ERNotSupportedYet, Message: fmt.Sprintf("Modification not allowed using set construct for: %s", svci.Name)}
} else {
warning = &querypb.QueryWarning{Code: mysql.ERNotSupportedYet, Message: fmt.Sprintf("Ignored inapplicable SET %v = %v", svci.Name, svci.Expr)}
}
vcursor.Session().RecordWarning(warning)
return nil
}
22 changes: 14 additions & 8 deletions go/vt/vtgate/engine/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestSetTable(t *testing.T) {
Sharded: true,
},
TargetDestination: key.DestinationAnyShard{},
CheckSysVarQuery: "dummy_query",
Expr: "dummy_expr",
},
},
qr: []*sqltypes.Result{sqltypes.MakeTestResult(
Expand All @@ -91,7 +91,10 @@ func TestSetTable(t *testing.T) {
)},
expectedQueryLog: []string{
`ResolveDestinations ks [] Destinations:DestinationAnyShard()`,
`ExecuteMultiShard ks.-20: dummy_query {} false false`,
`ExecuteMultiShard ks.-20: select 1 from dual where @@x = dummy_expr {} false false`,
},
expectedWarning: []*querypb.QueryWarning{
{Code: 1235, Message: "Ignored inapplicable SET x = dummy_expr"},
},
},
{
Expand All @@ -104,14 +107,16 @@ func TestSetTable(t *testing.T) {
Sharded: true,
},
TargetDestination: key.DestinationAnyShard{},
CheckSysVarQuery: "dummy_query",
Expr: "dummy_expr",
},
},
expectedQueryLog: []string{
`ResolveDestinations ks [] Destinations:DestinationAnyShard()`,
`ExecuteMultiShard ks.-20: dummy_query {} false false`,
`ExecuteMultiShard ks.-20: select 1 from dual where @@x = dummy_expr {} false false`,
},
expectedWarning: []*querypb.QueryWarning{
{Code: 1235, Message: "Modification not allowed using set construct for: x"},
},
expectedError: "Modification not allowed using set construct for: x",
},
{
testName: "sysvar checkAndIgnore multi destination error",
Expand All @@ -123,7 +128,7 @@ func TestSetTable(t *testing.T) {
Sharded: true,
},
TargetDestination: key.DestinationAllShards{},
CheckSysVarQuery: "dummy_query",
Expr: "dummy_expr",
},
},
expectedQueryLog: []string{
Expand Down Expand Up @@ -151,16 +156,17 @@ func TestSetTable(t *testing.T) {
Sharded: true,
},
TargetDestination: key.DestinationAnyShard{},
CheckSysVarQuery: "dummy_query",
Expr: "dummy_expr",
},
},
expectedQueryLog: []string{
`UDV set with (x,INT64(1))`,
`ResolveDestinations ks [] Destinations:DestinationAnyShard()`,
`ExecuteMultiShard ks.-20: dummy_query {} false false`,
`ExecuteMultiShard ks.-20: select 1 from dual where @@z = dummy_expr {} false false`,
},
expectedWarning: []*querypb.QueryWarning{
{Code: 1235, Message: "Ignored inapplicable SET y = 2"},
{Code: 1235, Message: "Ignored inapplicable SET z = dummy_expr"},
},
qr: []*sqltypes.Result{sqltypes.MakeTestResult(
sqltypes.MakeTestFields(
Expand Down
3 changes: 1 addition & 2 deletions go/vt/vtgate/planbuilder/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ limitations under the License.
package planbuilder

import (
"fmt"
"strings"

vtrpcpb "vitess.io/vitess/go/vt/proto/vtrpc"
Expand Down Expand Up @@ -104,6 +103,6 @@ func buildSetOpCheckAndIgnore(expr *sqlparser.SetExpr, vschema ContextVSchema) (
Name: expr.Name.Lowered(),
Keyspace: keyspace,
TargetDestination: dest,
CheckSysVarQuery: fmt.Sprintf("select 1 from dual where @@%s = %s", expr.Name.Lowered(), buf.String()),
Expr: buf.String(),
}, nil
}
2 changes: 1 addition & 1 deletion go/vt/vtgate/planbuilder/testdata/set_sysvar_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"Sharded": false
},
"TargetDestination": {},
"CheckSysVarQuery": "select 1 from dual where @@sql_mode = concat(@@sql_mode, ',NO_AUTO_CREATE_USER')"
"Expr": "concat(@@sql_mode, ',NO_AUTO_CREATE_USER')"
}
]
}
Expand Down