Skip to content

Latest commit

 

History

History
913 lines (605 loc) · 41.8 KB

File metadata and controls

913 lines (605 loc) · 41.8 KB

src/minisql/executor/aggregate.ml

Home · Files

Provides minisql executor aggregate facilities for this project.

Package: minisql.executor.aggregate

Reachable from entry: yes

Imports

Declarations

accumulate

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.

View source

accumulateBatch

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.

View source

aggregatePageRange

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.

View source

aggregateValue

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.

View source

BINDING_ERROR

const BINDING_ERROR = 9020

Defines the binding error constant used by the minisql executor aggregate module.

View source

componentName

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.

View source

createAccumulator

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.

View source

distinctValues

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.

View source

evaluateArgument

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.

View source

evaluateGroup

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.

View source

evaluateList

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.

View source

fail

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.

View source

findMatching

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.

View source

finishAccumulator

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.

View source

finishStreaming

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.

View source

groupRows

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.

View source

HASH_BUCKET_COUNT

const HASH_BUCKET_COUNT = 257

Defines the hash bucket count constant used by the minisql executor aggregate module.

View source

HASH_MASK

const HASH_MASK = 2147483647

Defines the hash mask constant used by the minisql executor aggregate module.

View source

hashBytes

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.

View source

hashValue

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.

View source

hashValues

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.

View source

integerDivide

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.

View source

INTRA_QUERY_WORKERS

const INTRA_QUERY_WORKERS = 4

Defines the intra query workers constant used by the minisql executor aggregate module.

View source

INVALID_ARGUMENT

const INVALID_ARGUMENT = 9001

Grouping, SQL aggregates and set operations. The first implementation uses

View source

isImplemented

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.

View source

mergeAccumulator

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.

View source

PARALLEL_SCAN_MINIMUM_PAGES

const PARALLEL_SCAN_MINIMUM_PAGES = 128

Defines the parallel scan minimum pages constant used by the minisql executor aggregate module.

View source

project

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.

View source

projectedSpillRows

function projectedSpillRows(rows)

Converts scanned rows to the shared validated spill representation.

Parameter Type Default Description
rows dynamic rows value consumed by this operation.

View source

projectSpilledPartition

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.

View source

projectStreamingRows

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.

View source

projectStreamingRowsControlled

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.

View source

projectStreamingRowsCore

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.

View source

projectStreamingTable

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.

View source

projectStreamingTableControlled

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.

View source

projectStreamingTableCore

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.

View source

projectStreamingTableFiltered

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.

View source

projectStreamingTableFilteredControlled

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.

View source

projectStreamingTableFilteredCore

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.

View source

projectStreamingTableParallel

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.

View source

projectStreamingTableParallelControlled

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.

View source

projectStreamingTableParallelCore

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.

View source

projectWithSpill

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.

View source

sameValue

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.

View source

sameValues

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.

View source

scannedSpillRows

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.

View source

setOperation

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.

View source

streamingAccumulators

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.

View source

streamingRequiredColumns

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.

View source

targetMilestone

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.

View source

TYPE_MISMATCH

const TYPE_MISMATCH = 9017

Defines the type mismatch constant used by the minisql executor aggregate module.

View source

VECTOR_BATCH_ROWS

const VECTOR_BATCH_ROWS = 256

Defines the vector batch rows constant used by the minisql executor aggregate module.

View source