I working on SQL server 2012 I face issue update statement take too much time
and it is very slow
my query is
update t set t.Revision_ID = r.rec_id
FROM extractreports.dbo.TempROHS t
INNER join Z2urlSystem.zsrc.Local_URL l (NOLOCK) ON isnull(t.ZURLSource1,'N/A') = l.local_url
INNER join Z2urlSystem.zsrc.Online_URL o (NOLOCK) ON ISNULL(t.OnlineSource1,'N/A') = o.url
INNER join Z2urlSystem.zsrc.Revision r (NOLOCK) ON l.rec_id = r.local_id AND o.Rec_ID = r.online_id
WHERE t.[Status] IS NULL
and execution plan as below :
sample data for test :
CREATE TABLE [dbo].[TempROHS](
[ID] [int] IDENTITY(1,1) NOT NULL,
[ZURLSource1] [nvarchar](3000) NULL,
[OnlineSource1] [nvarchar](3000) NULL,
[Revision_ID] [bigint] NULL,
[status] [nvarchar](300) NULL
) ON [PRIMARY]
GO
/****** Object: Table [zsrc].[Local_URL] Script Date: 10/13/2021 8:59:21 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Local_URL](
[rec_id] [bigint] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[local_url] [nvarchar](2048) NOT NULL,
) ON [PRIMARY]
GO
/****** Object: Table [zsrc].[Online_URL] Script Date: 10/13/2021 8:59:21 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Online_URL](
[Rec_ID] [bigint] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[URL] [nvarchar](500) NOT NULL,
CONSTRAINT [PK_Rec_ID_OnlineURL] PRIMARY KEY CLUSTERED
(
[Rec_ID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
/****** Object: Table [zsrc].[Revision] Script Date: 10/13/2021 8:59:21 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[Revision](
[rec_id] [bigint] IDENTITY(1,1) NOT FOR REPLICATION NOT NULL,
[online_id] [bigint] NOT NULL,
[local_id] [bigint] NOT NULL,
CONSTRAINT [PK_Rec_ID] PRIMARY KEY CLUSTERED
(
[rec_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET IDENTITY_INSERT [dbo].[TempROHS] ON
INSERT [dbo].[TempROHS] ([ID], [ZURLSource1], [OnlineSource1], [Revision_ID], [status]) VALUES (1, N'https://source.z2data.com/2017/3/30/11/41/56/874/706167429/Compliance.pdf', N'http://2t70un3m1d9z1kztamkdrd38.wpengine.netdna-cdn.com/wp-content/uploads/2016/03/5-wireTouch.pdf', NULL, NULL)
INSERT [dbo].[TempROHS] ([ID], [ZURLSource1], [OnlineSource1], [Revision_ID], [status]) VALUES (2, N'https://source.z2data.com/2017/11/19/11/26/36/82/1315668739/rohsCoC.pdf',N'http://2t70un3m1d9z1kztamkdrd38.wpengine.netdna-cdn.com/wp-content/uploads/2016/02/accessories-hardware-1.pdf', NULL, NULL)
INSERT [dbo].[TempROHS] ([ID], [ZURLSource1], [OnlineSource1], [Revision_ID], [status]) VALUES (3, N'https://source.z2data.com/2018/10/24/1/8/18/621/542663177/Statement_of_Compliance_PN_YACT20MJ43JNV00100_181024_160527.pdf',N'http://ac-dc.power.com/design-support/product-documents/data-sheets/linkzero-lp-datasheet', NULL, NULL)
INSERT [dbo].[TempROHS] ([ID], [ZURLSource1], [OnlineSource1], [Revision_ID], [status]) VALUES (4, N'https://source.z2data.com/2017/6/30/8/50/44/270/1593045455/RoHS.ECC36DTAH.pdf', N'http://ark.intel.com/products/78945/Intel-Pentium-Processor-3558U-2M-Cache-1_70-GHz', NULL, NULL)
INSERT [dbo].[TempROHS] ([ID], [ZURLSource1], [OnlineSource1], [Revision_ID], [status]) VALUES (5, N'https://source.z2data.com/2017/8/20/10/11/49/132/1114175001/t1116p.pdf', N'http://assmann.us/specs/A-DS25-HOOD-WP.pdf', NULL, NULL)
SET IDENTITY_INSERT [dbo].[TempROHS] OFF
SET IDENTITY_INSERT [dbo].[Local_URL] ON
INSERT [dbo].[Local_URL] ([rec_id], [local_url]) VALUES (2, N'https://source.z2data.com/2017/3/30/11/41/56/874/706167429/Compliance.pdf')
INSERT [dbo].[Local_URL] ([rec_id], [local_url]) VALUES (3, N'https://source.z2data.com/2017/11/19/11/26/36/82/1315668739/rohsCoC.pdf')
INSERT [dbo].[Local_URL] ([rec_id], [local_url]) VALUES (4, N'https://source.z2data.com/2018/10/24/1/8/18/621/542663177/Statement_of_Compliance_PN_YACT20MJ43JNV00100_181024_160527.pdf')
INSERT [dbo].[Local_URL] ([rec_id], [local_url]) VALUES (5, N'https://source.z2data.com/2017/6/30/8/50/44/270/1593045455/RoHS.ECC36DTAH.pdf')
INSERT [dbo].[Local_URL] ([rec_id], [local_url]) VALUES (6, N'https://source.z2data.com/2017/8/20/10/11/49/132/1114175001/t1116p.pdf')
SET IDENTITY_INSERT [dbo].[Local_URL] OFF
SET IDENTITY_INSERT [dbo].[Online_URL] ON
INSERT [dbo].[Online_URL] ([Rec_ID], [URL]) VALUES (2, N'http://2t70un3m1d9z1kztamkdrd38.wpengine.netdna-cdn.com/wp-content/uploads/2016/03/5-wireTouch.pdf')
INSERT [dbo].[Online_URL] ([Rec_ID], [URL]) VALUES (3, N'http://2t70un3m1d9z1kztamkdrd38.wpengine.netdna-cdn.com/wp-content/uploads/2016/02/accessories-hardware-1.pdf')
INSERT [dbo].[Online_URL] ([Rec_ID], [URL]) VALUES (4, N'http://ac-dc.power.com/design-support/product-documents/data-sheets/linkzero-lp-datasheet')
INSERT [dbo].[Online_URL] ([Rec_ID], [URL]) VALUES (5, N'http://ark.intel.com/products/78945/Intel-Pentium-Processor-3558U-2M-Cache-1_70-GHz')
INSERT [dbo].[Online_URL] ([Rec_ID], [URL]) VALUES (6, N'http://assmann.us/specs/A-DS25-HOOD-WP.pdf')
SET IDENTITY_INSERT [dbo].[Online_URL] OFF
SET IDENTITY_INSERT [dbo].[Revision] ON
INSERT [dbo].[Revision] ([rec_id], [online_id], [local_id]) VALUES (1, 2, 2)
INSERT [dbo].[Revision] ([rec_id], [online_id], [local_id]) VALUES (2, 3, 3)
INSERT [dbo].[Revision] ([rec_id], [online_id], [local_id]) VALUES (3, 4, 4)
INSERT [dbo].[Revision] ([rec_id], [online_id], [local_id]) VALUES (4, 5, 5)
INSERT [dbo].[Revision] ([rec_id], [online_id], [local_id]) VALUES (5, 6, 6)
SET IDENTITY_INSERT [dbo].[Revision] OFF
/****** Object: Index [Key2] Script Date: 10/13/2021 8:59:24 AM ******/
ALTER TABLE [dbo].[Local_URL] ADD CONSTRAINT [Key2] PRIMARY KEY NONCLUSTERED
(
[rec_id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
GO
update t set t.Revision_ID = r.rec_id
FROM dbo.TempROHS t
INNER join dbo.Local_URL l (NOLOCK) ON t.ZURLSource1 = l.local_url
INNER join dbo.Online_URL o (NOLOCK) ON t.OnlineSource1 = o.url
INNER join dbo.Revision r (NOLOCK) ON l.rec_id = r.local_id AND o.Rec_ID = r.online_id
WHERE t.[Status] IS NULL