我正在运行这个查询。
SELECT dom,
COUNT(url) AS counted
FROM results
GROUP BY dom
ORDER BY COUNT(url) DESC;
我有 dom 索引,但我不能索引 url,因为它是一个长文本。我该怎么做才能让它更快?
我正在运行这个查询。
SELECT dom,
COUNT(url) AS counted
FROM results
GROUP BY dom
ORDER BY COUNT(url) DESC;
我有 dom 索引,但我不能索引 url,因为它是一个长文本。我该怎么做才能让它更快?
尝试这个:
SELECT dom,
COUNT(url) AS counted
FROM results
GROUP BY dom
ORDER BY counted DESC;
假设 dom 的 url 很少,这应该不是问题。如果每个 dom 有很多 url,count 会很昂贵。
count(url) 表示对 url 字段不为空的行进行计数。也许您可以提高创建和索引的性能,例如:
create index idx__1 on results (dom, url (1));
然后将您的查询更改为:
SELECT dom,
COUNT( left(url,1)) AS counted
FROM results
GROUP BY dom
ORDER BY counted DESC;
如果您只要求列出的两个字段,RDBMS 只需要索引,不需要从表中获取数据。