December 21, 2011 at 7:31 am
the following qry is very slow. qry have CTE command with union all...
In my environment we need to find telephone no with two different tables. both tables have more than 5 crore records..
the qry template...
WITH telephoneresult AS
(
SELECT telephoneno, telephoneid, telephoneaddress
FROM telephoneregion1 t1
join telephoneaddresscommon tc on t1.telephoneno = tc.telephoneno
.....
.....
WHERE t1.telephoneno = @telephoneno
UNION ALL
SELECT telephoneno, telephoneid, telephoneaddress
FROM telephoneregion2 t1
join telephoneaddresscommon tc on t1.telephoneno = tc.telephoneno
.....
.....
WHERE t1.telephoneno = @telephoneno
)
SELECT *
FROM telephoneresult
now this query returns result with in 5 seconds...
we have checked indexes and other parts... all are ok.
we need to get result quickly. is any option instead of CTE?
December 21, 2011 at 7:41 am
Please read this article (http://www.sqlservercentral.com/articles/SQLServerCentral/66909/) on how best to post performance problem questions. Help us to help you!![/url] 😉
December 21, 2011 at 9:44 am
How did you check indexes and how did you arrive at the conclusion "all are ok"?
Another option would be to build the UNION ALL cte based on telephoneregion1 and telephoneregion2 only and join the result to telephoneaddresscommon.
I would have provided the syntax for it but I don't know which column belongs to which table (due to incomplete column reference)...
Other than that: please provide more information as already stated by Cadavre
December 24, 2011 at 2:09 pm
nithiyanandam-447806 (12/21/2011)
the following qry is very slow. qry have CTE command with union all...In my environment we need to find telephone no with two different tables. both tables have more than 5 crore records..
the qry template...
WITH telephoneresult AS
(
SELECT telephoneno, telephoneid, telephoneaddress
FROM telephoneregion1 t1
join telephoneaddresscommon tc on t1.telephoneno = tc.telephoneno
.....
.....
WHERE t1.telephoneno = @telephoneno
UNION ALL
SELECT telephoneno, telephoneid, telephoneaddress
FROM telephoneregion2 t1
join telephoneaddresscommon tc on t1.telephoneno = tc.telephoneno
.....
.....
WHERE t1.telephoneno = @telephoneno
)
SELECT *
FROM telephoneresult
now this query returns result with in 5 seconds...
we have checked indexes and other parts... all are ok.
we need to get result quickly. is any option instead of CTE?
MR missing code
MR not
MR2 CM "....."
IB MR missing code
😀
If the "....." represent missing code, then please post your entire query and the items previously requested so we can actually help with this. Also, make sure that all of the columns in your query use the correct table alias so we can tell which columns belong to which tables. 😉
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply