mysql - MySQL 可以为 JSON 列动态创建索引吗?

标签 mysql sql

假设您有一个名为 slug 的 JSON 列,其结构如下:

{
    "en_US": "slug",
    "nl_NL": "nl/different-slug"
}

这可以通过将生成的列添加到指向 en_USnl_NL 值的表中来建立索引。这工作正常,但添加第三个语言环境需要更新表架构。

是否可以让 MySQL 自动索引 JSON 中的所有键值对,而无需在模式中明确定义它们?

最佳答案

作为 json data type 上的 mysql 手册说:

JSON columns, like columns of other binary types, are not indexed directly; instead, you can create an index on a generated column that extracts a scalar value from the JSON column. See Indexing a Generated Column to Provide a JSON Column Index, for a detailed example.

所以,答案是否定的,mysql 不能自动索引 json 列的内容。您需要定义和索引生成的列。

关于mysql - MySQL 可以为 JSON 列动态创建索引吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51810313/

相关文章:

mysql - 在没有 FROM 子句的 SELECT 语句中乘以值

SQL注入(inject)利用登录表单

mysql - MySQL 中复杂的 COUNT 查询

mysql - 在 phpmyadmin 中上传数据库时出错

sql - db2 "DB21018E A system error occurred. The command line processor could not continue processing."

mysql - 如何更新Mysql中的选定行

sql - 选择查询的问题

php - Mysql 查询花费太多时间

mysql - SQL - 获取包含特定记录的数据库

java mysql 更新