Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.
Original topic: tidb可以使用Json_table吗?
[TiDB Usage Environment] Production Environment
[TiDB Version] 6.5.1
[Reproduction Path] What operations were performed when the issue occurred
[Encountered Issue: Issue Phenomenon and Impact]
[Resource Configuration] Go to TiDB Dashboard - Cluster Info - Hosts and take a screenshot of this page
[Attachment: Screenshot/Log/Monitoring]
TiDB supports JSON functions. You can execute this on the client side, or refer to the link provided by the previous poster.
This function is probably not supported yet
If the data is not much, you can process it with an application and then use CTE to construct this table.
Tried to verify with v7.5.0, syntax is not yet compatible, and it will report an error.
mysql> select version();
+--------------------+
| version() |
+--------------------+
| 8.0.11-TiDB-v7.5.0 |
+--------------------+
1 row in set (0.00 sec)
mysql> SELECT * FROM JSON_TABLE ('[ {"c1": 1} ]', '$[*]' COLUMNS( c1 INT PATH '$.c1' ERROR ON ERROR )) as jt;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your TiDB version for the right syntax to use line 1 column 27 near "('[ {"c1": 1} ]', '$[*]' COLUMNS( c1 INT PATH '$.c1' ERROR ON ERROR )) as jt"
MySQL official documentation
https://dev.mysql.com/doc/refman/8.0/en/json-table-functions.html
Extracts data from a JSON document and returns it as a relational table having the specified columns.
One of the new JSON functions in MySQL 8.0 is JSON_TABLE.
It is also MySQL’s first table function.
That is, the return value is not a scalar value, but a result set.
JSON_TABLE will convert (part of) a JSON document into a relational table.
Conclusion:
JSON_TABLE is a function of MySQL 8.0, TiDB v6.5 probably does not support it yet, and it should be compatible in subsequent new versions.
You can verify it in your version, and you will likely reach a similar conclusion.
If your business heavily relies on it, you should bypass the JSON_TABLE function using other methods for now.
The performance will be terrible when associating more than a dozen tables in a distributed database.
The support is probably not very good.
It depends on the user’s tolerance. As long as the user can accept it, associating twenty tables is not impossible
Sorry, I can’t assist with that.
Redistributing data across various TiKV nodes or retrieving all data to the TiDB server for association both incur very high costs.
It’s already in the planning stage and will be implemented later. You can follow this issue:
opened 01:07PM - 15 Jan 20 UTC
type/enhancement
help wanted
good first issue
component/json
All issues are open and welcomed to contributors. You can join **#sig-exec** on … [tidb community slack](https://pingcap.com/tidbslack/) to discuss and get help from someone.
## Feature Request
**Is your feature request related to a problem? Please describe:**
Here we collect some issues about JSON functions, please help us to fix them if you are interested in any of them:
- [x] Implement the unsupported JSON function `JSON_MERGE_PATCH`; **difficulty: medium**
- [x] Implement the unsupported JSON function `JSON_PRETTY`; **difficulty: medium**
- [x] [7623](https://github.com/pingcap/tidb/issues/7623) Implement the unsupported JSON function `JSON_ARRAYAGG`; **difficulty: medium** https://github.com/pingcap/tidb/pull/19957
- [x] [7623](https://github.com/pingcap/tidb/issues/7623) Implement the unsupported JSON function `JSON_OBJECTAGG`; **difficulty: medium**; @hg2990656 https://github.com/pingcap/tidb/pull/11154
- [x] [14488](https://github.com/pingcap/tidb/issues/14488) Implement the unsupported JSON function `JSON_STORAGE_SIZE `; **difficulty: medium**
- [x] [12178](https://github.com/pingcap/tidb/issues/12178) `JSON_EXTRACT` gets wrong decimal when insert into table; **difficulty: easy**
- [x] [13722](https://github.com/pingcap/tidb/issues/13722) Invalid JSON value for CAST to DATE/TIME/DATETIME/TIMESTAMP from column json_extract for virtual column; **difficulty: easy**
- [x] [9995](https://github.com/pingcap/tidb/issues/9995) `JSON_OBJECT` handle long strings wrongly; **difficulty: easy**
- [x] [10460](https://github.com/pingcap/tidb/issues/10460) Compare json objects wrongly; **difficulty: easy**
- [x] [10461](https://github.com/pingcap/tidb/issues/10461) Compare json floats wrongly; difficulty: easy
- [x] [11386](https://github.com/pingcap/tidb/issues/11386) Loss accuracy when inserting json records; **difficulty: easy**
- [x] [9988](https://github.com/pingcap/tidb/issues/9988) Casting times to json cannot be compatible with MySQL; **difficulty: easy**
- [x] [10390](https://github.com/pingcap/tidb/issues/10390) Casting strings to json cannot be compatible with MySQL; **difficulty: easy**
- [x] [12233](https://github.com/pingcap/tidb/issues/12233) JSON_EXTRACT fails to cast as bool; **difficulty: easy**
- [x] [11489](https://github.com/pingcap/tidb/issues/11489) Convert json to uint different from mysql; **difficulty: easy**
- [x] [10467](https://github.com/pingcap/tidb/issues/10467) Incorrect GROUP BY for JSON values; **difficulty: easy**
- [x] [13710](https://github.com/pingcap/tidb/issues/13710) Incorrect results when processing `JSON_EXTRACT(...) IN (...)`; **difficulty: easy**
Thanks for your help! If you have any question, please discuss it with us in our slack channel **#sig-exec** on [tidb community slack](https://pingcap.com/tidbslack/) or in this issue by comments :D
## Document Collection
- Proposal doc: (follow reference implementation in MySQL)
- Weekly report: TODO
## Talent Challenge Program information
- Mentor of this issue: @morgo
- Recommended skills: Golang, MySQL
- Estimated Workloads: 1 month
## Milestones and action items
Milestone 1: Merge missing functions from 5.7.
- [x] JSON_MERGE_PATCH
- [x] JSON_ARRAYAGG
Milestone 2: Fix bugs in current implementation
- [x] JSON_OBJECT handle long strings wrongly
- [x] Casting times to json cannot be compatible with MySQL
Milestone 3: Implement functionality from MySQL 8.0
- [ ] JSON_TABLE function
- [ ] JSON_VALUE function
- [x] Multi-valued indexes (member of function)
\* The MySQL 8.0 functionality may need to be broken down into design docs, since TiDB does not currently support TABLE functions or multi-valued indexes. There may be some assumptions that we've made that will need to be fixed for these to be added.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.