A
A
Alexey Lebedev2014-04-23 14:55:05
SQL
Alexey Lebedev, 2014-04-23 14:55:05

How to implement user selection in online MS SQL?

There is a table for 200,000 records with the following indexes:
location (ASC), freebonus_day (DESC)
freebonus_day (DESC)
vkid (DESC) - primary cluster.
arena_win (DESC)
credits (DESC)
exp (DESC)
level (DESC), search_name (DESC)
side (ASC)
win (DESC)
work (DESC)
Just in case, I gave all indexes.
We execute the following query:
SELECT TOP 100 vkid, online, side, name, level FROM sw.dbo.users where [email protected] and freebonus_day<@next_day and freebonus_day>@prev_day and vkid>-100 order by online DESC;
Query plan: habrastorage.org/files/046/5df/ed2/0465dfed236843f...
(too wide)
The request is executed on average in: 0.67 ms, I would consider this normal, but such a query plan made me think that something was wrong.
The online field is not indexed because it is updated every few seconds.
Now most of the CPU time is spent by 2 queries:
1) this one
2) setting the user online ( UPDATE sw.dbo.users SET [email protected] WHERE vkid = @vkid;)
Here are the most difficult queries:
e0356aff44114af7ba75c7aa40749219.png
Interested in how you can speed it all up?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DimonZ, 2014-04-23
@DimonZ

In the execution plan that you provided for the search, the IX_Users_online index is used, it is not clear from the information you provided which fields it includes.
You can speed up the query by creating a special index for this query.
Most likely, an index built on the location field is well suited, but with included columns, including freebonus_day, vkid and online
You can add other fields that are already used in the selection (side, name, level), but this can lead to an increase in size index and slowing down the insertion, but the DBMS will not have to do an additional search by PK.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question