pingcap / tidb

TiDB is an open-source, cloud-native, distributed, MySQL-Compatible database for elastic scale and real-time analytics. Try AI-powered Chat2Query free at : https://www.pingcap.com/tidb-serverless/
https://pingcap.com
Apache License 2.0
36.9k stars 5.81k forks source link

*: incorrect result when invalid `DATE` conversion in `WHERE` condition #48501

Open bb7133 opened 10 months ago

bb7133 commented 10 months ago

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

Reported by the internal expression pushdown test: example.

A simple reproduce step:

create table t(a int, b year);
insert into t values (1, 2021)

/* with pushdown */
delete from mysql.expr_pushdown_blacklist;
admin reload expr_pushdown_blacklist;
explain select * from t where date(b);
select * from t where date(b);

/* without pushdown */
insert into mysql.expr_pushdown_blacklist(name, store_type) values ('date', 'tikv');
admin reload expr_pushdown_blacklist;
explain select * from t where date(b);
select * from t where date(b);

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

Empty result, the same with MySQL:

tidb> select * from t where date(b);
Empty set, 1 warning (0.00 sec)

3. What did you see instead (Required)

/* with pushdown */
tidb> select * from t where date(b);
Empty set, 1 warning (0.00 sec)

/* without pushdown */
tidb> select * from t where date(b);
+------+------+
| a    | b    |
+------+------+
|    1 | 2021 |
+------+------+
1 row in set (0.01 sec)

4. What is your TiDB version? (Required)

Reproduced with v7.1.4, v7.4.0 and latest master: 4ae5622ef3c1b606fec9e12e4c269f4589e7a1f9

I didn't try more versions(<v7.1)

zanmato1984 commented 10 months ago

/label severity/major

ti-chi-bot[bot] commented 10 months ago

@zanmato1984: The label(s) severity/major cannot be applied. These labels are supported: fuzz/sqlancer, challenge-program, compatibility-breaker, first-time-contributor, contribution, good first issue, correctness, duplicate, proposal, security, ok-to-test, needs-ok-to-test, needs-more-info, needs-cherry-pick-release-5.3, needs-cherry-pick-release-5.4, needs-cherry-pick-release-6.1, needs-cherry-pick-release-6.5, needs-cherry-pick-release-7.1, needs-cherry-pick-release-7.5, affects-5.3, affects-5.4, affects-6.1, affects-6.5, affects-7.1, affects-7.5, may-affects-5.3, may-affects-5.4, may-affects-6.1, may-affects-6.5, may-affects-7.1, may-affects-7.5.

In response to [this](https://github.com/pingcap/tidb/issues/48501#issuecomment-1805021946): >/label severity/major Instructions for interacting with me using PR comments are available [here](https://prow.tidb.net/command-help). If you have questions or suggestions related to my behavior, please file an issue against the [ti-community-infra/tichi](https://github.com/ti-community-infra/tichi/issues/new?title=Prow%20issue:) repository.
zanmato1984 commented 10 months ago

/severity major

zanmato1984 commented 4 months ago

TiDB:

select date(b) from t;
+------------+
| date(b)    |
+------------+
| 2021-00-00 |
+------------+
1 row in set (0.01 sec)

MySQL 8.0:

select date(b) from t;
+------------+
| date(b)    |
+------------+
| 2021-00-00 |
+------------+
1 row in set (0.01 sec)

There may have been some change between MySQL 5.7 and 8.0. That may imply that the correctness between TiDB (non-push-down) and TiKV (push-down) are reversed.