Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected result when using JSON_VALID #56293

Closed
suyZhong opened this issue Sep 25, 2024 · 4 comments · Fixed by #57496
Closed

Unexpected result when using JSON_VALID #56293

suyZhong opened this issue Sep 25, 2024 · 4 comments · Fixed by #57496
Assignees
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. fuzz/sqlancer impact/wrong-result severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.

Comments

@suyZhong
Copy link

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

DROP DATABASE IF EXISTS db0;
CREATE DATABASE db0;
USE db0;

CREATE  TABLE  t0(c0 VARCHAR(500) , c1 INT );
CREATE VIEW v0(c0) AS SELECT 'a' FROM t0;
INSERT INTO t0(c0) VALUES ('b');

SELECT * FROM t0 NATURAL RIGHT JOIN v0; -- a NULL
SELECT (JSON_VALID(t0.c1)=0) FROM t0 NATURAL RIGHT JOIN v0; -- 1
SELECT * FROM t0 NATURAL RIGHT JOIN v0 WHERE (JSON_VALID(t0.c1)=0);
-- Expected: a NULL
-- Actual: empty

This could be reproduced on MySQL also, but still, I suspect it is unexpected.

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

The second query returns a NULL value or the third query returns the row in the table after join.

3. What did you see instead (Required)

empty set

4. What is your TiDB version? (Required)

select tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                                                       |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.4.0-alpha-244-ga5e07a2
Edition: Community
Git Commit Hash: a5e07a2ed360f29216c912775ce482f536f4102b
Git Branch: HEAD
UTC Build Time: 2024-09-25 05:10:21
GoVersion: go1.21.13
Race Enabled: false
Check Table Before Drop: false
Store: unistore |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
@suyZhong suyZhong added the type/bug The issue is confirmed as a bug. label Sep 25, 2024
@suyZhong
Copy link
Author

/label fuzz/sqlancer

@YangKeao
Copy link
Member

YangKeao commented Sep 27, 2024

There is another case that the result is not compatible with MySQL:

SELECT * FROM t0 WHERE (JSON_VALID(t0.c1)=0);

TiDB (with TiKV) gives nothing, but TiDB (unistore) and MySQL gives one row. Maybe the implementation has some bugs in TiKV side.

@ti-chi-bot ti-chi-bot bot added the affects-8.5 This bug affects the 8.5.x(LTS) versions. label Nov 1, 2024
@YangKeao
Copy link
Member

YangKeao commented Nov 19, 2024

SELECT * FROM t0 WHERE (JSON_VALID(t0.c1)=0);

For this case, I submitted a bug report for MySQL. The behavior is inconsistent for MySQL and its document: https://bugs.mysql.com/bug.php?id=116703, and it has been confirmed as a bug.

For TiDB, I suggest to temporarily modify the behavior of unistore to keep consistent with TiKV and document (which is different with the MySQL).

@YangKeao
Copy link
Member

YangKeao commented Nov 19, 2024

SELECT * FROM t0 WHERE (JSON_VALID(t0.c1)=0);

For this case, I submitted a bug report for MySQL. The behavior is inconsistent for MySQL and its document: https://bugs.mysql.com/bug.php?id=116703.

For TiDB, I suggest to temporarily modify the behavior of unistore to keep consistent with TiKV and document (which is different with the MySQL).

And it caused the unexpected behavior in TiDB. The Projection on TiDB side and the Selection in TiKV side has different implementation.

BTW, I don't know why this strange behavior exists in MySQL. Maybe you can also submit a bug for MySQL.

@YangKeao YangKeao added severity/moderate affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. and removed severity/major may-affects-6.5 may-affects-7.1 may-affects-7.5 may-affects-8.1 may-affects-5.4 This bug maybe affects 5.4.x versions. may-affects-6.1 labels Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
affects-6.5 This bug affects the 6.5.x(LTS) versions. affects-7.1 This bug affects the 7.1.x(LTS) versions. affects-7.5 This bug affects the 7.5.x(LTS) versions. affects-8.1 This bug affects the 8.1.x(LTS) versions. affects-8.5 This bug affects the 8.5.x(LTS) versions. fuzz/sqlancer impact/wrong-result severity/moderate sig/sql-infra SIG: SQL Infra type/bug The issue is confirmed as a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants