March 25, 2015 at 5:49 am
Hi all
I have 2 sql queries
that each of them take 5 sec
but when i am using INTERSECT its take 20 min
can someone explain me why ?
SELECT
distinct table0.col1
FROM table0
where table0.col2 > 0 and table0.Date_id BETWEEN 20141223 AND 20150323
intersect
SELECT
distinct table0.col1
FROM table0
where table0.col2 > 0 and table0.Date_id BETWEEN 20140723 AND 20141123
March 25, 2015 at 6:00 am
table0 IS VIEW
March 25, 2015 at 6:08 am
View definitions please, index definitions from the base tables and the execution plan of that query?
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
March 25, 2015 at 6:34 am
Since INTERSECT does distinct values, why would you also need the DISTINCT word in each of your queries?
But, what Gail said. No way to tell you what's going on without some idea of structures and the execution plan that the optimizer is creating.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply