[quoted text, click to view] > I have a big 200 line stored procedure that pulls (select ...) data from
10
> joined tables. Results are slow, often taking about 4-10 seconds for
1000
> rows of output. The SQL Server hardware is new and fast.
First, I am not suggesting in any way that SQL Server has "rushmore
technology", but I have two suggestions:
1. Strongly consider indexing any column that fits one of these conditions:
Primary Key
Foreign Key
Used frequently in a JOIN, WHERE or ORDER BY
2. Read up on the "Rushmore Technology" that Microsoft Access has. I have
observed that applying the same good sense to query's in SQL Server has paid
off.
Further, strategize the statements in your SQL. For example, if you know
that you are about to do a 12 table join in your from clause, try to phrase
the joins so that the order of the joins is from the most specific to the
least specific so that when the underlying engine processes them, it can
eliminate the most rows first.
For Example, one of the things I have written at work is a complex
algorithm that decides which set of records to export to a partner system.
This set of records is dependent on a "ColocKey". Another process builds a
list of ColocKeys in a table, and then my code JOINs that with like 17 other
tables to build a huge export file. The first step in my export process is
to select from that table. When I JOIN other tables, the record base is
limited by the ColocKey items. As other tables are also joined, I use
parens to make sure the joins happen in the order I want.
Before I was there, this process ran overnight to process roughly 100,000
records. After I fixed it like this, it processes the same amount of data
in less than 30 seconds.
--
Peace & happy computing,
Mike Labosh, MCSD
"SELECT * FROM Users WHERE Clue > 0"