-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow order by on non-indexed fields #1961
Conversation
d884c10
to
3026ce1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we have some small benchmark for this PR? just to know if there are implications for performance
@@ -75,3 +80,8 @@ func (opts *Options) WithMultiDBHandler(multidbHandler MultiDBHandler) *Options | |||
opts.multidbHandler = multidbHandler | |||
return opts | |||
} | |||
|
|||
func (opts *Options) WithSortBufferSize(size int) *Options { | |||
opts.sortBufferSize = size |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should document it - what it is, what will increase of this value provide, what if we will set to 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added validity check and description
} | ||
|
||
if sortingIndex == nil { | ||
return nil, ErrNoAvailableIndex |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this could potentially affects current users code, should be communicated somehow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated doc: codenotary/immudb.io#510
Signed-off-by: Stefano Scafiti <[email protected]>
9b630ad
to
a2d377a
Compare
This merge request is meant to support the order by clause on non indexed fields.
If the query planner determines that the output is not already sorted, then an additional sorting step is added through a new type of reader:
sortReader
.When the client attempts to read the first row on the sort reader, all rows gets fetched from the underlying reader and collected to a buffer. When the buffer contains at least 1024 rows, sorting is performed in memory and the sorted chunk is spilled to a temporary disk file. The process continues until all the result rows have been read.
At this point, sorted disk chunks (if any) are merged into a single bigger sorted chunk and a reader to such a file is returned to the client. If the output contains a number of rows <= 1024, then a reader to the buffer is simply returned.