pingcap / pingcap/tidb

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

Open
#59,566 1 comment 0 reactions 0 assignees View on GitHub
affects-5.4 affects-6.1 affects-6.5 affects-7.1 affects-7.5 affects-8.1 affects-8.5 severity/major sig/execution type/bug
Dominant language
Go
Stars
40.5k
Forks
6.2k
PR merge metrics
PR metrics pending

Description

## 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.