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

Multi-valued index should implicitly cast the json type #53243

Open
YangKeao opened this issue May 14, 2024 · 2 comments · May be fixed by #53363
Open

Multi-valued index should implicitly cast the json type #53243

YangKeao opened this issue May 14, 2024 · 2 comments · May be fixed by #53363
Assignees
Labels

Comments

@YangKeao
Copy link
Member

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

CREATE TABLE t ( id INT PRIMARY KEY, j JSON, INDEX idx_a ((CAST(j->'$.a' AS DATE ARRAY))) );
INSERT INTO t VALUES (1, JSON_OBJECT('a', JSON_ARRAY('2024-05-13', '2020-01-01')));

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

mysql> CREATE TABLE t ( id INT PRIMARY KEY, j JSON, INDEX idx_a ((CAST(j->'$.a' AS DATE ARRAY))) );
Query OK, 0 rows affected (0.02 sec)

mysql> INSERT INTO t VALUES (1, JSON_OBJECT('a', JSON_ARRAY('2024-05-13', '2020-01-01')));
Query OK, 1 row affected (0.01 sec)

3. What did you see instead (Required)

mysql> CREATE TABLE t ( id INT PRIMARY KEY, j JSON, INDEX idx_a ((CAST(j->'$.a' AS DATE ARRAY))) );
Query OK, 0 rows affected (0.11 sec)

mysql> INSERT INTO t VALUES (1, JSON_OBJECT('a', JSON_ARRAY('2024-05-13', '2020-01-01')));
ERROR 3903 (HY000): Invalid JSON value for CAST for expression index 'idx_a'

A workaround is manually casting the type to date:

mysql> INSERT INTO t VALUES (1, JSON_OBJECT('a', JSON_ARRAY(cast('2024-05-13' as date))));
Query OK, 1 row affected (0.01 sec)

4. What is your TiDB version? (Required)

mysql> select tidb_version();
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| tidb_version()                                                                                                                                                                                                                               |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Release Version: v8.0.0
Edition: Community
Git Commit Hash: 8ba1fa452b1ccdbfb85879ea94b9254aabba2916
Git Branch: HEAD
UTC Build Time: 2024-03-28 14:22:15
GoVersion: go1.21.4
Race Enabled: false
Check Table Before Drop: false
Store: tikv |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)
@xiongjiwei
Copy link
Contributor

I am afraid it should not. ref https://bugs.mysql.com/bug.php?id=109333, doc

@YangKeao
Copy link
Member Author

I am afraid it should not. ref https://bugs.mysql.com/bug.php?id=109333, doc

Thanks for the information. I remembered that I also submitted a similar bug report in the comment #50370 (comment), bug report.

I thought that the implicitly casting doesn't mean we'll introduce this bug (as long as the planner works well). But now, I agree to hold this PR for a while and see whether MySQL will change its behavior or not 🤔. As this issue has a workaround, it'll not be a big problem for the users.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants