Advertisement

04.19.2008 at 06:03PM PDT, ID: 23337227
[x]
Attachment Details

Speed up big SQL SELECT

Asked by AntoniL in MS SQL Server, VB Database Programming, .Net Editors & IDEs

Tags: VB.NET

Hi lads,

I'm trying to query a SQL table (which contains more than 100.000 recordsets) in the fastest possible way. This table contains IDs and customer details, similar to these ones:
ID1          ID2             Name             Surname
1               1               John               Walsh
1               1               Jamie              Clint
1               2               Sue                 Sullivan
2               1               Tom                 Jacobs
2               2               Judith              James
...              ...              ...                    ...

My queries are as follows:  

SELECT Name FROM MyTable WHERE (ID1 = 2 AND ID2 = 1 AND Name = 'John') OR (ID1 = 2 AND ID2 = 1 AND Name = 'Judith') OR (ID1 = 2 AND ID2 = 1 AND Name = 'Ronan')

so as you can see, I always use the same ID1 and ID2 and the variable part comes to the Name column. To construct my final select statement, I'm looping though a big array which contains the names I'm looking for, ending up in a big select.

My first attempts were with a few thousands of "OR (ID1 = X AND ID2 = Y AND Name = 'Z')", and my SQL server 2000 just timed out after a couple of minutes. After that, I decided to divide the action into chunks, in such a way I did a query with the first one thousand names, then the second group of one thousand and so on. Now I'm getting results for each query but it's taking too long (about a minute) per group of 1000 statements "OR (ID1 = X AND ID2 = Y AND Name = 'Z')". So let's say, If I try to seek 4000 names, it takes about 4 minutes.

Then I thought if adding up autonumeric values to each of my 100.000 recordsets, that could speed up the search. Unfortunately, I'm getting roughly the same time.

The next step could be using stored procedures, but I've never used something like that before. Finally, my last fear is if this will be getting worse in case my table grows up (about 1000 new recordsets per day now). In that case I don't either know the possibility of using truncated tables, but again, I've never worked with such scenarios for DBs.

Could anybody point out the right direction to deal with this scenario?, how should I carry out this kind of selects?

If the final answer is about stored procedures, please, put down an example to show me how to construct this "lengthy" select, together with the DB connection (connection string) and the way to read back the values found. If possible, in VB.NET.

Cheers lads
Start Free Trial
 
Keywords: Speed up big SQL SELECT
 
Loading Advertisement...
 
[+][-]04.19.2008 at 06:27PM PDT, ID: 21394692

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.19.2008 at 09:05PM PDT, ID: 21394979

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.19.2008 at 09:12PM PDT, ID: 21394987

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 07:02AM PDT, ID: 21396022

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.20.2008 at 08:39AM PDT, ID: 21396428

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 08:44AM PDT, ID: 21396443

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 08:58AM PDT, ID: 21396504

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 04:35PM PDT, ID: 21397991

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 05:36PM PDT, ID: 21398111

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 06:44PM PDT, ID: 21398264

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 07:10PM PDT, ID: 21398359

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 07:49PM PDT, ID: 21398500

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 08:21PM PDT, ID: 21398672

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 09:58PM PDT, ID: 21398931

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.20.2008 at 10:59PM PDT, ID: 21399052

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 12:27AM PDT, ID: 21399333

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 10:33AM PDT, ID: 21404109

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 11:21AM PDT, ID: 21404542

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, VB Database Programming, .Net Editors & IDEs
Tags: VB.NET
Sign Up Now!
Solution Provided By: mark_wills
Participating Experts: 3
Solution Grade: A
 
 
[+][-]04.21.2008 at 12:02PM PDT, ID: 21404885

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 12:09PM PDT, ID: 21404958

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.21.2008 at 01:04PM PDT, ID: 21405432

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.22.2008 at 12:46AM PDT, ID: 21408797

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628