mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-01-20 15:16:42 +00:00
wip
This commit is contained in:
parent
fcce0fc6e1
commit
ff2b6fbe35
2 changed files with 28 additions and 0 deletions
|
@ -36,6 +36,7 @@ func ProcessQueryRequest(ctx context.Context, w http.ResponseWriter, r *http.Req
|
||||||
if limit > 0 {
|
if limit > 0 {
|
||||||
q.AddPipeLimit(uint64(limit))
|
q.AddPipeLimit(uint64(limit))
|
||||||
}
|
}
|
||||||
|
q.Optimize()
|
||||||
|
|
||||||
tenantIDs := []logstorage.TenantID{tenantID}
|
tenantIDs := []logstorage.TenantID{tenantID}
|
||||||
|
|
||||||
|
|
|
@ -215,6 +215,33 @@ func (q *Query) AddPipeLimit(n uint64) {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Optimize tries optimizing the query.
|
||||||
|
func (q *Query) Optimize() {
|
||||||
|
q.pipes = optimizeSortLimitPipes(q.pipes)
|
||||||
|
}
|
||||||
|
|
||||||
|
func optimizeSortLimitPipes(pipes []pipe) []pipe {
|
||||||
|
// Merge 'sort ... | limit ...' into 'sort ... limit ...'
|
||||||
|
i := 1
|
||||||
|
for i < len(pipes) {
|
||||||
|
pl, ok := pipes[i].(*pipeLimit)
|
||||||
|
if !ok {
|
||||||
|
i++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
ps, ok := pipes[i-1].(*pipeSort)
|
||||||
|
if !ok {
|
||||||
|
i++
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if ps.limit == 0 || pl.n < ps.limit {
|
||||||
|
ps.limit = pl.n
|
||||||
|
}
|
||||||
|
pipes = append(pipes[:i], pipes[i+1:]...)
|
||||||
|
}
|
||||||
|
return pipes
|
||||||
|
}
|
||||||
|
|
||||||
func (q *Query) getNeededColumns() ([]string, []string) {
|
func (q *Query) getNeededColumns() ([]string, []string) {
|
||||||
neededFields := newFieldsSet()
|
neededFields := newFieldsSet()
|
||||||
neededFields.add("*")
|
neededFields.add("*")
|
||||||
|
|
Loading…
Reference in a new issue