Documentation
¶
Overview ¶
Package utxocond builds fixed-shape "(tx_id = ? AND output_idx = ?)" OR-list conditions for the UTxO block-apply UPDATEs (consume, collateral, reference inputs) shared by the sqlite, postgres, and mysql metadata plugins.
The block-apply path builds one such UPDATE per transaction, matching that transaction's consumed/collateral/reference inputs. Building the WHERE clause as a variable-length list of OR-ed placeholder pairs made the SQL text vary with the input count, so GORM's prepared-statement cache (keyed on SQL text) could not reuse statements and thrashed on parse/prepare under dense sync (issue #2943).
Chunks pads each chunk's term count up to the next power of two by repeating the chunk's last ref. Because these UPDATEs match rows by an OR of composite keys, repeating a ref is idempotent: it does not change which rows match or how many rows are affected. Padding to powers of two bounds the number of distinct SQL shapes to about log2(maxTerms)+1 regardless of input count, so the prepared-statement cache can reuse them.
Index ¶
Constants ¶
const DefaultMaxTerms = 256
DefaultMaxTerms bounds the OR-terms per statement. Each term binds two parameters, so 256 terms is 512 parameters, comfortably under driver parameter limits (SQLite's default SQLITE_MAX_VARIABLE_NUMBER is 999, newer builds 32766; postgres/mysql are far higher). It is a power of two so a full chunk reuses the single largest SQL shape.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Chunk ¶
type Chunk struct {
// Condition is the parenthesized OR-list, e.g.
// "(tx_id = ? AND output_idx = ?) OR (tx_id = ? AND output_idx = ?)".
// Its placeholder count is padded to a power of two, so only a handful
// of distinct Condition strings are ever produced.
Condition string
// Args holds TxID, Idx pairs for every term including padding, in order:
// len(Args) == 2 * (padded term count).
Args []any
// Real is the number of leading terms that correspond to distinct input
// refs (the remainder are idempotent padding). Callers that verify an
// affected-row count should sum Real across chunks.
Real int
}
Chunk is one fixed-shape OR-list condition and its bound arguments.
func Chunks ¶
Chunks splits refs into chunks of at most maxTerms terms and pads each chunk's term count up to the next power of two (repeating the chunk's last ref). It returns nil for an empty input. maxTerms values below 1 fall back to DefaultMaxTerms; a maxTerms that is not a power of two is used as-is for the split boundary, but padded chunk lengths are still powers of two capped at maxTerms.