我在azure数据仓库中创建了一个简单的表,该表包含三列,下面是表定义
create table conf
(
uuid uniqueidentifier not null,
pk bigint null,
content nvarchar(2048) null
)
with
(
Distribution= HASH(pk),
CLUSTERED columnstore index
)
我的要求不是很复杂,只需在内容中搜索关键字并返回唯一的pk,查询将被嵌套,并可以具有如下所示的许多层:
SELECT pk FROM ( SELECT pk FROM conf WHERE content like 'enable %keyword1%' GROUP BY pk) a WHERE pk IN (SELECT pk FROM ( SELECT pk FROM conf WHERE content like '%keyword2%' GROUP BY pk union SELECT pk FROM conf WHERE pk NOT IN (SELECT pk FROM conf WHERE content like '%keyword3%' GROUP BY pk) GROUP BY pk) b GROUP BY pk) GROUP BY pk
根据我的测试,这将需要几分钟的时间才能返回结果,如何优化并加快此查询的速度?
此外,我遇到了一个奇怪的问题。有时我在DWU100上对相同数据运行相同的查询要比DWU500快