Я хотел знать, почему мой оператор выбора на несколько порядков быстрее, чем мой оператор обновления при обновлении значений из одной таблицы в другую, в отличие от выбора значений из одной таблицы в другую.Приведенный ниже пример иллюстрирует мою проблему: я могу очень быстро выполнить оператор select
select customers.name, countries.country
from customers
inner join countries on customers.countrycode = countries.countrycode
Однако написанное мной заявление об обновлении (которое, я уверен, это то же самое) занимает на несколько порядков большедля завершения.
update customers
set customers.country = countries.country
from customers
inner join countries on customers.countrycode = countries.countrycode
Есть предложения?
ОБНОВЛЕНИЕ:
Ниже приведен план инструкции SELECT
|--Hash Match(Inner Join, HASH:([countries].[countrycode])=([Testing].[dbo].[customers].[countrycode]), RESIDUAL:(@countries.[countrycode] as [countries].[countrycode]=[Testing].[dbo].[customers].[countrycode]))
|--Table Scan(OBJECT:(@countries AS [countries]))
|--Table Scan(OBJECT:([Testing].[dbo].[customers]))
Ниже приведен пландля оператора UPDATE
|--Table Update(OBJECT:([Testing].[dbo].[Customers]), SET:([Testing].[dbo].[Customers].[Country] = @countries.[country] as [countries].[country]))
|--Top(ROWCOUNT est 0)
|--Stream Aggregate(GROUP BY:([Bmk1000]) DEFINE:([countries].[country]=ANY(@countries.[country] as [countries].[country])))
|--Nested Loops(Inner Join, WHERE:(@countries.[countrycode] as [countries].[countrycode]=[Testing].[dbo].[Customers].[countrycode]))
|--Table Scan(OBJECT:([Testing].[dbo].[Customers]))
|--Table Scan(OBJECT:(@countries AS [countries]))