Question

i am working on a table which currently contains 100000 records, and will be more and more in future, now my clients want the LATEST TOP 10 RECORDS...

using top clause diminishes the performance, and as this is the mobile application, performance is the only concern, so is there any alternate and the best way for getting Latest Top 10 records also the order by could result in loss of performance

does these two have any best performance alternative..

Était-ce utile?

La solution

I think the best option is use another table where you have the latest 10 records.

So, when your app insert a record, it has to record it in both tables... The big one and the top 10 one. Or it is possible to do a trigger that do this work.

Autres conseils

Using the TOP clause hurts performance only because you don't have the proper index on the date field (or whatever field you are using to identify the 10 latest). For a query like:

SELECT TOP 10 OrderID, OrderDate, TotalPrice, Shipping, Status
FROM CustomerOrder
ORDER By OrderDate DESC

You'll need (ideally) an index on:

(OrderDate, OrderID) INCLUDE (TotalPrice, Shipping, Status)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top