Skip to content

Commit 60726b7

Browse files
lzmhhh123zimulala
authored andcommitted
expression: improve length and decimal size when a base type add/minus/multiply a decimal (pingcap#11873) (pingcap#11909)
1 parent 79790e1 commit 60726b7

File tree

6 files changed

+89
-52
lines changed

6 files changed

+89
-52
lines changed

expression/builtin_arithmetic.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,12 @@ func setFlenDecimal4Int(retTp, a, b *types.FieldType) {
9090

9191
// setFlenDecimal4RealOrDecimal is called to set proper `Flen` and `Decimal` of return
9292
// type according to the two input parameter's types.
93-
func setFlenDecimal4RealOrDecimal(retTp, a, b *types.FieldType, isReal bool) {
93+
func setFlenDecimal4RealOrDecimal(retTp, a, b *types.FieldType, isReal bool, isMultiply bool) {
9494
if a.Decimal != types.UnspecifiedLength && b.Decimal != types.UnspecifiedLength {
9595
retTp.Decimal = a.Decimal + b.Decimal
96+
if !isMultiply {
97+
retTp.Decimal = mathutil.Max(a.Decimal, b.Decimal)
98+
}
9699
if !isReal && retTp.Decimal > mysql.MaxDecimalScale {
97100
retTp.Decimal = mysql.MaxDecimalScale
98101
}
@@ -101,6 +104,9 @@ func setFlenDecimal4RealOrDecimal(retTp, a, b *types.FieldType, isReal bool) {
101104
return
102105
}
103106
digitsInt := mathutil.Max(a.Flen-a.Decimal, b.Flen-b.Decimal)
107+
if isMultiply {
108+
digitsInt = a.Flen - a.Decimal + b.Flen - b.Decimal
109+
}
104110
retTp.Flen = digitsInt + retTp.Decimal + 3
105111
if isReal {
106112
retTp.Flen = mathutil.Min(retTp.Flen, mysql.MaxRealWidth)
@@ -155,13 +161,13 @@ func (c *arithmeticPlusFunctionClass) getFunction(ctx sessionctx.Context, args [
155161
lhsEvalTp, rhsEvalTp := numericContextResultType(lhsTp), numericContextResultType(rhsTp)
156162
if lhsEvalTp == types.ETReal || rhsEvalTp == types.ETReal {
157163
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETReal, types.ETReal, types.ETReal)
158-
setFlenDecimal4RealOrDecimal(bf.tp, args[0].GetType(), args[1].GetType(), true)
164+
setFlenDecimal4RealOrDecimal(bf.tp, args[0].GetType(), args[1].GetType(), true, false)
159165
sig := &builtinArithmeticPlusRealSig{bf}
160166
sig.setPbCode(tipb.ScalarFuncSig_PlusReal)
161167
return sig, nil
162168
} else if lhsEvalTp == types.ETDecimal || rhsEvalTp == types.ETDecimal {
163169
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETDecimal, types.ETDecimal, types.ETDecimal)
164-
setFlenDecimal4RealOrDecimal(bf.tp, args[0].GetType(), args[1].GetType(), false)
170+
setFlenDecimal4RealOrDecimal(bf.tp, args[0].GetType(), args[1].GetType(), false, false)
165171
sig := &builtinArithmeticPlusDecimalSig{bf}
166172
sig.setPbCode(tipb.ScalarFuncSig_PlusDecimal)
167173
return sig, nil
@@ -293,13 +299,13 @@ func (c *arithmeticMinusFunctionClass) getFunction(ctx sessionctx.Context, args
293299
lhsEvalTp, rhsEvalTp := numericContextResultType(lhsTp), numericContextResultType(rhsTp)
294300
if lhsEvalTp == types.ETReal || rhsEvalTp == types.ETReal {
295301
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETReal, types.ETReal, types.ETReal)
296-
setFlenDecimal4RealOrDecimal(bf.tp, args[0].GetType(), args[1].GetType(), true)
302+
setFlenDecimal4RealOrDecimal(bf.tp, args[0].GetType(), args[1].GetType(), true, false)
297303
sig := &builtinArithmeticMinusRealSig{bf}
298304
sig.setPbCode(tipb.ScalarFuncSig_MinusReal)
299305
return sig, nil
300306
} else if lhsEvalTp == types.ETDecimal || rhsEvalTp == types.ETDecimal {
301307
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETDecimal, types.ETDecimal, types.ETDecimal)
302-
setFlenDecimal4RealOrDecimal(bf.tp, args[0].GetType(), args[1].GetType(), false)
308+
setFlenDecimal4RealOrDecimal(bf.tp, args[0].GetType(), args[1].GetType(), false, false)
303309
sig := &builtinArithmeticMinusDecimalSig{bf}
304310
sig.setPbCode(tipb.ScalarFuncSig_MinusDecimal)
305311
return sig, nil
@@ -439,13 +445,13 @@ func (c *arithmeticMultiplyFunctionClass) getFunction(ctx sessionctx.Context, ar
439445
lhsEvalTp, rhsEvalTp := numericContextResultType(lhsTp), numericContextResultType(rhsTp)
440446
if lhsEvalTp == types.ETReal || rhsEvalTp == types.ETReal {
441447
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETReal, types.ETReal, types.ETReal)
442-
setFlenDecimal4RealOrDecimal(bf.tp, args[0].GetType(), args[1].GetType(), true)
448+
setFlenDecimal4RealOrDecimal(bf.tp, args[0].GetType(), args[1].GetType(), true, true)
443449
sig := &builtinArithmeticMultiplyRealSig{bf}
444450
sig.setPbCode(tipb.ScalarFuncSig_MultiplyReal)
445451
return sig, nil
446452
} else if lhsEvalTp == types.ETDecimal || rhsEvalTp == types.ETDecimal {
447453
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETDecimal, types.ETDecimal, types.ETDecimal)
448-
setFlenDecimal4RealOrDecimal(bf.tp, args[0].GetType(), args[1].GetType(), false)
454+
setFlenDecimal4RealOrDecimal(bf.tp, args[0].GetType(), args[1].GetType(), false, true)
449455
sig := &builtinArithmeticMultiplyDecimalSig{bf}
450456
sig.setPbCode(tipb.ScalarFuncSig_MultiplyDecimal)
451457
return sig, nil

expression/builtin_arithmetic_test.go

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,25 +37,56 @@ func (s *testEvaluatorSuite) TestSetFlenDecimal4RealOrDecimal(c *C) {
3737
Decimal: 0,
3838
Flen: 2,
3939
}
40-
setFlenDecimal4RealOrDecimal(ret, a, b, true)
40+
setFlenDecimal4RealOrDecimal(ret, a, b, true, false)
4141
c.Assert(ret.Decimal, Equals, 1)
4242
c.Assert(ret.Flen, Equals, 6)
4343

4444
b.Flen = 65
45-
setFlenDecimal4RealOrDecimal(ret, a, b, true)
45+
setFlenDecimal4RealOrDecimal(ret, a, b, true, false)
4646
c.Assert(ret.Decimal, Equals, 1)
4747
c.Assert(ret.Flen, Equals, mysql.MaxRealWidth)
48-
setFlenDecimal4RealOrDecimal(ret, a, b, false)
48+
setFlenDecimal4RealOrDecimal(ret, a, b, false, false)
4949
c.Assert(ret.Decimal, Equals, 1)
5050
c.Assert(ret.Flen, Equals, mysql.MaxDecimalWidth)
5151

5252
b.Flen = types.UnspecifiedLength
53-
setFlenDecimal4RealOrDecimal(ret, a, b, true)
53+
setFlenDecimal4RealOrDecimal(ret, a, b, true, false)
5454
c.Assert(ret.Decimal, Equals, 1)
5555
c.Assert(ret.Flen, Equals, types.UnspecifiedLength)
5656

5757
b.Decimal = types.UnspecifiedLength
58-
setFlenDecimal4RealOrDecimal(ret, a, b, true)
58+
setFlenDecimal4RealOrDecimal(ret, a, b, true, false)
59+
c.Assert(ret.Decimal, Equals, types.UnspecifiedLength)
60+
c.Assert(ret.Flen, Equals, types.UnspecifiedLength)
61+
62+
ret = &types.FieldType{}
63+
a = &types.FieldType{
64+
Decimal: 1,
65+
Flen: 3,
66+
}
67+
b = &types.FieldType{
68+
Decimal: 0,
69+
Flen: 2,
70+
}
71+
setFlenDecimal4RealOrDecimal(ret, a, b, true, true)
72+
c.Assert(ret.Decimal, Equals, 1)
73+
c.Assert(ret.Flen, Equals, 8)
74+
75+
b.Flen = 65
76+
setFlenDecimal4RealOrDecimal(ret, a, b, true, true)
77+
c.Assert(ret.Decimal, Equals, 1)
78+
c.Assert(ret.Flen, Equals, mysql.MaxRealWidth)
79+
setFlenDecimal4RealOrDecimal(ret, a, b, false, true)
80+
c.Assert(ret.Decimal, Equals, 1)
81+
c.Assert(ret.Flen, Equals, mysql.MaxDecimalWidth)
82+
83+
b.Flen = types.UnspecifiedLength
84+
setFlenDecimal4RealOrDecimal(ret, a, b, true, true)
85+
c.Assert(ret.Decimal, Equals, 1)
86+
c.Assert(ret.Flen, Equals, types.UnspecifiedLength)
87+
88+
b.Decimal = types.UnspecifiedLength
89+
setFlenDecimal4RealOrDecimal(ret, a, b, true, true)
5990
c.Assert(ret.Decimal, Equals, types.UnspecifiedLength)
6091
c.Assert(ret.Flen, Equals, types.UnspecifiedLength)
6192
}

expression/builtin_cast.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1775,7 +1775,7 @@ func WrapWithCastAsDecimal(ctx sessionctx.Context, expr Expression) Expression {
17751775
return expr
17761776
}
17771777
tp := types.NewFieldType(mysql.TypeNewDecimal)
1778-
tp.Flen, tp.Decimal = expr.GetType().Flen, types.UnspecifiedLength
1778+
tp.Flen, tp.Decimal = expr.GetType().Flen, expr.GetType().Decimal
17791779
types.SetBinChsClnFlag(tp)
17801780
tp.Flag |= expr.GetType().Flag & mysql.UnsignedFlag
17811781
return BuildCastFunction(ctx, expr, tp)

expression/builtin_time.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4398,7 +4398,7 @@ func (c *timestampFunctionClass) getFunction(ctx sessionctx.Context, args []Expr
43984398
isFloat = true
43994399
}
44004400
bf := newBaseBuiltinFuncWithTp(ctx, args, types.ETDatetime, evalTps...)
4401-
bf.tp.Decimal, bf.tp.Flen = fsp, 19
4401+
bf.tp.Decimal, bf.tp.Flen = -1, 19
44024402
if fsp != 0 {
44034403
bf.tp.Flen += 1 + fsp
44044404
}

expression/typeinfer_test.go

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,9 @@ func (s *testInferTypeSuite) createTestCase4Constants() []typeInferTestCase {
171171
{"b'0001'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 1, 0},
172172
{"b'000100001'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 2, 0},
173173
{"b'0000000000010000'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag, 2, 0},
174-
{"x'10'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag, 1, 0},
175-
{"x'ff10'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag, 2, 0},
176-
{"x'0000000000000000ff10'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag, 10, 0},
174+
{"x'10'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag, 3, 0},
175+
{"x'ff10'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag, 6, 0},
176+
{"x'0000000000000000ff10'", mysql.TypeVarString, charset.CharsetBin, mysql.BinaryFlag | mysql.UnsignedFlag, 30, 0},
177177
}
178178
}
179179

@@ -693,9 +693,9 @@ func (s *testInferTypeSuite) createTestCase4ArithmeticFuncs() []typeInferTestCas
693693
{"c_int_d + c_char", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
694694
{"c_int_d + c_time_d", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0},
695695
{"c_int_d + c_double_d", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
696-
{"c_int_d + c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDecimalWidth, mysql.MaxDecimalScale},
697-
{"c_datetime + c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDecimalWidth, mysql.MaxDecimalScale},
698-
{"c_bigint_d + c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDecimalWidth, mysql.MaxDecimalScale},
696+
{"c_int_d + c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 17, 3},
697+
{"c_datetime + c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 26, 3},
698+
{"c_bigint_d + c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 26, 3},
699699
{"c_double_d + c_decimal", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
700700
{"c_double_d + c_char", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
701701
{"c_double_d + c_enum", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
@@ -705,9 +705,9 @@ func (s *testInferTypeSuite) createTestCase4ArithmeticFuncs() []typeInferTestCas
705705
{"c_int_d - c_char", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
706706
{"c_int_d - c_time_d", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0},
707707
{"c_int_d - c_double_d", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
708-
{"c_int_d - c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDecimalWidth, mysql.MaxDecimalScale},
709-
{"c_datetime - c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDecimalWidth, mysql.MaxDecimalScale},
710-
{"c_bigint_d - c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDecimalWidth, mysql.MaxDecimalScale},
708+
{"c_int_d - c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 17, 3},
709+
{"c_datetime - c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 26, 3},
710+
{"c_bigint_d - c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 26, 3},
711711
{"c_double_d - c_decimal", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
712712
{"c_double_d - c_char", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
713713
{"c_double_d - c_enum", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
@@ -717,9 +717,9 @@ func (s *testInferTypeSuite) createTestCase4ArithmeticFuncs() []typeInferTestCas
717717
{"c_int_d * c_char", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
718718
{"c_int_d * c_time_d", mysql.TypeLonglong, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxIntWidth, 0},
719719
{"c_int_d * c_double_d", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
720-
{"c_int_d * c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDecimalWidth, mysql.MaxDecimalScale},
721-
{"c_datetime * c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDecimalWidth, mysql.MaxDecimalScale},
722-
{"c_bigint_d * c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, mysql.MaxDecimalWidth, mysql.MaxDecimalScale},
720+
{"c_int_d * c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 20, 3},
721+
{"c_datetime * c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 31, 5},
722+
{"c_bigint_d * c_decimal", mysql.TypeNewDecimal, charset.CharsetBin, mysql.BinaryFlag, 29, 3},
723723
{"c_double_d * c_decimal", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
724724
{"c_double_d * c_char", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
725725
{"c_double_d * c_enum", mysql.TypeDouble, charset.CharsetBin, mysql.BinaryFlag, types.UnspecifiedLength, types.UnspecifiedLength},
@@ -1267,31 +1267,31 @@ func (s *testInferTypeSuite) createTestCase4TimeFuncs() []typeInferTestCase {
12671267
{"subtime(c_date, c_timestamp)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength},
12681268
{"subtime(c_date, c_time)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength},
12691269

1270-
{"timestamp(c_int_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, 0},
1271-
{"timestamp(c_float_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6},
1272-
{"timestamp(c_double_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6},
1273-
{"timestamp(c_decimal)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 23, 3},
1274-
{"timestamp(c_udecimal)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 23, 3},
1275-
{"timestamp(c_decimal_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, 0},
1276-
{"timestamp(c_udecimal_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, 0},
1277-
{"timestamp(c_datetime)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 22, 2},
1278-
{"timestamp(c_datetime_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, 0},
1279-
{"timestamp(c_timestamp)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 24, 4},
1280-
{"timestamp(c_time)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 23, 3},
1281-
{"timestamp(c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, 0},
1282-
{"timestamp(c_bchar)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6},
1283-
{"timestamp(c_char)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6},
1284-
{"timestamp(c_varchar)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6},
1285-
{"timestamp(c_text_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6},
1286-
{"timestamp(c_btext_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6},
1287-
{"timestamp(c_blob_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6},
1288-
{"timestamp(c_set)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6},
1289-
{"timestamp(c_enum)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6},
1290-
1291-
{"timestamp(c_int_d, c_float_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6},
1292-
{"timestamp(c_datetime, c_timestamp)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 24, 4},
1293-
{"timestamp(c_timestamp, c_char)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 6},
1294-
{"timestamp(c_int_d, c_datetime)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 22, 2},
1270+
{"timestamp(c_int_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, types.UnspecifiedLength},
1271+
{"timestamp(c_float_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, types.UnspecifiedLength},
1272+
{"timestamp(c_double_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, types.UnspecifiedLength},
1273+
{"timestamp(c_decimal)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 23, types.UnspecifiedLength},
1274+
{"timestamp(c_udecimal)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 23, types.UnspecifiedLength},
1275+
{"timestamp(c_decimal_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, types.UnspecifiedLength},
1276+
{"timestamp(c_udecimal_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, types.UnspecifiedLength},
1277+
{"timestamp(c_datetime)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 22, types.UnspecifiedLength},
1278+
{"timestamp(c_datetime_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, types.UnspecifiedLength},
1279+
{"timestamp(c_timestamp)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 24, types.UnspecifiedLength},
1280+
{"timestamp(c_time)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 23, types.UnspecifiedLength},
1281+
{"timestamp(c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 19, types.UnspecifiedLength},
1282+
{"timestamp(c_bchar)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, types.UnspecifiedLength},
1283+
{"timestamp(c_char)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, types.UnspecifiedLength},
1284+
{"timestamp(c_varchar)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, types.UnspecifiedLength},
1285+
{"timestamp(c_text_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, types.UnspecifiedLength},
1286+
{"timestamp(c_btext_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, types.UnspecifiedLength},
1287+
{"timestamp(c_blob_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, types.UnspecifiedLength},
1288+
{"timestamp(c_set)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, types.UnspecifiedLength},
1289+
{"timestamp(c_enum)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, types.UnspecifiedLength},
1290+
1291+
{"timestamp(c_int_d, c_float_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, types.UnspecifiedLength},
1292+
{"timestamp(c_datetime, c_timestamp)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 24, types.UnspecifiedLength},
1293+
{"timestamp(c_timestamp, c_char)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, types.UnspecifiedLength},
1294+
{"timestamp(c_int_d, c_datetime)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 22, types.UnspecifiedLength},
12951295

12961296
{"addtime(c_int_d, c_time_d)", mysql.TypeString, charset.CharsetUTF8MB4, 0, 26, types.UnspecifiedLength},
12971297
{"addtime(c_datetime_d, c_time_d)", mysql.TypeDatetime, charset.CharsetBin, mysql.BinaryFlag, 26, 0},

types/field_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ func DefaultTypeForValue(value interface{}, tp *FieldType) {
201201
SetBinChsClnFlag(tp)
202202
case HexLiteral:
203203
tp.Tp = mysql.TypeVarString
204-
tp.Flen = len(x)
204+
tp.Flen = len(x) * 3
205205
tp.Decimal = 0
206206
tp.Flag |= mysql.UnsignedFlag
207207
SetBinChsClnFlag(tp)

0 commit comments

Comments
 (0)