假设您有一个名为 slug
的 JSON 列,其结构如下:
{
"en_US": "slug",
"nl_NL": "nl/different-slug"
}
这可以通过将生成的列添加到指向 en_US
和 nl_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/