improve search performance by scanning with the timestamp index iteratively #2698
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Or else SQLite uses the
command
index and sort. Even with thetimestamp
index, SQLite still needs sort.This is what atuin uses:
Try to tell SQLite to use the
timestamp
index. Slightly faster.The fastest index to use is...not to use an index at all.
The following one is very fast, but it might not fetch enough rows due to duplications. So we do the deduplication ourselves instead and let SQLite just scan using the index and never sort. The downside of this method is that it doesn't perform well when there are too many duplicates, hence #2697.
For the following command, the elapsed times are (lowest among several runs):
atuin search --search-mode fuzzy --limit 100 --cmd-only > /dev/null
See also #475, #493, #2015.
BTW, the
idx_history_command
index is unnecessary since there isidx_history_command_timestamp
.The SQL atuin used is something like:
The
HAVING max(timestamp)
part doesn't seem right.SELECT
says:So
HAVING max(timestamp)
is true all the time, and we are not sure which row is outputted. In the following section it saysBut it refers to the columns being
select
ed, not in theHAVING
clause.Checks