Heuristic:2giosangmitom Sqmeow nvim Result Row Cap Management
| Knowledge Sources | |
|---|---|
| Domains | Optimization, Memory_Management, Query_Execution |
| Last Updated | 2026-10-16 14:00 GMT |
Overview
Tribal knowledge for managing the max_rows cap (default 100,000) that limits retained rows per result, with truncation marking and its downstream effects on paging, export, and aggregation.
Description
The engine retains query results in lossless Polars DataFrames, but caps the number of rows to prevent unbounded memory growth. The max_rows setting (default 100,000, configurable to 0 for unlimited) is enforced by each adapter during row ingestion. When the cap is reached, the result is marked truncated — more rows existed but were not retained.
A truncated result has permanent consequences: paging and export operate only on retained rows, local view filters cannot recover omitted rows, and aggregation warns that it covers only the retained subset. The page_size setting is separate: it controls how many rows the grid shows per page, not how many are retained.
Usage
Use this heuristic when configuring query limits or diagnosing issues with large results:
- Memory pressure: Reduce
max_rowsif the editor or engine runs out of memory on large queries. - Missing rows in export: If exported data has fewer rows than expected, check if the result was truncated.
- Aggregation accuracy: Aggregates on truncated results cover only retained rows; a warning is emitted.
- Unlimited rows: Set
max_rows = 0for no cap, but beware of memory exhaustion on very large tables.
The Insight (Rule of Thumb)
- Action: Set
query.max_rowsto balance memory usage against result completeness. - Value: Default is 100,000. Set to 0 for unlimited rows.
ui.result.page_sizeis separate (controls display, not retention). - Trade-off: Lower values save memory but truncate large results. Higher values retain more rows but risk OOM. Truncated rows are permanently lost — only an explicit refresh reruns the query.
- Compatibility: Truncation affects export (cannot export unretrived rows), aggregation (covers retained subset only), and paging (cannot page past the cap). Views never rerun the query; only explicit refresh does.
Reasoning
Retained rows live in Polars DataFrames in the engine process. Without a cap, a SELECT * on a billion-row table would exhaust memory and freeze the editor. The cap is enforced at ingestion time in each adapter: when result.row_count() >= max_rows, the adapter calls result.mark_truncated() and stops reading.
The truncation flag propagates to the editor, which displays a SqmeowTruncated warning highlight. This tells the user that the displayed data is incomplete. Export and aggregation respect this: a truncated export explicitly cannot include rows that were never fetched, and a truncated aggregation warns that only retained rows were aggregated.
The zero sentinel (max_rows = 0) is normalized to usize::MAX by Options::update, so adapters always receive a finite limit — never a zero that would truncate immediately.
Code Evidence
Default options and zero-sentinel normalization from core/sqmeow-core/src/server/session.rs:64-87:
impl Default for Options {
fn default() -> Self {
Self {
max_rows: 100_000,
history_size: 32,
timeout_ms: 0,
}
}
}
impl Options {
pub fn update(&mut self, other: OptionsPatch) {
if let Some(value) = other.max_rows {
// Zero is no cap.
self.max_rows = if value == 0 { usize::MAX } else { value };
}
// ...
}
}
Truncation in the DuckDB adapter from core/sqmeow-adapters/src/duckdb.rs:663-664:
if result.row_count() >= max_rows {
result.mark_truncated();
}
Truncation field on ResultSet from core/sqmeow-db/src/result.rs:69-71:
/// `truncated` means more rows existed than were retained; paging/export
/// cannot recover those omitted rows.
#[derive(Debug, Default)]
pub struct ResultSet {
// ...
truncated: bool,
Truncated aggregation warning from tests/test_aggregate.lua:224:
T['truncated snapshots warn and aggregate only retained rows'] = function()