我正在尝试运行这个查询:
SELECT id, duration, type, `from`, `to`, queue_name, created_at
FROM conference
WHERE duration >= 60
AND JSON_OVERLAPS('["6","7","8"]', `groups`)
但是,运行它相当耗时。以下是EXPLAIN
该查询:
id: 1
select_type: SIMPLE
table: conference
partitions: NULL
type: ALL
possible_key: NULL
key: NULL
key_len: NULL
ref: NULL
rows: 1994483
filtered: 33.33
Extra: Using where
该groups
列未被索引,但是当我尝试添加带有ALTER TABLE conference ADD INDEX
组 (
组的索引时);
,出现此错误:
Error Code: 3152. JSON column 'groups' supports indexing only via generated columns on a specified JSON path.
我可以添加生成的列,但我不知道可以创建什么样的生成列才能让我使用JSON_OVERLAPS
。
有什么想法吗?
我正在运行 MySQL 8.0.32。
请参阅手册中的多值索引。
输出: