简体   繁体   中英

WCF Connection very slow - Is the WPF Client the issue or the SQL Query?

I have a SQL Server database with table containing 300.000 data rows. There is an Index on the Primary Key and another key. I am using the following query in my standalone WCF server to fetch the data using an SQLConnection and SQLDataReader.

SELECT * FROM Users WHERE UserTypeId = @UserTypeId ORDER BY Users.Id OFFSET    
@OFFSET ROWS FETCH NEXT @NUMBER ROWS ONLY

The Data returned by the DataReader is pushed into my own Class/Model and than returned by the function of the WCF server.

The WPF Client connects to the server and starts the command and only wants 500 data rows. However the time needed for this task is about 3-4 seconds. (Not mentioning the time for all data...)

The returned List is then used as the DataContext for the WPF Datagrid.

My question is, what can I check or what might be wrong. If you need more Information,CodeSamples,etc. please let me know!

First, don't use select * , instead specify what fields you want from the table. Now you are getting data that you don't need, for example the UserTypeId field which you already know for all the records that you get.

Then you can create a covering index that contains UserTypeId and Id , and has any other fields that you want to return from the query as included fields. That way the database can run the query against the index alone, and doesn't have to read anything from the actual table.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM