Skip to content
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

opt: build partial index predicates as FiltersExprs #51164

Merged
merged 1 commit into from
Jul 9, 2020

Conversation

mgartner
Copy link
Collaborator

@mgartner mgartner commented Jul 8, 2020

This commit updates optbuilder to build a partial index predicate as
FiltersExpr instead of an arbitrary ScalarExpr. The primary reason for
doing so is to make it easier to calculate statistics for partial index
scans. By representing the predicate as a FiltersExpr, the statistics
builder can generate stats for partial index scans using existing
functions that help generate statistics for Selects.

SimplifyFilters and ConsolidateFilters are manually called on the
predicate so that it is similar in form to a normalized Select filter.
Flattening the expression and generating constraints for each top-level
conjunction will make it simpler and cheaper to calculate stats
accurately for unapplied conjunctions.

This commit also updates Implicator to handle predicates that are
FiltersExprs and have RangeExprs in them. This change benefits the
performance of Implicator significantly in some of the slowest
benchmark cases because flattening predicate conjunctions means that the
exact-match fast path can prove implication in more cases. This change
only worsens performance significantly in some of the fastest cases that
take <400ns/op.

name                                               old time/op  new time/op  delta
Implicator/single-exact-match-16                   61.7ns ± 0%  89.1ns ± 0%  +44.47%  (p=0.008 n=5+5)
Implicator/single-inexact-match-16                  878ns ± 0%   912ns ± 1%   +3.94%  (p=0.008 n=5+5)
Implicator/range-inexact-match-16                  2.32µs ± 2%  2.40µs ± 1%   +3.78%  (p=0.008 n=5+5)
Implicator/single-exact-match-extra-filters-16      321ns ± 1%   371ns ± 1%  +15.70%  (p=0.008 n=5+5)
Implicator/single-inexact-match-extra-filters-16   4.00µs ± 0%  4.11µs ± 1%   +2.78%  (p=0.008 n=5+5)
Implicator/multi-column-and-exact-match-16          455ns ± 0%   100ns ± 1%  -78.02%  (p=0.016 n=4+5)
Implicator/multi-column-and-inexact-match-16       1.94µs ± 1%  1.97µs ± 0%   +1.32%  (p=0.040 n=5+5)
Implicator/multi-column-or-exact-match-16          62.1ns ± 0%  91.4ns ± 0%  +47.23%  (p=0.008 n=5+5)
Implicator/multi-column-or-exact-match-reverse-16  1.72µs ± 0%  1.79µs ± 0%   +4.08%  (p=0.008 n=5+5)
Implicator/multi-column-or-inexact-match-16        2.18µs ± 0%  2.25µs ± 1%   +3.56%  (p=0.008 n=5+5)
Implicator/and-filters-do-not-imply-pred-16        3.65µs ± 2%  3.76µs ± 5%     ~     (p=0.056 n=5+5)
Implicator/or-filters-do-not-imply-pred-16          774ns ± 1%   850ns ± 1%   +9.71%  (p=0.008 n=5+5)
Implicator/many-columns-exact-match10-16           4.93µs ± 1%  0.30µs ± 1%  -93.87%  (p=0.008 n=5+5)
Implicator/many-columns-inexact-match10-16         11.3µs ± 1%  11.1µs ± 0%   -1.86%  (p=0.008 n=5+5)
Implicator/many-columns-exact-match100-16           352µs ± 1%    18µs ± 1%  -94.92%  (p=0.008 n=5+5)
Implicator/many-columns-inexact-match100-16         382µs ± 1%   372µs ± 1%   -2.47%  (p=0.008 n=5+5)

Release note: None

@mgartner mgartner requested a review from a team as a code owner July 8, 2020 17:56
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@mgartner mgartner force-pushed the predicate-filters-expr branch from 9cc10c7 to 2f593db Compare July 8, 2020 17:59
Copy link
Member

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

@mgartner mgartner force-pushed the predicate-filters-expr branch from 2f593db to b56a675 Compare July 8, 2020 22:39
@mgartner
Copy link
Collaborator Author

mgartner commented Jul 8, 2020

bors r=RaduBerinde

@mgartner
Copy link
Collaborator Author

mgartner commented Jul 9, 2020

bors r=RaduBerinde

@craig
Copy link
Contributor

craig bot commented Jul 9, 2020

Build failed

This commit updates optbuilder to build a partial index predicate as
`FiltersExpr` instead of an arbitrary ScalarExpr. The primary reason for
doing so is to make it easier to calculate statistics for partial index
scans. By representing the predicate as a `FiltersExpr`, the statistics
builder can generate stats for partial index scans using existing
functions that help generate statistics for Selects.

`SimplifyFilters` and `ConsolidateFilters` are manually called on the
predicate so that it is similar in form to a normalized Select filter.
Flattening the expression and generating constraints for each top-level
conjunction will make it simpler and cheaper to calculate stats
accurately for unapplied conjunctions.

This commit also updates `Implicator` to handle predicates that are
`FiltersExpr`s and have `RangeExpr`s in them. This change benefits the
performance of `Implicator` significantly in some of the slowest
benchmark cases because flattening predicate conjunctions means that the
exact-match fast path can prove implication in more cases. This change
only worsens performance significantly in some of the fastest cases that
take <400ns/op.

    name                                               old time/op  new time/op  delta
    Implicator/single-exact-match-16                   61.7ns ± 0%  89.1ns ± 0%  +44.47%  (p=0.008 n=5+5)
    Implicator/single-inexact-match-16                  878ns ± 0%   912ns ± 1%   +3.94%  (p=0.008 n=5+5)
    Implicator/range-inexact-match-16                  2.32µs ± 2%  2.40µs ± 1%   +3.78%  (p=0.008 n=5+5)
    Implicator/single-exact-match-extra-filters-16      321ns ± 1%   371ns ± 1%  +15.70%  (p=0.008 n=5+5)
    Implicator/single-inexact-match-extra-filters-16   4.00µs ± 0%  4.11µs ± 1%   +2.78%  (p=0.008 n=5+5)
    Implicator/multi-column-and-exact-match-16          455ns ± 0%   100ns ± 1%  -78.02%  (p=0.016 n=4+5)
    Implicator/multi-column-and-inexact-match-16       1.94µs ± 1%  1.97µs ± 0%   +1.32%  (p=0.040 n=5+5)
    Implicator/multi-column-or-exact-match-16          62.1ns ± 0%  91.4ns ± 0%  +47.23%  (p=0.008 n=5+5)
    Implicator/multi-column-or-exact-match-reverse-16  1.72µs ± 0%  1.79µs ± 0%   +4.08%  (p=0.008 n=5+5)
    Implicator/multi-column-or-inexact-match-16        2.18µs ± 0%  2.25µs ± 1%   +3.56%  (p=0.008 n=5+5)
    Implicator/and-filters-do-not-imply-pred-16        3.65µs ± 2%  3.76µs ± 5%     ~     (p=0.056 n=5+5)
    Implicator/or-filters-do-not-imply-pred-16          774ns ± 1%   850ns ± 1%   +9.71%  (p=0.008 n=5+5)
    Implicator/many-columns-exact-match10-16           4.93µs ± 1%  0.30µs ± 1%  -93.87%  (p=0.008 n=5+5)
    Implicator/many-columns-inexact-match10-16         11.3µs ± 1%  11.1µs ± 0%   -1.86%  (p=0.008 n=5+5)
    Implicator/many-columns-exact-match100-16           352µs ± 1%    18µs ± 1%  -94.92%  (p=0.008 n=5+5)
    Implicator/many-columns-inexact-match100-16         382µs ± 1%   372µs ± 1%   -2.47%  (p=0.008 n=5+5)

Release note: None
@mgartner mgartner force-pushed the predicate-filters-expr branch from b56a675 to be87984 Compare July 9, 2020 17:00
@mgartner
Copy link
Collaborator Author

mgartner commented Jul 9, 2020

bors r=RaduBerinde

@craig
Copy link
Contributor

craig bot commented Jul 9, 2020

Build succeeded

@craig craig bot merged commit e84d0cb into cockroachdb:master Jul 9, 2020
@mgartner mgartner deleted the predicate-filters-expr branch July 9, 2020 18:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants