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

expression: check corCol in DisableParseJSONFlag4Expr (#10224) #10694

Merged
merged 4 commits into from
Jun 4, 2019
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
10 changes: 7 additions & 3 deletions expression/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -542,12 +542,16 @@ func ColumnSliceIsIntersect(s1, s2 []*Column) bool {

// DisableParseJSONFlag4Expr disables ParseToJSONFlag for `expr` except Column.
// We should not *PARSE* a string as JSON under some scenarios. ParseToJSONFlag
// is 0 for JSON column yet, so we can skip it. Moreover, Column.RetType refers
// to the infoschema, if we modify it, data race may happen if another goroutine
// read from the infoschema at the same time.
// is 0 for JSON column yet(as well as JSON correlated column), so we can skip
// it. Moreover, Column.RetType refers to the infoschema, if we modify it, data
// race may happen if another goroutine read from the infoschema at the same
// time.
func DisableParseJSONFlag4Expr(expr Expression) {
if _, isColumn := expr.(*Column); isColumn {
return
}
if _, isCorCol := expr.(*CorrelatedColumn); isCorCol {
return
}
expr.GetType().Flag &= ^mysql.ParseToJSONFlag
}
30 changes: 30 additions & 0 deletions expression/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,27 @@ func isLogicOrFunction(e Expression) bool {
return false
}

func (s *testUtilSuite) TestDisableParseJSONFlag4Expr(c *check.C) {
var expr Expression
expr = &Column{RetType: newIntFieldType()}
ft := expr.GetType()
ft.Flag |= mysql.ParseToJSONFlag
DisableParseJSONFlag4Expr(expr)
c.Assert(mysql.HasParseToJSONFlag(ft.Flag), check.IsTrue)

expr = &CorrelatedColumn{Column: Column{RetType: newIntFieldType()}}
ft = expr.GetType()
ft.Flag |= mysql.ParseToJSONFlag
DisableParseJSONFlag4Expr(expr)
c.Assert(mysql.HasParseToJSONFlag(ft.Flag), check.IsTrue)

expr = &ScalarFunction{RetType: newIntFieldType()}
ft = expr.GetType()
ft.Flag |= mysql.ParseToJSONFlag
DisableParseJSONFlag4Expr(expr)
c.Assert(mysql.HasParseToJSONFlag(ft.Flag), check.IsFalse)
}

func BenchmarkExtractColumns(b *testing.B) {
conditions := []Expression{
newFunction(ast.EQ, newColumn(0), newColumn(1)),
Expand Down Expand Up @@ -126,3 +147,12 @@ func BenchmarkExprFromSchema(b *testing.B) {
}
b.ReportAllocs()
}

func newIntFieldType() *types.FieldType {
return &types.FieldType{
Tp: mysql.TypeLonglong,
Flen: mysql.MaxIntWidth,
Decimal: 0,
Flag: mysql.BinaryFlag,
}
}