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 万条记录。