Skip to content

Commit

Permalink
expression: fix wrong flen infer for bit constant (#23867) (#24267)
Browse files Browse the repository at this point in the history
  • Loading branch information
ti-srebot committed Aug 12, 2021
1 parent 4f9b0b6 commit 899c2f0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 5 additions & 0 deletions expression/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4618,6 +4618,11 @@ func (s *testIntegrationSuite) TestIssues(c *C) {
tk.MustExec(`insert into t2 values(1,"1111"),(2,"2222"),(3,"3333"),(4,"4444"),(5,"5555"),(6,"6666"),(7,"7777"),(8,"8888"),(9,"9999"),(10,"0000")`)
tk.MustQuery(`select (@j := case when substr(t2.b,1,3)=@i then 1 else @j+1 end) from t2, (select @j := 0, @i := "0") tt limit 10`).Check(testkit.Rows(
"1", "2", "3", "4", "5", "6", "7", "8", "9", "10"))

// for issue #23479
tk.MustQuery("select b'10000000' DIV 10").Check(testkit.Rows("12"))
tk.MustQuery("select cast(b'10000000' as unsigned) / 10").Check(testkit.Rows("12.8000"))
tk.MustQuery("select b'10000000' / 10").Check(testkit.Rows("12.8000"))
}

func (s *testIntegrationSuite) TestInPredicate4UnsignedInt(c *C) {
Expand Down
6 changes: 3 additions & 3 deletions expression/typeinfer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,9 @@ func (s *testInferTypeSuite) createTestCase4Constants() []typeInferTestCase {
{"'1234'", mysql.TypeVarString, charset.CharsetUTF8MB4, 0 | mysql.NotNullFlag, 4, types.UnspecifiedLength},
{"_utf8'1234'", mysql.TypeVarString, charset.CharsetUTF8, 0 | mysql.NotNullFlag, 4, types.UnspecifiedLength},
{"_binary'1234'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.NotNullFlag, 4, types.UnspecifiedLength},
{"b'0001'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.NotNullFlag, 1, 0},
{"b'000100001'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.NotNullFlag, 2, 0},
{"b'0000000000010000'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.NotNullFlag, 2, 0},
{"b'0001'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.NotNullFlag, 3, 0},
{"b'000100001'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.NotNullFlag, 6, 0},
{"b'0000000000010000'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.NotNullFlag, 6, 0},
{"x'10'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag | mysql.NotNullFlag, 3, 0},
{"x'ff10'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag | mysql.NotNullFlag, 6, 0},
{"x'0000000000000000ff10'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag | mysql.NotNullFlag, 30, 0},
Expand Down
2 changes: 1 addition & 1 deletion types/field_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func DefaultTypeForValue(value interface{}, tp *FieldType, char string, collate
SetBinChsClnFlag(tp)
case BitLiteral:
tp.Tp = mysql.TypeVarString
tp.Flen = len(x)
tp.Flen = len(x) * 3
tp.Decimal = 0
SetBinChsClnFlag(tp)
case HexLiteral:
Expand Down

0 comments on commit 899c2f0

Please sign in to comment.