all groups > sql server (alternate) > january 2007 >
You're in the

sql server (alternate)

group:

Querying towards a responsive UI



Querying towards a responsive UI shripathikamath NO[at]SPAM gmail.com
1/31/2007 11:04:26 AM
sql server (alternate): I realize that this may not be the correct ng for this question, and
if so, I'd appreciate a pointer to the correct group.

I am not including DDL/DML for this question, because I do not believe
it is relevant.

What I have is a SQL query, which when executed in Query Analyzer
takes about 10-12 seconds. From the time I issue the query, I see an
initial lag of about 1 seconds after which the grid starts getting
populated, and then runs its course.

The UI responsiveness is impressive. Almost immediately, well, within
1 second at most, I see data appear from the server into my query
analyzer grid.

I'd like to get the same responsiveness if possible on my client
application written in C# using ADO.NET.


I use the SqlDataReader class off the SqlCommand class to make the
same query (identical), and yet it takes close to 9 or 10 seconds
before even the first row is retrieved by the application. I am not
saying that it takes 9 or 10 second for my DataGrid to start being
populated; it is simply that the first Read operation of the
SqlDataReader after I connect (which is instantaneous), that takes 9
to 10 seconds. Once the data retrieval starts, the grid populates in
short order.

Are there any pointer by which I can get just a few rows fast enough
to give the user the impression that the query is executing. In other
words, what techniques can I use to get the same sort of
responsiveness as in the SQL query analyzer?

In case it is relevant, there are some 250,000 rows returned by the
query.

Thanks for all helpful responses in advance.
Re: Querying towards a responsive UI Erland Sommarskog
1/31/2007 11:09:34 PM
(shripathikamath@gmail.com) writes:
[quoted text, click to view]

Eh? If you have results to grid in QA, you will not see anything
until the batch has completed.

Do you mean Results to text? In this mode, rows are displayed as
they arraive.

[quoted text, click to view]

Try adding OPTION (FAST 10) at the end of the query. This may have
an adverse effect on the total execution time though.

[quoted text, click to view]

But it may also be an issue with ADO .Net when you have so many rows.
I would expect SqlClient to not buffer all rows before it opens the
reader, but maybe it does. Maybe they know more in a group like
microsoft.public.dotnet.framework.adonet.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Re: Querying towards a responsive UI Plamen Ratchev
2/1/2007 5:45:37 AM
DataReader by definition returns data as the query executes, one row at a
time. The only buffering occurs on the client where data is kept in the
network buffer until requested by the Read method. Based on that you should
be seeing faster response.

Do you use an ORDER BY clause in your query? That could be the issue, since
in that case the data needs to be sorted on the SQL Server side before the
first row is returned.

Is there any reason to display all 250,000 rows in your DataGrid? I have
implemented many similar client applications and the best way to handle huge
load has been to use paging. Normally 25-100 records per page are easy for
users to look through. With that page size returning data is instantaneous.
Then provide direct links to the other pages and allow users to jump quickly
to a page.

Here is an article with a few useful hints on optimizing ADO.NET
performance:
http://msdn2.microsoft.com/en-us/library/ms998569.aspx

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Re: Querying towards a responsive UI Plamen Ratchev
2/1/2007 6:29:41 AM
Forgot to mention that if you have an ORDER BY clause then having an
appropriate index will help.

Plamen Ratchev
http://www.SQLStudio.com

Re: Querying towards a responsive UI shripathikamath NO[at]SPAM gmail.com
2/1/2007 4:38:18 PM
[quoted text, click to view]

Thanks, I'll try your suggestion.


I must make a correction: It was not Query Analyzer, it was the Query
Window in the Management Studio tools
Re: Querying towards a responsive UI shripathikamath NO[at]SPAM gmail.com
2/1/2007 4:44:46 PM
[quoted text, click to view]


I don't, but I do not see the relevance. The *exact* same query in
the Query Window of Management Studio starts executing immediately,
and the grid starts populating within a second, where as the
DataReader takes about 8-10 seconds before the first row is returned.


[quoted text, click to view]

Yes, it is a customer requirement. The idea is to start populating,
and continue populating the grid in the background, and the user can
see that more rows are being retrieved, and he can cancel the
retrieval at any time.

Look at the Query Window in the Management Studio, that is exactly the
behavior I seek.


[quoted text, click to view]

Yes, I know of that technique.

[quoted text, click to view]


Thanks.
Re: Querying towards a responsive UI Plamen Ratchev
2/2/2007 3:24:10 AM
[quoted text, click to view]

I pointed this out only because in my experiments with DataReader I have
seen the effect of ORDER BY. As for the comparison with the Query Window I
do not know what method was used to retrieve the data there, so it might not
be possible to achieve the same result with DataReader.

[quoted text, click to view]

Here is another idea. If you are using ADO.NET 2.0 you can explore the new
asynchronous execution. Maybe you can break your big result set to smaller
sets (similar to paging) and return each set asynchronously.

http://msdn2.microsoft.com/en-us/library/ms379553(VS.80).aspx

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Re: Querying towards a responsive UI Erland Sommarskog
2/2/2007 11:08:23 PM
(shripathikamath@gmail.com) writes:
[quoted text, click to view]

Since MgmtStudio uses SqlClient to connect to SQL Server, this means
that you should be able to do this in your program as well.

If you haven't already, you should probably talk with the people in
microsoft.public.dotnet.framework.adonet. It probably helps if your
post your actual code, so that any flaws can be uncovered.


--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
Re: Querying towards a responsive UI shripathikamath NO[at]SPAM gmail.com
2/3/2007 8:18:13 PM
[quoted text, click to view]


Thank you Erland, I followed your advice and posted in the appropriate
newsgroup. While the OPTION (FAST 10) did not make a difference, it
was something that I learned, and may come in handy in the future.

Thanks to everyone who responded.
AddThis Social Bookmark Button