pingcap / pingcap/tidb

div function pushed down to tikv does not respect sql mode

Open
#50,049 2 comments 0 reactions 0 assignees View on GitHub
affects-8.1 affects-8.5 may-affects-5.4 may-affects-6.1 may-affects-6.5 may-affects-7.1 may-affects-7.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 reproduction step (Required)

```
> create table t1(a int);
> create table t2 like t1;
> insert into t1 values(0);
> insert into t2 select a from t1 where 100/a > 0;
```

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

In mysql

```
mysql> insert into t2 select a from t1 where 100/a>0;
ERROR 1365 (22012): Division by 0
```

### 3. What did you see instead (Required)

```
mysql> insert into t2 select a from t1 where 100/a>0;
Query OK, 0 rows affected (0.00 sec)
Records: 0 Duplicates: 0 Warnings: 0
```

The div function is pushed to tikv layer, but not return an error

```
mysql> explain insert into t2 select a from t1 where 100/a>0;
+---------------------------+---------+-----------+---------------+--------------------------------------------------------+
| id | estRows | task | access object | operator info |
+---------------------------+---------+-----------+---------------+--------------------------------------------------------+
| Insert_1 | N/A | root | | N/A |
| └─TableReader_9 | 0.80 | root | | data:Selection_8 |
| └─Selection_8 | 0.80 | cop[tikv] | | gt(div(100, cast(test.t1.a, decimal(10,0) BINARY)), 0) |
| └─TableFullScan_7 | 1.00 | cop[tikv] | table:t1 | keep order:false, stats:pseudo |
+---------------------------+---------+-----------+---------------+--------------------------------------------------------+
```

### 4. What is your TiDB version? (Required)

master

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.