-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Reject invalid ASIN and ACOS arguments and fix PK index for other numeric data types #3985
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
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.
What this is all about? MVPrimaryIndex is a data table itself. It's key is always of type long and values are data rows of type SearchRow. How would you make this new code ever execute?
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.
There is a mandatory requirement from the SQL Standard: all numeric data types are comparable with algebraic rules.
H2 (and some other database systems, such as PostgreSQL) additionally support non-finite IEEE values: positive and negative infinities and NaN. For infinities comparison rules are obvious, for NaN they aren't that clear, but H2 behaves exactly as PostgreSQL.
If operand of comparison operation is a numeric column with an index, we usually can't just convert value of other operand into data type of this column, because its data type usually can't hold all possible numeric values.
For example, a query with
WHERE ID > 1e100
is perfectly valid forBIGINT
column, butBIGINT
data type isn't large enough for1e100
, that's why all modern versions of H2 don't perform such conversion.When we use
MVSecondardyIndex
, numeric values with different data types (BIGINT
from this index andDECFLOAT
or whatever else from the search row) can be compared directly.But
MVDelegateIndex
is a different thing. It is based onMVPrimaryIndex
and there is a real problem: it doesn't useValue
instances as its keys. It usesLong
objects instead. We can't compareLong
withValue
, so H2 historically has a quirk forNULL
(it isn't changed here). But what can we do with infinities or other large values? The simplest solution is to map negative infinities and values smaller thanLong.MIN_VALUE
toLong.MIN_VALUE
and positive infinities, NaNs and values larger thanLong.MAX_VALUE
toLong.MAX_VALUE
. The only drawback of such mapping is a possible selection of rows with these boundary values when these rows aren't required, but it is cheap enough.These cases can be improved: we can return an empty cursor if there is nothing to select, but I think it will require many additional conditions in the code.
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.
As an accountant and engineer I can only ask: Please let's not do that! If I understand this correctly, 'NaN" will suddenly match Long.MAX_VALUE and if my table actually holds a value Long.MAX_VALUE we would return a match?! This was a typical Boing 737 Max condition!
I know, chances this to happen are slim, but impact when it happens may be very big.
So the "Best Estimate" may still be very big despite the small odds.
We should never return wrong result sets, but better throw an exception. Because then I have a chance to know that I am on my own.
(Similar to the
WITH ...
returning no records when having parameters: an exception about unsupported feature would be much better than wrongly no records.)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.
No, it will not be returned. Index cursors created with index conditions may return additional rows, each row will be re-tested anyway.
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.
Ok then, thank you for re-assurance!
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.
I rewrote this method, new implementation returns an empty cursor when possible. It also avoids creation of lower and upper bounds for MVStore cursor when these sides aren't limited by index condition or when lower condition is smaller than any
BIGINT
value or upper condition is larger than anyBIGINT
value. New implementation has many branches, but they are covered by unit tests.