Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: tidb 同一条sql语句,where条件不一样,查出的结果一样
[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
Please share the table structure.
Post the actual execution plan using EXPLAIN ANALYZE + SQL
.
You didn’t select two statements to execute simultaneously, did you? In that case, the result would be the last statement.
Refer to these two topics.
The image is not visible. Please provide the text you need translated.
Start a transaction, then execute these two SQL statements.
I’m using version 5.4, is this a bug?
Execute these two SQL statements one by one and observe the results.
How about enclosing the value of is_finished in single quotes after where?
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.
Last year, when we migrated from AWS, we used BR. It shouldn’t be a problem with BR, right?
What type is the is_finished
field?
Have you tried select ... from ... where is_finished='';
? What does the result look like?
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.