appy-one / acebase

A fast, low memory, transactional, index & query enabled NoSQL database engine and server for node.js and browser with realtime data change notifications
MIT License
488 stars 27 forks source link

.sort causes each item to be read again #190

Closed meaningg closed 1 year ago

meaningg commented 1 year ago

.sort causes each item to be read from the database a second time - is it okay ?

with .sort image

without .sort image

appy-one commented 1 year ago

It's a bit hard to say without the rest of your code, but if you are using sort in combination with take and skip, it will first need to determine which nodes should be loaded for the result set. If you have no index on the target sort column(s), it needs to perform a "table scan" to read all sort column(s) values. Then, it will read all requested data from nodes that are in the take / skip window: those records will have effectively been read twice.

Without sort, using take / skip is a as easy as just skipping n child nodes, then reading m nodes once

meaningg commented 1 year ago

Yes, I use a combination of .sort and .take. Now that explains it all. Thank you!

appy-one commented 1 year ago

You're welcome!

Spread the word contribute Sponsor AceBase