I currently use the following statement, for 10,000 rows it takes about 150 seconds. I tried removing the index on the target table, but this didn't help. Running the loop without the INSERT INTO
takes less then 50ms. I need it to update about 300 million rows and I can't really wait 52 days (!) for it to complete.
Bottom line of the following update query is that I need to go over each row, perform calculations on a VARBINARY
and extract proper values from it (we need to get rid of the packed VARBINARY
fields), and store that in a new table.
FETCH NEXT FROM LocCities INTO @LocCity
WHILE (@@FETCH_STATUS = 0)
BEGIN
-- several sets, removed calculations for clarity
SET @LocationId = Calculation1()
SET @CityId = Calculation2()
IF(@LocCity <> 0)
BEGIN
-- left out an inner loop here on the VARBINARY based on its length
INSERT INTO LocationCities (LocationId, CityId)
VALUES (@LocationId, @CityId)
END
FETCH NEXT FROM RespCursor INTO @TuningRow
END
I understand that I can use the WITH
keyword with table hints, but I am not sure what to use. I expect the final update query to run in several hours, and hope there's a way to do that. I really can't wait almost two months ;).
Isn't there something similar like BULKINSERT
that I can use?
varbinary
of varying length. I need to loop over that field and create the many-to-many relation it has with its internal values. I.e., suppose the varbinary has0x010734
and0x030735040736
, the first row will create 1 row with int values(1, 1844)
, the second row will create 2 rows with int values(3, 1845)
and(4, 1846)
respectively. The depth of the varbinary field can be over 300 corresponding rows, and I need to flat-to-hier that.