Tidb: Incorrect FieldType.Decimal Inference for INT, BIGINT, FLOAT, DOUBLE, TIMESTAMP Column

Created on 18 Aug 2017  Â·  8Comments  Â·  Source: pingcap/tidb

SQL:

create table t (
        c_int int,
        c_bigint bigint,
        c_float float,
        c_double double,
        c_decimal decimal(6, 3),
        c_datetime datetime(2),
        c_time time,
        c_timestamp timestamp,
        c_char char(20))

FieldType.Decimal of c_int, c_bigint, c_float, c_double, c_timestamp is -1.

typbug

Most helpful comment

you can support it in mysql/util.go: GetDefaultDecimal @breeswish

All 8 comments

@XuHuaiyu PTAL

you can support it in mysql/util.go: GetDefaultDecimal @breeswish

Set default in parser.y?

We may take this opportunity to unify this, set default in parser.y may be also feasible. @jackysp
What's your opinion? @breeswish
MySQL uses opt_field_length and opt_precision(in sql/ sql_yacc.yy) to parse this, and set it to NULL to indicate that the length and dec to be default if length and dec is not set explicitly.

Currently in ddl_api.go we sets the default value if it is unspecified.

If we set flen and decimal of all types in parser.y,
we can avoid checking this in ddl_api.go.

I think both is acceptable since they are identical in some ways. The only difference is when the default value is set. Setting flen and decimal in parser might be better since at that time we have more confidence for "unspecified". However it should be noticed that our flen is not exactly equal to the field length. For example, for DECIMAL, its default field length is 10 and flen is 11.

ok

Was this page helpful?
0 / 5 - 0 ratings