I've been lately working on some performance optimization and have been a bit stuck with the below query. Breaking it down, the individual steps don't seem to take very long, but when I run the query as a whole, it takes about 30minutes to complete.
The TABLE has around 100k rows, and the VIEW has around 400k rows, so they're not terribly large. I wasn't sure if I'm just not understanding the EXCEPT logic accurately, and if that's the likely culprit? Would there be an alternative to EXCEPT perhaps?
EDIT - The view itself has about 4 joins and a UNION, so it does have some logic to it.
CREATE TABLE [SCHEMA].[TABLE](
ColumnA [int] IDENTITY(1,1) NOT NULL,
ColumnB [tinyint] NOT NULL,
ColumnC [tinyint] NOT NULL,
ColumnD [int] NULL,
ColumnE [nvarchar](50) NOT NULL,
ColumnF [int] NOT NULL,
ColumnG [nvarchar](250) NULL,
ColumnH [nvarchar](250) NULL,
ColumnI [nvarchar](250) NULL,
ColumnJ [nvarchar](50) NULL,
columnK [nvarchar](400) NULL,
ColumnL [nvarchar](2) NULL,
ColumnM [nvarchar](250) NULL,
ColumnN [nvarchar](3) NULL,
----
DELETE FROM [DB].[SCHEMA].[TABLE] WHERE ColumnB NOT IN (4,6)
AND ColumnG not in
(SELECT ColumnG
FROM
(
SELECT ColumnG,ColumH,ColumnI FROM [DB].[SCHEMA].[TABLE] EXCEPT
SELECT ColumnG,ColumnH,ColumnI FROM [DB].[SCHEMA].[VIEW]
WHERE VIEW.ColumnB='Active' and year(LastChgDateTime) = 9999
) AAA )
Thanks for any help!