Something went wrong. Try again.
SQLite file format and SQL engine in pure OCaml
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114(** Internal select execute operations. *)
module Ast = Sql.Astmodule Query = Sql.Private.Querymodule Engine = Sql.Private.Enginemodule Resolve = Sql.Private.Resolvemodule Plan = Sql.Private.Planmodule Lower = Sql.Private.Lowermodule Value_ops = Sql.Value_opsmodule Value_op = Sql.Private.Value_opmodule Register = Catalog.Registermodule Ident = Catalog.Identmodule Seek = Seekmodule Cursor = Cursormodule Catalog_view = Catalog_viewmodule Fast_path = Fast_path
type value = Ast.value = | Null | Int of int64 | Float of float | Blob of string | Text of string
module type S = Select_intf.S
module Make (R : S) : sig include module type of Select_source.Make (R) include Select_intf.RUN with type t := R.t
val plan_query : R.t -> bound:Select_source.Ident.t list -> reads -> Ast.select -> Plan.layout -> Plan.t (** Plans the select over its resolved sources and bound CTE names. *)
type scan_plan = { plan : Plan.t; paths : R.seek_path option array; unmatched_paths : R.seek_path option array; read : int list array; tables : string option list; }
val unsorted : scan_plan -> Ast.select -> Ast.select (** [s] without the ORDER BY its plan's loop already yields in order, so the rows stream as they are read instead of filling a sorter. A scan, and a range of the rowid, walk the table forwards only, so the rowid order they yield backwards is still sorted, which a key that unique leaves as it was. *)
exception Refused
val stored_table : R.t -> bound:Select_source.Ident.t list -> Ast.table_ref -> bool (** Whether [tr] names a table the database stores, which an EXISTS over it may join ({!Query.exists_to_join}): not a derived table, not a WITH table [bound] names, not a view. *)
val resolve : R.t -> Query.catalog -> Ast.select -> Sql.Ast.select (** The schema read into a select that has no [WITH] and no compound arm: its ordinals, collations and aliases resolved, an aggregate of an enclosing query lifted out of its subqueries, and its EXISTS conjuncts joined. *)
val limited_to_one : Ast.select -> Ast.select (** A scalar or EXISTS subquery as sqlite3 runs it: under a LIMIT of one, or of whether its own LIMIT is not zero (expr.c, sqlite3CodeSubselect). *)
val explain_layout : R.t -> Ast.select -> (string * string list) list (** The alias and column names each source of [s] publishes, enough to decide an access path without materialising anything. A plain rowid table's cursor carries a trailing hidden rowid slot, appended here so EXPLAIN plans over the same list the executed plan reads. *)
val prepared : ?memo:Handle.memo -> R.t -> Query.catalog -> Ast.select -> Handle.prepared (** The work an earlier run of [s] left in [memo], where it was made of this select against this schema, else a fresh start, kept for the next run. *)
type kept = { mutable names : string list option; mutable infos : (string * string list * (unit -> Catalog.Cursor.t)) list option; mutable grouped : bool option; plan : Sql.Closure.plan option ref; regs : Catalog.Register.t array option ref; }
val cat_subquery_rows : R.t -> Query.catalog -> (string * (string * Sql.Ast.value) list) list -> Ast.select -> Sql.Ast.value array -> Sql.Ast.value list list (** A subquery over the outer row [scope], run as the VM runs one under a query of its own ({!run_subquery_impl}): the row bound as parameters, so every outer row runs the one select, and its plan kept on the catalog, compiled at the first run. Only what [s] and [cat] alone decide is kept: the sources are read again at every run, since a table-valued function may take its arguments from the row.
A subquery that reads no relation of [cat]'s own ({!Query.binds}) reads the database's, and is a select of its own as sqlite3 codes it ({!stored_rows}): through its access paths, and as the database stands at each run, so a subquery correlated to a row an UPDATE rewrites reads the rows rewritten before it. One that reads no outer row runs once for the catalog, as sqlite3 runs an uncorrelated subquery once (expr.c, sqlite3CodeSubselect, OP_Once). *)end