Skip to content

Latest commit

 

History

History
504 lines (322 loc) · 20.5 KB

File metadata and controls

504 lines (322 loc) · 20.5 KB

src/minisql/executor/sort.ml

Home · Files

Provides minisql executor sort facilities for this project.

Package: minisql.executor.sort

Reachable from entry: yes

Imports

Declarations

bytesEqual

function bytesEqual(left, right)

Performs the bytesEqual operation for the minisql executor sort 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
left dynamic left value consumed by this operation.
right dynamic right value consumed by this operation.

View source

cleanupRuns

function cleanupRuns(runs)

Implements cleanup runs for this module. Returns its result or propagates a structured error from validation or a dependency. Performs I/O through its file, transport, or storage dependencies.

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

View source

combinedValues

function combinedValues(row)

Implements combined 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
row dynamic row value consumed by this operation.

View source

compareNullable

function compareNullable(left, right, descending, nullsFirst, nullsSpecified)

Compares nullable using the supplied inputs. Returns the computed value or operation status. Does not modify its inputs.

Parameter Type Default Description
left dynamic left value consumed by this operation.
right dynamic right value consumed by this operation.
descending dynamic descending value consumed by this operation.
nullsFirst dynamic nullsFirst value consumed by this operation.
nullsSpecified dynamic nullsSpecified value consumed by this operation.

View source

compareRows

function compareRows(left, right, orderItems)

Compares rows using the supplied inputs. Returns the computed value or operation status. Does not modify its inputs.

Parameter Type Default Description
left dynamic left value consumed by this operation.
right dynamic right value consumed by this operation.
orderItems dynamic orderItems value consumed by this operation.

View source

componentName

function componentName()

Performs the componentName operation for the minisql executor sort module. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.

View source

CORRUPT_DATA

const CORRUPT_DATA = 9004

Defines the corrupt data constant used by the minisql executor sort module.

View source

decodeSqlValue

function decodeSqlValue(kind, raw)

Decodes SQL value 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
kind dynamic kind value consumed by this operation.
raw dynamic raw value consumed by this operation.

View source

encodeHeader

function encodeHeader(valueCount, orderCount, encrypted)

Encodes header 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
valueCount dynamic Number of value to process.
orderCount dynamic Number of order to process.
encrypted dynamic encrypted value consumed by this operation.

View source

fail

function fail(code, operation, message)

Performs the fail operation for the minisql executor sort 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

INVALID_ARGUMENT

const INVALID_ARGUMENT = 9001

Stable merge sorting for projected rows. M46 adds a correctness-first

View source

isImplemented

function isImplemented()

Returns whether implemented satisfies the condition required by the minisql executor sort module. Returns the computed value or operation status. Does not modify its inputs.

View source

MAX_SPILL_FILE_BYTES

const MAX_SPILL_FILE_BYTES = 268435456

Defines the max spill file bytes constant used by the minisql executor sort module.

View source

merge

function merge(left, right, orderItems)

Implements merge 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.
orderItems dynamic orderItems value consumed by this operation.

View source

nextSpillToken

synchronized function nextSpillToken()

Generates a process-unique spill namespace under an intrinsic function lock. The synchronized modifier serializes nonce updates across parallel SELECT workers.

View source

rawValues

function rawValues(input)

Implements raw 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

readRun

function readRun(run)

Reads run using the supplied inputs. Requires arguments that satisfy the validation performed below. Returns its result or propagates a structured error from validation or a dependency. Performs I/O through its file, transport, or storage dependencies.

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

View source

runPath

function runPath(root, token, index)

Runs path using the supplied inputs. Returns the computed value or operation status. Performs I/O through its file, transport, or storage dependencies.

Parameter Type Default Description
root dynamic root value consumed by this operation.
token dynamic token value consumed by this operation.
index dynamic Zero-based index of the affected item.

View source

sortProjected

function sortProjected(rows, orderItems)

Sorts projected using the supplied inputs. 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.
orderItems dynamic orderItems value consumed by this operation.

View source

sortProjectedWithSpill

function sortProjectedWithSpill(rows, orderItems, temporaryRoot, threshold)

Performs stable external merge sorting when rows exceed threshold. Sorted chunks are written as validated runs, then merged pairwise until one remains. Every success and failure path removes owned temporary files.

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

View source

SPILL_HEADER_SIZE

const SPILL_HEADER_SIZE = 16

Defines the spill header size constant used by the minisql executor sort module.

View source

SPILL_VERSION

const SPILL_VERSION = 1

Defines the spill version constant used by the minisql executor sort module.

View source

spillAad

function spillAad(rowIndex)

Creates domain-separated AAD for one ordered spill row.

Parameter Type Default Description
rowIndex dynamic Zero-based index of row.

View source

spillMagic

function spillMagic()

Implements spill magic for this module. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.

View source

spillNonce

spillNonce

Stores module-wide spill nonce state for the minisql executor sort module.

View source

spillSchema

function spillSchema(rows, valueCount, orderCount)

Implements spill schema for this module. 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.
valueCount dynamic Number of value to process.
orderCount dynamic Number of order to process.

View source

spillSpec

function spillSpec(kind)

Implements spill spec for this module. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.

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

View source

spillType

function spillType(kind)

Implements spill type for this module. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.

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

View source

targetMilestone

function targetMilestone()

Performs the targetMilestone operation for the minisql executor sort module. Returns the computed value or operation status. Any side effects are limited to the explicitly invoked dependencies.

View source

topNProjected

function topNProjected(rows, orderItems, count)

Retains only the best count rows in stable ORDER BY order. The optimizer limits this O(rows*count) implementation to small windows, avoiding external runs and a complete result sort for interactive ORDER BY ... LIMIT queries.

Parameter Type Default Description
rows dynamic rows value consumed by this operation.
orderItems dynamic orderItems value consumed by this operation.
count dynamic Number of items or units to process.

View source

writeRun

function writeRun(path, rows, valueCount, orderCount)

Writes run using the supplied inputs. Requires arguments that satisfy the validation performed below. Returns its result or propagates a structured error from validation or a dependency. Performs I/O through its file, transport, or storage dependencies.

Parameter Type Default Description
path dynamic Path of the file or directory used by the operation.
rows dynamic rows value consumed by this operation.
valueCount dynamic Number of value to process.
orderCount dynamic Number of order to process.

View source