mirror of https://github.com/tidwall/tile38.git
Map field names to array indices in scanwriter, once per query.
This commit is contained in:
parent
9e7766b346
commit
d5132a9eae
|
@ -97,8 +97,6 @@ func (s *Server) newScanWriter(
|
||||||
msg: msg,
|
msg: msg,
|
||||||
cursor: cursor,
|
cursor: cursor,
|
||||||
limit: limit,
|
limit: limit,
|
||||||
wheres: wheres,
|
|
||||||
whereins: whereins,
|
|
||||||
whereevals: whereevals,
|
whereevals: whereevals,
|
||||||
output: output,
|
output: output,
|
||||||
nofields: nofields,
|
nofields: nofields,
|
||||||
|
@ -117,6 +115,19 @@ func (s *Server) newScanWriter(
|
||||||
if sw.col != nil {
|
if sw.col != nil {
|
||||||
sw.fmap = sw.col.FieldMap()
|
sw.fmap = sw.col.FieldMap()
|
||||||
sw.farr = sw.col.FieldArr()
|
sw.farr = sw.col.FieldArr()
|
||||||
|
// This fills index value in wheres/whereins
|
||||||
|
// so we don't have to map string field names for each tested object
|
||||||
|
var ok bool
|
||||||
|
for _, where := range wheres {
|
||||||
|
if where.index, ok = sw.fmap[where.field]; ok {
|
||||||
|
sw.wheres = append(sw.wheres, where)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for _, wherein := range whereins {
|
||||||
|
if wherein.index, ok = sw.fmap[wherein.field]; ok {
|
||||||
|
sw.whereins = append(sw.whereins, wherein)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
sw.fvals = make([]float64, len(sw.farr))
|
sw.fvals = make([]float64, len(sw.farr))
|
||||||
return sw, nil
|
return sw, nil
|
||||||
|
@ -212,11 +223,8 @@ func (sw *scanWriter) fieldMatch(fields []float64, o geojson.Object) (fvals []fl
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
var value float64
|
var value float64
|
||||||
idx, ok := sw.fmap[where.field]
|
if len(fields) > where.index {
|
||||||
if ok {
|
value = fields[where.index]
|
||||||
if len(fields) > idx {
|
|
||||||
value = fields[idx]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !where.match(value) {
|
if !where.match(value) {
|
||||||
return
|
return
|
||||||
|
@ -224,11 +232,8 @@ func (sw *scanWriter) fieldMatch(fields []float64, o geojson.Object) (fvals []fl
|
||||||
}
|
}
|
||||||
for _, wherein := range sw.whereins {
|
for _, wherein := range sw.whereins {
|
||||||
var value float64
|
var value float64
|
||||||
idx, ok := sw.fmap[wherein.field]
|
if len(fields) > wherein.index {
|
||||||
if ok {
|
value = fields[wherein.index]
|
||||||
if len(fields) > idx {
|
|
||||||
value = fields[idx]
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if !wherein.match(value) {
|
if !wherein.match(value) {
|
||||||
return
|
return
|
||||||
|
@ -265,13 +270,13 @@ func (sw *scanWriter) fieldMatch(fields []float64, o geojson.Object) (fvals []fl
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
value := sw.fvals[sw.fmap[where.field]]
|
value := sw.fvals[where.index]
|
||||||
if !where.match(value) {
|
if !where.match(value) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for _, wherein := range sw.whereins {
|
for _, wherein := range sw.whereins {
|
||||||
value := sw.fvals[sw.fmap[wherein.field]]
|
value := sw.fvals[wherein.index]
|
||||||
if !wherein.match(value) {
|
if !wherein.match(value) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,12 +31,12 @@ func BenchmarkFieldMatch(t *testing.B) {
|
||||||
}
|
}
|
||||||
sw := &scanWriter{
|
sw := &scanWriter{
|
||||||
wheres: []whereT{
|
wheres: []whereT{
|
||||||
{"foo", false, 1, false, 3},
|
{"foo", 0, false, 1, false, 3},
|
||||||
{"bar", false, 10, false, 30},
|
{"bar", 1, false, 10, false, 30},
|
||||||
},
|
},
|
||||||
whereins: []whereinT{
|
whereins: []whereinT{
|
||||||
{"foo", []float64{1, 2}},
|
{"foo", 0, []float64{1, 2}},
|
||||||
{"bar", []float64{11, 25}},
|
{"bar", 1, []float64{11, 25}},
|
||||||
},
|
},
|
||||||
fmap: map[string]int{"foo": 0, "bar": 1},
|
fmap: map[string]int{"foo": 0, "bar": 1},
|
||||||
farr: []string{"bar", "foo"},
|
farr: []string{"bar", "foo"},
|
||||||
|
|
|
@ -116,6 +116,7 @@ func lc(s1, s2 string) bool {
|
||||||
|
|
||||||
type whereT struct {
|
type whereT struct {
|
||||||
field string
|
field string
|
||||||
|
index int
|
||||||
minx bool
|
minx bool
|
||||||
min float64
|
min float64
|
||||||
maxx bool
|
maxx bool
|
||||||
|
@ -159,6 +160,7 @@ func zMinMaxFromWheres(wheres []whereT) (minZ, maxZ float64) {
|
||||||
|
|
||||||
type whereinT struct {
|
type whereinT struct {
|
||||||
field string
|
field string
|
||||||
|
index int
|
||||||
valArr []float64
|
valArr []float64
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -328,7 +330,7 @@ func (s *Server) parseSearchScanBaseTokens(
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
t.wheres = append(t.wheres, whereT{field, minx, min, maxx, max})
|
t.wheres = append(t.wheres, whereT{field, -1, minx, min, maxx, max})
|
||||||
continue
|
continue
|
||||||
case "wherein":
|
case "wherein":
|
||||||
vs = nvs
|
vs = nvs
|
||||||
|
@ -359,7 +361,7 @@ func (s *Server) parseSearchScanBaseTokens(
|
||||||
}
|
}
|
||||||
valArr = append(valArr, val)
|
valArr = append(valArr, val)
|
||||||
}
|
}
|
||||||
t.whereins = append(t.whereins, whereinT{field, valArr})
|
t.whereins = append(t.whereins, whereinT{field, -1, valArr})
|
||||||
continue
|
continue
|
||||||
case "whereevalsha":
|
case "whereevalsha":
|
||||||
fallthrough
|
fallthrough
|
||||||
|
|
Loading…
Reference in New Issue