Re: would a Stored Procedure help
From: David Browne (meat_at_hotmail.com)
Date: 03/01/05
- Next message: --CELKO--: "Re: Exists"
- Previous message: Utada P.W. SIU: "Re: question about database design"
- In reply to: Brian Higgins: "would a Stored Procedure help"
- Next in thread: Brian Higgins: "Re: would a Stored Procedure help"
- Reply: Brian Higgins: "Re: would a Stored Procedure help"
- Messages sorted by: [ date ] [ thread ]
Date: Mon, 28 Feb 2005 19:44:42 -0600
"Brian Higgins" <brian@-NO-accentconsulting-SPAM-.com> wrote in message
news:Oz51rSfHFHA.2976@TK2MSFTNGP15.phx.gbl...
>I have a large and ever growing database with over 15 million records, all
>timestamped, and increasing by roughly 30,000 records per day so efficient
>queries are essential.
>
> I need to pull a list of records that match certain criteria, that have
> timestamps in the last hour. and I need to run it 45 times in a row, and I
> need the results in the shortest amount of time as possible.
>
> the only thing I need at this point in the program is a boolean value
> telling me that either something has been logged recently, or it has not.
>
> the basic logic of the program is currently as follows:
>
You don't need a stored procedure, you just need to change the SQL. You
need to end up with a query of the form
select * from t where DateCol > '2005-03-01 16:00:00'
Yes, you want to hard-code the date in the query. This is one of the
exceptions to the rule of using parameter markers for your queries. This
will give SQL Server the maximum amount of statistical information about how
to process your query.
First, ditch the query builder, and write the SQL by hand. All those
useless parentheses just confuse the issue:
Also ditch the HAVING clause and return all the ServerID's then you can
iterate them on the client side and process all 45 servers with one query.
Just ORDER BY ServerId so you know that if the first row has ServerID=2 then
there was no row with ServerID=1, etc.
SELECT ServerInfo.ServerID
FROM ServerInfo
INNER JOIN PInfo
ON ServerInfo.ID = PInfo.ID
INNER JOIN PDetails
ON PInfo.ID = PDetails.ID
WHERE PDetails.Status<>2
And PDetails.Status)<>5
AND TmeStamp >= '2005-03-01 16:00:00'
GROUP BY ServerInfo.ServerID
ORDER BY ServerInfo.ServerID
With any kind of index on TmeStamp this query should be reasonably cheap.
With a clustered index on TmeStamp it should be downright fast.
David
- Next message: --CELKO--: "Re: Exists"
- Previous message: Utada P.W. SIU: "Re: question about database design"
- In reply to: Brian Higgins: "would a Stored Procedure help"
- Next in thread: Brian Higgins: "Re: would a Stored Procedure help"
- Reply: Brian Higgins: "Re: would a Stored Procedure help"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|