Article View: borland.public.cppbuilder.database.ado
Article #339Re: Too Slow
From: Arnie
Date: Wed, 09 Aug 2006 16:29
Date: Wed, 09 Aug 2006 16:29
86 lines
3261 bytes
3261 bytes
You have been given some good advice here. I'll try to add to it.
"Cenk" <cenk1536@yahoo.com> wrote in message
news:44d8a854@newsgroups.borland.com...
> Hi,
>
> i have a code sample below,
>
> TADODataSet *CountQuery = new TADODataSet(this);
> CountQuery->ConnectionString = "Provider=SQLOLEDB.1;Integrated
> Security=SSPI;Persist Security Info=False;Initial
> Catalog=Raw;Data Source=CENK";
> CountQuery->CommandTimeout = 0;
// Why aren't you using a TADOConnection and creating the
TADODataset on it. Is there any particular reason you need a new
connection for the dataset?
>
>
// You have just created CountQuery. There's no reason for this.
> if (CountQuery->Active)
> CountQuery->Close ();
>
>
> CountQuery->CommandText = "select [bid],[fTime] from
> ["+table+"] order by [fTime] ASC";
// "ASC" is the default,but ifyou're a stickler ...
// When you know you'regoing to be dealing with a lot of records
...
CountQuery->CursorLocation = clUseServer;
CountQuery->CacheSize = 1000;
CountQuery->LockType = ltReadOnly;
CountQuery->CursorType = ctOpenForwardOnly;
> CountQuery->Open ();
// As VVV has said:
VField * fBid = CountQuery->FieldByName ("bid");
VField * fTime = CountQuery->FieldByName ("fTime");
// This avoids the overhead of looking up the field by name on
each iteration of the loop.
// We're guessing the table may contain 1000000 rows. So let's
be generous.
v_bid.reserve( 1500000 );
v_time.reserve( 1500000 );
// Note that if there are 1500001 rows, the vectors will realloc
to 3000000 elements.
>
> while (!CountQuery->Eof) -------> table has 1000000 rows of
> data inside but this loop takes appox. 45 minutes to complete!
> {
>
> // v_bid.push_back(CountQuery->FieldByName
> ("bid")->AsFloat);
v_bid.push_back( fBid->AsFloat );
>
> // v_time.push_back(CountQuery->FieldByName
> ("fTime")->AsDateTime);
v_time.push_back( fTime->AsDateTime );
>
> CountQuery->Next ();
> }
>
> why is this too slow? any suggestions?
Yes, see above.
> thanks
You're welcome.
As someone else said, you'd need an index on fTime for the ORDER
BY for decent performance.
ADO needs to be pretty finely tuned for good performance. It
might take some experimentation.
Good Luck,
- Arnie
Technical Details
Message-ID:
<44da0c88$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<44d8a854@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,9e074baf94073a9a X-Google-Attributes: gid10698b,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Arnie" <none> Newsgroups: borland.public.cppbuilder.database.ado References: <44d8a854@newsgroups.borland.com> Subject: Re: Too Slow Date: Wed, 9 Aug 2006 12:29:04 -0400 Lines: 88 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.2869 X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2869 X-RFC2646: Format=Flowed; Response NNTP-Posting-Host: 24.151.53.204 Message-ID: <44da0c88$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1155140744 24.151.53.204 (9 Aug 2006 09:25:44 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail