Why is my stored procedure so slow?

Posted on 2003-02-18
Medium Priority
Last Modified: 2012-06-27
Hi friends!

I have a stored procedure that creates a temporary table with many columns, inserts a line into this table by using INSERT SELECT statement, executes some updates and finally select all columns of this table.

When I execute step-by-step it's OK, but when I execute the stored procedure it's very very slow. It doesn't happen in the development server.

Do you have any idea?

Thanks by advance!


Question by:katahira
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Accepted Solution

amitpagarwal earned 100 total points
ID: 7979587
creating a temp table locks the sysobjects/syscolumns tables of the tempdb database.

so if other processes are using those tables, your temp table creation would get slowed down and overall slowdown your proc.

also - just verify the queryplan using

Expert Comment

ID: 7986920
Calling stored procedure more than once and when you use table (same or temp) could result in a lock. So, you should think of multiuser calls while you wrote this. DEBUG with some PRINT to see what's going on when you call it.

Expert Comment

ID: 7998888
Are you inserting one row at a time or multiple rows using
insert <table> select ....
If the result set is large it may hold tempdb as long running transaction.
You may insert a fixed number of rows at a time and commit.
set rowcount <num>

may help.

or Cursor may help which inserts one row at a time.

Look at the size of tempdb on dev and prod servers also number of users logged in both servers.
Try avoiding creating tables in tempdb if you can make a proper join with subquery to satisfy what you want without saving intermediate results in tempdb.

Author Comment

ID: 8023551
Hi friends!

I figured out that the datatype of parameter I was using in a select statement didn't match with the column datatype.

So the procedure wasn't using the indexes. That's why the query was so slow.

Anyway, thanks for the help. I appreciate so much!

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An introduction to the wonderful sport of Scam Baiting.  Learn how to help fight scammers by beating them at their own game. This great pass time helps the world, while providing an endless source of entertainment. Enjoy!
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question