-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Generated columns index replacement rule not support JSON functions like MySQL #35490
Comments
Hi, @sunnyfun888
|
Hi @wjhuang2016, |
The problem is that the expression type and the generated column type need to be strictly equal. |
I think all other virtual columns use expressions will meet the same problem, infact in MySQL if the string is longer than 64 when insert or update, will get Data too long for column error, and the truncation is rollbacked. The behavior of MySQL is more like syntactic sugar. |
@sunnyfun888 For the strict sql-mode, it would report an error. But if in the empty sql-mode, it can insert successfully. |
It's not true if the sql_mode is "".
If users can accept the possible wrong result, it's ok the do this optimization. But when designed this feature, we tend to choose the correctness. |
I agree and can use a switch then leave the choice to users. |
it is a mysql bug, consider the following case CREATE TABLE person (id INT PRIMARY KEY,address_info JSON,city VARCHAR(2) AS (JSON_UNQUOTE(address_info->"$.city")),KEY (city));
set @@sql_mode='';
INSERT INTO `person` (`id`, `address_info`) VALUES('1','{\"city\": \"Beijing\"}'); -- success with warning
set @@sql_mode=default;
SELECT id FROM person ignore index(`city`) WHERE address_info->>"$.city" = 'Beijing'; -- 1 record
SELECT id FROM person force index(`city`) WHERE address_info->>"$.city" = 'Beijing'; -- 0 record use or not use an index will get a different result, it is absolutely a bug |
close due to MySQL has confirmed it is a bug https://bugs.mysql.com/bug.php?id=108114 |
Bug Report
Please answer these questions before submitting your issue. Thanks!
In MySQL, use this way, optimizer will look for compatible virtual columns with indexes that match the expression in JSON queries:
But same SQL in TiDB, the query will be TableFullScan:
It seems the Generated columns index replacement rule not work in this case.
2. What did you expect to see? (Required)
Generated columns index replacement rule supports JSON functions, like MySQL.
3. What did you see instead (Required)
Current version of TiDB not support.
4. What is your TiDB version? (Required)
6.1.0
The text was updated successfully, but these errors were encountered: