Documentation
¶
Overview ¶
Package chunksql holds the statements that put a chunk of source rows into the shadow, and the search_path and output settings they run under. The copier runs Insert for every chunk it lands and the verifier runs it for every chunk it repairs; one text in one place is what makes a repair put back exactly what a copy would have, and keeps the statement off the public API, where a caller could run it outside the guard both packages wrap around it. InsertSkipping and InsertKeys are the copier's statements for a chunk whose Insert collided; they select the rows exactly as Insert does. The applier's flush shares the path and the settings, since it evaluates the same conversion expressions.
Index ¶
- Constants
- func Insert(schema, source, shadow, key string, columns []string, ...) string
- func InsertKeys(schema, source, shadow, key string, columns []string, ...) string
- func InsertSkipping(schema, source, shadow, key string, columns []string, ...) string
- func ResolutionFingerprint(ctx context.Context, q querier, schema string, conversions map[string]string) (string, error)
- func SearchPath(schema string, converted bool) string
Constants ¶
const Rendering = "SET LOCAL extra_float_digits = 3; SET LOCAL bytea_output = 'hex'"
Rendering pins, for the rest of the transaction, the two output settings under which one value has more than one text rendering: extra_float_digits at its maximum, so float4, float8, and the geometric types render every digit rather than rounding to fifteen at zero or below, and bytea_output at hex rather than escape. The server classifies a float or bytea cast to text as immutable, so a conversion such as `value::text` passes the shadow build's probe although its result follows these settings; the chunk copy, the verifier's recopy and digest, the catch-up's flush, and the swap's drain each evaluate it in a session of their own, and a database or role configured differently from the copier's pool would otherwise land one rendering from the copy and another from the flush, which the digest then reads as divergence and the repair recopies forever. The flush's marker completions read a value as text and bind it back, so they need the same pin whether or not the proof carries conversions. SET LOCAL cannot take bind parameters; both values are constants.
Variables ¶
This section is empty.
Functions ¶
func Insert ¶
func Insert(schema, source, shadow, key string, columns []string, conversions map[string]string) string
Insert is the statement that copies one chunk: insert the shared columns of the source rows whose key lies in the closed range [$1, $2] into the shadow, skipping any key the shadow already holds — the applier always overwrites and the copier never does, which is what lets the two run concurrently (CO-4). The bounds are declared bigint whatever the key's integer type, as the chunker's boundary query declares them, so a bound outside a smaller key type's range can still be sent and the primary-key index still serves the range scan.
A column named in conversions is selected as that expression — the USING clause the gated statement retyped it with, as pkg/statement renders it — so the copy converts each value the way the schema change declared, and a value the expression refuses fails the chunk the way the statement would have failed on the source. Every other column is selected bare and converted, where the two tables' types differ, by the server's assignment cast. Every identifier is quoted and the relations are schema-qualified; the expressions are the user's text, which is why SearchPath puts the source schema on the path they resolve in.
func InsertKeys ¶ added in v0.4.1
func InsertKeys(schema, source, shadow, key string, columns []string, conversions map[string]string) string
InsertKeys is InsertSkipping over the source rows whose key is in the bigint array $1 rather than over a key range: the copier's statement for the keys an earlier pass left held off, and only those, since a source row that arrived in the chunk after that pass is the catch-up's to write.
func InsertSkipping ¶ added in v0.4.1
func InsertSkipping(schema, source, shadow, key string, columns []string, conversions map[string]string) string
InsertSkipping is the statement the copier runs over a chunk whose Insert collided: the same rows, selected the same way, inserted with ON CONFLICT DO NOTHING on every unique index and exclusion constraint rather than on the key alone, so a source row whose value a shadow row still holds under another key is left out instead of failing the chunk. It returns one row: the number of rows it inserted, and the ascending bigint keys of the source rows it read that are in the shadow neither now nor from before — the rows still held off, which the copier runs InsertKeys for once the catch-up has rewritten the rows holding their values (CO-4). Every part of the statement runs on the one snapshot its start took, so the shadow it reads for "from before" is the shadow before this statement's own inserts, which the insert's RETURNING accounts for instead.
func ResolutionFingerprint ¶
func ResolutionFingerprint(ctx context.Context, q querier, schema string, conversions map[string]string) (string, error)
ResolutionFingerprint pins what the conversion expressions resolve to. Insert carries the expressions as the user wrote them, and every chunk resolves their unqualified names afresh on the path SearchPath sets — pg_catalog, then schema, then public — so a function, operator, type, or collation created, replaced, or dropped under one of those names after the shadow build can change what a later chunk runs without any chunk failing. The fingerprint is a digest of every catalog entry under a name an expression spells, in every schema the path would look in: the signature the server resolves a call by and the definition it then runs, which for a function is its body in either form (prosrc or a SQL-standard prosqlbody), its strictness, its own SET settings, and its argument defaults, since each of them changes what a call returns. The shadow build records it in the proof, and each guarded transaction recomputes it and refuses to write when it differs (CO-9).
The digest is over renderings that depend on nothing but the catalog: names are the spelled text, every reference to another object is its OID, and nothing goes through a deparser that would render differently under another search_path. It is deliberately wider than resolution: an overload added under a spelled name that the server would never pick changes it too, and a changed function body under a name an expression calls changes it although resolution did not, since either is a catalog the build did not see. It is also narrower than everything a resolution touches: an implicit cast the server picks from pg_cast, the function behind a cast the expression performs, the functions a called function calls in turn, the labels of an enum type, and the constraints of a domain are not under a name the expression spells and are not digested.
The result is empty when conversions is empty, so a proof for a copy that evaluates no expression carries no fingerprint; a copy that does always carries one, even when its expressions spell no name at all.
func SearchPath ¶
SearchPath is the transaction-local path statement, built by dbconn, for a transaction that runs Insert. Without conversions the statement names nothing the path resolves — every relation is qualified and the catalog answers the key range's operators — so the path is the catalog alone, and a schema ahead of it on the caller's pool cannot answer a shadow default or trigger (CO-9). With conversions the statement carries the user's expressions, whose unqualified types, functions, and operators must resolve as they did when the gated statement ran on the shadow: the path is the one the shadow build sets, the source schema then public. Either way dbconn builds the path, so pg_catalog stays ahead of both.
Types ¶
This section is empty.