pub struct ColumnSchema {Show 23 fields
pub name: String,
pub ty: DataType,
pub nullable: bool,
pub default: Option<Value<'static>>,
pub runtime_default: Option<String>,
pub collation_name: Option<String>,
pub auto_increment: bool,
pub user_enum_type: Option<String>,
pub user_domain_type: Option<String>,
pub user_composite_type: Option<String>,
pub acl: Vec<AclItem>,
pub on_update_runtime: Option<String>,
pub collation: Collation,
pub is_unsigned: bool,
pub inline_enum_variants: Option<Vec<String>>,
pub inline_set_variants: Option<Vec<String>>,
pub generated_stored_expr: Option<String>,
pub identity_always: bool,
pub default_text: Option<String>,
pub auto_restart: Option<i64>,
pub scalar_row_source: bool,
pub mysql_int_width: Option<MysqlIntWidth>,
pub mysql_fsp: Option<u8>,
}Expand description
Each bool is an independent, separately-persisted column attribute
(nullable, auto_increment, is_unsigned, identity_always) that the
catalog appendix reads and writes by name. Packing them into a bitflags
word would buy nothing and would put a decoding step between the on-disk
format and every reader of the schema.
Fields§
§name: String§ty: DataType§nullable: bool§default: Option<Value<'static>>Optional DEFAULT value, frozen at CREATE TABLE time. None
means “no default” (so omitted columns become NULL, or error
out when the column is NOT NULL). Literal defaults take this
path.
v7.37.42-arena Phase 1: explicitly Value<'static> — catalog
defaults must outlive any per-query arena.
runtime_default: Option<String>v7.9.21 — for DEFAULT expressions that need INSERT-time
evaluation (e.g. DEFAULT now(), DEFAULT CURRENT_TIMESTAMP),
the Display form of the expression. The engine re-parses
it on each INSERT default-fill, evaluates against an empty
row context, and coerces to the column type. mailrs G4.
Persisted in catalog FILE_VERSION 15+; older catalogs
deserialise with None.
collation_name: Option<String>MySQL-style AUTO_INCREMENT. When set, an INSERT that leaves
this column unbound (or sets it to NULL) gets the next integer
computed from the column’s current max + 1.
v7.39 (round 676) — the collation NAME as written, when the column
carried an explicit COLLATE.
spg_sql::Collation cannot carry it: it is a two-variant MySQL enum
and from_collation_name folds C, POSIX, en_US and default
all into Binary. Without the name pg_attribute.attcollation can
only ever report the type’s default, which is what F36 records as
“the declaration is taken and ignored”.
None means the column was written without a COLLATE clause and
takes its type’s collation. Persisted through the v88 appendix,
which costs two bytes for a table that declares none.
auto_increment: bool§user_enum_type: Option<String>v7.17.0 Phase 1.4 — when the column is bound to a user-
defined ENUM type (the parser saw an unknown type ident
and the engine resolved it against catalog.enum_types),
this carries the enum name so INSERT/UPDATE can validate
the cell value against the enum’s labels. ty is
DataType::Text in that case. Persisted in catalog
FILE_VERSION 29+; older catalogs deserialise with None.
user_domain_type: Option<String>v7.17.0 Phase 1.5 — when the column is bound to a user-
defined DOMAIN (the parser saw an unknown type ident and
the engine resolved it against catalog.domain_types),
this carries the domain name. ty is the domain’s base
type; INSERT/UPDATE re-evaluates the domain’s CHECK list
- NOT NULL against the cell value. Persisted in catalog FILE_VERSION 30+; older catalogs deserialise with None.
user_composite_type: Option<String>v7.39 (read01 round 56) — when the column is bound to a user-defined
COMPOSITE type. ty stays DataType::Jsonb (the on-disk form), but the
engine REHYDRATES the stored JSON into a Value::Composite on read, so
field access (p).x, = ROW(…), ordering and the canonical (2,b)
text form all work — they were already implemented on Value::Composite;
what was missing was that the column never recorded WHICH composite type
it holds (this field’s doc comment existed for two releases, the field
itself did not). Persisted in the composite-column appendix
(FILE_VERSION 63+); older catalogs deserialise with None.
acl: Vec<AclItem>v7.39 (read01 round 59) — column-level privileges (PG
pg_attribute.attacl). GRANT SELECT (pub) ON t TO dan lands here and
does NOT touch the table’s relacl. Empty = no column grant, which is
every column until one is made.
on_update_runtime: Option<String>v7.17.0 Phase 2.1 — MySQL ON UPDATE CURRENT_TIMESTAMP
column attribute. When Some(expr_src), an UPDATE that
does NOT bind this column overrides the new value with
the engine-evaluated expression (always now() in
v7.17.0). Stored as Display-form source so storage
stays free of spg-sql; the engine re-parses at UPDATE
time. Persisted in catalog FILE_VERSION 32+; older
catalogs deserialise with None — preserves the existing
“silent ignore” behaviour for snapshots written before
the upgrade.
collation: Collationv7.17.0 Phase 2.5 — text collation. Pre-2.5 SPG accepted
COLLATE <name> clauses but discarded the name, so a
column declared COLLATE "case_insensitive" (or any
MySQL _ci collation) still compared byte-wise — a
Tier-S silent failure where WHERE name = 'foo' never
matched stored 'Foo'. This carries the parser-derived
classification so the engine’s WHERE evaluator can route
text equality through a case-aware compare. Binary (the
default) preserves the prior byte-wise behaviour. Only
CaseInsensitive lands in the catalog appendix — Binary
columns stay implicit, keeping snapshots compact.
Persisted in catalog FILE_VERSION 34+; older catalogs
deserialise every column as Binary.
is_unsigned: boolv7.17.0 Phase 4.4 — MySQL UNSIGNED modifier flag. Drives
engine-side INSERT / UPDATE range enforcement (rejects
negative values on UNSIGNED int columns). Pre-4.4 the
parser consumed and discarded the keyword silently, so
every UNSIGNED column quietly accepted negatives — a
Tier-A correctness drift. Sparse: only UNSIGNED columns
land in the catalog appendix; the default false keeps
snapshots compact for the common signed-int path.
Persisted in catalog FILE_VERSION 35+; older catalogs
deserialise every column as is_unsigned = false.
inline_enum_variants: Option<Vec<String>>v7.17.0 Phase 3.P0-36 — MySQL inline ENUM('a','b','c')
value list. Distinct from user_enum_type (which points
to a separately CREATE TYPE’d PG enum); this carries the
column-local list MySQL DDL declares inline. When Some,
ty is DataType::Text and INSERT/UPDATE validates the
cell value against this list. Variant ORDER is preserved
(MySQL uses it for ORDER BY col). Sparse: only ENUM
columns land in the catalog appendix.
Persisted in catalog FILE_VERSION 41+; older catalogs
deserialise with None — preserves silent-drop behaviour
for snapshots written before P0-36.
inline_set_variants: Option<Vec<String>>v7.17.0 Phase 3.P0-37 — MySQL inline SET('a','b','c')
variant list. Storage is TEXT (canonical comma-joined in
definition order, de-duplicated). INSERT/UPDATE validates
every comma-separated token against this list. Sparse:
only SET columns land in the catalog appendix.
Persisted in catalog FILE_VERSION 42+; older catalogs
deserialise with None.
generated_stored_expr: Option<String>v7.37.7(sentori Epic 3 P1)— GENERATED ALWAYS AS (<expr>) STORED computed-column source. When Some, INSERT / UPDATE
recompute the cell against the candidate row(re-parse the
stored Display form and evaluate)and overwrite any
user-supplied value, matching PG’s stored-generated-column
semantics. None (the default) preserves the regular
“column value is whatever the caller passed” path.
Persisted in catalog FILE_VERSION 50+; older catalogs
deserialise with None.
identity_always: boolv7.38 (read01) — GENERATED ALWAYS AS IDENTITY. Both identity
flavours set auto_increment; this additionally marks the ALWAYS
flavour, whose explicit INSERT value PG rejects (“cannot insert a
non-DEFAULT value into column …”) unless OVERRIDING SYSTEM VALUE.
false (serial / BY DEFAULT) keeps the permissive path. In-memory
only for now — not yet in the catalog appendix, so a reloaded table
deserialises as false (the pre-existing permissive behaviour).
default_text: Option<String>v7.38 (read01) — the DEFAULT expression’s source text, deparsed to
PG-compatible form at CREATE TABLE time (e.g. 0, (3 + 4),
'hi'::text, now(), CURRENT_DATE). Distinct from default
(the coerced value the INSERT path fills) and runtime_default
(the recompute-per-row Display form): those lose the source
spelling, so information_schema.columns.column_default /
pg_attrdef / pg_get_expr reported the coerced render
(0.00 for numeric(10,2) DEFAULT 0) instead of PG’s 0.
None for a column with no explicit default. Persisted in catalog
FILE_VERSION 58+; older catalogs deserialise with None.
auto_restart: Option<i64>v7.39 (round 220) — ALTER TABLE … ALTER COLUMN … RESTART [WITH n]
on an identity column. SPG’s identity allocation is a max+1 scan;
this floor lifts the next allocated value to at least n
(max(max+1, n)) — exactly what a dump-restore RESTART needs, and
safer than PG for a backward RESTART (no duplicate-key landmine).
Persisted in the FILE_VERSION 73+ sparse appendix; older catalogs
deserialise with None.
scalar_row_source: boolv7.39 (read01 round 78) — this column is the ONLY column of a FROM item
that calls a function returning a BASE type, so the item’s row type IS
this column: a whole-row reference collapses to the value
(SELECT j FROM jsonb_array_elements('[1]') AS j → 1, PG). Runtime
only — a catalogued table column is never one, and it is not persisted.
mysql_int_width: Option<MysqlIntWidth>v7.39 (round 386, type-fidelity epic P1) — the declared MySQL narrow
integer width (TINYINT / MEDIUMINT) whose range the storage ty
(SmallInt / Int) is too wide to enforce. None for every other
column. Drives the epic-P2 write-path range check. Persisted in the
FILE_VERSION 81+ sparse appendix; older catalogs deserialise as None.
mysql_fsp: Option<u8>v7.39 (round 424, type-fidelity epic) — the declared MySQL
fractional-seconds precision of a temporal column: DATETIME(3) is
Some(3), a BARE DATETIME / TIME / TIMESTAMP is Some(0)
(MySQL’s default is zero — the fraction is dropped on write), and
None means “not a MySQL-declared temporal column”, which is every
PG column and leaves microsecond behaviour untouched.
Drives write-path truncation (toward zero) and render padding
(exactly this many digits, .000 when the fraction is zero).
Persisted in the FILE_VERSION 82+ sparse appendix; older catalogs
deserialise as None.
Implementations§
Source§impl ColumnSchema
impl ColumnSchema
pub fn new(name: impl Into<String>, ty: DataType, nullable: bool) -> Self
Sourcepub fn with_default(self, default: Value<'static>) -> Self
pub fn with_default(self, default: Value<'static>) -> Self
Builder-style helper to attach a default value to an otherwise
plain column schema. Used by the engine when CREATE TABLE
specifies column TYPE DEFAULT <expr>.
Sourcepub fn with_runtime_default(self, expr: impl Into<String>) -> Self
pub fn with_runtime_default(self, expr: impl Into<String>) -> Self
v7.9.21 — builder for runtime-evaluated defaults
(DEFAULT now(), DEFAULT CURRENT_TIMESTAMP, …).
expr is the Expr’s Display form, re-parsed by the
engine at each INSERT.
Sourcepub const fn with_auto_increment(self) -> Self
pub const fn with_auto_increment(self) -> Self
Builder-style helper to mark a column as AUTO_INCREMENT.
Trait Implementations§
Source§impl Clone for ColumnSchema
impl Clone for ColumnSchema
Source§fn clone(&self) -> ColumnSchema
fn clone(&self) -> ColumnSchema
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more