Skip to main content

Module database

Module database 

Source
Expand description

Statements in a session with a .ursa database.

The engine’s Database keeps the catalog file: the statements that defined each object, in replay order. This module decides what a statement does to that list, and replays it when a database is opened.

  • CREATE VIEW, CREATE EXTERNAL TABLE and CREATE PROPERTY GRAPH add their statement once they succeed. An object already in the catalog (CREATE OR REPLACE) has its statement replaced in place, except that with IF NOT EXISTS it keeps its statement.
  • DROP VIEW, DROP TABLE and DROP PROPERTY GRAPH remove the object’s statement.
  • Tables with data (CREATE TABLE, INSERT and other DML) are refused: version 1 of the file does not store rows. So is any other DDL (CREATE SCHEMA, CREATE FUNCTION, ALTER …), which the file could not replay.
  • SET ursa.index_storage_limit = … and RESET ursa.index_storage_limit are kept in the catalog’s settings (#327), and applied to the session again when the database is opened: the limit belongs to the database, which obeys only its stored limit (or the default). In a read-only session they run for the session only. Other settings are the session’s.
  • TEMPORARY views and external tables run and are not stored.
  • In a read-only session, every statement that defines or drops anything is refused.

A statement is stored as its Display form when that parses back to the same statement, and otherwise as the text the user wrote (DataFusion’s Display for CREATE EXTERNAL TABLE leaves out columns and options).

Paths. A relative path resolves against the current directory when a statement runs, as in DuckDB. Before a definition is stored, each local file path in it (see [crate::paths]) is rewritten relative to the database’s directory, or made absolute when it is outside that directory; URLs are kept. In the stored-as-written case the paths are replaced in the text token by token, and the statement is refused if the result does not parse back to the rewritten statement. Replay resolves each stored relative path against the database’s directory, so the catalog finds the same files from any directory, and a database moved with its data still does. (M3a stored paths as written and resolved them against the database’s directory, so its files replay unchanged.)

Views and tables share one namespace, keyed by their name resolved against the default catalog and schema; graphs have their own.

Functions§

open_session
Open a new session on the database at path: open the file (creating it unless read-only), then replay its catalog.