mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-31 15:06:26 +00:00
wip
This commit is contained in:
parent
12fe2b265c
commit
a080c9e4e5
1 changed files with 23 additions and 0 deletions
|
@ -217,9 +217,32 @@ func (q *Query) AddPipeLimit(n uint64) {
|
|||
|
||||
// Optimize tries optimizing the query.
|
||||
func (q *Query) Optimize() {
|
||||
q.pipes = optimizeSortOffsetPipes(q.pipes)
|
||||
q.pipes = optimizeSortLimitPipes(q.pipes)
|
||||
}
|
||||
|
||||
func optimizeSortOffsetPipes(pipes []pipe) []pipe {
|
||||
// Merge 'sort ... | offset ...' into 'sort ... offset ...'
|
||||
i := 1
|
||||
for i < len(pipes) {
|
||||
po, ok := pipes[i].(*pipeOffset)
|
||||
if !ok {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
ps, ok := pipes[i-1].(*pipeSort)
|
||||
if !ok {
|
||||
i++
|
||||
continue
|
||||
}
|
||||
if ps.offset == 0 && ps.limit == 0 {
|
||||
ps.offset = po.n
|
||||
}
|
||||
pipes = append(pipes[:i], pipes[i+1:]...)
|
||||
}
|
||||
return pipes
|
||||
}
|
||||
|
||||
func optimizeSortLimitPipes(pipes []pipe) []pipe {
|
||||
// Merge 'sort ... | limit ...' into 'sort ... limit ...'
|
||||
i := 1
|
||||
|
|
Loading…
Reference in a new issue