Skip to content

tikv/unistore can't handle sql mode and get wrong sql result #59566

@wshwsh12

Description

@wshwsh12

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

tidb> drop table t;
Query OK, 0 rows affected (0.23 sec)

tidb> create table t(a varchar(100), b varchar(100));
Query OK, 0 rows affected (0.10 sec)

tidb>  insert into t values("2000-00-00", "%Y-%m-%d");
Query OK, 1 row affected (0.02 sec)

tidb>  select str_to_date(a,b) from t  where str_to_date(a,b) is not null;
+----------------------------+
| str_to_date(a,b)           |
+----------------------------+
| NULL                       |
+----------------------------+
1 rows in set, 1 warning (0.01 sec)

2. What did you expect to see? (Required)

3. What did you see instead (Required)

4. What is your TiDB version? (Required)

master

Analyse:

Add a log in the function str_to_date. Run tidb + unistore

diff --git a/pkg/expression/builtin_time_vec.go b/pkg/expression/builtin_time_vec.go
index e563d0221b..7775871e5e 100644
--- a/pkg/expression/builtin_time_vec.go
+++ b/pkg/expression/builtin_time_vec.go
@@ -26,7 +26,9 @@ import (
        "github.com/pingcap/tidb/pkg/types"
        "github.com/pingcap/tidb/pkg/util"
        "github.com/pingcap/tidb/pkg/util/chunk"
+       "github.com/pingcap/tidb/pkg/util/logutil"
        "github.com/tikv/client-go/v2/oracle"
+       "go.uber.org/zap"
 )
 
 func (b *builtinMonthSig) vecEvalInt(ctx EvalContext, input *chunk.Chunk, result *chunk.Column) error {
@@ -1493,6 +1495,7 @@ func (b *builtinStrToDateDatetimeSig) vecEvalTime(ctx EvalContext, input *chunk.
        times := result.Times()
        tc := typeCtx(ctx)
        hasNoZeroDateMode := sqlMode(ctx).HasNoZeroDateMode()
+       logutil.BgLogger().Error("builtinStrToDateDatetimeSig", zap.Any("hasNoZeroDateMode", hasNoZeroDateMode), zap.Stack(""))
        fsp := b.tp.GetDecimal()
 
        for i := 0; i < n; i++ {

And run the sql, we can see unistore can't handle the sqlmode.

Image

Metadata

Metadata

Assignees

No one assigned

    Labels

    affects-5.4This bug affects the 5.4.x(LTS) versions.affects-6.1This bug affects the 6.1.x(LTS) versions.affects-6.5This bug affects the 6.5.x(LTS) versions.affects-7.1This bug affects the 7.1.x(LTS) versions.affects-7.5This bug affects the 7.5.x(LTS) versions.affects-8.1This bug affects the 8.1.x(LTS) versions.affects-8.5This bug affects the 8.5.x(LTS) versions.severity/majorsig/executionSIG executiontype/bugThe issue is confirmed as a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions