Provides minisql executor aggregate facilities for this project.
Package: minisql.executor.aggregate
Reachable from entry: yes
minisql/common/endian.mlasendian→ src/minisql/common/endian.mlminisql/executor/projection.mlasprojection→ src/minisql/executor/projection.mlminisql/executor/scan.mlasscan→ src/minisql/executor/scan.mlminisql/executor/sort.mlassort→ src/minisql/executor/sort.mlminisql/platform/file.mlasfile_api→ src/minisql/platform/file.mlminisql/server/database_manager.mlasdatabase_manager→ src/minisql/server/database_manager.mlminisql/sql/ast.mlasast→ src/minisql/sql/ast.mlminisql/sql/expressions.mlasexpressions→ src/minisql/sql/expressions.mlminisql/sql/types.mlastypes→ src/minisql/sql/types.mlminisql/sql/values.mlasvalues→ src/minisql/sql/values.mlstd/concurrent/thread_pool.mlasthread_pool→../MiniLangCompilerML/std/concurrent/thread_pool.ml— external dependency
function accumulate(state, row)Updates one accumulator from one row without retaining the row.
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
dynamic |
— | Mutable state inspected or updated by the operation. |
row |
dynamic |
— | row value consumed by this operation. |
function accumulateBatch(states, rows)Updates all aggregate lanes from one bounded row batch. Keeping accumulator dispatch outside the storage cursor makes the operator batch-at-a-time and gives the native compiler a compact, allocation-free numeric inner loop.
| Parameter | Type | Default | Description |
|---|---|---|---|
states |
dynamic |
— | states value consumed by this operation. |
rows |
dynamic |
— | rows value consumed by this operation. |
- minisql.executor.aggregate.AggregateAccumulator — struct
- minisql.executor.aggregate.AggregateGroup — struct
function aggregatePageRange(task)Scans one disjoint heap-page range and returns mergeable partial states.
| Parameter | Type | Default | Description |
|---|---|---|---|
task |
dynamic |
— | task value consumed by this operation. |
function aggregateValue(expression, rows)Implements aggregate value for this module. Requires arguments that satisfy the validation performed below. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.
| Parameter | Type | Default | Description |
|---|---|---|---|
expression |
dynamic |
— | expression value consumed by this operation. |
rows |
dynamic |
— | rows value consumed by this operation. |
const BINDING_ERROR = 9020Defines the binding error constant used by the minisql executor aggregate module.
function componentName()Performs the componentName operation for the minisql executor aggregate module. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.
function createAccumulator(expression)Creates an accumulator whose neutral state matches SQL empty-input rules.
| Parameter | Type | Default | Description |
|---|---|---|---|
expression |
dynamic |
— | expression value consumed by this operation. |
function distinctValues(input)Implements distinct values for this module. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.
| Parameter | Type | Default | Description |
|---|---|---|---|
input |
dynamic |
— | input value consumed by this operation. |
function evaluateArgument(expression, row)Evaluates argument using the supplied inputs. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.
| Parameter | Type | Default | Description |
|---|---|---|---|
expression |
dynamic |
— | expression value consumed by this operation. |
row |
dynamic |
— | row value consumed by this operation. |
function evaluateGroup(expression, rows, representative)Evaluates group using the supplied inputs. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.
| Parameter | Type | Default | Description |
|---|---|---|---|
expression |
dynamic |
— | expression value consumed by this operation. |
rows |
dynamic |
— | rows value consumed by this operation. |
representative |
dynamic |
— | representative value consumed by this operation. |
function evaluateList(boundExpressions, rows, representative)Evaluates list using the supplied inputs. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.
| Parameter | Type | Default | Description |
|---|---|---|---|
boundExpressions |
dynamic |
— | boundExpressions value consumed by this operation. |
rows |
dynamic |
— | rows value consumed by this operation. |
representative |
dynamic |
— | representative value consumed by this operation. |
function fail(code, operation, message)Performs the fail operation for the minisql executor aggregate module. Returns its result or propagates a structured error from validation or a dependency. Any side effects are limited to the explicitly invoked dependencies.
| Parameter | Type | Default | Description |
|---|---|---|---|
code |
dynamic |
— | code value consumed by this operation. |
operation |
dynamic |
— | operation value consumed by this operation. |
message |
dynamic |
— | Human-readable message associated with the operation. |
function findMatching(rows, candidate, used)Finds matching using the supplied inputs. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.
| Parameter | Type | Default | Description |
|---|---|---|---|
rows |
dynamic |
— | rows value consumed by this operation. |
candidate |
dynamic |
— | candidate value consumed by this operation. |
used |
dynamic |
— | used value consumed by this operation. |
function finishAccumulator(state)Converts an accumulator into the same SqlValue produced by aggregateValue.
| Parameter | Type | Default | Description |
|---|---|---|---|
state |
dynamic |
— | Mutable state inspected or updated by the operation. |
function finishStreaming(states)Finalizes fixed-size accumulators into the ordinary one-row projection shape.
| Parameter | Type | Default | Description |
|---|---|---|---|
states |
dynamic |
— | states value consumed by this operation. |
function groupRows(rows, groupExpressions, aggregateQuery)Partitions rows with a fixed-bucket hash table and explicit collision chains. Full-key comparison preserves SQL NULL/equality semantics; the separate groups array preserves first-key encounter order. Empty global aggregation yields one group.
| Parameter | Type | Default | Description |
|---|---|---|---|
rows |
dynamic |
— | rows value consumed by this operation. |
groupExpressions |
dynamic |
— | groupExpressions value consumed by this operation. |
aggregateQuery |
dynamic |
— | aggregateQuery value consumed by this operation. |
const HASH_BUCKET_COUNT = 257Defines the hash bucket count constant used by the minisql executor aggregate module.
const HASH_MASK = 2147483647Defines the hash mask constant used by the minisql executor aggregate module.
function hashBytes(input, seed)Implements hash bytes for this module. Returns the computed value or operation status. Does not modify its inputs.
| Parameter | Type | Default | Description |
|---|---|---|---|
input |
dynamic |
— | input value consumed by this operation. |
seed |
dynamic |
— | seed value consumed by this operation. |
function hashValue(value)Implements hash value for this module. Requires arguments that satisfy the validation performed below. Returns the computed value or operation status. Does not modify its inputs.
| Parameter | Type | Default | Description |
|---|---|---|---|
value |
dynamic |
— | Value consumed or transformed by the operation. |
function hashValues(input)Implements hash values for this module. Returns the computed value or operation status. Does not modify its inputs.
| Parameter | Type | Default | Description |
|---|---|---|---|
input |
dynamic |
— | input value consumed by this operation. |
function integerDivide(numerator, denominator)Computes non-negative truncating integer division for spill partition sizing.
| Parameter | Type | Default | Description |
|---|---|---|---|
numerator |
dynamic |
— | numerator value consumed by this operation. |
denominator |
dynamic |
— | denominator value consumed by this operation. |
const INTRA_QUERY_WORKERS = 4Defines the intra query workers constant used by the minisql executor aggregate module.
const INVALID_ARGUMENT = 9001Grouping, SQL aggregates and set operations. The first implementation uses
function isImplemented()Returns whether implemented satisfies the condition required by the minisql executor aggregate module. Returns the computed value or operation status. Does not modify its inputs.
function mergeAccumulator(target, partial)Merges one worker's fixed-size partial aggregate into the coordinator state. AVG is represented by SUM+COUNT, while extrema and boolean folds preserve SQL NULL behavior through the explicit hasValue bit.
| Parameter | Type | Default | Description |
|---|---|---|---|
target |
dynamic |
— | target value consumed by this operation. |
partial |
dynamic |
— | partial value consumed by this operation. |
const PARALLEL_SCAN_MINIMUM_PAGES = 128Defines the parallel scan minimum pages constant used by the minisql executor aggregate module.
function project(rows, selectExpressions, groupExpressions, havingExpression, orderExpressions)Implements project for this module. Requires arguments that satisfy the validation performed below. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.
| Parameter | Type | Default | Description |
|---|---|---|---|
rows |
dynamic |
— | rows value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
groupExpressions |
dynamic |
— | groupExpressions value consumed by this operation. |
havingExpression |
dynamic |
— | havingExpression value consumed by this operation. |
orderExpressions |
dynamic |
— | orderExpressions value consumed by this operation. |
function projectedSpillRows(rows)Converts scanned rows to the shared validated spill representation.
| Parameter | Type | Default | Description |
|---|---|---|---|
rows |
dynamic |
— | rows value consumed by this operation. |
function projectSpilledPartition(task)Reads, aggregates, and removes one partition. Different tasks own disjoint files and disjoint hash tables, so native workers require no shared lock.
| Parameter | Type | Default | Description |
|---|---|---|---|
task |
dynamic |
— | task value consumed by this operation. |
function projectStreamingRows(rows, selectExpressions, predicate)Preserves the direct aggregate API for callers without server session state.
| Parameter | Type | Default | Description |
|---|---|---|---|
rows |
dynamic |
— | rows value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
predicate |
dynamic |
— | predicate value consumed by this operation. |
function projectStreamingRowsControlled(rows, selectExpressions, predicate, database, sessionId)Streams selected rows while honoring one server query control token.
| Parameter | Type | Default | Description |
|---|---|---|---|
rows |
dynamic |
— | rows value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
predicate |
dynamic |
— | predicate value consumed by this operation. |
database |
dynamic |
— | database value consumed by this operation. |
sessionId |
dynamic |
— | Identifier of session. |
function projectStreamingRowsCore(rows, selectExpressions, predicate, database, sessionId)Streams already selected rows through a predicate and fixed-size scalar aggregate state. This is used by planned index scans without rebuilding the general grouping structures.
| Parameter | Type | Default | Description |
|---|---|---|---|
rows |
dynamic |
— | rows value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
predicate |
dynamic |
— | predicate value consumed by this operation. |
database |
dynamic |
— | database value consumed by this operation. |
sessionId |
dynamic |
— | Identifier of session. |
function projectStreamingTable(databasePath, table, pageTransaction, readCache, selectExpressions)Preserves unfiltered streaming aggregation for non-server callers.
| Parameter | Type | Default | Description |
|---|---|---|---|
databasePath |
dynamic |
— | Path associated with database. |
table |
dynamic |
— | table value consumed by this operation. |
pageTransaction |
dynamic |
— | pageTransaction value consumed by this operation. |
readCache |
dynamic |
— | readCache value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
function projectStreamingTableControlled(databasePath, table, pageTransaction, readCache, selectExpressions, database, sessionId)Aggregates an unfiltered table under cooperative server control.
| Parameter | Type | Default | Description |
|---|---|---|---|
databasePath |
dynamic |
— | Path associated with database. |
table |
dynamic |
— | table value consumed by this operation. |
pageTransaction |
dynamic |
— | pageTransaction value consumed by this operation. |
readCache |
dynamic |
— | readCache value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
database |
dynamic |
— | database value consumed by this operation. |
sessionId |
dynamic |
— | Identifier of session. |
function projectStreamingTableCore(databasePath, table, pageTransaction, readCache, selectExpressions, database, sessionId)Keeps the unfiltered hot path branch-free inside the row loop. This function is intentionally separate from projectStreamingTableFiltered because scalar whole-table aggregates are common and execute the loop once per stored row.
| Parameter | Type | Default | Description |
|---|---|---|---|
databasePath |
dynamic |
— | Path associated with database. |
table |
dynamic |
— | table value consumed by this operation. |
pageTransaction |
dynamic |
— | pageTransaction value consumed by this operation. |
readCache |
dynamic |
— | readCache value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
database |
dynamic |
— | database value consumed by this operation. |
sessionId |
dynamic |
— | Identifier of session. |
function projectStreamingTableFiltered(databasePath, table, pageTransaction, readCache, selectExpressions, predicate, requiredColumns)Preserves filtered streaming aggregation for non-server callers.
| Parameter | Type | Default | Description |
|---|---|---|---|
databasePath |
dynamic |
— | Path associated with database. |
table |
dynamic |
— | table value consumed by this operation. |
pageTransaction |
dynamic |
— | pageTransaction value consumed by this operation. |
readCache |
dynamic |
— | readCache value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
predicate |
dynamic |
— | predicate value consumed by this operation. |
requiredColumns |
dynamic |
— | requiredColumns value consumed by this operation. |
function projectStreamingTableFilteredControlled(databasePath, table, pageTransaction, readCache, selectExpressions, predicate, requiredColumns, database, sessionId)Filters and aggregates a table under cooperative server control.
| Parameter | Type | Default | Description |
|---|---|---|---|
databasePath |
dynamic |
— | Path associated with database. |
table |
dynamic |
— | table value consumed by this operation. |
pageTransaction |
dynamic |
— | pageTransaction value consumed by this operation. |
readCache |
dynamic |
— | readCache value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
predicate |
dynamic |
— | predicate value consumed by this operation. |
requiredColumns |
dynamic |
— | requiredColumns value consumed by this operation. |
database |
dynamic |
— | database value consumed by this operation. |
sessionId |
dynamic |
— | Identifier of session. |
function projectStreamingTableFilteredCore(databasePath, table, pageTransaction, readCache, selectExpressions, predicate, requiredColumns, database, sessionId)Streams one filtered base table through fixed-size scalar aggregate accumulators. The caller-supplied mask includes both aggregate and predicate columns, and the reader closes on every reported failure path.
| Parameter | Type | Default | Description |
|---|---|---|---|
databasePath |
dynamic |
— | Path associated with database. |
table |
dynamic |
— | table value consumed by this operation. |
pageTransaction |
dynamic |
— | pageTransaction value consumed by this operation. |
readCache |
dynamic |
— | readCache value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
predicate |
dynamic |
— | predicate value consumed by this operation. |
requiredColumns |
dynamic |
— | requiredColumns value consumed by this operation. |
database |
dynamic |
— | database value consumed by this operation. |
sessionId |
dynamic |
— | Identifier of session. |
function projectStreamingTableParallel(databasePath, table, readCache, selectExpressions)Preserves parallel aggregate execution for callers without a query token.
| Parameter | Type | Default | Description |
|---|---|---|---|
databasePath |
dynamic |
— | Path associated with database. |
table |
dynamic |
— | table value consumed by this operation. |
readCache |
dynamic |
— | readCache value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
function projectStreamingTableParallelControlled(databasePath, table, readCache, selectExpressions, database, sessionId)Propagates server cancellation and deadlines into parallel aggregate workers.
| Parameter | Type | Default | Description |
|---|---|---|---|
databasePath |
dynamic |
— | Path associated with database. |
table |
dynamic |
— | table value consumed by this operation. |
readCache |
dynamic |
— | readCache value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
database |
dynamic |
— | database value consumed by this operation. |
sessionId |
dynamic |
— | Identifier of session. |
function projectStreamingTableParallelCore(databasePath, table, readCache, selectExpressions, database, sessionId)Executes an unfiltered scalar aggregate with page-partitioned native workers. Small tables and transactional readers stay on the lower-overhead serial path; every worker sees committed pages only and returns constant-size state.
| Parameter | Type | Default | Description |
|---|---|---|---|
databasePath |
dynamic |
— | Path associated with database. |
table |
dynamic |
— | table value consumed by this operation. |
readCache |
dynamic |
— | readCache value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
database |
dynamic |
— | database value consumed by this operation. |
sessionId |
dynamic |
— | Identifier of session. |
function projectWithSpill(rows, selectExpressions, groupExpressions, havingExpression, orderExpressions, temporaryRoot, threshold)Executes grouped aggregation one hash partition at a time when the input exceeds the configured threshold. Equal group keys always select the same partition; final ORDER BY, when present, restores requested output ordering.
| Parameter | Type | Default | Description |
|---|---|---|---|
rows |
dynamic |
— | rows value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
groupExpressions |
dynamic |
— | groupExpressions value consumed by this operation. |
havingExpression |
dynamic |
— | havingExpression value consumed by this operation. |
orderExpressions |
dynamic |
— | orderExpressions value consumed by this operation. |
temporaryRoot |
dynamic |
— | temporaryRoot value consumed by this operation. |
threshold |
dynamic |
— | threshold value consumed by this operation. |
function sameValue(left, right)Implements same value for this module. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.
| Parameter | Type | Default | Description |
|---|---|---|---|
left |
dynamic |
— | left value consumed by this operation. |
right |
dynamic |
— | right value consumed by this operation. |
function sameValues(left, right)Implements same values for this module. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.
| Parameter | Type | Default | Description |
|---|---|---|---|
left |
dynamic |
— | left value consumed by this operation. |
right |
dynamic |
— | right value consumed by this operation. |
function scannedSpillRows(rows)Restores value-only scanned rows from a validated spill partition.
| Parameter | Type | Default | Description |
|---|---|---|---|
rows |
dynamic |
— | rows value consumed by this operation. |
function setOperation(leftRows, rightRows, operator, all)Implements set operation for this module. Requires arguments that satisfy the validation performed below. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.
| Parameter | Type | Default | Description |
|---|---|---|---|
leftRows |
dynamic |
— | leftRows value consumed by this operation. |
rightRows |
dynamic |
— | rightRows value consumed by this operation. |
operator |
dynamic |
— | operator value consumed by this operation. |
all |
dynamic |
— | all value consumed by this operation. |
function streamingAccumulators(selectExpressions, operation)Creates accumulator state for a validated streaming scalar aggregate list.
| Parameter | Type | Default | Description |
|---|---|---|---|
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
operation |
dynamic |
— | operation value consumed by this operation. |
function streamingRequiredColumns(table, selectExpressions)Builds the narrowest safe source-column mask for direct aggregate arguments. Complex scalar arguments retain full decoding while still avoiding row materialization; direct column aggregates skip unrelated external values.
| Parameter | Type | Default | Description |
|---|---|---|---|
table |
dynamic |
— | table value consumed by this operation. |
selectExpressions |
dynamic |
— | selectExpressions value consumed by this operation. |
function targetMilestone()Performs the targetMilestone operation for the minisql executor aggregate module. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.
const TYPE_MISMATCH = 9017Defines the type mismatch constant used by the minisql executor aggregate module.
const VECTOR_BATCH_ROWS = 256Defines the vector batch rows constant used by the minisql executor aggregate module.