-
Notifications
You must be signed in to change notification settings - Fork 14
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
scan: fix filter erroneous early exit #419
Merged
DifferentialOrange
merged 2 commits into
master
from
DifferentialOrange/gh-418-conditions-order
Feb 5, 2024
Merged
scan: fix filter erroneous early exit #419
DifferentialOrange
merged 2 commits into
master
from
DifferentialOrange/gh-418-conditions-order
Feb 5, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DifferentialOrange
force-pushed
the
DifferentialOrange/gh-418-conditions-order
branch
2 times, most recently
from
February 5, 2024 07:35
0142c03
to
660ac7f
Compare
oleg-jukovec
approved these changes
Feb 5, 2024
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.
Thank you for the patch!
The issue described below is related to the read operations which allows to scan: `crud.select`, `crud.pairs`, `crud.count`, `readview:select` and `readview:pairs`. The erroneous behavior reported by [1] and #418 is as follows: - result changes when reordering operation conditions; - when `>=` condition operation is changed to `=`, there are more rows in the result. The reason is as follows. Scanning read operates with two entities: an iterator and a filter. The iterator includes an index, a starting value and iterator type (EQ, GT, etc.). The iterator is built from conditions, if possible, otherwise primary index is used. Remaining conditions form the filter, so the actual result satisfies all operation conditions. The filter supports early exit. Let's consider the following example. For `crud.select(space, {{'>=', 'id', 1}, {'<=', 'id', 10}})`, where `id` is an index (or an indexed field), the iterator uses index `id`, starts from key = `1` and goes by GE rules, covering [1, +inf) ordered keys. On the other hand, when iterator reaches the tuple with `id` = `11`, all tuples after this one will never satisfy the second condition, because our iterator yields tuples sorted by `id` (due to underlying index). So filter tells than there is no reason to scan anymore, and we finish the scanning procedure. Before this patch, the function behind early exit decision had worked as follows: "if the condition is an index, we go in forward (reverse) order and `<=` or `<` (`>=` or `>`) condition is violated, there is no reason to scan anymore". But the valid approach is "if the condition is SCANNING index...". Before this patch, filter had assumed that if the condition for index is specified, tuples are ordered, but it works only if iterator uses the same index as in the condition. This patch fixes the issue. The erroneous behavior may happen in the following case: - there are multiple conditions, - there are at least two different index operands, - non-scanning index condition uses `<=`, `<`, `>=` or `>` operation. 1. https://jira.vk.team/browse/TNT-941 Closes #418
DifferentialOrange
force-pushed
the
DifferentialOrange/gh-418-conditions-order
branch
from
February 5, 2024 11:44
660ac7f
to
52e3deb
Compare
DifferentialOrange
deleted the
DifferentialOrange/gh-418-conditions-order
branch
February 5, 2024 11:59
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The issue described below is related to the read operations which allows to scan:
crud.select
,crud.pairs
,crud.count
,readview:select
andreadview:pairs
.The erroneous behavior reported by [1] and #418 is as follows:
>=
condition operation is changed to=
, there are more rows in the result.The reason is as follows. Scanning read operates with two entities: an iterator and a filter. The iterator includes an index, a starting
value and iterator type (EQ, GT, etc.). The iterator is built from conditions, if possible, otherwise primary index is used. Remaining conditions form the filter, so the actual result satisfies all operation conditions.
The filter supports early exit. Let's consider the following example. For
crud.select(space, {{'>=', 'id', 1}, {'<=', 'id', 10}})
, whereid
is an index (or an indexed field), the iterator uses indexid
, starts from key =1
and goes by GE rules, covering [1, +inf) ordered keys. On the other hand, when iterator reaches the tuple withid
=11
, all tuples after this one will never satisfy the second condition, because our iterator yields tuples sorted byid
(due to underlying index). So filter tells than there is no reason to scan anymore, and we finish the scanning procedure.Before this patch, the function behind early exit decision had worked as follows: "if the condition is an index, we go in forward (reverse) order and
<=
or<
(>=
or>
) condition is violated, there is no reason to scan anymore". But the valid approach is "if the condition is SCANNING index...". Before this patch, filter had assumed that if the condition for index is specified, tuples are ordered, but it works only if iterator uses the same index as in the condition. This patch fixes the issue.The erroneous behavior may happen in the following case:
<=
,<
,>=
or>
operation.Closes #418