TiDB: Different WHERE Conditions in the Same SQL Statement Yield the Same Results

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: tidb 同一条sql语句,where条件不一样,查出的结果一样

| username: leoones

[Overview] Scenario + Problem Overview
The same SQL statement with different WHERE conditions yields the same result.
The SQL is as follows:

SELECT /*+ SQL_NO_CACHE */
    id,
    seller_id,
    is_finished,
    gmt_create,
    gmt_modified 
FROM
    temp_order_trace 
WHERE
    is_finished = 0 
    AND seller_id = 'AZPSNNS54BFCZ';

SELECT /*+ SQL_NO_CACHE */
    id,
    seller_id,
    is_finished,
    gmt_create,
    gmt_modified 
FROM
    temp_order_trace 
WHERE
    is_finished = 2 
    AND seller_id = 'AZPSNNS54BFCZ';

[Problem] Current Issue Encountered
The results are as follows:


[Business Impact]
Affects business, data query inconsistency.
[TiDB Version]
V5.4.0

| username: Hacker007 | Original post link

Is the data type int?

| username: forever | Original post link

Please share the table structure.

| username: wakaka | Original post link

Post the actual execution plan using EXPLAIN ANALYZE + SQL.

| username: wakaka | Original post link

You didn’t select two statements to execute simultaneously, did you? In that case, the result would be the last statement.

| username: Billmay表妹 | Original post link

Refer to these two topics.

| username: leoones | Original post link

It’s int

| username: leoones | Original post link

The image is not visible. Please provide the text you need translated.

| username: wuxiangdong | Original post link

Start a transaction, then execute these two SQL statements.

| username: leoones | Original post link

There’s no difference.

| username: leoones | Original post link

I’m using version 5.4, is this a bug?

| username: h5n1 | Original post link

Execute these two SQL statements one by one and observe the results.

| username: xiaohetao | Original post link

How about enclosing the value of is_finished in single quotes after where?

| username: Kongdom | Original post link

Have you done data restoration before? I encountered a situation where, after performing a BR restoration on a non-empty cluster, the query results did not match the WHERE conditions.

| username: leoones | Original post link

Tried it, not feasible.

| username: leoones | Original post link

Last year, when we migrated from AWS, we used BR. It shouldn’t be a problem with BR, right?

| username: xiaohetao | Original post link

What type is the is_finished field?

| username: leoones | Original post link

int(1)

| username: xiaohetao | Original post link

Have you tried select ... from ... where is_finished='';? What does the result look like?

| username: Tank001 | Original post link

is_finished looks like a boolean type, so using tinyint(1) would be more reasonable. Your int(1) is no different from int(10). As for why it’s different later, let’s listen to the experts.