[GH-ISSUE #190] .sort causes each item to be read again #91

Closed
opened 2026-05-23 08:30:14 -06:00 by gitea-mirror · 3 comments
Owner

Originally created by @meaningg on GitHub (Dec 17, 2022).
Original GitHub issue: https://github.com/appy-one/acebase/issues/190

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

with .sort
image

without .sort
image

Originally created by @meaningg on GitHub (Dec 17, 2022). Original GitHub issue: https://github.com/appy-one/acebase/issues/190 .sort causes each item to be read from the database a second time - is it okay ? with .sort ![image](https://user-images.githubusercontent.com/61989272/208239938-b339f4c7-d7bc-4a00-a02d-f8bff8b21edd.png) without .sort ![image](https://user-images.githubusercontent.com/61989272/208239951-0a2c8223-65c3-4d43-adf6-3c563e071f74.png)
Author
Owner

@appy-one commented on GitHub (Dec 19, 2022):

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

<!-- gh-comment-id:1357277303 --> @appy-one commented on GitHub (Dec 19, 2022): 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
Author
Owner

@meaningg commented on GitHub (Dec 19, 2022):

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

<!-- gh-comment-id:1357637639 --> @meaningg commented on GitHub (Dec 19, 2022): Yes, I use a combination of .sort and .take. Now that explains it all. Thank you!
Author
Owner

@appy-one commented on GitHub (Dec 19, 2022):

You're welcome!

Spread the word contribute Sponsor AceBase

<!-- gh-comment-id:1358367000 --> @appy-one commented on GitHub (Dec 19, 2022): You're welcome! [![Spread the word](https://user-images.githubusercontent.com/26569719/169265089-3d593555-e1ad-4390-986b-877ac2c38a47.svg)](https://twitter.com/intent/tweet?button=&url=https://github.com/appy-one/acebase&text=I'm+using+@AcebaseRealtime+in+my+project+to+make+my+life+easier!&button=) [![contribute](https://user-images.githubusercontent.com/26569719/169265318-30c4c6a5-7c89-46a0-a7a2-ef433a8192f4.svg)](https://github.com/appy-one/acebase#contributing) [![Sponsor AceBase](https://user-images.githubusercontent.com/26569719/168233053-8e56b243-4140-40ab-9a30-4cb3cc149bfe.svg)](https://github.com/sponsors/appy-one)
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference: github-starred/acebase#91
No description provided.