-
Notifications
You must be signed in to change notification settings - Fork 8k
Fix GH-20122: getColumnMeta() for JSON-column in MySQL #20143
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
Conversation
While at it, also add VECTOR.
$stmt = $db->query('SELECT * from test'); | ||
$meta = $stmt->getColumnMeta(0); | ||
|
||
// Note: JSON is an alias for LONGTEXT on MariaDB! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is true, the behaviour is not 100% the same, for example encoding JSON field as JSON does not add quotes when the value is not a string.
repro: https://dbfiddle.uk/YilhsCEk
JSON type must be preserved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not possible because mariadb protocol does not make the distinction in its metadata
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@vuvova do you have an idea if the distinction of a JSON field is somehow possible?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can even try this in a MariaDB CLI session to see it's even stored like LONGTEXT:
MariaDB [(none)]> create database testdb;
Query OK, 1 row affected (0.000 sec)
MariaDB [(none)]> use testdb;
Database changed
MariaDB [testdb]> create table test(a JSON);
Query OK, 0 rows affected (0.032 sec)
MariaDB [testdb]> describe test;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| a | longtext | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
1 row in set (0.002 sec)
MariaDB [testdb]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MariaDB internally checks the JSON type like in https://github.com/MariaDB/server/blob/mariadb-12.1.1/sql/item_jsonfunc.cc#L1848.
Then I found https://github.com/MariaDB/server/blob/mariadb-12.1.1/sql/sql_type_json.h#L86 - is this really sent in the protocol?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay got it, thanks for the info
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation of the string change should still only be done on master. So I'll make a reminder issue to implement sending the flag + incorporating the string MariaDB sends us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is going to be changed for MySQL, I do not see any reason to not change it for MariaDB. It is more or less transport protocol detail.
I consider this as a bug as JSON type is present almost in every DB since about y2020 and the type info is important to handle the data correctly, as reproduced above.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The JSON type was absent on both MariaDB & MySQL.
Other types may change if we send the flag and use the string the server sends back. This part is the BC break.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In PHP it shouldn't replace the old information, it should be presented as additional information too. If it is to replace the native type then it should be behind a user facing option and disabled by default.
As far as I know, there is no JSON datatype in MySQL protocol. Has something changed recently? |
The JSON type was introduced in Mysql 5.7.8: https://dev.mysql.com/doc/refman/5.7/en/json.html but it's mainly treated as a string. |
I cannot set up PDO_MYSQL testing environment for some reason, but I looked into this topic more and it seems I was confused before. The JSON type seems to be present in the protocol and so it can be reported as you showed. I think I confused it with ENUM. This line can also be added in
|
While at it, also add VECTOR.