-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sql: clarify/fix the meaning of "Datum comparisons"
Prior to this patch, the interface method `(Datum).Compare()` had the dual role to *order* datums (which requires a total relation) and to *compare* datums in the SQL logical sense where NULLs have a special behavior. Contrary to intuition, the two relations are not derivable from each other and need separate code. The implementation of the `Compare()` method is currently tailored towards ordering (although it also contains a bug in that role) and, meanwhile, does not suitably perform SQL logical comparisons. So there two groups of issues at hand: - every caller of `Compare()` which is interested in a SQL logical comparison other than "distinctness" is mistaken+erroneous. - every caller of `Compare()` which is interested in ordering is currently subject to a bug/limitation of `Compare()` in some edge cases involving tuples of arrays containing NULL elements. The fix to the 2nd issue, which will come in a later patch, will cause the ordering function to become *completely* inadequate to perform SQL logical comparisons. This, in turn, will really require two separate interfaces for the two comparison functions. In advance of that patch, this first commit creates a new API for datum comparisons. It is defined as follows (`tree/compare.go`): ```go // This implements the comparators for three separate relations. // // - a total ordering for the purpose of sorting and searching // values in indexes. In that relation, NULL sorts at the // same location as itself and before other values. // // Functions: TotalOrderLess(), TotalOrderCompare(). // // - the logical SQL scalar partial ordering, where non-NULL // values can be compared to each others but NULL comparisons // themselves produce a NULL result. // // Function: scalarCompare() // // - the IS [NOT] DISTINCT relation, in which every value can // be compared to every other, NULLs are distinct from every // non-NULL value but not distinct from each other. // // Function: Distinct(). // // Due to the way the SQL language semantics are constructed, it is // the case Distinct() returns true if and only if // TotalOrderCompare() returns nonzero. However, one should be // careful when using this methods to properly convey *intent* to the // reader of the code: // // - the functions related to the total order for sorting should only // be used in contexts that are about sorting values. // // - Distinct() and scalarCompare() should be used everywhere else. // // Besides, separating Distinct() from TotalOrderCompare() enables // later performance optimizations of the former by specializing the // code. This is currently done for e.g. EncDatums. ``` This commit only introduces the new API without change in behavior. Release note: None
- Loading branch information
Showing
43 changed files
with
445 additions
and
309 deletions.
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
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.