我有一个包含几百万条记录的大表。每条记录都包含来自外部来源的类型。我知道类型的数量大约是100 - 200个。
我需要获取搜索提示的类型子集。
我需要这样的东西:
select distinct my_type from my_table where my_type like '%XXX%';但它的速度非常慢。8M条记录需要4-5秒。
我的问题是:我能以某种方式提高这个select或使用不同查询的性能吗?
发布于 2017-02-28 06:28:57
distinct和group by采用不同的代码路径,因此您可以分别对它们进行测试:
select my_type
from (select distinct my_type from my_table) as t
where my_type like '%XXX%';
select my_type
from (select my_type from my_table group by my_type) as t
where my_type like '%XXX%';https://stackoverflow.com/questions/42496808
复制相似问题