From 31516298f41509fb2510237eea98f5e1912abee1 Mon Sep 17 00:00:00 2001 From: wjhuang2016 Date: Thu, 25 Mar 2021 20:00:51 +0800 Subject: [PATCH 1/5] done Signed-off-by: wjhuang2016 --- a | 175 +++++++++++++++++++++++++++++++++++++ types/datum.go | 53 +---------- util/ranger/points.go | 60 +++++++++---- util/ranger/ranger_test.go | 6 +- 4 files changed, 224 insertions(+), 70 deletions(-) create mode 100644 a diff --git a/a b/a new file mode 100644 index 0000000000000..fd53f8b97ca81 --- /dev/null +++ b/a @@ -0,0 +1,175 @@ +cat checklist.md +# Following the checklist saves the reviewers' time and gets your PR reviewed faster. + +# Self Review +Have you reviewed every line of your changes by yourself? + +# Test +Have you added enough test cases to cover the new feature or bug fix? +Also, add comments to describe your test cases. + +# Naming +Do function names keep consistent with its behavior? +Is it easy to infer the function's behavior by its name? + +# Comment +Is there any code that confuses the reviewer? +Add comments on them! You'll be asked to do so anyway. +Make sure there is no syntax or spelling error in your comments. +Some online syntax checking tools like Grammarly may be helpful. + +# Refactor +Is there any way to refactor the code to make it more readable? +If the refactoring touches a lot of existing code, send another PR to do it. + +# Single Purpose +Make sure the PR does only one thing and nothing else. + +# Diff Size +Make sure the diff size is no more than 500, split it into small PRs if it is too large. +GO111MODULE=on go build -tags codes -ldflags '-X "github.com/pingcap/parser/mysql.TiDBReleaseVersion=v4.0.0-beta.2-2378-g9c48b24cb-dirty" -X "github.com/pingcap/tidb/util/versioninfo.TiDBBuildTS=2021-03-25 11:41:40" -X "github.com/pingcap/tidb/util/versioninfo.TiDBGitHash=9c48b24cb108d8239534730961a17aa66cfbf36b" -X "github.com/pingcap/tidb/util/versioninfo.TiDBGitBranch=master" -X "github.com/pingcap/tidb/util/versioninfo.TiDBEdition=Community" -X "github.com/pingcap/tidb/config.checkBeforeDropLDFlag=1"' -o bin/tidb-server tidb-server/main.go +extracting statistics: s +skip building tidb-server, using existing binary: ../../bin/tidb-server +building portgenerator binary: ./portgenerator +building explain-test binary: ./explain_test +start tidb-server, log file: ./explain-test.out +tidb-server(PID: 56714) started +run all explain test cases +explaintest end +GO111MODULE=on go list -f '{{ join .Imports "\n" }}' github.com/pingcap/tidb/store/tikv | grep ^github.com/pingcap/parser$ || exit 0; exit 1 +Running in native mode. +ok github.com/pingcap/tidb/bindinfo 9.743s coverage: 86.1% of statements +ok github.com/pingcap/tidb/config 0.604s coverage: 71.4% of statements +ok github.com/pingcap/tidb/ddl 177.816s coverage: 85.6% of statements +ok github.com/pingcap/tidb/ddl/failtest 146.774s coverage: [no statements] +ok github.com/pingcap/tidb/ddl/placement 0.458s coverage: 41.7% of statements +? github.com/pingcap/tidb/ddl/testutil [no test files] +ok github.com/pingcap/tidb/ddl/util 3.482s coverage: 45.5% of statements +ok github.com/pingcap/tidb/distsql 0.632s coverage: 64.8% of statements +ok github.com/pingcap/tidb/domain 5.063s coverage: 75.5% of statements +ok github.com/pingcap/tidb/domain/infosync 2.383s coverage: 18.3% of statements +ok github.com/pingcap/tidb/errno 0.342s coverage: 100.0% of statements +ok github.com/pingcap/tidb/executor 265.257s coverage: 78.4% of statements +ok github.com/pingcap/tidb/executor/aggfuncs 4.129s coverage: 76.0% of statements +ok github.com/pingcap/tidb/executor/oomtest 2.309s coverage: [no statements] [no tests to run] +ok github.com/pingcap/tidb/executor/seqtest 9.491s coverage: [no statements] +ok github.com/pingcap/tidb/expression 17.979s coverage: 81.8% of statements +ok github.com/pingcap/tidb/expression/aggregation 2.262s coverage: 43.4% of statements +? github.com/pingcap/tidb/expression/generator/helper [no test files] +ok github.com/pingcap/tidb/infoschema 5.504s coverage: 62.6% of statements +ok github.com/pingcap/tidb/infoschema/perfschema 2.843s coverage: 70.6% of statements +ok github.com/pingcap/tidb/kv 39.466s coverage: 76.9% of statements +? github.com/pingcap/tidb/lock [no test files] +ok github.com/pingcap/tidb/meta 1.461s coverage: 74.0% of statements +ok github.com/pingcap/tidb/meta/autoid 2.729s coverage: 72.2% of statements +ok github.com/pingcap/tidb/metrics 0.551s coverage: 98.9% of statements +ok github.com/pingcap/tidb/owner 22.495s coverage: 69.6% of statements +? github.com/pingcap/tidb/planner [no test files] +ok github.com/pingcap/tidb/planner/cascades 1.687s coverage: 94.6% of statements +ok github.com/pingcap/tidb/planner/core 55.583s coverage: 79.1% of statements +ok github.com/pingcap/tidb/planner/implementation 0.579s coverage: 3.7% of statements +ok github.com/pingcap/tidb/planner/memo 1.266s coverage: 86.9% of statements +? github.com/pingcap/tidb/planner/property [no test files] +? github.com/pingcap/tidb/planner/util [no test files] +ok github.com/pingcap/tidb/plugin 1.645s coverage: 59.0% of statements +ok github.com/pingcap/tidb/plugin/conn_ip_example 0.573s coverage: 0.0% of statements +? github.com/pingcap/tidb/privilege [no test files] +ok github.com/pingcap/tidb/privilege/privileges 4.369s coverage: 81.9% of statements +ok github.com/pingcap/tidb/server 238.189s coverage: 69.1% of statements +ok github.com/pingcap/tidb/session 45.837s coverage: 78.9% of statements +ok github.com/pingcap/tidb/sessionctx 0.495s coverage: 100.0% of statements +ok github.com/pingcap/tidb/sessionctx/binloginfo 2.666s coverage: 74.8% of statements +ok github.com/pingcap/tidb/sessionctx/stmtctx 0.545s coverage: 31.1% of statements +ok github.com/pingcap/tidb/sessionctx/variable 0.512s coverage: 45.7% of statements +ok github.com/pingcap/tidb/statistics 5.608s coverage: 77.9% of statements +ok github.com/pingcap/tidb/statistics/handle 18.417s coverage: 83.6% of statements +ok github.com/pingcap/tidb/store 87.985s coverage: 95.5% of statements +ok github.com/pingcap/tidb/store/copr 0.473s coverage: 0.2% of statements [no tests to run] +ok github.com/pingcap/tidb/store/driver 0.728s coverage: 1.9% of statements [no tests to run] +? github.com/pingcap/tidb/store/driver/txn [no test files] +ok github.com/pingcap/tidb/store/gcworker 15.520s coverage: 76.2% of statements +ok github.com/pingcap/tidb/store/helper 0.713s coverage: 49.5% of statements +ok github.com/pingcap/tidb/store/mockstore 0.610s coverage: 39.1% of statements +ok github.com/pingcap/tidb/store/mockstore/mocktikv 0.940s coverage: 44.0% of statements +ok github.com/pingcap/tidb/store/mockstore/unistore 0.479s coverage: 14.7% of statements +? github.com/pingcap/tidb/store/mockstore/unistore/client [no test files] +ok github.com/pingcap/tidb/store/mockstore/unistore/cophandler 0.681s coverage: 12.8% of statements +ok github.com/pingcap/tidb/store/tikv 40.980s coverage: 67.6% of statements +ok github.com/pingcap/tidb/store/tikv/config 0.631s coverage: 44.4% of statements +ok github.com/pingcap/tidb/store/tikv/latch 0.747s coverage: 95.2% of statements +? github.com/pingcap/tidb/store/tikv/logutil [no test files] +? github.com/pingcap/tidb/store/tikv/metrics [no test files] +? github.com/pingcap/tidb/store/tikv/mockstore/cluster [no test files] +? github.com/pingcap/tidb/store/tikv/oracle [no test files] +ok github.com/pingcap/tidb/store/tikv/oracle/oracles 0.712s coverage: 30.5% of statements +? github.com/pingcap/tidb/store/tikv/storeutil [no test files] +ok github.com/pingcap/tidb/store/tikv/tests 10.920s coverage: [no statements] +ok github.com/pingcap/tidb/store/tikv/tikvrpc 0.396s coverage: 0.6% of statements +ok github.com/pingcap/tidb/store/tikv/util 0.663s coverage: 38.9% of statements +? github.com/pingcap/tidb/store/tikv/util/codec [no test files] +ok github.com/pingcap/tidb/structure 1.073s coverage: 81.2% of statements +ok github.com/pingcap/tidb/table 0.489s coverage: 70.3% of statements +ok github.com/pingcap/tidb/table/tables 2.788s coverage: 55.9% of statements +ok github.com/pingcap/tidb/tablecodec 0.414s coverage: 31.9% of statements +ok github.com/pingcap/tidb/telemetry 3.269s coverage: 56.8% of statements +ok github.com/pingcap/tidb/tidb-server 0.803s coverage: 20.8% of statements +ok github.com/pingcap/tidb/types 1.328s coverage: 82.5% of statements +ok github.com/pingcap/tidb/types/json 0.427s coverage: 80.6% of statements +ok github.com/pingcap/tidb/types/parser_driver 0.404s coverage: 28.7% of statements +ok github.com/pingcap/tidb/util 0.733s coverage: 54.3% of statements +ok github.com/pingcap/tidb/util/admin 2.555s coverage: 55.6% of statements +ok github.com/pingcap/tidb/util/arena 0.428s coverage: 100.0% of statements +ok github.com/pingcap/tidb/util/bitmap 0.737s coverage: 85.7% of statements +ok github.com/pingcap/tidb/util/checksum 0.383s coverage: 85.1% of statements +ok github.com/pingcap/tidb/util/chunk 2.960s coverage: 82.0% of statements +ok github.com/pingcap/tidb/util/codec 0.446s coverage: 82.9% of statements +ok github.com/pingcap/tidb/util/collate 1.563s coverage: 72.7% of statements +ok github.com/pingcap/tidb/util/dbterror 0.558s coverage: 100.0% of statements +ok github.com/pingcap/tidb/util/deadlock 0.566s coverage: 100.0% of statements +ok github.com/pingcap/tidb/util/disjointset 0.564s coverage: 100.0% of statements +ok github.com/pingcap/tidb/util/disk 0.373s coverage: 50.0% of statements +? github.com/pingcap/tidb/util/domainutil [no test files] +ok github.com/pingcap/tidb/util/encrypt 0.513s coverage: 92.6% of statements +ok github.com/pingcap/tidb/util/execdetails 0.683s coverage: 63.2% of statements +ok github.com/pingcap/tidb/util/expensivequery 0.737s coverage: 13.4% of statements +ok github.com/pingcap/tidb/util/fastrand 0.335s coverage: 0.0% of statements [no tests to run] +ok github.com/pingcap/tidb/util/filesort 1.876s coverage: 86.3% of statements +ok github.com/pingcap/tidb/util/format 1.097s coverage: 83.6% of statements +? github.com/pingcap/tidb/util/gcutil [no test files] +ok github.com/pingcap/tidb/util/generatedexpr 1.258s coverage: 0.0% of statements [no tests to run] +ok github.com/pingcap/tidb/util/hack 1.343s coverage: 92.3% of statements +? github.com/pingcap/tidb/util/hint [no test files] +? github.com/pingcap/tidb/util/israce [no test files] +ok github.com/pingcap/tidb/util/kvcache 2.352s coverage: 57.0% of statements +ok github.com/pingcap/tidb/util/localpool 2.676s coverage: 96.8% of statements +ok github.com/pingcap/tidb/util/logutil 2.077s coverage: 77.8% of statements +ok github.com/pingcap/tidb/util/math 2.691s coverage: 33.3% of statements +ok github.com/pingcap/tidb/util/memory 1.888s coverage: 64.6% of statements +ok github.com/pingcap/tidb/util/mock 0.987s coverage: 15.8% of statements +ok github.com/pingcap/tidb/util/mvmap 1.309s coverage: 86.6% of statements +ok github.com/pingcap/tidb/util/parser 0.503s coverage: 60.0% of statements +? github.com/pingcap/tidb/util/pdapi [no test files] +ok github.com/pingcap/tidb/util/plancodec 0.891s coverage: 3.9% of statements +ok github.com/pingcap/tidb/util/printer 0.439s coverage: 88.3% of statements +ok github.com/pingcap/tidb/util/profile 2.166s coverage: 55.4% of statements +ok github.com/pingcap/tidb/util/ranger 6.506s coverage: 82.1% of statements +ok github.com/pingcap/tidb/util/rowDecoder 1.050s coverage: 77.6% of statements +ok github.com/pingcap/tidb/util/rowcodec 0.532s coverage: 87.6% of statements +ok github.com/pingcap/tidb/util/selection 1.440s coverage: 86.8% of statements +ok github.com/pingcap/tidb/util/set 0.738s coverage: 48.6% of statements +? github.com/pingcap/tidb/util/signal [no test files] +ok github.com/pingcap/tidb/util/sqlexec 1.199s coverage: 96.3% of statements +ok github.com/pingcap/tidb/util/stmtsummary 1.635s coverage: 91.1% of statements +ok github.com/pingcap/tidb/util/stringutil 1.194s coverage: 87.9% of statements +ok github.com/pingcap/tidb/util/sys/linux 2.147s coverage: 66.7% of statements +ok github.com/pingcap/tidb/util/sys/storage 2.108s coverage: 83.3% of statements +ok github.com/pingcap/tidb/util/systimemon 2.625s coverage: 100.0% of statements +ok github.com/pingcap/tidb/util/testkit 0.872s coverage: 6.2% of statements +? github.com/pingcap/tidb/util/testleak [no test files] +ok github.com/pingcap/tidb/util/testutil 0.694s coverage: 18.7% of statements +ok github.com/pingcap/tidb/util/texttree 0.411s coverage: 100.0% of statements +ok github.com/pingcap/tidb/util/timeutil 0.435s coverage: 48.7% of statements +ok github.com/pingcap/tidb/util/tracing 0.842s coverage: 93.3% of statements +? github.com/pingcap/tidb/util/versioninfo [no test files] +go generate ./... +./tools/check/check-gogenerate.sh diff --git a/types/datum.go b/types/datum.go index d6542f7507631..2720c468a1a77 100644 --- a/types/datum.go +++ b/types/datum.go @@ -831,7 +831,7 @@ func (d *Datum) ConvertTo(sc *stmtctx.StatementContext, target *FieldType) (Datu case mysql.TypeNewDecimal: return d.convertToMysqlDecimal(sc, target) case mysql.TypeYear: - return d.convertToMysqlYear(sc, target) + return d.ConvertToMysqlYear(sc, target) case mysql.TypeEnum: return d.convertToMysqlEnum(sc, target) case mysql.TypeBit: @@ -1349,7 +1349,8 @@ func ProduceDecWithSpecifiedTp(dec *MyDecimal, tp *FieldType, sc *stmtctx.Statem return dec, err } -func (d *Datum) convertToMysqlYear(sc *stmtctx.StatementContext, target *FieldType) (Datum, error) { +// ConvertToMysqlYear converts a datum to MySQLYear. +func (d *Datum) ConvertToMysqlYear(sc *stmtctx.StatementContext, target *FieldType) (Datum, error) { var ( ret Datum y int64 @@ -1394,54 +1395,6 @@ func (d *Datum) convertToMysqlYear(sc *stmtctx.StatementContext, target *FieldTy return ret, errors.Trace(err) } -// ConvertDatumToFloatYear converts datum into MySQL year with float type -func ConvertDatumToFloatYear(sc *stmtctx.StatementContext, d Datum) (Datum, error) { - return d.convertToMysqlFloatYear(sc, types.NewFieldType(mysql.TypeYear)) -} - -func (d *Datum) convertToMysqlFloatYear(sc *stmtctx.StatementContext, target *FieldType) (Datum, error) { - var ( - ret Datum - y float64 - err error - adjust bool - ) - switch d.k { - case KindString, KindBytes: - s := d.GetString() - trimS := strings.TrimSpace(s) - y, err = StrToFloat(sc, trimS, false) - if err != nil { - ret.SetFloat64(0) - return ret, errors.Trace(err) - } - // condition: - // parsed to 0, not a string of length 4, the first valid char is a 0 digit - if len(s) != 4 && y == 0 && strings.HasPrefix(trimS, "0") { - adjust = true - } - case KindMysqlTime: - y = float64(d.GetMysqlTime().Year()) - case KindMysqlDuration: - y = float64(time.Now().Year()) - case KindNull: - // if datum is NULL, we should keep it as it is, instead of setting it to zero or any other value. - ret = *d - return ret, nil - default: - ret, err = d.convertToFloat(sc, NewFieldType(mysql.TypeDouble)) - if err != nil { - _, err = invalidConv(d, target.Tp) - ret.SetFloat64(0) - return ret, err - } - y = ret.GetFloat64() - } - y = adjustYearForFloat(y, adjust) - ret.SetFloat64(y) - return ret, err -} - func (d *Datum) convertStringToMysqlBit(sc *stmtctx.StatementContext) (uint64, error) { bitStr, err := ParseBitStr(BinaryLiteral(d.b).ToString()) if err != nil { diff --git a/util/ranger/points.go b/util/ranger/points.go index 26359213f5c22..b376437424a79 100644 --- a/util/ranger/points.go +++ b/util/ranger/points.go @@ -135,6 +135,13 @@ func getFullRange() []*point { } } +func getNotNullFullRange() []*point { + return []*point{ + {value: types.MinNotNullDatum(), start: true}, + {value: types.MaxValueDatum()}, + } +} + // FullIntRange is used for table range. Since table range cannot accept MaxValueDatum as the max value. // So we need to set it to MaxInt64. func FullIntRange(isUnsigned bool) []*Range { @@ -221,31 +228,49 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []*point { ft *types.FieldType ) - // refineValue refines the constant datum: + // refineValueAndOp refines the constant datum and operator: // 1. for string type since we may eval the constant to another collation instead of its own collation. // 2. for year type since 2-digit year value need adjustment, see https://dev.mysql.com/doc/refman/5.6/en/year.html - refineValue := func(col *expression.Column, value *types.Datum) (err error) { + refineValueAndOp := func(col *expression.Column, value *types.Datum, op *string) (err error) { if col.RetType.EvalType() == types.ETString && value.Kind() == types.KindString { value.SetString(value.GetString(), col.RetType.Collate) } if col.GetType().Tp == mysql.TypeYear { - *value, err = types.ConvertDatumToFloatYear(r.sc, *value) + preValue, err1 := value.ToInt64(r.sc) + if err1 != nil { + return err1 + } + *value, err = value.ConvertToMysqlYear(r.sc, col.RetType) + if errors.ErrorEqual(err, types.ErrInvalidYear) { + switch *op { + case ast.GT: + if value.GetInt64() > preValue { + *op = ast.GE + } + err = nil + case ast.LT: + if value.GetInt64() < preValue { + *op = ast.LE + } + err = nil + case ast.GE, ast.LE: + err = nil + } + } } return } - if col, ok := expr.GetArgs()[0].(*expression.Column); ok { + var col *expression.Column + var ok bool + if col, ok = expr.GetArgs()[0].(*expression.Column); ok { ft = col.RetType value, err = expr.GetArgs()[1].Eval(chunk.Row{}) if err != nil { return nil } - err = refineValue(col, &value) - if err != nil { - return nil - } op = expr.FuncName.L } else { - col, ok := expr.GetArgs()[1].(*expression.Column) + col, ok = expr.GetArgs()[1].(*expression.Column) if !ok { return nil } @@ -254,11 +279,6 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []*point { if err != nil { return nil } - err = refineValue(col, &value) - if err != nil { - return nil - } - switch expr.FuncName.L { case ast.GE: op = ast.LE @@ -275,6 +295,13 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []*point { if op != ast.NullEQ && value.IsNull() { return nil } + err = refineValueAndOp(col, &value, &op) + if err != nil { + if op == ast.NE { + return getNotNullFullRange() + } + return nil + } value, op, isValidRange := handleUnsignedCol(ft, value, op) if !isValidRange { @@ -472,10 +499,9 @@ func (r *builder) buildFromIn(expr *expression.ScalarFunction) ([]*point, bool) dt.SetString(dt.GetString(), colCollate) } if expr.GetArgs()[0].GetType().Tp == mysql.TypeYear { - dt, err = types.ConvertDatumToFloatYear(r.sc, dt) + dt, err = dt.ConvertToMysqlYear(r.sc, expr.GetArgs()[0].GetType()) if err != nil { - r.err = ErrUnsupportedType.GenWithStack("expr:%v is not converted to year", e) - return getFullRange(), hasNull + continue } } var startValue, endValue types.Datum diff --git a/util/ranger/ranger_test.go b/util/ranger/ranger_test.go index e26624f752381..7c0d0d30b760e 100644 --- a/util/ranger/ranger_test.go +++ b/util/ranger/ranger_test.go @@ -1529,7 +1529,7 @@ func (s *testRangerSuite) TestIndexRangeForYear(c *C) { exprStr: `a not in (-1, 1, 2)`, accessConds: "[not(in(test.t.a, -1, 1, 2))]", filterConds: "[]", - resultStr: `[(NULL,0) [0,2001) (2002,+inf]]`, + resultStr: `[(NULL,2001) (2002,+inf]]`, }, { indexPos: 0, @@ -1557,7 +1557,7 @@ func (s *testRangerSuite) TestIndexRangeForYear(c *C) { exprStr: `a not in (1, 2, 15698)`, accessConds: "[not(in(test.t.a, 1, 2, 15698))]", filterConds: "[]", - resultStr: `[(NULL,2001) (2002,2155] (2155,+inf]]`, + resultStr: `[(NULL,2001) (2002,+inf]]`, }, { indexPos: 0, @@ -1585,7 +1585,7 @@ func (s *testRangerSuite) TestIndexRangeForYear(c *C) { exprStr: `a != 2156`, accessConds: "[ne(test.t.a, 2156)]", filterConds: "[]", - resultStr: `[[-inf,2155] (2155,+inf]]`, + resultStr: `[[-inf,+inf]]`, }, { exprStr: "a < 99 or a > 01", From b8340df6a9004bbadfdcc42913704dc439a6011b Mon Sep 17 00:00:00 2001 From: wjhuang2016 Date: Thu, 25 Mar 2021 20:02:14 +0800 Subject: [PATCH 2/5] fix Signed-off-by: wjhuang2016 --- a | 175 -------------------------------------------------------------- 1 file changed, 175 deletions(-) delete mode 100644 a diff --git a/a b/a deleted file mode 100644 index fd53f8b97ca81..0000000000000 --- a/a +++ /dev/null @@ -1,175 +0,0 @@ -cat checklist.md -# Following the checklist saves the reviewers' time and gets your PR reviewed faster. - -# Self Review -Have you reviewed every line of your changes by yourself? - -# Test -Have you added enough test cases to cover the new feature or bug fix? -Also, add comments to describe your test cases. - -# Naming -Do function names keep consistent with its behavior? -Is it easy to infer the function's behavior by its name? - -# Comment -Is there any code that confuses the reviewer? -Add comments on them! You'll be asked to do so anyway. -Make sure there is no syntax or spelling error in your comments. -Some online syntax checking tools like Grammarly may be helpful. - -# Refactor -Is there any way to refactor the code to make it more readable? -If the refactoring touches a lot of existing code, send another PR to do it. - -# Single Purpose -Make sure the PR does only one thing and nothing else. - -# Diff Size -Make sure the diff size is no more than 500, split it into small PRs if it is too large. -GO111MODULE=on go build -tags codes -ldflags '-X "github.com/pingcap/parser/mysql.TiDBReleaseVersion=v4.0.0-beta.2-2378-g9c48b24cb-dirty" -X "github.com/pingcap/tidb/util/versioninfo.TiDBBuildTS=2021-03-25 11:41:40" -X "github.com/pingcap/tidb/util/versioninfo.TiDBGitHash=9c48b24cb108d8239534730961a17aa66cfbf36b" -X "github.com/pingcap/tidb/util/versioninfo.TiDBGitBranch=master" -X "github.com/pingcap/tidb/util/versioninfo.TiDBEdition=Community" -X "github.com/pingcap/tidb/config.checkBeforeDropLDFlag=1"' -o bin/tidb-server tidb-server/main.go -extracting statistics: s -skip building tidb-server, using existing binary: ../../bin/tidb-server -building portgenerator binary: ./portgenerator -building explain-test binary: ./explain_test -start tidb-server, log file: ./explain-test.out -tidb-server(PID: 56714) started -run all explain test cases -explaintest end -GO111MODULE=on go list -f '{{ join .Imports "\n" }}' github.com/pingcap/tidb/store/tikv | grep ^github.com/pingcap/parser$ || exit 0; exit 1 -Running in native mode. -ok github.com/pingcap/tidb/bindinfo 9.743s coverage: 86.1% of statements -ok github.com/pingcap/tidb/config 0.604s coverage: 71.4% of statements -ok github.com/pingcap/tidb/ddl 177.816s coverage: 85.6% of statements -ok github.com/pingcap/tidb/ddl/failtest 146.774s coverage: [no statements] -ok github.com/pingcap/tidb/ddl/placement 0.458s coverage: 41.7% of statements -? github.com/pingcap/tidb/ddl/testutil [no test files] -ok github.com/pingcap/tidb/ddl/util 3.482s coverage: 45.5% of statements -ok github.com/pingcap/tidb/distsql 0.632s coverage: 64.8% of statements -ok github.com/pingcap/tidb/domain 5.063s coverage: 75.5% of statements -ok github.com/pingcap/tidb/domain/infosync 2.383s coverage: 18.3% of statements -ok github.com/pingcap/tidb/errno 0.342s coverage: 100.0% of statements -ok github.com/pingcap/tidb/executor 265.257s coverage: 78.4% of statements -ok github.com/pingcap/tidb/executor/aggfuncs 4.129s coverage: 76.0% of statements -ok github.com/pingcap/tidb/executor/oomtest 2.309s coverage: [no statements] [no tests to run] -ok github.com/pingcap/tidb/executor/seqtest 9.491s coverage: [no statements] -ok github.com/pingcap/tidb/expression 17.979s coverage: 81.8% of statements -ok github.com/pingcap/tidb/expression/aggregation 2.262s coverage: 43.4% of statements -? github.com/pingcap/tidb/expression/generator/helper [no test files] -ok github.com/pingcap/tidb/infoschema 5.504s coverage: 62.6% of statements -ok github.com/pingcap/tidb/infoschema/perfschema 2.843s coverage: 70.6% of statements -ok github.com/pingcap/tidb/kv 39.466s coverage: 76.9% of statements -? github.com/pingcap/tidb/lock [no test files] -ok github.com/pingcap/tidb/meta 1.461s coverage: 74.0% of statements -ok github.com/pingcap/tidb/meta/autoid 2.729s coverage: 72.2% of statements -ok github.com/pingcap/tidb/metrics 0.551s coverage: 98.9% of statements -ok github.com/pingcap/tidb/owner 22.495s coverage: 69.6% of statements -? github.com/pingcap/tidb/planner [no test files] -ok github.com/pingcap/tidb/planner/cascades 1.687s coverage: 94.6% of statements -ok github.com/pingcap/tidb/planner/core 55.583s coverage: 79.1% of statements -ok github.com/pingcap/tidb/planner/implementation 0.579s coverage: 3.7% of statements -ok github.com/pingcap/tidb/planner/memo 1.266s coverage: 86.9% of statements -? github.com/pingcap/tidb/planner/property [no test files] -? github.com/pingcap/tidb/planner/util [no test files] -ok github.com/pingcap/tidb/plugin 1.645s coverage: 59.0% of statements -ok github.com/pingcap/tidb/plugin/conn_ip_example 0.573s coverage: 0.0% of statements -? github.com/pingcap/tidb/privilege [no test files] -ok github.com/pingcap/tidb/privilege/privileges 4.369s coverage: 81.9% of statements -ok github.com/pingcap/tidb/server 238.189s coverage: 69.1% of statements -ok github.com/pingcap/tidb/session 45.837s coverage: 78.9% of statements -ok github.com/pingcap/tidb/sessionctx 0.495s coverage: 100.0% of statements -ok github.com/pingcap/tidb/sessionctx/binloginfo 2.666s coverage: 74.8% of statements -ok github.com/pingcap/tidb/sessionctx/stmtctx 0.545s coverage: 31.1% of statements -ok github.com/pingcap/tidb/sessionctx/variable 0.512s coverage: 45.7% of statements -ok github.com/pingcap/tidb/statistics 5.608s coverage: 77.9% of statements -ok github.com/pingcap/tidb/statistics/handle 18.417s coverage: 83.6% of statements -ok github.com/pingcap/tidb/store 87.985s coverage: 95.5% of statements -ok github.com/pingcap/tidb/store/copr 0.473s coverage: 0.2% of statements [no tests to run] -ok github.com/pingcap/tidb/store/driver 0.728s coverage: 1.9% of statements [no tests to run] -? github.com/pingcap/tidb/store/driver/txn [no test files] -ok github.com/pingcap/tidb/store/gcworker 15.520s coverage: 76.2% of statements -ok github.com/pingcap/tidb/store/helper 0.713s coverage: 49.5% of statements -ok github.com/pingcap/tidb/store/mockstore 0.610s coverage: 39.1% of statements -ok github.com/pingcap/tidb/store/mockstore/mocktikv 0.940s coverage: 44.0% of statements -ok github.com/pingcap/tidb/store/mockstore/unistore 0.479s coverage: 14.7% of statements -? github.com/pingcap/tidb/store/mockstore/unistore/client [no test files] -ok github.com/pingcap/tidb/store/mockstore/unistore/cophandler 0.681s coverage: 12.8% of statements -ok github.com/pingcap/tidb/store/tikv 40.980s coverage: 67.6% of statements -ok github.com/pingcap/tidb/store/tikv/config 0.631s coverage: 44.4% of statements -ok github.com/pingcap/tidb/store/tikv/latch 0.747s coverage: 95.2% of statements -? github.com/pingcap/tidb/store/tikv/logutil [no test files] -? github.com/pingcap/tidb/store/tikv/metrics [no test files] -? github.com/pingcap/tidb/store/tikv/mockstore/cluster [no test files] -? github.com/pingcap/tidb/store/tikv/oracle [no test files] -ok github.com/pingcap/tidb/store/tikv/oracle/oracles 0.712s coverage: 30.5% of statements -? github.com/pingcap/tidb/store/tikv/storeutil [no test files] -ok github.com/pingcap/tidb/store/tikv/tests 10.920s coverage: [no statements] -ok github.com/pingcap/tidb/store/tikv/tikvrpc 0.396s coverage: 0.6% of statements -ok github.com/pingcap/tidb/store/tikv/util 0.663s coverage: 38.9% of statements -? github.com/pingcap/tidb/store/tikv/util/codec [no test files] -ok github.com/pingcap/tidb/structure 1.073s coverage: 81.2% of statements -ok github.com/pingcap/tidb/table 0.489s coverage: 70.3% of statements -ok github.com/pingcap/tidb/table/tables 2.788s coverage: 55.9% of statements -ok github.com/pingcap/tidb/tablecodec 0.414s coverage: 31.9% of statements -ok github.com/pingcap/tidb/telemetry 3.269s coverage: 56.8% of statements -ok github.com/pingcap/tidb/tidb-server 0.803s coverage: 20.8% of statements -ok github.com/pingcap/tidb/types 1.328s coverage: 82.5% of statements -ok github.com/pingcap/tidb/types/json 0.427s coverage: 80.6% of statements -ok github.com/pingcap/tidb/types/parser_driver 0.404s coverage: 28.7% of statements -ok github.com/pingcap/tidb/util 0.733s coverage: 54.3% of statements -ok github.com/pingcap/tidb/util/admin 2.555s coverage: 55.6% of statements -ok github.com/pingcap/tidb/util/arena 0.428s coverage: 100.0% of statements -ok github.com/pingcap/tidb/util/bitmap 0.737s coverage: 85.7% of statements -ok github.com/pingcap/tidb/util/checksum 0.383s coverage: 85.1% of statements -ok github.com/pingcap/tidb/util/chunk 2.960s coverage: 82.0% of statements -ok github.com/pingcap/tidb/util/codec 0.446s coverage: 82.9% of statements -ok github.com/pingcap/tidb/util/collate 1.563s coverage: 72.7% of statements -ok github.com/pingcap/tidb/util/dbterror 0.558s coverage: 100.0% of statements -ok github.com/pingcap/tidb/util/deadlock 0.566s coverage: 100.0% of statements -ok github.com/pingcap/tidb/util/disjointset 0.564s coverage: 100.0% of statements -ok github.com/pingcap/tidb/util/disk 0.373s coverage: 50.0% of statements -? github.com/pingcap/tidb/util/domainutil [no test files] -ok github.com/pingcap/tidb/util/encrypt 0.513s coverage: 92.6% of statements -ok github.com/pingcap/tidb/util/execdetails 0.683s coverage: 63.2% of statements -ok github.com/pingcap/tidb/util/expensivequery 0.737s coverage: 13.4% of statements -ok github.com/pingcap/tidb/util/fastrand 0.335s coverage: 0.0% of statements [no tests to run] -ok github.com/pingcap/tidb/util/filesort 1.876s coverage: 86.3% of statements -ok github.com/pingcap/tidb/util/format 1.097s coverage: 83.6% of statements -? github.com/pingcap/tidb/util/gcutil [no test files] -ok github.com/pingcap/tidb/util/generatedexpr 1.258s coverage: 0.0% of statements [no tests to run] -ok github.com/pingcap/tidb/util/hack 1.343s coverage: 92.3% of statements -? github.com/pingcap/tidb/util/hint [no test files] -? github.com/pingcap/tidb/util/israce [no test files] -ok github.com/pingcap/tidb/util/kvcache 2.352s coverage: 57.0% of statements -ok github.com/pingcap/tidb/util/localpool 2.676s coverage: 96.8% of statements -ok github.com/pingcap/tidb/util/logutil 2.077s coverage: 77.8% of statements -ok github.com/pingcap/tidb/util/math 2.691s coverage: 33.3% of statements -ok github.com/pingcap/tidb/util/memory 1.888s coverage: 64.6% of statements -ok github.com/pingcap/tidb/util/mock 0.987s coverage: 15.8% of statements -ok github.com/pingcap/tidb/util/mvmap 1.309s coverage: 86.6% of statements -ok github.com/pingcap/tidb/util/parser 0.503s coverage: 60.0% of statements -? github.com/pingcap/tidb/util/pdapi [no test files] -ok github.com/pingcap/tidb/util/plancodec 0.891s coverage: 3.9% of statements -ok github.com/pingcap/tidb/util/printer 0.439s coverage: 88.3% of statements -ok github.com/pingcap/tidb/util/profile 2.166s coverage: 55.4% of statements -ok github.com/pingcap/tidb/util/ranger 6.506s coverage: 82.1% of statements -ok github.com/pingcap/tidb/util/rowDecoder 1.050s coverage: 77.6% of statements -ok github.com/pingcap/tidb/util/rowcodec 0.532s coverage: 87.6% of statements -ok github.com/pingcap/tidb/util/selection 1.440s coverage: 86.8% of statements -ok github.com/pingcap/tidb/util/set 0.738s coverage: 48.6% of statements -? github.com/pingcap/tidb/util/signal [no test files] -ok github.com/pingcap/tidb/util/sqlexec 1.199s coverage: 96.3% of statements -ok github.com/pingcap/tidb/util/stmtsummary 1.635s coverage: 91.1% of statements -ok github.com/pingcap/tidb/util/stringutil 1.194s coverage: 87.9% of statements -ok github.com/pingcap/tidb/util/sys/linux 2.147s coverage: 66.7% of statements -ok github.com/pingcap/tidb/util/sys/storage 2.108s coverage: 83.3% of statements -ok github.com/pingcap/tidb/util/systimemon 2.625s coverage: 100.0% of statements -ok github.com/pingcap/tidb/util/testkit 0.872s coverage: 6.2% of statements -? github.com/pingcap/tidb/util/testleak [no test files] -ok github.com/pingcap/tidb/util/testutil 0.694s coverage: 18.7% of statements -ok github.com/pingcap/tidb/util/texttree 0.411s coverage: 100.0% of statements -ok github.com/pingcap/tidb/util/timeutil 0.435s coverage: 48.7% of statements -ok github.com/pingcap/tidb/util/tracing 0.842s coverage: 93.3% of statements -? github.com/pingcap/tidb/util/versioninfo [no test files] -go generate ./... -./tools/check/check-gogenerate.sh From 0deb55fb53f119e49a3ba0a293ca2b8ad19ac26d Mon Sep 17 00:00:00 2001 From: wjhuang2016 Date: Fri, 26 Mar 2021 19:33:27 +0800 Subject: [PATCH 3/5] add comment Signed-off-by: wjhuang2016 --- util/ranger/points.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/util/ranger/points.go b/util/ranger/points.go index b376437424a79..e2a875f01dd10 100644 --- a/util/ranger/points.go +++ b/util/ranger/points.go @@ -236,12 +236,16 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []*point { value.SetString(value.GetString(), col.RetType.Collate) } if col.GetType().Tp == mysql.TypeYear { + // If the original value is adjusted, we need to change the condition. + // For example, col < 2156. Since the max year is 2155, 2156 is changed to 2155. + // col < 2155 is wrong. It should be col <= 2155. preValue, err1 := value.ToInt64(r.sc) if err1 != nil { return err1 } *value, err = value.ConvertToMysqlYear(r.sc, col.RetType) if errors.ErrorEqual(err, types.ErrInvalidYear) { + // Keep err for EQ and NE. switch *op { case ast.GT: if value.GetInt64() > preValue { @@ -298,8 +302,10 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []*point { err = refineValueAndOp(col, &value, &op) if err != nil { if op == ast.NE { + // col != an impossible value (not valid year) return getNotNullFullRange() } + // col = an impossible value (not valid year) return nil } @@ -501,6 +507,7 @@ func (r *builder) buildFromIn(expr *expression.ScalarFunction) ([]*point, bool) if expr.GetArgs()[0].GetType().Tp == mysql.TypeYear { dt, err = dt.ConvertToMysqlYear(r.sc, expr.GetArgs()[0].GetType()) if err != nil { + // in (..., an impossible value (not valid year), ...), the range is empty, so skip it. continue } } From 89848372c69143f5cda440b91d3766757cf15625 Mon Sep 17 00:00:00 2001 From: wjHuang Date: Fri, 9 Apr 2021 18:56:33 +0800 Subject: [PATCH 4/5] Update points.go --- util/ranger/points.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/ranger/points.go b/util/ranger/points.go index 8e61a7c4fec8d..e12233062b8a2 100644 --- a/util/ranger/points.go +++ b/util/ranger/points.go @@ -232,7 +232,7 @@ func (r *builder) buildFormBinOp(expr *expression.ScalarFunction) []*point { // 1. for string type since we may eval the constant to another collation instead of its own collation. // 2. for year type since 2-digit year value need adjustment, see https://dev.mysql.com/doc/refman/5.6/en/year.html refineValueAndOp := func(col *expression.Column, value *types.Datum, op *string) (err error) { - if col.RetType.EvalType() == types.ETString && value.Kind() == types.KindString || value.Kind() == types.KindBinaryLiteral { + if col.RetType.EvalType() == types.ETString && (value.Kind() == types.KindString || value.Kind() == types.KindBinaryLiteral) { value.SetString(value.GetString(), col.RetType.Collate) } if col.GetType().Tp == mysql.TypeYear { From fca84b22efda7b70f6c044e4ab9572f15796a2c8 Mon Sep 17 00:00:00 2001 From: wjhuang2016 Date: Mon, 12 Apr 2021 18:45:59 +0800 Subject: [PATCH 5/5] fix Signed-off-by: wjhuang2016 --- types/time.go | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/types/time.go b/types/time.go index d2c2585e0486f..cae6123dd1f24 100644 --- a/types/time.go +++ b/types/time.go @@ -1260,18 +1260,6 @@ func AdjustYear(y int64, adjustZero bool) (int64, error) { return y, nil } -func adjustYearForFloat(y float64, shouldAdjust bool) float64 { - if y == 0 && !shouldAdjust { - return y - } - if y >= 0 && y <= 69 { - y = 2000 + y - } else if y >= 70 && y <= 99 { - y = 1900 + y - } - return y -} - // NewDuration construct duration with time. func NewDuration(hour, minute, second, microsecond int, fsp int8) Duration { return Duration{