It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have a big stored procedure, which runs for 2-3 secs at 100% CPU. Its not a big deal, if the SP runs once for a while, however this particular SP runs every second. so you can understand the total processor usage in a minute and through-out the day.
This stored procedure contains lots of queries, temporary tables, one or two cursors and some dynamic queries.
what will the best possible solution to tune-up my SP, and different ways to do that.
What are the points we need to remember while writing an SP in general?
Please Help...
To tune up your stored procedure you need to address each query and process contained within it individually. Make sure that your indexes are set correctly and check whether your approach with the temp tables and dynamic SQL is appropriate. Also make sure that you're not abusing other stored procs and views that may have been designed to be used directly rather than as cogs in a larger process.
It is difficult to make more suggestions but, from your description on what is entailed in the stored procedure and how often it runs, it sounds like this is a key process in your system and the data involved a likely candidate for denormalization. If you denormalize the data then you would rewrite the stored proc to query that part of the database to get better performance.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
We have an application which needs to write data to a particular table in oracle DBMS. But before writing to the table it do certain manipulation on the data it writes.
We are now planning to take this 'manipulation of data' out of the application and delegate this responsibility to a stored procedure in ORACLE DBMS. Their procedure, on other hand, will take help of different in-built and explicitly written functions to do its job.
Now my concern is how efficient is the 'procedure run' in ORACLE DBMS. I am supposing Oracle will invoke different functions call from the stored procedure in an in-line fashion, or otherwise , but will definitely not make those calls as part of some child process, which will otherwise give a big hit to the performance of this stored-procedure.
Note:This procedure will be called through-out the day, with hundreds of thousand of row to be updated. This make the performance of this stored-procedure very crucial for the application.
Can you comment on the performance of the stored procedure in general as compared to when manipulation is part of an application.
EDIT:
Manipulation is as simple as taking few values out from a map, collating them together and update them in a particular column of a table.
Many Thanks,
Mawia
The PL/SQL code will access data with lower latency than the application, and you're unlikely to have a problem If you follow good practice's. Do as much as possible in SQL, and use implicit cursors instead of explicit cursors.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
What is the purpose of table hints in SQL Server like NOLOCK and READUNCOMMITTED?
Please explain this with example.
Also why can't they be specified for tables modified by INSERT, UPDATE, or DELETE operations?
They allow you to set transaction isolation level on a table-by-table basis instead of for the entire query or connection.
They can also be used to trigger some features like minimal logging (use TABLOCK with the right trace flags set on an INSERT and it can be minimally logged).
As a rule it's a better idea to use connection-level settings.
As the commentor pointed out, Books Online has an excellent description (and samples) of Table Hints, including which hints can be used for which operations.
http://msdn.microsoft.com/en-us/library/ms187373.aspx
There is also a big fat caveat at the top of the page, which often goes unnoticed:
Caution Because the SQL Server query optimizer typically selects the
best execution plan for a query, we recommend that hints be used only
as a last resort by experienced developers and database
administrators.
While the accuracy of the optimizer in choosing the best plan can be debatable, the latter half of the warning is certainly true; don't use Table Hints unless you are sure that you need them, and that assurance typically only comes with experience.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I am using SQL Server 2008.
i am creating an NON CLUSTERED index on a table in my database.
What I see while creating that index is that the query is taking a lot of time; in my case now 8-9 mins is done but still create index query is running.
Can somebody help me to get why it is so ?
I would bet there's nothing special causing it to be slow outside of the ordinary considerations. Obviously the number of rows in the database is going to be a primary factor, then the processor speed and amount of memory on your computer. Also, many people do not realize how much the hard disk speed affects sql operations. Depending on how you use sql, you could easily increase speed quite noticeably by just getting a faster hard drive.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I have worked on several rails applications and now I work on a very complex one, from the database side. A lots of nested models, several polymorphyc associations...
How you deal with that complexity ? How can I know that we are working in the good direction ? What about performance issues ?
Thansk for your opinions.
First of all, you need to estimate the performance of the queries that your application runs against the database. Then you can try to optimize the queries, for example, by adding some indexes. Maybe in some cases you will also need to consider denormalizing some data to get better performance.
Performance of the queries may also depend on your data size. If you have really big data set and queries are optimal, then you may consider introducing (distributed) caching. Or if data model allows that think of partitioning your database on several nodes to improve query performance.
But still the first step should be a setup of some SQL query performance monitoring.
You should consider a NOSQL solution such as MongoDB or CouchDB. Sometimes an RDBMS is not the right tool for the job.
http://www.mongodb.org/
http://couchdb.apache.org/
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
There were a number of questions related to sharing data results of one stored procedure in another in MS SqlServer.
Depending of the version of SQL Server people would suggest using temporary tables, xml (SQLServer 2005) or table variables (SQL Server 2008).
There is a great article written by Erland Sommarskog that provides comprehensive answer and list all options available in different versions of SQL:
How to Share Data Between Stored Procedures
I thought it was worth sharing.
I came across that article when reading an answer by deevus suggesting the use of INSERT-EXEC Statement, something that I was not really familiar with before
There is a great article written by Erland Sommarskog that provides the comprehensive answer and list all options available in different versions of SQL:
How to Share Data Between Stored Procedures
This article tackles two related
questions:
How can I use the result set from one
stored procedure in another, also
expressed as How can I use the result
set from a stored procedure in a
SELECT statement?
How can I pass a
table as a parameter from one stored
procedure to another?
In this article
I will discuss a number of methods,
and also point out their advantages
and drawbacks. Some of the methods
apply only when you want to reuse a
result set, whereas others apply in
both situations. In the case you want
to reuse a result set, most methods
require you to rewrite the stored
procedure in one way or another, but
there are some methods that do not.