mirror of
https://github.com/GreptimeTeam/greptimedb.git
synced 2026-11-28 13:44:03 +00:00
perf(promql): find the run a chunk would overlap without scanning history
The stored runs are sorted and disjoint, so at most one of them can share a position with an incoming run. Searching the whole array made a sparse series split across chunks cost a pass over its history per chunk. Signed-off-by: discord9 <55937128+discord9@users.noreply.github.com>
This commit is contained in:
@@ -335,7 +335,13 @@ impl Emitted {
|
||||
for (index, runs) in occupied.iter().enumerate() {
|
||||
let stored = history.fields.get(index).map_or(&[][..], Vec::as_slice);
|
||||
for run in runs {
|
||||
if let Some(previous) = stored.iter().find(|stored| stored.overlaps(*run)) {
|
||||
// The stored runs are sorted and disjoint, so only the one holding `run.start`
|
||||
// or the one just before it can share a position. Scanning them all would make
|
||||
// a sparse series split across chunks cost a pass over its whole history per
|
||||
// chunk.
|
||||
let at = stored.partition_point(|stored| stored.end <= run.start);
|
||||
let previous = stored.get(at).filter(|stored| stored.overlaps(*run));
|
||||
if let Some(previous) = previous {
|
||||
return Err(occupied_position(path, &labels, index, run, previous));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user