【发布时间】:2014-06-12 10:07:59
【问题描述】:
UPDATE nas_backup
SET fiber_serviceability_class = '0',
last_updated_ts = CURRENT_TIMESTAMP
WHERE location_id IN (
SELECT location_id
FROM (
WITH distinct_locs AS (
SELECT location_id, boundary_type
FROM (
SELECT location_id, boundary_type
FROM nc
WHERE technology_type = 'Fibre'
)
GROUP BY location_id, boundary_type
HAVING COUNT( * ) = 1
)
SELECT nas.location_id
FROM distinct_locs, nas_backup nas
WHERE distinct_locs.location_id = nas.location_id
AND distinct_locs.boundary_type = 'FSA'
GROUP BY nas.location_id
)
);
谁能建议一种优化查询的方法。现在需要超过 5 分钟。
表 nc 有 1600 万条记录,表 nas_backup 有 200 万条记录。
【问题讨论】:
-
您没有提到任何索引,因此添加这些将是一个不错的起点。
-
相关列的索引已经到位。我只想要一个更优化的查询版本。
-
如果您能提供实际的执行计划,我们或许能够确定瓶颈在哪里?
-
只是为了确保我理解您的目标:您希望更新
nas_backup中的所有记录,其中位置的技术类型为“光纤”,边界类型为“FSA”。还有什么要检查的吗?
标签: sql sql-tuning