Skip to content

Conversation

@nik9000
Copy link
Member

@nik9000 nik9000 commented Sep 8, 2025

Tracks the more memory that's involved in topn.

Lucene doesn't track memory usage for TopN and can use a fair bit of it. Try this query:

FROM big_table
| SORT a, b, c, d, e
| LIMIT 1000000
| STATS MAX(a)

We attempt to return all million documents from lucene. Is we did this with the compute engine we're track all of the memory usage. With lucene we have to reserve it.

In the case of the query above the sort keys weight 8 bytes each. 40 bytes total. Plus another 72 for Lucene's FieldDoc. And another 40 at least for copying to the values to FieldDoc. That totals something like 152 bytes a piece. That's 145mb. Worth tracking!

Esql Engine TopN

Esql does track memory for topn, but it doesn't track the memory used by the min heap itself. It's just a big array of pointers. But it can get very big!

Tracks the more memory that's involved in topn.

Lucene doesn't track memory usage for TopN and can use a fair bit of it.
Try this query:
```
FROM big_table
| SORT a, b, c, d, e
| LIMIT 1000000
| STATS MAX(a)
```

We attempt to return all million documents from lucene. Is we did this
with the compute engine we're track all of the memory usage. With lucene
we have to reserve it.

In the case of the query above the sort keys weight 8 bytes each. 40
bytes total. Plus another 72 for Lucene's `FieldDoc`. And another 40 at
least for copying to the values to `FieldDoc`. That totals something
like 152 bytes a piece. That's 145mb. Worth tracking!

 ## Esql Engine TopN

Esql *does* track memory for topn, but it doesn't track the memory used by the min heap itself. It's just a big array of pointers. But it can get very big!
@nik9000 nik9000 merged commit 9deb8cf into elastic:9.1 Sep 8, 2025
34 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant