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

unexpect invalid json text error when query with json_extract #11883

Closed
Deardrops opened this issue Aug 27, 2019 · 4 comments · Fixed by #21903
Closed

unexpect invalid json text error when query with json_extract #11883

Deardrops opened this issue Aug 27, 2019 · 4 comments · Fixed by #21903
Assignees
Labels
challenge-program component/expression help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. priority/P3 The issue has P3 priority. Assigned to backlog. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.

Comments

@Deardrops
Copy link
Contributor

Deardrops commented Aug 27, 2019

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

  1. What did you do?
    If possible, provide a recipe for reproducing the error.
create table t1(f1 json);
insert into t1(f1) values ('"asd"'),('"asdf"'),('"asasas"');
select f1 from t1 where json_extract(f1,"$") in ("asd","asasas","asdf");
  1. What did you expect to see?

image

  1. What did you see instead?

image

  1. What version of TiDB are you using (tidb-server -V or run select tidb_version(); on TiDB)?

image

SIG slack channel

#sig-exec

Score

  • 300

Mentor

@Deardrops Deardrops added the type/bug The issue is confirmed as a bug. label Aug 27, 2019
@Deardrops Deardrops changed the title unexpect error when query with json_extract unexpect invalid json text error when query with json_extract Aug 27, 2019
@wjhuang2016
Copy link
Member

https://dev.mysql.com/doc/refman/8.0/en/json.html#json-comparison
The problem is that TiDB supports json comparison in in claue while MySQL doesn't.

@wjhuang2016
Copy link
Member

MySQL support json comparison in in clause now, in 8.0.18

@ghost
Copy link

ghost commented Jul 21, 2020

I have to say, the MySQL handling of just throwing a warning here is very unsafe. It should be an error (as it is in TiDB). Having said that, this works as expected in MySQL 8.0. Here is a testcase showing the behavior of MySQL 5.7/8.0 and TiDB:

DROP TABLE IF EXISTS t1;
create table t1(f1 json);
insert into t1(f1) values ('"asd"'),('"asdf"'),('"asasas"');
select f1 from t1 where json_extract(f1,"$") in ("asd","asasas","asdf");

..

mysql [localhost:5731] {root} (test) > select f1 from t1 where json_extract(f1,"$") in ("asd","asasas","asdf");
Empty set, 1 warning (0.00 sec)

mysql [localhost:5731] {root} (test) > show warnings;
+---------+------+-----------------------------------------------------------------------------------+
| Level   | Code | Message                                                                           |
+---------+------+-----------------------------------------------------------------------------------+
| Warning | 1235 | This version of MySQL doesn't yet support 'comparison of JSON in the IN operator' |
+---------+------+-----------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql [localhost:8021] {msandbox} (test) > select f1 from t1 where json_extract(f1,"$") in ("asd","asasas","asdf");
+----------+
| f1       |
+----------+
| "asd"    |
| "asdf"   |
| "asasas" |
+----------+
3 rows in set (0.00 sec)

mysql> select f1 from t1 where json_extract(f1,"$") in ("asd","asasas","asdf");
ERROR 1105 (HY000): invalid data type: Illegal Json text: Error("expected value", line: 1, column: 1)
mysql> select tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta.2-807-g824df7675
Edition: Community
Git Commit Hash: 824df767559b8544af0cb71509135d322de1cd47
Git Branch: master
UTC Build Time: 2020-07-20 04:47:45
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

@qw4990 qw4990 added component/expression severity/critical help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. priority/P3 The issue has P3 priority. Assigned to backlog. labels Aug 26, 2020
@scsldb scsldb added this to the v4.0.12 milestone Oct 29, 2020
@jebter jebter assigned SunRunAway and unassigned SunRunAway Nov 4, 2020
@scsldb scsldb modified the milestones: v4.0.12, v4.0.9 Nov 4, 2020
@zz-jason zz-jason removed this from the v4.0.9 milestone Nov 30, 2020
@ti-srebot
Copy link
Contributor

Please edit this comment or add a new comment to complete the following information

Not a bug

  1. Remove the 'type/bug' label
  2. Add notes to indicate why it is not a bug

Duplicate bug

  1. Add the 'type/duplicate' label
  2. Add the link to the original bug

Bug

Note: Make Sure that 'component', and 'severity' labels are added
Example for how to fill out the template: #20100

1. Root Cause Analysis (RCA) (optional)

2. Symptom (optional)

3. All Trigger Conditions (optional)

4. Workaround (optional)

5. Affected versions

6. Fixed versions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
challenge-program component/expression help wanted Denotes an issue that needs help from a contributor. Must meet "help wanted" guidelines. priority/P3 The issue has P3 priority. Assigned to backlog. severity/major sig/execution SIG execution type/bug The issue is confirmed as a bug.
Projects
None yet
9 participants