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

MB-54131: Geoshape query decode optimization #1864

Merged
merged 8 commits into from Aug 31, 2023
9 changes: 9 additions & 0 deletions index_impl.go
Expand Up @@ -35,6 +35,7 @@ import (
"github.com/blevesearch/bleve/v2/search/facet"
"github.com/blevesearch/bleve/v2/search/highlight"
index "github.com/blevesearch/bleve_index_api"
"github.com/blevesearch/geo/s2"
)

type indexImpl struct {
Expand Down Expand Up @@ -482,6 +483,14 @@ func (i *indexImpl) SearchInContext(ctx context.Context, req *SearchRequest) (sr
ctx = context.WithValue(ctx, search.SearchIOStatsCallbackKey,
search.SearchIOStatsCallbackFunc(sendBytesRead))

bufPool := s2.NewGeoBufferPool(24 * 1024, 24)
Likith101 marked this conversation as resolved.
Show resolved Hide resolved
getBufferPool := func() *s2.GeoBufferPool {
return bufPool
Likith101 marked this conversation as resolved.
Show resolved Hide resolved
}

ctx = context.WithValue(ctx, search.GeoBufferPoolCallbackKey,
search.GeoBufferPoolCallbackFunc(getBufferPool))
Likith101 marked this conversation as resolved.
Show resolved Hide resolved

searcher, err := req.Query.Searcher(ctx, indexReader, i.m, search.SearcherOptions{
Explain: req.Explain,
IncludeTermVectors: req.IncludeLocations || req.Highlight != nil,
Expand Down
5 changes: 4 additions & 1 deletion search/searcher/search_geoshape.go
Expand Up @@ -70,6 +70,9 @@ func buildRelationFilterOnShapes(ctx context.Context, dvReader index.DocValueRea
var dvShapeValue []byte
var startReading, finishReading bool
var reader *bytes.Reader

bufPool := ctx.Value(search.GeoBufferPoolCallbackKey).(search.GeoBufferPoolCallbackFunc)()

return func(d *search.DocumentMatch) bool {
var found bool

Expand Down Expand Up @@ -104,7 +107,7 @@ func buildRelationFilterOnShapes(ctx context.Context, dvReader index.DocValueRea
// apply the filter once the entire docvalue is finished reading.
if finishReading {
v, err := geojson.FilterGeoShapesOnRelation(shape,
dvShapeValue, relation, &reader)
dvShapeValue, relation, &reader, bufPool)
if err == nil && v {
found = true
}
Expand Down
16 changes: 15 additions & 1 deletion search/util.go
Expand Up @@ -14,7 +14,11 @@

package search

import "context"
import (
"context"

"github.com/blevesearch/geo/s2"
)

func MergeLocations(locations []FieldTermLocationMap) FieldTermLocationMap {
rv := locations[0]
Expand Down Expand Up @@ -118,3 +122,13 @@
}
}
}

const GeoBufferPoolCallbackKey = "_geo_buffer_pool_callback_key"

// Assigning the size of the largest buffer in the pool to 24KB and
// the smallest buffer to 24 bytes. The pools are used to read a
// sequence of vertices which are always 24 bytes each.
const MaxBufPoolSize = 24 * 1024
const MinBufPoolSize = 24
Likith101 marked this conversation as resolved.
Show resolved Hide resolved

type GeoBufferPoolCallbackFunc func() *s2.GeoBufferPool