forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
opt: add a range operator to fix selectivity estimation of range pred…
…icates This commit adds a new scalar operator called Range. Range contains a single input, which is an And expression that constrains a single variable to a range. For example, the And expression might be x >= 6 AND x <= 10. This commit also adds a new normalization rule called ConsolidateSelectFilters, which consolidates filters that constrain a single variable, and puts them into a Range operation. For example, filters x >= 6 and x <= 10 would be consolidated into a single Range operation. The benefit of consolidating these filters is it allows a single constraint to be generated for the variable instead of multiple. In the example above, we can generate the single constraint [/6 - /10] instead of the two constraints [/6 - ] and [ - /10]. The single constraint allows us to better estimate the selectivity of the predicate when calculating statistics for the Select expression. For example, suppose that x initially has 1,000,000 distinct values. Once we apply the predicate x >= 6 AND x <= 10, it has at most 5 distinct values. Assuming a uniform data distribution, the selectivity of this predicate is 5/1,000,000, or 0.000005. Prior to this commit, we were significantly overestimating the selectivity as 1/9, or 0.111111. Fixes cockroachdb#35947 Release note (performance improvement): Improved the selectivity estimation of range predicates during query optimization.
- Loading branch information
Showing
24 changed files
with
2,996 additions
and
464 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
Oops, something went wrong.