I am processing massive updates to tables - usually between 150 million and 200 million rows updating. The queries can grind for 30-48 hours before finishing.
I want to reduce processing time - will LOOP statements to select sub-sets of the data assist in performance? The first table has 168 million rows, the second over 550 million rows. Here is a sample of the code:
USE db_owner.Database_Build_Unique_Email;
GO
DECLARE @TMin int;
DECLARE @TMax int;
DECLARE @Rmin int;
DECLARE @Rmax int;
SELECT @Tmin = MIN(TEMP_PK)
FROM db_owner.Database_Build_Unique_Email;
-- SELECT @TMax = MAX(TEMP_PK)
-- FROM db_owner.Database_Build_Unique_Email;
SET @Tmax = 100000
Set @Rmin = @TMin;
Set @Rmax = @Rmin + 1000;
WHILE (@Rmax < @TMax + 1000)
BEGIN;
UPDATE db_owner.Database_Build_Unique_Email
SET url_id = db_owner.aroi_campaign.url_id, url = db_owner.aroi_sources.source_url, ip = db_owner.aroi_campaign.source_ip, lead_date = db_owner.aroi_campaign.source_date, campaign_disabled = '0'
FROM db_owner.Database_Build_Unique_Email INNER JOIN db_owner.aroi_campaign ON db_owner.Database_Build_Unique_Email.cust_id = db_owner.aroi_campaign.cust_id INNER JOIN db_owner.aroi_sources ON db_owner.aroi_campaign.url_id = db_owner.aroi_sources.url_id
WHERE (db_owner.aroi_campaign.Disabled = 0) AND (db_owner.Database_Build_Unique_Email.lead_date IS NULL) AND (db_owner.Database_Build_Unique_Email between @Rmin AND @Rmax);
PRINT 'Records '+@Rmin+' of '+@Rmax+' have been updated. '+@Tmax-@Rmax+' records to go.';
SET @Rmin = @Rmin + 1000;
SET @Rmax = @Rmin + 1000;
END;
GO
Any suggestions?
I want to reduce processing time - will LOOP statements to select sub-sets of the data assist in performance? The first table has 168 million rows, the second over 550 million rows. Here is a sample of the code:
USE db_owner.Database_Build_Unique_Email;
GO
DECLARE @TMin int;
DECLARE @TMax int;
DECLARE @Rmin int;
DECLARE @Rmax int;
SELECT @Tmin = MIN(TEMP_PK)
FROM db_owner.Database_Build_Unique_Email;
-- SELECT @TMax = MAX(TEMP_PK)
-- FROM db_owner.Database_Build_Unique_Email;
SET @Tmax = 100000
Set @Rmin = @TMin;
Set @Rmax = @Rmin + 1000;
WHILE (@Rmax < @TMax + 1000)
BEGIN;
UPDATE db_owner.Database_Build_Unique_Email
SET url_id = db_owner.aroi_campaign.url_id, url = db_owner.aroi_sources.source_url, ip = db_owner.aroi_campaign.source_ip, lead_date = db_owner.aroi_campaign.source_date, campaign_disabled = '0'
FROM db_owner.Database_Build_Unique_Email INNER JOIN db_owner.aroi_campaign ON db_owner.Database_Build_Unique_Email.cust_id = db_owner.aroi_campaign.cust_id INNER JOIN db_owner.aroi_sources ON db_owner.aroi_campaign.url_id = db_owner.aroi_sources.url_id
WHERE (db_owner.aroi_campaign.Disabled = 0) AND (db_owner.Database_Build_Unique_Email.lead_date IS NULL) AND (db_owner.Database_Build_Unique_Email between @Rmin AND @Rmax);
PRINT 'Records '+@Rmin+' of '+@Rmax+' have been updated. '+@Tmax-@Rmax+' records to go.';
SET @Rmin = @Rmin + 1000;
SET @Rmax = @Rmin + 1000;
END;
GO
Any suggestions?