Skip to content

Commit

Permalink
MB-53028 Do not generate index filters if _EMPTY_SPAN is used
Browse files Browse the repository at this point in the history
As a special case, if an index scan is using _EMPTY_SPAN,
then nothing will be returned from the index scan, and
in such cases there is no need to generate index filters
as well as other optimizations based on index keys such
as early order and bloom filters.

Change-Id: Ib9dc24532b1432a406fd55aac1d31cdd234e0d3e
Reviewed-on: https://review.couchbase.org/c/query/+/177756
Reviewed-by: Sitaram Vemulapalli <sitaram.vemulapalli@couchbase.com>
Tested-by: Bingjie Miao <bingjie.miao@couchbase.com>
  • Loading branch information
miaobingjie committed Jul 19, 2022
1 parent 9d988e3 commit d83151b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
5 changes: 5 additions & 0 deletions planner/build_scan_secondary.go
Expand Up @@ -1027,6 +1027,11 @@ func (this *builder) eqJoinFilter(fl *base.Filter, alias string) (bool, expressi
func (this *builder) getIndexFilters(entry *indexEntry, node *algebra.KeyspaceTerm,
baseKeyspace *base.BaseKeyspace, id expression.Expression) (err error) {

// special case, if the span is an empty span, no need to proceed
if isSpecialSpan(entry.spans, plan.RANGE_EMPTY_SPAN) {
return nil
}

alias := node.Alias()
useCBO := this.useCBO && this.keyspaceUseCBO(alias)
advisorValidate := this.advisorValidate()
Expand Down
13 changes: 13 additions & 0 deletions planner/spans_term.go
Expand Up @@ -554,6 +554,19 @@ func setSpecialSpan(rg *plan.Range2) {
}
}

func isSpecialSpan(sspans SargSpans, flag uint32) bool {
if tspans, ok := sspans.(*TermSpans); ok {
spans := tspans.spans
if len(spans) == 1 {
rgs := spans[0].Ranges
if len(rgs) == 1 {
return (rgs[0].Flags & flag) != 0
}
}
}
return false
}

func ConvertSpans2ToSpan(spans2 plan.Spans2, total int) (plan.Spans, bool) {
exact := true
spans := make(plan.Spans, 0, len(spans2))
Expand Down

0 comments on commit d83151b

Please sign in to comment.