Click here to Skip to main content
15,915,093 members
Home / Discussions / Database
   

Database

 
GeneralADO memory leak Pin
Droiddr29-Sep-04 23:47
Droiddr29-Sep-04 23:47 
GeneralRe: ADO memory leak Pin
sreejith ss nair7-Oct-04 0:53
sreejith ss nair7-Oct-04 0:53 
GeneralRunning SQL Agent from VB.NET and getting execution status Pin
Emilio Crespo29-Sep-04 6:53
Emilio Crespo29-Sep-04 6:53 
Generalvery strange behaviour Pin
ricardojb29-Sep-04 5:54
ricardojb29-Sep-04 5:54 
GeneralRe: very strange behaviour Pin
sreejith ss nair7-Oct-04 0:51
sreejith ss nair7-Oct-04 0:51 
GeneralStored Procedures and Return Values Pin
Ryan@SalamanderTechnologies29-Sep-04 3:53
sussRyan@SalamanderTechnologies29-Sep-04 3:53 
GeneralRe: Stored Procedures and Return Values Pin
Colin Angus Mackay29-Sep-04 4:41
Colin Angus Mackay29-Sep-04 4:41 
GeneralStored procedure / query optimization Pin
Vagif Abilov28-Sep-04 7:47
professionalVagif Abilov28-Sep-04 7:47 
Hello,

I have a question regarding stored procedure desing that provides the
optimal performance. Let's say we have a table Products that consists of
three columns: Name, Status, RegistrationTime. All columns are indexed and
users should be able to lookup data by any of the columns. We have two main
options to design stored procedures for data retrieval:

1. Design separate stored procedures for each search criteria:
LookupProductsByName, LookupProductsByStatus, LookupProductsByTime.

2. Write a generic stored procedure that will fit any search criteria:

CREATE PROCEDURE GetProducts (
@Name varchar(20),
@Status int = NULL,
@FromTime datetime = NULL,
@ToTime datetime = NULL)
AS BEGIN
SELECT
[Name],
[Status],
[RegistrationTime]
FROM [Products]
WHERE [Name]=CASE
WHEN @Name<>NULL THEN @Name
ELSE [Name]
END
AND [Status]=CASE
WHEN @Status<>NULL THEN @Status
ELSE [Status]
END
AND [RegistrationTime]>=CASE
WHEN @FromTimestamp<>NULL THEN @FromTimestamp
ELSE [RegistrationTime]
END
AND [RegistrationTime]<=CASE
WHEN @ToTimestamp<>NULL THEN @ToTimestamp
ELSE [RegistrationTime]
END
ORDER BY [RegistrationTime]
END;

The second option is very attractive, because it is obviously easier to
maintain such code. However, I am a little concerned about performance of
such stored procedure. It is not possible to foresee what index should be
used, index can only be selected each during procedure execution, because
search criteria can include either Name, Status or RegistrationTime. Will it
make this SP inefficient? Or perormance difference in such case is not big
(if any) and we should choose the second option because of its significant
code reduction?

Thanks in advance


Вагиф Абилов
MCP (Visual C++)
Oslo, Norway


Hex is for sissies. Real men use binary. And the most hardcore types use only zeros - uppercase zeros and lowercase zeros.
Tomasz Sowinski
GeneralRe: Stored procedure / query optimization Pin
Steven Campbell28-Sep-04 8:19
Steven Campbell28-Sep-04 8:19 
GeneralRe: Stored procedure / query optimization Pin
Vagif Abilov28-Sep-04 8:52
professionalVagif Abilov28-Sep-04 8:52 
GeneralRe: Stored procedure / query optimization Pin
Steven Campbell28-Sep-04 9:48
Steven Campbell28-Sep-04 9:48 
GeneralRe: Stored procedure / query optimization Pin
Vagif Abilov28-Sep-04 9:55
professionalVagif Abilov28-Sep-04 9:55 
GeneralRe: Stored procedure / query optimization Pin
Colin Angus Mackay28-Sep-04 23:12
Colin Angus Mackay28-Sep-04 23:12 
GeneralRe: Stored procedure / query optimization Pin
Bill Dean29-Sep-04 6:31
Bill Dean29-Sep-04 6:31 
GeneralRe: Stored procedure / query optimization Pin
Steven Campbell29-Sep-04 8:30
Steven Campbell29-Sep-04 8:30 
GeneralRe: Stored procedure / query optimization Pin
Colin Angus Mackay29-Sep-04 13:24
Colin Angus Mackay29-Sep-04 13:24 
GeneralRe: Stored procedure / query optimization Pin
Bill Dean30-Sep-04 2:21
Bill Dean30-Sep-04 2:21 
GeneralRe: Stored procedure / query optimization Pin
Jeremy Oldham29-Sep-04 13:50
Jeremy Oldham29-Sep-04 13:50 
GeneralRe: Stored procedure / query optimization Pin
Vagif Abilov29-Sep-04 19:40
professionalVagif Abilov29-Sep-04 19:40 
Generaleqivalent of "FOR UPDATE" Pin
WinDotNet27-Sep-04 19:35
WinDotNet27-Sep-04 19:35 
GeneralRe: eqivalent of &quot;FOR UPDATE&quot; Pin
Anonymous30-Sep-04 0:34
Anonymous30-Sep-04 0:34 
GeneralOracleClient StoredProcedure Pin
jzb27-Sep-04 17:01
jzb27-Sep-04 17:01 
QuestionAny way to optomize this? Pin
Jacob Hammack27-Sep-04 16:48
Jacob Hammack27-Sep-04 16:48 
AnswerRe: Any way to optomize this? Pin
Mike Ellison27-Sep-04 17:15
Mike Ellison27-Sep-04 17:15 
GeneralRe: Any way to optomize this? Pin
Jacob Hammack29-Sep-04 11:39
Jacob Hammack29-Sep-04 11:39 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.