planner

package
v0.5.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 9 Imported by: 2 modules, 1 package

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package planner classifies schema-change statements: for each operation it decides whether PostgreSQL can run it online natively (possibly via a safer idiom it suggests), whether it needs the engine's copy-and-swap path, or whether it is refused. The mapping is the "Needs copy-and-swap?" column of docs/postgres-online-ddl-reference.md, applied conservatively: anything the planner cannot prove safe routes to copy-and-swap or refuse. Classification predicts; executors keep their own protections regardless.

In MySQL terms, the planner is PostgreSQL's missing ALGORITHM= / LOCK= declaration: MySQL lets authors assert the cost bracket (INSTANT/INPLACE/COPY) and the lock impact (NONE/SHARED/EXCLUSIVE) and fails closed; PostgreSQL has no such clause, so the planner proves both dimensions before execution and routes to the safest sequence that exists.

The rules assume PostgreSQL 14, the oldest major the test matrix runs; every rule holds unconditionally across the supported range (14–18). Rules that were version-dependent below that floor — fast default (PG 11+), SET NOT NULL proven by a validated CHECK (PG 12+), DETACH PARTITION CONCURRENTLY (PG 14+) — carry no version annotation because the floor makes them unconditional. A rule that varies within the supported range must carry an explicit version fact before it lands.

Index

Constants

View Source
const GeneratedColumnHelp = "drop those generated columns first, then re-plan; " +
	"adding a stored one back afterwards, or changing a stored one's expression instead, rewrites the table"

GeneratedColumnHelp is the operator-facing manual path for a dependent-generated-column decision, phrased to follow a sentence that names the generated columns.

View Source
const NotNullWithoutDefaultHelp = "give the column a constant DEFAULT, which PostgreSQL stores without rewriting the table, " +
	"or add it without NOT NULL, backfill it, then set NOT NULL"

NotNullWithoutDefaultHelp is the operator-facing manual path for a not-null-without-default decision.

View Source
const PartitionKeyHelp = "create a new partitioned table with the new column definition and move the rows into it"

PartitionKeyHelp is the operator-facing manual path for a partition-key decision, phrased to follow a sentence that names the partitioned tables.

View Source
const RulesPostgresVersions = "14-18"

RulesPostgresVersions is the inclusive PostgreSQL major-version range the classification rules are derived for (see the package comment and docs/postgresql-version-support.md). Offline consumers such as the linter stamp it into their reports so a stored result names the assumptions behind it.

Variables

This section is empty.

Functions

func DependentsPhrase added in v0.5.0

func DependentsPhrase(singular, plural string, names []string) string

DependentsPhrase names dependents after "read by": the singular noun before one name and the plural before several, joined with commas.

func DestructiveOpKinds added in v0.5.0

func DestructiveOpKinds() []statement.OpKind

DestructiveOpKinds returns every operation shape the planner marks destructive, in statement.OpKinds() order. The front door's irreversible-operations registry derives its operation entries from it, so this classification stays the only list of destructive shapes.

func NullFillCandidates added in v0.5.0

func NullFillCandidates(ops []statement.Op, columns map[string]string) []string

NullFillCandidates names the columns the operations of one ALTER TABLE add with no DEFAULT of their own, the ones whose existing rows may be left NULL: a front door reads Facts.NullFilledColumns only for these. The statement need not spell NOT NULL, since the column's domain or an inline PRIMARY KEY can make it NOT NULL, so the server's probe decides which candidates PostgreSQL would refuse. columns are the table's live columns. A column the table already has is skipped by ADD COLUMN IF NOT EXISTS, and refused as a duplicate otherwise, so neither fills anything, unless an earlier operation of the same statement drops it, which makes the add a new column again.

Types

type ColumnDependents added in v0.5.0

type ColumnDependents struct {
	// Tree covers the table and every table below it, which is what a
	// recursive ALTER COLUMN TYPE changes.
	Tree map[string][]string
	// Drop covers the tables whose copy of the column a recursive DROP
	// COLUMN drops: a child that declares the column itself or also
	// inherits it from a table outside the drop keeps its copy.
	Drop map[string][]string
	// Own covers the table alone, which is all an ALTER TABLE ONLY
	// changes.
	Own map[string][]string
}

ColumnDependents maps a column to the objects that depend on it, read for each set of tables an ALTER COLUMN TYPE or DROP COLUMN reaches (preflight.ReadColumnDependents). A column absent from a map has none, or the facts were not read, as in an offline lint; either way the server's own refusal at execution remains the backstop.

type Decision

type Decision struct {
	// Operation is the operator-facing label (display only).
	Operation string `json:"operation"`
	// Kind is the operation's parsed shape. The router's availability
	// policy branches on it together with Reason: whether a backend
	// carries a rewrite depends on what the operation does to the table,
	// not only on why PostgreSQL would rewrite it. It is not part of the
	// plan-report contract; a consumer branches on Reason.
	Kind statement.OpKind `json:"-"`
	// Destructive marks operations that discard live structure — a dropped
	// column, constraint, index, or NOT NULL. It is derived from the operation shape
	// here, in the one place every front door shares, so a plan reports the
	// same statement as destructive no matter how it was submitted. It is
	// always emitted, never omitted: a safety flag a consumer gates on must
	// be explicit even when false.
	Destructive bool `json:"destructive"`
	// Route is where the operation goes.
	Route Route `json:"route"`
	// Reason is why.
	Reason Reason `json:"reason"`
	// Unverified marks a decision the planner took without the live facts
	// needed to prove a cheaper one — it failed closed to the heavier
	// route. The route is what the engine would do, not a proven property
	// of the change: with facts (a live introspection or a supplied
	// column type) the same operation may classify as native.
	Unverified bool `json:"unverified,omitempty"`
	// SaferSQL is the ordered safer native sequence, present only for
	// safer-idiom decisions where the planner could construct it. It is a
	// safer form of the submitted statement, not a semantic equivalent: it
	// converges on the same declared end state with different locking,
	// transactionality, and failure modes. SaferSQLExecution carries the
	// execution contract: the steps run one at a time, in order, each in
	// its own implicit transaction — never inside an enclosing transaction
	// block, which the CONCURRENTLY forms refuse. Each sequence constructor
	// documents what a failed step leaves behind and how a retry resumes
	// (a failed CONCURRENTLY build leaves an invalid index the runner must
	// detect via pg_index.indisvalid and rebuild).
	SaferSQL []string `json:"safer_sql,omitempty"`
	// SaferSQLExecution is the typed execution contract for SaferSQL,
	// present exactly when SaferSQL is. Automation branches on it instead
	// of prose — it is what tells a consumer the sequence must not be
	// wrapped in a transaction block.
	SaferSQLExecution Execution `json:"safer_sql_execution,omitempty"`
	// DependentViews names the views and materialized views that read the
	// column, each schema-qualified with every identifier quoted, present
	// whenever one blocks the change, whatever the decision's reason.
	DependentViews []string `json:"dependent_views,omitempty"`
	// DependentPolicies names the row-level security policies that read
	// the column, each rendered "policy" ON "schema"."table" with every
	// identifier quoted, present whenever one blocks the change, whatever
	// the decision's reason.
	DependentPolicies []string `json:"dependent_policies,omitempty"`
	// DependentTriggers names the triggers whose UPDATE OF list or WHEN
	// condition names the column, each rendered "trigger" ON
	// "schema"."table" with every identifier quoted, present whenever one
	// blocks the change, whatever the decision's reason.
	DependentTriggers []string `json:"dependent_triggers,omitempty"`
	// DependentGeneratedColumns names the generated columns whose
	// expression reads the column, each rendered "schema"."table"."column"
	// with every identifier quoted, present whenever one blocks the change,
	// whatever the decision's reason. A copy that dropping the table's own
	// generated column removes is left out, since PostgreSQL refuses to
	// drop it on its own.
	DependentGeneratedColumns []string `json:"dependent_generated_columns,omitempty"`
	// PartitionKeyTables names the partitioned tables whose partition key
	// includes the column, each schema-qualified with every identifier
	// quoted, present exactly for partition-key decisions.
	PartitionKeyTables []string `json:"partition_key_tables,omitempty"`
	// DependentFix is the manual path for the policies and triggers that
	// block the change, which depends on what the change would do with
	// those dependents out of the way. Like Kind, it is not part
	// of the plan-report contract: it selects the help the engine's own
	// text renders.
	DependentFix DependentFix `json:"-"`
}

Decision is the classification of one operation.

func (Decision) ExecutableAsSubmitted

func (d Decision) ExecutableAsSubmitted() bool

ExecutableAsSubmitted reports whether the operation's submitted form is itself safe to run. It is false for the decisions whose submitted form must be replaced by a safer sequence, whether or not one was constructed: a safer-idiom decision, whose submitted form blocks the table, and an app-breaking rename, whose submitted form breaks every running application instance that still uses the old name. Routing fails closed on the combination of a false ExecutableAsSubmitted and an empty SaferSQL.

func (Decision) OtherDependents added in v0.5.0

func (d Decision) OtherDependents() string

OtherDependents phrases the dependents that block the change besides the kind its reason names, such as the triggers on a dependent-policy decision, or returns "" when there are none. PostgreSQL refuses the change until every one of them is out of the way.

type DependentFix added in v0.5.0

type DependentFix string

DependentFix is the manual path for a change PostgreSQL refuses while a row-level security policy or a trigger reads the column: objects that can be dropped and recreated around the change.

const (
	// DependentFixRewriteDependents is for a column drop. The dependents
	// have to stop reading the column before it can go, and the drop then
	// plans on its own.
	DependentFixRewriteDependents DependentFix = "rewrite-dependents"
	// DependentFixRecreateAroundChange is for a type change PostgreSQL runs
	// in place. Dropping the dependents, running the change, and
	// recreating them in one transaction holds the table's exclusive lock
	// only briefly, and no session sees the table without them.
	DependentFixRecreateAroundChange DependentFix = "recreate-around-change"
	// DependentFixExpandContract is for a type change that rewrites the
	// table. Recreating the dependents around it would hold the exclusive
	// lock for the whole rewrite, and copy-and-swap rebuilds the table's
	// policies before it retypes the column, so it meets the same refusal
	// (it refuses a table with triggers outright). A new column of the
	// target type takes the dependents over instead.
	DependentFixExpandContract DependentFix = "expand-contract"
)

func (DependentFix) Help added in v0.5.0

func (f DependentFix) Help(plural string) string

Help is the operator-facing manual path, phrased to follow a sentence that names the dependents; plural is their noun, such as "policies".

type Execution

type Execution string

Execution is the typed execution contract for a planner-produced SQL sequence; automation branches on it, never on prose. It tells a consumer how the steps must run and that a failed step can leave partial state the runner owns detecting and recovering.

const (
	// ExecutionAutocommit: the steps run one at a time, in order, each in
	// its own implicit transaction — never inside an enclosing transaction
	// block. The CONCURRENTLY forms refuse an enclosing block outright,
	// and a multi-step sequence inside one block holds every earlier
	// step's locks across the steps designed to avoid them. A failed step
	// leaves partial state the runner must detect and recover before
	// retrying (a failed CONCURRENTLY build leaves an invalid index,
	// pg_index.indisvalid = false).
	ExecutionAutocommit Execution = "autocommit-each-step"
	// ExecutionPartitionedIndexBuild: the one step is a CREATE INDEX on a
	// partitioned table, and it runs as the partition-aware index build, not
	// as the statement: the parent's index is created with ONLY, each
	// partition's index is built concurrently and attached, and the parent's
	// index turns valid with the last attach. The partitions are listed when
	// the build runs, not when the plan is made. The statement must not be
	// run as written, which would build every partition's index under a lock
	// that blocks writes to the whole tree. A failed or interrupted run
	// leaves an invalid parent index and the partition indexes built so far;
	// running the same statement again resumes from them.
	ExecutionPartitionedIndexBuild Execution = "partitioned-index-build"
)

The execution contracts a sequence can carry.

func Executions

func Executions() []Execution

Executions returns the closed set of Execution values. It is part of the plan-report contract (docs/plan-report.md): the set changes only with a format_version bump, and a consumer that meets an unrecognized value must treat the sequence as unknown and refuse to run it.

type Facts

type Facts struct {
	// ColumnTypes maps a column name to its live type as rendered by
	// PostgreSQL's format_type (e.g. "character varying(50)").
	ColumnTypes map[string]string
	// ColumnCollations maps each live column whose collation is not its
	// type's default to that collation, as schemadiff renders it. A column
	// absent from the map has the default collation. Retyping a column
	// without a COLLATE clause resets it to the new type's default, so a
	// column present here loses its collation and every index on it is
	// rebuilt: never a relabel.
	ColumnCollations map[string]string
	// ReplicaIdentity is what the replica identity indexes of the table and
	// the tables below it key on; the zero value when none has one to
	// protect.
	ReplicaIdentity schemadiff.ReplicaIdentityKeys
	// AddColumnProofs maps a column the change adds to what the server
	// proved about adding it (preflight.AddColumnRewrites). A column absent
	// from the map is unproven and classifies by the statement's shape
	// alone, which assumes the worst of any default it cannot read as a
	// constant; the proof leaves out only an ADD COLUMN IF NOT EXISTS for a
	// column the table already has, which the server skips.
	AddColumnProofs map[string]statement.AddColumnProof
	// DependentViews maps a column to the views and materialized views that
	// read it, on the table or on any table below it, which is what a
	// recursive ALTER COLUMN TYPE changes
	// (preflight.ReadColumnDependents). A column absent from the map has
	// none, or the facts were not read, as in an offline lint; either way
	// the server's own refusal at execution remains the backstop.
	DependentViews map[string][]string
	// DropDependentViews is DependentViews for the tables whose copy of
	// the column a recursive DROP COLUMN drops: a child that declares the
	// column itself or also inherits it from a table outside the drop
	// keeps its copy.
	DropDependentViews map[string][]string
	// OwnDependentViews is DependentViews for the table alone, which is
	// all an ALTER TABLE ONLY changes.
	OwnDependentViews map[string][]string
	// DependentPolicies maps a column to the row-level security policies
	// that read it, wherever they are defined, on the table or on any
	// table below it (preflight.ReadColumnDependents), each rendered
	// "policy" ON "schema"."table". A column absent from the map has none,
	// or the facts were not read; either way the server's own refusal at
	// execution remains the backstop.
	DependentPolicies map[string][]string
	// DropDependentPolicies is DependentPolicies for the tables whose copy
	// of the column a recursive DROP COLUMN drops.
	DropDependentPolicies map[string][]string
	// OwnDependentPolicies is DependentPolicies for the table alone.
	OwnDependentPolicies map[string][]string
	// DependentTriggers maps a column to the triggers whose UPDATE OF list
	// or WHEN condition names it (preflight.ReadColumnDependents), each
	// rendered "trigger" ON "schema"."table". A trigger whose function
	// reads the column is not one: the server records no dependency for
	// it and lets the change run.
	DependentTriggers ColumnDependents
	// GeneratedColumnCopies maps each generated column to its own copies,
	// named as DependentGeneratedColumns names them, so a statement that
	// drops a generated column stops it blocking a change to the columns
	// it reads (preflight.ReadColumnDependents).
	GeneratedColumnCopies ColumnDependents
	// DependentGeneratedColumns maps a column to the generated columns
	// whose expression reads it, each rendered "schema"."table"."column".
	DependentGeneratedColumns ColumnDependents
	// PartitionKeys maps a column to the partitioned tables whose
	// partition key includes it, each schema-qualified.
	PartitionKeys ColumnDependents
	// NullFilledColumns are the columns the statement adds NOT NULL, as
	// spelled or through the column's domain or an inline PRIMARY KEY,
	// that PostgreSQL would refuse to add because the table, or a
	// partition or inheritance child below it with storage of its own,
	// holds a row the column would be NULL in
	// (preflight.NullFilledColumns). It is read only for the columns
	// NullFillCandidates names. A column absent from the map gets a value
	// in every row, the table holds none, or the fact was not read, as in
	// an offline lint; without it the server's own refusal at execution
	// remains the backstop.
	NullFilledColumns map[string]bool
	// ConstraintNames are the names of the constraints already in the
	// table's schema, which the server passes over when it names an
	// unnamed CHECK or FOREIGN KEY. Without them the safer sequence states
	// the server's first choice, and if the table already uses that name
	// its NOT VALID step fails before anything is added.
	ConstraintNames map[string]bool
	// RenamedIndexConstraint is the name of the primary-key, unique, or
	// exclusion constraint the index an ALTER INDEX ... RENAME TO renames
	// backs, which the rename renames with it; empty when the index backs
	// none, or when the fact was not read, as in an offline lint.
	RenamedIndexConstraint string
}

Facts are properties of the live table that sharpen classification, and they are trusted as stated: the CLI fills them by introspecting the target database, and a library caller may supply facts it already holds — but they must describe the database the change will run on, because a wrong fact can upgrade a rewrite to native. Missing facts never let an unsafe change succeed: the zero value is valid, routes every type change to copy-and-swap, and only defers some refusals, such as a column a view or a policy reads, to the server's own refusal at execution.

func FactsAfter added in v0.5.0

func FactsAfter(sql string, facts Facts) (Facts, error)

FactsAfter returns facts as they stand once sql has run: the generated columns it drops no longer block a later statement's change to the columns they read.

func FactsFrom

func FactsFrom(live schemadiff.Model) Facts

FactsFrom extracts the facts a live introspection model provides: the canonical type of every live column, the collation of every column that has one of its own, and what the table's replica identity keys on. Every front door — the declarative diff and the imperative dry-run — extracts facts through this one function so equivalent changes classify identically.

type Plan

type Plan struct {
	// Statement is the submitted SQL.
	Statement string `json:"statement"`
	// Route is the aggregate route.
	Route Route `json:"route"`
	// Decisions are the per-operation classifications, in statement order.
	Decisions []Decision `json:"decisions"`
}

Plan is the classification of one statement: one decision per operation and the aggregate route (the worst of its decisions — one rewrite makes the whole statement a copy, one refusal refuses it).

func Classify

func Classify(sql string, facts Facts) (Plan, error)

Classify parses one statement and routes each of its operations. A parse failure is an error; an unrecognized operation is not — it comes back as a refuse decision so the caller can render the whole plan.

type Reason

type Reason string

Reason is the typed cause of a routing decision; automation branches on it, never on prose.

const (
	// ReasonMetadataOnly: a brief ACCESS EXCLUSIVE catalog change, no scan
	// and no rewrite.
	ReasonMetadataOnly Reason = "metadata-only"
	// ReasonOnlineIdiom: already the safe native form (CONCURRENTLY,
	// NOT VALID, VALIDATE, USING INDEX).
	ReasonOnlineIdiom Reason = "online-idiom"
	// ReasonFastDefault: ADD COLUMN with a default the catalog stores, so
	// no row is rewritten (PG 11+): a constant, or any default the server
	// proved does not rewrite (a non-volatile expression such as now()).
	ReasonFastDefault Reason = "fast-default"
	// ReasonBinaryCoercible: a type change PostgreSQL relabels without a
	// rewrite (widen varchar, varchar to text, widen numeric precision).
	ReasonBinaryCoercible Reason = "binary-coercible"
	// ReasonSaferIdiom: native, but the submitted form blocks; SaferSQL
	// carries the online rewrite when one can be constructed.
	ReasonSaferIdiom Reason = "safer-idiom"
	// ReasonAppBreakingRename: PostgreSQL executes the rename as a brief
	// metadata-only catalog flip, but it cannot land atomically across
	// running application instances — code still referencing the old
	// column, table, or constraint name starts erroring the instant it
	// commits. For a column the safe sequence is expand/contract: add the
	// new column, dual-write and backfill, switch reads, then drop the old
	// column as its own reviewed change. For a table, coordinate the
	// rename with the application deploy that adopts the new name. For an
	// index that backs a constraint, the rename renames the constraint,
	// so coordinate it with the deploy that adopts the new constraint
	// name. No sequence can be constructed from the statement, so the
	// rename is rewrite-required.
	ReasonAppBreakingRename Reason = "app-breaking-rename"
	// ReasonVolatileDefault: ADD COLUMN whose default PostgreSQL computes
	// for every row, rewriting the table — proven by the server, or assumed
	// (Unverified) when the default is not a constant and nothing proved
	// it.
	ReasonVolatileDefault Reason = "volatile-default"
	// ReasonGeneratedStored: adding a stored generated column computes
	// every row — a full rewrite.
	ReasonGeneratedStored Reason = "generated-stored"
	// ReasonTypeRewrite: a type PostgreSQL must check or convert row by
	// row — a type conversion it cannot relabel (rewrite plus reindex), a
	// type change that moves the column's collation (reindex alone), or an
	// added column of a domain type with constraints.
	ReasonTypeRewrite Reason = "type-rewrite"
	// ReasonRelocation: SET TABLESPACE moves the heap — a rewrite-scale
	// copy.
	ReasonRelocation Reason = "relocation"
	// ReasonPartitionParentLock: creating a partition takes a brief ACCESS
	// EXCLUSIVE on the partitioned parent — no scan, but it queues behind
	// and then blocks every query on the parent while held.
	ReasonPartitionParentLock Reason = "partition-parent-lock"
	// ReasonReplicaIdentity: the operation drops what the table's replica
	// identity index keys on — the index itself, the constraint that owns
	// it, or one of its columns. The index is the one REPLICA IDENTITY
	// USING INDEX selects, or the primary key under REPLICA IDENTITY
	// DEFAULT while a publication publishes the table's updates or
	// deletes. The setting outlives the index, so the table is left with
	// no usable identity, and every UPDATE and DELETE on it fails while a
	// publication publishes them. Move the identity first (ALTER TABLE ...
	// REPLICA IDENTITY), then re-plan.
	ReasonReplicaIdentity Reason = "replica-identity"
	// ReasonDependentView: the operation changes the type of, or drops, a
	// column that a view or materialized view reads. PostgreSQL refuses
	// both while the view exists, even a type change that rewrites
	// nothing, so the statement could only fail. The decision names the
	// views; change or drop them first, then re-plan.
	ReasonDependentView Reason = "dependent-view"
	// ReasonDependentPolicy: the operation changes the type of, or drops,
	// a column that a row-level security policy reads, in its USING or
	// WITH CHECK expression, on this table or on another table that reads
	// the column through a subquery. PostgreSQL refuses both while the
	// policy exists, even a type change that rewrites nothing, so the
	// statement could only fail. The decision names the policies; drop
	// them first and recreate them after the change, then re-plan.
	ReasonDependentPolicy Reason = "dependent-policy"
	// ReasonDependentTrigger: the operation changes the type of, or drops,
	// a column that a trigger's UPDATE OF list or WHEN condition names.
	// PostgreSQL refuses both while the trigger exists, even a type change
	// that rewrites nothing, so the statement could only fail. The
	// decision names the triggers; a trigger whose function reads the
	// column does not count, since the server records no dependency for
	// it.
	ReasonDependentTrigger Reason = "dependent-trigger"
	// ReasonDependentGeneratedColumn: the operation changes the type of,
	// or drops, a column that a generated column's expression reads.
	// PostgreSQL refuses both while the generated column exists, so the
	// statement could only fail, except that PostgreSQL 14 drops the
	// generated column along with a dropped column, so there the refusal
	// is what keeps it. The decision names the generated columns.
	ReasonDependentGeneratedColumn Reason = "dependent-generated-column"
	// ReasonPartitionKey: the operation changes the type of, or drops, a
	// column in the partition key of the table or of a partitioned table
	// below it that the change reaches. PostgreSQL never changes or drops
	// a partition key column, so the statement could only fail; the only
	// path is a new partitioned table with the new key, the rows moved
	// into it. The decision names the partitioned tables.
	ReasonPartitionKey Reason = "partition-key"
	// ReasonNotNullWithoutDefault: the operation adds a NOT NULL column
	// with no default to a table that holds rows. Every existing row would
	// hold NULL in the new column, so PostgreSQL refuses the statement
	// (SQLSTATE 23502) after taking the table's exclusive lock; it could
	// only fail. A default, identity, or generated column fills the rows,
	// and an empty table has none to fill, so neither is refused.
	ReasonNotNullWithoutDefault Reason = "not-null-without-default"
	// ReasonCascadingDrop: a drop with CASCADE, which also drops whatever
	// depends on what it drops: a view or policy that reads a dropped
	// column, or another table's foreign key on a dropped key. Those
	// objects are not in the statement, so neither the plan nor the
	// table's lock covers them. Drop each dependent object as its own
	// change, then resubmit without CASCADE, which PostgreSQL refuses
	// while anything still depends on the target.
	ReasonCascadingDrop Reason = "cascading-drop"
	// ReasonUnsupportedOperation: the planner does not recognize the
	// operation or knows no safe path for it.
	ReasonUnsupportedOperation Reason = "unsupported-operation"
)

The reasons a decision can carry.

func Reasons

func Reasons() []Reason

Reasons returns the closed set of Reason values. It is part of the plan-report contract (docs/plan-report.md): the set changes only with a format_version bump, and a consumer that meets an unrecognized value must treat the decision as unknown and refuse it.

type Route

type Route string

Route is where an operation is sent.

const (
	// RouteNative: PostgreSQL runs it online natively — directly or via
	// the safer idiom in Decision.SaferSQL.
	RouteNative Route = "native"
	// RouteCopyAndSwap: needs a table rewrite; only the engine's shadow
	// copy + cutover can do it online.
	RouteCopyAndSwap Route = "copy-and-swap"
	// RouteRefuse: no known safe path; not executed.
	RouteRefuse Route = "refuse"
)

The three routes.

func Routes

func Routes() []Route

Routes returns the closed set of Route values, in severity order. It is part of the plan-report contract (docs/plan-report.md): the set changes only with a format_version bump, and a consumer that meets an unrecognized value must treat the statement as unknown and refuse it.

type ScriptClassifier added in v0.4.0

type ScriptClassifier struct {
	// contains filtered or unexported fields
}

ScriptClassifier classifies the statements of one script in order, with zero live facts except the constraint names the script's own earlier statements leave behind. Running the script, the server numbers an unnamed CHECK or FOREIGN KEY past a name an earlier statement claimed, so a later safer sequence must state the numbered name too, or it would collide with the constraint the script just added. Names are tracked per schema as the statement writes it, an unqualified table under its own key. The zero value is ready to use.

func (*ScriptClassifier) Classify added in v0.4.0

func (c *ScriptClassifier) Classify(sql string) (Plan, error)

Classify parses and routes sql, the script's next statement, as Classify does, then records the constraint names it leaves: each constraint an ALTER TABLE adds, by its stated name or the name its NOT VALID sequence states, less each it drops. Any other constraint added unnamed is not recorded, since the planner states no name for it.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL