June 23, 2010 at 3:00 pm
Hi All:
I am trying to use the Database Tuning Advisor on a set of statements. The set goes something like this:
SELECT order_hdr_id, customer_id, order_date, amount, city, state, zip INTO #Open From Order WHERE ship is null
SELECT customer_name, customer_id,
order_hdr_id, order_num
FROM #Open
inner join Customer on #open.customer_id = Customer.customer_id
The Database Tuning Advisor can't figure it out. It seems to have an issue with temporary tables.
Any ideas?
Thanks,
Mike
June 23, 2010 at 5:38 pm
mike 57299 (6/23/2010)SELECT order_hdr_id, customer_id, order_date, amount, city, state, zip INTO #Open From Order WHERE ship is null
Assuming script is creating #Open temp table, how about...
insert into #Open
select order_hdr_id, customer_id, order_date, amount, city, state, zip
from Order
where ship is null
_____________________________________
Pablo (Paul) Berzukov
Author of Understanding Database Administration available at Amazon and other bookstores.
Disclaimer: Advice is provided to the best of my knowledge but no implicit or explicit warranties are provided. Since the advisor explicitly encourages testing any and all suggestions on a test non-production environment advisor should not held liable or responsible for any actions taken based on the given advice.June 23, 2010 at 7:11 pm
mike 57299 (6/23/2010)
Hi All:I am trying to use the Database Tuning Advisor on a set of statements. The set goes something like this:
SELECT order_hdr_id, customer_id, order_date, amount, city, state, zip INTO #Open From Order WHERE ship is null
SELECT customer_name, customer_id,
order_hdr_id, order_num
FROM #Open
inner join Customer on #open.customer_id = Customer.customer_id
The Database Tuning Advisor can't figure it out. It seems to have an issue with temporary tables.
Any ideas?
Thanks,
Mike
Correct... the Tuning Advisor cannot see temp tables because they're usually created in another session. You'll need to make the table materialize while you're trying to do the analysis.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 23, 2010 at 10:46 pm
Jeff Moden (6/23/2010)
Correct... the Tuning Advisor cannot see temp tables because they're usually created in another session. You'll need to make the table materialize while you're trying to do the analysis.
How do you make the table materialize? Does this mean making it a real table? If so, I have a problem because I use two temp tables through out the script I would like to optimize.
Mike
June 24, 2010 at 1:48 am
Yes, convert them to real tables or don't use DTA (second option may be best). If it's a small set of queries, ask here. http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
DTA is usually overly enthusiastic about indexes and stats. If you do use it, please check the effectiveness of each recommendation and only apply the ones that really do help.
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
June 25, 2010 at 7:44 am
mike 57299 (6/23/2010)
Jeff Moden (6/23/2010)
Correct... the Tuning Advisor cannot see temp tables because they're usually created in another session. You'll need to make the table materialize while you're trying to do the analysis.How do you make the table materialize? Does this mean making it a real table? If so, I have a problem because I use two temp tables through out the script I would like to optimize.
Mike
Like Gail said, "Yes"... turn them into permanent tables BUT... only temporarily. If you change "#" to "TempDB.dbo." using search'n'replace, you should be ok and, of course, that's pretty easy to change back to a "#" when you're done.
--Jeff Moden
Change is inevitable... Change for the better is not.
June 25, 2010 at 9:26 am
I have been doing some performance testing and I am beginning to think temp tables aren't so hot. I have one area where I insert into the table 1 record. I wanted to see what was in it and I did a "select * from #I". That line took 4 seconds to execute. I think it might be a caching issue. Anyone else have issues with temp tables?
Mike
June 25, 2010 at 9:31 am
I have had issues in the past, but I don't see a lot of issues reported in the last few versions of SQL Server.
tempdb is a shared resource, and the disks underlying it, and other uses do impact your use. Depending on how your load is on the server, it may or may not be an issue. It sounds like it is on your system.
Viewing 8 posts - 1 through 7 (of 7 total)
You must be logged in to reply to this topic. Login to reply