Fetching in a loop slows down in SqlServer

General discussion forum about all databases other than SqlBase.
FRBhote
India
Posts: 2201
Joined: 09 Mar 2017, 05:32
Location: Hyderabad, India

Fetching in a loop slows down in SqlServer

Post by FRBhote » 05 Sep 2015, 11:51

When I prepare once:

SELECT something FROM something INTO :something WHERE something = :something

and
SqlExecute
SqlFetchNext

in a loop, after a couple of hundred times, it becomes ultra slow. What could be the reason? TD 2.1

FRBhote
India
Posts: 2201
Joined: 09 Mar 2017, 05:32
Location: Hyderabad, India

Re: Fetching in a loop slows down in SqlServer

Post by FRBhote » 05 Sep 2015, 13:29

Funny... If there is a delay introduced then it becomes much faster.

Jeff Luther
Site Admin
Site Admin
United States of America
Posts: 2370
Joined: 04 Mar 2017, 18:34
Location: Palm Springs, California

Re: Fetching in a loop slows down in SqlServer

Post by Jeff Luther » 05 Sep 2015, 16:29

"If there is a delay introduced... -- when/where in the Loop? And what type of delay? SalPause()?

the
WHERE something = :something
is what catches my eye and I recall some issue some time ago about a bind in the WHERE clause vs. something like:
"... WHERE something = "|| <concat. string version of something>
Though you'll need to call SqlExecute() each time if you concatenate.

Since CTD v2.1 was so long ago it might have been a bug that got fixed in a later TD too. You might want to search this forum to see if this has been discussed before. Maybe it a memory alloc. issue with CTD? (If so, though, why the speed-up if you add a delay?) Let us know if you find out any more.

BTW, if you have a later TD installed (like latest PTF v4.2 for a non-Unicode issue, or v5.2 for Unicode testing), and you have a test case for this (1000 rows in a test DB table, etc.) then I'd try running your test with a later TD to see if there's an improvement.
Jeff Luther @ PC Design
Palm Springs, California

Return to “General Discussion”

Who is online

Users browsing this forum: [Ccbot] and 0 guests