Skip to content

Latest commit

 

History

History
1122 lines (750 loc) · 51.4 KB

File metadata and controls

1122 lines (750 loc) · 51.4 KB

src/minisql/executor/scan.ml

Home · Files

Provides minisql executor scan facilities for this project.

Package: minisql.executor.scan

Reachable from entry: yes

Imports

Declarations

all

function all(reader)

Materializes every live row. The range implementation is shared with LIMIT/OFFSET scans so checksum verification and transaction visibility have one implementation.

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

View source

allRange

function allRange(reader, offset, limit)

Scans a physical live-row range and materializes all columns.

Parameter Type Default Description
reader dynamic reader value consumed by this operation.
offset dynamic Zero-based offset at which processing starts.
limit dynamic limit value consumed by this operation.

View source

allRangeColumns

function allRangeColumns(reader, offset, limit, requiredColumns)

Implements all for this 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
reader dynamic reader value consumed by this operation.
offset dynamic Zero-based offset at which processing starts.
limit dynamic limit value consumed by this operation.
requiredColumns dynamic requiredColumns value consumed by this operation.

View source

appendArrayValue

function appendArrayValue(source, item, operation)

Appends array value 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
source dynamic source value consumed by this operation.
item dynamic item value consumed by this operation.
operation dynamic operation value consumed by this operation.

View source

close

function close(reader)

Closes close owned by the minisql executor scan module. Returns the computed value or operation status. May mutate supplied state and perform I/O through its dependencies.

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

View source

CLOSED_HANDLE

const CLOSED_HANDLE = 9008

Defines the closed handle constant used by the minisql executor scan module.

View source

componentName

function componentName()

Performs the componentName operation for the minisql executor scan 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 scan module.

View source

count

function count(reader)

Counts count 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
reader dynamic reader value consumed by this operation.

View source

countLiveRows

function countLiveRows(reader)

Counts live slots without decoding row values. Every heap page still passes through transaction visibility, the shared cache, and page checksum checks; only row allocation, schema conversion, and overflow payload reads are skipped.

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

View source

countTableRowsCached

function countTableRowsCached(databasePath, table, pageTransaction, readCache)

Opens a short-lived cached reader and returns only its number of visible rows.

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.

View source

countTableRowsCachedControlled

function countTableRowsCachedControlled(database, sessionId, table, pageTransaction)

Counts live rows through a cancellation-aware cached reader.

Parameter Type Default Description
database dynamic database value consumed by this operation.
sessionId dynamic Identifier of session.
table dynamic table value consumed by this operation.
pageTransaction dynamic pageTransaction value consumed by this operation.

View source

decodeRecord

function decodeRecord(reader, encoded)

Decodes record 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
reader dynamic reader value consumed by this operation.
encoded dynamic encoded value consumed by this operation.

View source

decodeRecordColumns

function decodeRecordColumns(reader, encoded, requiredColumns)

Decodes one record while materializing only columns required by the query. Unused values retain a correctly typed SQL NULL placeholder so bound column indexes remain stable, but external TEXT/BLOB payloads are never fetched. Generated columns conservatively use the full decoder because their stored expressions may depend on columns that are not explicit in the SELECT list.

Parameter Type Default Description
reader dynamic reader value consumed by this operation.
encoded dynamic encoded value consumed by this operation.
requiredColumns dynamic requiredColumns value consumed by this operation.

View source

evaluateDefault

function evaluateDefault(rule, column)

Evaluates default 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
rule dynamic rule value consumed by this operation.
column dynamic column value consumed by this operation.

View source

evaluateGenerated

function evaluateGenerated(reader, generated, column, currentValues)

Evaluates generated 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
reader dynamic reader value consumed by this operation.
generated dynamic generated value consumed by this operation.
column dynamic column value consumed by this operation.
currentValues dynamic currentValues value consumed by this operation.

View source

fail

function fail(code, operation, message)

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

findColumnRule

function findColumnRule(reader, columnName)

Finds column rule 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
reader dynamic reader value consumed by this operation.
columnName dynamic columnName value consumed by this operation.

View source

findGenerated

function findGenerated(reader, columnName)

Finds generated 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
reader dynamic reader value consumed by this operation.
columnName dynamic columnName value consumed by this operation.

View source

heapPageCount

function heapPageCount(reader)

Returns the number of physical heap pages advertised by the persistent page directory. Parallel operators use this metadata-only count to choose ranges.

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

View source

INVALID_ARGUMENT

const INVALID_ARGUMENT = 9001

Transaction-aware sequential table scan for the first executable SQL engine.

View source

isImplemented

function isImplemented()

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

View source

isRowBatch

function isRowBatch(value)

Reports whether a value is a bounded RowBatch.

Parameter Type Default Description
value dynamic Value consumed or transformed by the operation.

View source

isRowReference

function isRowReference(value)

Returns whether the supplied value satisfies the row reference condition. 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

isScannedRow

function isScannedRow(value)

Returns whether the supplied value satisfies the scanned row condition. 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

isTableReader

function isTableReader(value)

Returns whether the supplied value satisfies the table reader condition. 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

isTableRowCursor

function isTableRowCursor(value)

Returns whether value is a forward-only table row cursor.

Parameter Type Default Description
value dynamic Value consumed or transformed by the operation.

View source

materializeStoredValue

function materializeStoredValue(reader, index, raw)

Implements materialize stored 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
reader dynamic reader value consumed by this operation.
index dynamic Zero-based index of the affected item.
raw dynamic raw value consumed by this operation.

View source

nextBatch

function nextBatch(cursor, maximumRows)

Reads at most maximumRows from a forward-only cursor. A void result denotes end-of-input; every non-void batch contains at least one row.

Parameter Type Default Description
cursor dynamic cursor value consumed by this operation.
maximumRows dynamic maximumRows value consumed by this operation.

View source

nextRow

function nextRow(cursor)

Returns the next live row or void at end-of-table. Advancing before returning makes repeated calls deterministic even when the caller immediately discards a multi-megabyte decoded payload.

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

View source

open

function open(databasePath, table, pageTransaction)

Opens a table without a shared cache for storage tools and direct tests.

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.

View source

openCached

function openCached(databasePath, table, pageTransaction, readCache)

Opens cached for the minisql executor scan module. Requires arguments that satisfy the validation performed below. Returns the computed value or operation status. Performs I/O through its file, transport, or storage dependencies.

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.

View source

openCachedWithSchema

function openCachedWithSchema(databasePath, table, pageTransaction, readCache, state)

Opens a table using a database-owned immutable schema snapshot. Managed query execution uses this variant so point lookups do not reopen and verify schema.history. The paged table itself is still opened and validated here.

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.
state dynamic Mutable state inspected or updated by the operation.

View source

openCursor

function openCursor(reader, requiredColumns)

Creates a forward-only cursor over live rows. Heap-page discovery uses the persistent sidecar index, while each selected heap page is still checksum verified before any slot or overflow pointer is trusted.

Parameter Type Default Description
reader dynamic reader value consumed by this operation.
requiredColumns dynamic requiredColumns value consumed by this operation.

View source

openCursorRange

function openCursorRange(reader, requiredColumns, firstPageIndex, endPageIndex)

Creates a cursor over the half-open physical heap-page range [first, end). The range addresses entries in the persistent heap-page directory rather than raw file page numbers, so overflow and metadata pages are never scanned.

Parameter Type Default Description
reader dynamic reader value consumed by this operation.
requiredColumns dynamic requiredColumns value consumed by this operation.
firstPageIndex dynamic Zero-based index of first page.
endPageIndex dynamic Zero-based index of end page.

View source

openExisting

function openExisting(databasePath, file, table, pageTransaction)

Opens a caller-owned file without a shared cache.

Parameter Type Default Description
databasePath dynamic Path associated with database.
file dynamic file value consumed by this operation.
table dynamic table value consumed by this operation.
pageTransaction dynamic pageTransaction value consumed by this operation.

View source

openExistingCached

function openExistingCached(databasePath, file, table, pageTransaction, readCache)

Opens existing using the supplied inputs. Requires arguments that satisfy the validation performed below. Returns the computed value or operation status. Performs I/O through its file, transport, or storage dependencies.

Parameter Type Default Description
databasePath dynamic Path associated with database.
file dynamic file value consumed by this operation.
table dynamic table value consumed by this operation.
pageTransaction dynamic pageTransaction value consumed by this operation.
readCache dynamic readCache value consumed by this operation.

View source

openExistingCachedWithSchema

function openExistingCachedWithSchema(databasePath, file, table, pageTransaction, readCache, state)

Creates a non-owning reader over a persistent database-owned table handle and an already published immutable schema snapshot.

Parameter Type Default Description
databasePath dynamic Path associated with database.
file dynamic file value consumed by this operation.
table dynamic table value consumed by this operation.
pageTransaction dynamic pageTransaction value consumed by this operation.
readCache dynamic readCache value consumed by this operation.
state dynamic Mutable state inspected or updated by the operation.

View source

readReference

function readReference(reader, reference)

Reads reference 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. Any side effects are limited to the explicitly invoked dependencies.

Parameter Type Default Description
reader dynamic reader value consumed by this operation.
reference dynamic reference value consumed by this operation.

View source

readTableReference

function readTableReference(databasePath, table, pageTransaction, reference)

Reads table reference 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. Any side effects are limited to the explicitly invoked dependencies.

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.
reference dynamic reference value consumed by this operation.

View source

sampleRows

function sampleRows(reader, populationRows, maximumRows)

Decodes at most maximumRows uniformly spaced live rows while visiting each heap page once. ANALYZE obtains the exact population from slot headers first, then uses this pass to bound external-value I/O and retained memory.

Parameter Type Default Description
reader dynamic reader value consumed by this operation.
populationRows dynamic populationRows value consumed by this operation.
maximumRows dynamic maximumRows value consumed by this operation.

View source

sampleTableRowsCached

function sampleTableRowsCached(databasePath, table, populationRows, maximumRows, readCache)

Opens one cached reader for the bounded ANALYZE sampling pass.

Parameter Type Default Description
databasePath dynamic Path associated with database.
table dynamic table value consumed by this operation.
populationRows dynamic populationRows value consumed by this operation.
maximumRows dynamic maximumRows value consumed by this operation.
readCache dynamic readCache value consumed by this operation.

View source

scanExisting

function scanExisting(databasePath, file, table, pageTransaction)

Scans existing 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. Any side effects are limited to the explicitly invoked dependencies.

Parameter Type Default Description
databasePath dynamic Path associated with database.
file dynamic file value consumed by this operation.
table dynamic table value consumed by this operation.
pageTransaction dynamic pageTransaction value consumed by this operation.

View source

scanExistingRange

function scanExistingRange(databasePath, file, table, pageTransaction, offset, limit)

Applies a bounded range scan to a caller-owned paged file.

Parameter Type Default Description
databasePath dynamic Path associated with database.
file dynamic file value consumed by this operation.
table dynamic table value consumed by this operation.
pageTransaction dynamic pageTransaction value consumed by this operation.
offset dynamic Zero-based offset at which processing starts.
limit dynamic limit value consumed by this operation.

View source

scanExistingRangeColumns

function scanExistingRangeColumns(databasePath, file, table, pageTransaction, offset, limit, requiredColumns)

Applies both range and column pushdown to a caller-owned paged file.

Parameter Type Default Description
databasePath dynamic Path associated with database.
file dynamic file value consumed by this operation.
table dynamic table value consumed by this operation.
pageTransaction dynamic pageTransaction value consumed by this operation.
offset dynamic Zero-based offset at which processing starts.
limit dynamic limit value consumed by this operation.
requiredColumns dynamic requiredColumns value consumed by this operation.

View source

scanTable

function scanTable(databasePath, table, pageTransaction)

Scans table 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. Any side effects are limited to the explicitly invoked dependencies.

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.

View source

scanTableRange

function scanTableRange(databasePath, table, pageTransaction, offset, limit)

Scans only a physical live-row range and stops as soon as the requested number of rows has been decoded. This bounds memory for simple paginated SELECT statements and avoids reading overflow values outside the page.

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.
offset dynamic Zero-based offset at which processing starts.
limit dynamic limit value consumed by this operation.

View source

scanTableRangeColumns

function scanTableRangeColumns(databasePath, table, pageTransaction, offset, limit, requiredColumns)

Scans a range while fetching only columns referenced by the bound query.

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.
offset dynamic Zero-based offset at which processing starts.
limit dynamic limit value consumed by this operation.
requiredColumns dynamic requiredColumns value consumed by this operation.

View source

scanTableRangeColumnsCached

function scanTableRangeColumnsCached(databasePath, table, pageTransaction, offset, limit, requiredColumns, readCache)

Uses the database-owned concurrent page cache together with range and projection pushdown. The reader handle remains short-lived; cache frames are keyed only by stable path and page number.

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.
offset dynamic Zero-based offset at which processing starts.
limit dynamic limit value consumed by this operation.
requiredColumns dynamic requiredColumns value consumed by this operation.
readCache dynamic readCache value consumed by this operation.

View source

scanTableRangeColumnsCachedControlled

function scanTableRangeColumnsCachedControlled(database, sessionId, table, pageTransaction, offset, limit, requiredColumns)

Controlled cached scan used by network sessions. The ordinary helper stays available to embedded/offline callers that do not own an operational session.

Parameter Type Default Description
database dynamic database value consumed by this operation.
sessionId dynamic Identifier of session.
table dynamic table value consumed by this operation.
pageTransaction dynamic pageTransaction value consumed by this operation.
offset dynamic Zero-based offset at which processing starts.
limit dynamic limit value consumed by this operation.
requiredColumns dynamic requiredColumns value consumed by this operation.

View source

scanUsing

function scanUsing(databasePath, table, pageTransaction, existingFile)

Scans using 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
databasePath dynamic Path associated with database.
table dynamic table value consumed by this operation.
pageTransaction dynamic pageTransaction value consumed by this operation.
existingFile dynamic existingFile value consumed by this operation.

View source

scanUsingColumns

function scanUsingColumns(databasePath, table, pageTransaction, existingFile, requiredColumns)

Scans all rows but materializes only the supplied table-column mask.

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.
existingFile dynamic existingFile value consumed by this operation.
requiredColumns dynamic requiredColumns value consumed by this operation.

View source

scanUsingControlled

function scanUsingControlled(database, sessionId, table, pageTransaction, existingFile)

Controlled full scan over either a caller-owned table file or a short-lived reader. This is used by UPDATE, DELETE, and TRUNCATE before staging changes.

Parameter Type Default Description
database dynamic database value consumed by this operation.
sessionId dynamic Identifier of session.
table dynamic table value consumed by this operation.
pageTransaction dynamic pageTransaction value consumed by this operation.
existingFile dynamic existingFile value consumed by this operation.

View source

scanUsingRange

function scanUsingRange(databasePath, table, pageTransaction, existingFile, offset, limit)

Selects the bounded scan implementation for an optional caller-owned file.

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.
existingFile dynamic existingFile value consumed by this operation.
offset dynamic Zero-based offset at which processing starts.
limit dynamic limit value consumed by this operation.

View source

schemaForTable

function schemaForTable(table)

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

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

View source

setExecutionControl

function setExecutionControl(reader, database, sessionId)

Attaches statement cancellation and deadline state to a reader. Polling is deliberately performed once per physical heap page, which bounds abort latency without adding a registry lookup for every row or expression.

Parameter Type Default Description
reader dynamic reader value consumed by this operation.
database dynamic database value consumed by this operation.
sessionId dynamic Identifier of session.

View source

targetMilestone

function targetMilestone()

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

View source

UNSUPPORTED_SQL

const UNSUPPORTED_SQL = 9025

Defines the unsupported sql constant used by the minisql executor scan module.

View source

validateOpen

function validateOpen(reader, operation)

Validates open for the minisql executor scan workflow. Requires arguments that satisfy the validation performed below. Returns the computed value or operation status. Performs I/O through its file, transport, or storage dependencies.

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

View source

verifyAndCount

function verifyAndCount(reader)

Fully decodes and validates every live row while retaining only one row. This includes external TEXT/BLOB chains, UTF-8 conversion, schema compatibility, generated/default column handling, page checksums, and slot generations.

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

View source

verifyTable

function verifyTable(databasePath, table, pageTransaction)

Opens, streams, and closes one table for the offline consistency checker.

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.

View source

visiblePage

function visiblePage(reader, pageNumber)

Implements visible page for this module. Requires arguments that satisfy the validation performed below. Returns the computed value or operation status. Performs I/O through its file, transport, or storage dependencies.

Parameter Type Default Description
reader dynamic reader value consumed by this operation.
pageNumber dynamic pageNumber value consumed by this operation.

View source