Inconsistent Query Results Between Views and Tables with JSON and Boolean Expressions
- 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)
In TiDB, creating a view (t1) versus a materialized table (t1) from the same query produces inconsistent results when querying with conditions on JSON and boolean expressions.
Set up t0:
```sql
CREATE TABLE t0 (c0 DOUBLE, c1 JSON, c2 BIGINT);
INSERT INTO t0 (c0, c1, c2) VALUES
(-2.7905990902640713e+28, 'false', 2291093143052174936),
(8.875213116802489e+29, '[91, 98]', 2509511450440923249),
(-1.928444166558026e+29, 'true', -900357988710783461),
(7.453468333542395e+29, 'false', -1578572187664851125),
(-2.2154533233852085e+29, 'false', 6716764775321339260),
(-9.472193236642309e+29, '-18', -5442657192873713371),
(7.800560032677301e+29, '-82', -5228699381649601514),
(-6.04168005717068e+29, '"2"', 352821973451449461),
(-2.9579165138559852e+29, '-16', 8700558434200918342),
(-5.186036822365423e+29, 'true', -1360299298488740933),
(-7.334967531655038e+28, '["m", "3"]', -3970793373844690590),
(6.2636188231346425e+29, '48', 5056392401490136325),
(-1.1243010922299917e+29, '-65', 5875583777976927793);
```
Create t1 as view:
```sql
CREATE VIEW t1 AS (SELECT (c0 IS NULL) AS c0, c1, c2 FROM t0);
SELECT c1, c2 FROM t1 WHERE (c1 <= (c0)) = TRUE ORDER BY c1 ASC, c2 ASC;
my:root@127.0.0.1:4000=> SELECT c1, c2 FROM t1 WHERE (c1 <= (c0)) = TRUE ORDER BY c1 ASC, c2 ASC;
c1 | c2
------------+----------------------
-82 | -5228699381649601514
-65 | 5875583777976927793
-18 | -5442657192873713371
-16 | 8700558434200918342
48 | 5056392401490136325
"2" | 352821973451449461
[91, 98] | 2509511450440923249
["m", "3"] | -3970793373844690590
false | -1578572187664851125
false | 2291093143052174936
false | 6716764775321339260
(11 rows)
```
Create t1 as table:
```sql
CREATE TABLE t1 (c0 bigint , c1 JSON, c2 BIGINT);
INSERT INTO t1 SELECT (c0 IS NULL) , c1, c2 FROM t0;
SELECT c1, c2 FROM t1 WHERE (c1 <= (c0)) = TRUE ORDER BY c1 ASC, c2 ASC;
my:root@127.0.0.1:4000=> SELECT c1, c2 FROM t1 WHERE (c1 <= (c0)) = TRUE ORDER BY c1 ASC, c2 ASC;
c1 | c2
-----+----------------------
-82 | -5228699381649601514
-65 | 5875583777976927793
-18 | -5442657192873713371
-16 | 8700558434200918342
(4 rows)
```
### 2. What did you expect to see? (Required)
Both queries on the view and the materialized table should return the same number of rows, given that they are based on the same data and conditions.
### 3. What did you see instead (Required)
The query on the view (t1) returns 11 rows.
The query on the materialized table (t1) returns only 4 rows.
### 4. What is your TiDB version? (Required)
```
my:root@127.0.0.1:4000=> SELECT tidb_version();
tidb_version()
-----------------------------------------------------------
Release Version: v8.3.0 +
Edition: Community +
Git Commit Hash: 1a0c3ac3292fff7742faa0c00a662ccb66ba40db+
Git Branch: HEAD +
UTC Build Time: 2024-08-20 10:23:00 +
GoVersion: go1.21.10 +
Race Enabled: false +
Check Table Before Drop: false +
Store: tikv
(1 row)
```
Contributor guide
Assessment
This issue has not been assessed yet.