queries

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: PostgreSQL Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const CurrentHashVersion = 2

CurrentHashVersion is the version of the hash algorithm used by this build. Increment when the SQL hash computation changes (e.g., switching from whole-row ::text to per-column concat_ws with trim_scale).

Variables

View Source
var SQLTemplates = Templates{}/* 111 elements not displayed */

Functions

func AlterPublicationAddTable

func AlterPublicationAddTable(ctx context.Context, db DBQuerier, publicationName, tableName string) error

func AlterPublicationDropTable

func AlterPublicationDropTable(ctx context.Context, db DBQuerier, publicationName, tableName string) error

func BlockHashSQL

func BlockHashSQL(schema, table string, primaryKeyCols []string, mode string, includeLower, includeUpper bool, filter string, allCols []string, colTypes map[string]string) (string, error)

func BuildParentNodes

func BuildParentNodes(ctx context.Context, db DBQuerier, mtreeTable string, nodeLevel int) (int, error)

func CheckRepSetExists

func CheckRepSetExists(ctx context.Context, db DBQuerier, repSet string) (bool, error)

func CheckSchemaExists

func CheckSchemaExists(ctx context.Context, db DBQuerier, schema string) (bool, error)

func CheckUserPrivileges

func CheckUserPrivileges(ctx context.Context, db DBQuerier, username, schema, table string) (*types.UserPrivileges, error)

TODO: Need to add Spock privilege checks!!

func ClearDirtyFlags

func ClearDirtyFlags(ctx context.Context, db DBQuerier, mtreeTable string, nodePositions []int64) error

func CommitTimestampFilter added in v1.9.0

func CommitTimestampFilter(t *time.Time) string

CommitTimestampFilter returns a SQL predicate that restricts rows to those committed at or before the given timestamp. Frozen rows (where pg_xact_commit_timestamp returns NULL after VACUUM FREEZE) are always included. Returns an empty string when t is nil.

func ComputeLeafHashes

func ComputeLeafHashes(ctx context.Context, db DBQuerier, schema, table string, _ bool, key []string, start []any, end []any, allCols []string, colTypes map[string]string) ([]byte, error)

func CreateCDCMetadataTable

func CreateCDCMetadataTable(ctx context.Context, db DBQuerier) error

func CreateCompositeMtreeTable

func CreateCompositeMtreeTable(ctx context.Context, db DBQuerier, mtreeTable, compositeTypeName string) error

func CreateCompositeType

func CreateCompositeType(ctx context.Context, db DBQuerier, compositeTypeName, keyTypeColumns string) error

func CreateMetadataTable

func CreateMetadataTable(ctx context.Context, db DBQuerier) error

func CreatePublication

func CreatePublication(ctx context.Context, db DBQuerier, publicationName string) error

func CreateReplicationOrigin added in v1.7.0

func CreateReplicationOrigin(ctx context.Context, db DBQuerier, originName string) (uint32, error)

func CreateReplicationSlot

func CreateReplicationSlot(ctx context.Context, db DBQuerier, slotName string) error

func CreateSchema

func CreateSchema(ctx context.Context, db DBQuerier, schemaName string) error

func CreateSimpleMtreeTable

func CreateSimpleMtreeTable(ctx context.Context, db DBQuerier, mtreeTable, pkeyType string) error

func CreateXORFunction

func CreateXORFunction(ctx context.Context, db DBQuerier) error

func DeleteBlock

func DeleteBlock(ctx context.Context, db DBQuerier, mtreeTable string, position int64) error

func DeleteMetadata

func DeleteMetadata(ctx context.Context, db DBQuerier, schema, table string) error

func DeleteParentNodes

func DeleteParentNodes(ctx context.Context, db DBQuerier, mtreeTable string) error

func DropCDCMetadataTable

func DropCDCMetadataTable(ctx context.Context, db DBQuerier) error

func DropCompositeType

func DropCompositeType(ctx context.Context, db DBQuerier, compositeTypeName string) error

func DropMetadataTable

func DropMetadataTable(ctx context.Context, db DBQuerier) error

func DropMtreeTable

func DropMtreeTable(ctx context.Context, db DBQuerier, mtreeTable string) error

func DropPublication

func DropPublication(ctx context.Context, db DBQuerier, publicationName string) error

func DropReplicationSlot

func DropReplicationSlot(ctx context.Context, db DBQuerier, slotName string) error

func DropXORFunction

func DropXORFunction(ctx context.Context, db DBQuerier) error

func EnsureHashVersionColumn added in v1.6.0

func EnsureHashVersionColumn(ctx context.Context, db DBQuerier) error

func EnsurePgcrypto added in v1.5.0

func EnsurePgcrypto(ctx context.Context, db DBQuerier) error

func FindBlocksToMerge

func FindBlocksToMerge(ctx context.Context, db DBQuerier, mtreeTableName string, simplePrimaryKey bool, schema string, table string, key []string, mergeThreshold float64, blockPositions []int64) ([]types.BlockRange, error)

func FindBlocksToMergeComposite

func FindBlocksToMergeComposite(ctx context.Context, db DBQuerier, mtreeTable, schema, table string, keyColumns []string, nodePositions []int64, mergeThreshold float64) ([]types.BlockRange, error)

func FindBlocksToMergeSimple

func FindBlocksToMergeSimple(ctx context.Context, db DBQuerier, mtreeTable, schema, table, key string, nodePositions []int64, mergeThreshold float64) ([]types.BlockRange, error)

func FindBlocksToSplit

func FindBlocksToSplit(ctx context.Context, db DBQuerier, mtreeTable string, insertsSinceUpdate int, nodePositions []int64, simplePrimaryKey bool, key []string) ([]types.BlockRange, error)

func GeneratePkeyOffsetsQuery

func GeneratePkeyOffsetsQuery(
	schema, table string,
	keyColumns []string,
	tableSampleMethod string,
	samplePercent float64,
	ntileCount int,
	filter string,
) (string, error)

func GetBlockCountComposite

func GetBlockCountComposite(ctx context.Context, db DBQuerier, mtreeTable, schema, table, pkeyCols string, nodePosition int64) (*types.BlockCountComposite, error)

func GetBlockCountSimple

func GetBlockCountSimple(ctx context.Context, db DBQuerier, mtreeTable, schema, table, key string, nodePosition int64) (*types.BlockCountSimple, error)

func GetBlockRowCount

func GetBlockRowCount(ctx context.Context, db DBQuerier, schema string, table string, keyColumns []string, isComposite bool, start, end []any) (int64, error)

func GetBlockSizeFromMetadata

func GetBlockSizeFromMetadata(ctx context.Context, db DBQuerier, schema, table string) (int, error)

func GetBlockWithCount

func GetBlockWithCount(ctx context.Context, db DBQuerier, mtreeTable, schema, table string, key []string, isComposite bool, position int64) (*types.BlockRangeWithCount, error)

func GetBulkSplitPoints

func GetBulkSplitPoints(ctx context.Context, db DBQuerier, schema, table string, key []string, pkeyType string, isComposite bool, start, end []any, blockSize int) ([][]any, error)

func GetCDCMetadata

func GetCDCMetadata(ctx context.Context, db DBQuerier, publicationName string) (string, string, []string, error)

func GetColumnTypes

func GetColumnTypes(ctx context.Context, db DBQuerier, schema, table string) (map[string]string, error)

func GetColumns

func GetColumns(ctx context.Context, db DBQuerier, schema, table string) ([]string, error)

GetColumns retrieves the column names for a given table.

func GetCountComposite

func GetCountComposite(ctx context.Context, db DBQuerier, schema, table, whereClause string) (int64, error)

func GetCountSimple

func GetCountSimple(ctx context.Context, db DBQuerier, schema, table, key, pkeyType string, rangeStart, rangeEnd interface{}) (int64, error)

func GetDirtyAndNewBlocks

func GetDirtyAndNewBlocks(ctx context.Context, db DBQuerier, mtreeTable string, simplePrimaryKey bool, key []string) ([]types.BlockRange, error)

func GetFunctionsInSchema

func GetFunctionsInSchema(ctx context.Context, db DBQuerier, schema string) ([]string, error)

func GetHashVersion added in v1.6.0

func GetHashVersion(ctx context.Context, db DBQuerier, schema, table string) (int, error)

func GetIndicesInSchema

func GetIndicesInSchema(ctx context.Context, db DBQuerier, schema string) ([]string, error)

func GetLeafRanges

func GetLeafRanges(ctx context.Context, db DBQuerier, mtreeTable string, nodePositions []int64, simplePrimaryKey bool, key []string) ([]types.LeafRange, error)

func GetMaxNodeLevel

func GetMaxNodeLevel(ctx context.Context, db DBQuerier, mtreeTable string) (int, error)

func GetMaxNodePosition

func GetMaxNodePosition(ctx context.Context, db DBQuerier, mtreeTable string) (int64, error)

func GetMaxValComposite

func GetMaxValComposite(ctx context.Context, db DBQuerier, schema, table string, pkeyCols []string, pkeyValues []any) ([]interface{}, error)

func GetMaxValSimple

func GetMaxValSimple(ctx context.Context, db DBQuerier, schema, table, key string, rangeStart interface{}) (interface{}, error)

func GetMinValComposite

func GetMinValComposite(ctx context.Context, db DBQuerier, schema, table string, pkeyCols []string) ([]interface{}, error)

func GetMinValSimple

func GetMinValSimple(ctx context.Context, db DBQuerier, schema, table, key string) (interface{}, error)

func GetNodeChildren

func GetNodeChildren(ctx context.Context, db DBQuerier, mtreeTable string, nodeLevel, nodePosition int) ([]types.NodeChild, error)

func GetPkeyColumnTypes

func GetPkeyColumnTypes(ctx context.Context, db DBQuerier, schema, table string, pkeys []string) (map[string]string, error)

func GetPkeyOffsets

func GetPkeyOffsets(ctx context.Context, db DBQuerier, schema, table string, keyColumns []string, tableSampleMethod string, samplePercent float64, ntileCount int) ([]types.PkeyOffset, error)

func GetPkeyType

func GetPkeyType(ctx context.Context, db DBQuerier, schema, table, pkey string) (string, error)

func GetPrimaryKey

func GetPrimaryKey(ctx context.Context, db DBQuerier, schema, table string) ([]string, error)

func GetReplicationOriginByName added in v1.7.0

func GetReplicationOriginByName(ctx context.Context, db DBQuerier, originName string) (*uint32, error)

func GetRootNode

func GetRootNode(ctx context.Context, db DBQuerier, mtreeTable string) (*types.RootNode, error)

func GetRowCountEstimate

func GetRowCountEstimate(ctx context.Context, db DBQuerier, schema, table string) (int64, error)

func GetRowCountEstimateFromMetadata

func GetRowCountEstimateFromMetadata(ctx context.Context, db DBQuerier, schema, table string) (int64, error)

func GetSimplePrimaryKey

func GetSimplePrimaryKey(ctx context.Context, db DBQuerier, schema, table string) (bool, error)

func GetSpockNodeAndSubInfo

func GetSpockNodeAndSubInfo(ctx context.Context, db DBQuerier) ([]types.SpockNodeAndSubInfo, error)

func GetSpockNodeNames added in v1.5.0

func GetSpockNodeNames(ctx context.Context, db DBQuerier) (map[string]string, error)

func GetSpockOriginLSNForNode added in v1.5.0

func GetSpockOriginLSNForNode(ctx context.Context, db DBQuerier, originNodeName string) (*string, error)

func GetSpockRepSetInfo

func GetSpockRepSetInfo(ctx context.Context, db DBQuerier) ([]types.SpockRepSetInfo, error)

func GetSpockSlotLSNForNode added in v1.5.0

func GetSpockSlotLSNForNode(ctx context.Context, db DBQuerier, failedNode string) (*string, error)

func GetTablesInRepSet

func GetTablesInRepSet(ctx context.Context, db DBQuerier, repSet string) ([]string, error)

func GetTablesInSchema

func GetTablesInSchema(ctx context.Context, db DBQuerier, schema string) ([]string, error)

func GetViewsInSchema

func GetViewsInSchema(ctx context.Context, db DBQuerier, schema string) ([]string, error)

func InsertBlockRanges

func InsertBlockRanges(ctx context.Context, db DBQuerier, mtreeTable string, nodePosition int64, rangeStart, rangeEnd interface{}) error

func InsertBlockRangesBatchComposite

func InsertBlockRangesBatchComposite(ctx context.Context, db DBQuerier, mtreeTable string, ranges []types.BlockRange, keyLen int) error

func InsertBlockRangesBatchSimple

func InsertBlockRangesBatchSimple(ctx context.Context, db DBQuerier, mtreeTable string, ranges []types.BlockRange) error

func InsertCompositeBlockRanges

func InsertCompositeBlockRanges(ctx context.Context, db DBQuerier, mtreeTable string, nodePosition int64, startVals, endVals []any) error

func MarkAllLeavesDirty added in v1.6.0

func MarkAllLeavesDirty(ctx context.Context, db DBQuerier, mtreeTable string) (int64, error)

func MarkBlockDirty

func MarkBlockDirty(ctx context.Context, db DBQuerier, mtreeTable, pkeyValue string) error

func MaxColumnSize

func MaxColumnSize(ctx context.Context, db DBQuerier, schema, table, column string) (int64, error)

func RemoveTableFromCDCMetadata

func RemoveTableFromCDCMetadata(ctx context.Context, db DBQuerier, tableName, publicationName string) error

func RenderSQL

func RenderSQL(t *template.Template, data any) (string, error)

func ResetPositionsByStart

func ResetPositionsByStart(ctx context.Context, db DBQuerier, mtreeTable string, key []string, isComposite bool) error

func ResetPositionsByStartFromTemp

func ResetPositionsByStartFromTemp(ctx context.Context, db DBQuerier, mtreeTable string, offset int64) error

func ResetReplicationOriginSession added in v1.7.0

func ResetReplicationOriginSession(ctx context.Context, db DBQuerier) error

func ResetReplicationOriginXact added in v1.7.0

func ResetReplicationOriginXact(ctx context.Context, db DBQuerier) error

func SanitiseIdentifier

func SanitiseIdentifier(ident string) error

func SetupReplicationOriginSession added in v1.7.0

func SetupReplicationOriginSession(ctx context.Context, db DBQuerier, originName string) error

func SetupReplicationOriginXact added in v1.7.0

func SetupReplicationOriginXact(ctx context.Context, db DBQuerier, originLSN string, originTimestamp *time.Time) error

func UpdateAllLeafNodePositionsToTemp

func UpdateAllLeafNodePositionsToTemp(ctx context.Context, db DBQuerier, mtreeTable string, offset int64) error

func UpdateBlockRangeEnd

func UpdateBlockRangeEnd(ctx context.Context, db DBQuerier, mtreeTable string, rangeEnd any, nodePosition int64) error

func UpdateBlockRangeEndComposite

func UpdateBlockRangeEndComposite(ctx context.Context, db DBQuerier, mtreeTable string, compositeTypeName string, endVals []any, pos int64) error

func UpdateBlockRangeStart

func UpdateBlockRangeStart(ctx context.Context, db DBQuerier, mtreeTable string, rangeStart any, nodePosition int64) error

func UpdateBlockRangeStartComposite

func UpdateBlockRangeStartComposite(ctx context.Context, db DBQuerier, mtreeTable string, compositeTypeName string, startVals []any, pos int64) error

func UpdateCDCMetadata

func UpdateCDCMetadata(ctx context.Context, db DBQuerier, publicationName, slotName, startLSN string, tables []string) error

func UpdateHashVersion added in v1.6.0

func UpdateHashVersion(ctx context.Context, db DBQuerier, schema, table string, version int) error

func UpdateLeafHashes

func UpdateLeafHashes(ctx context.Context, db DBQuerier, mtreeTable string, leafHash []byte, nodePosition int64) (int64, error)

func UpdateLeafHashesBatch added in v1.3.1

func UpdateLeafHashesBatch(ctx context.Context, db DBQuerier, mtreeTable string, leafHashes map[int64][]byte) error

func UpdateMaxVal

func UpdateMaxVal(ctx context.Context, db DBQuerier, mtreeTable string, rangeEnd interface{}, nodePosition int64) error

func UpdateMetadata

func UpdateMetadata(ctx context.Context, db DBQuerier, schema, table string, totalRows int64, blockSize, numBlocks int, isComposite bool, hashVersion int) error

func UpdateMtreeCounters

func UpdateMtreeCounters(ctx context.Context, db DBQuerier, mtreeTable string, isComposite bool, compositeTypeName string, pkeyType string, inserts, deletes, updates []string) error

func UpdateNodePosition

func UpdateNodePosition(ctx context.Context, db DBQuerier, mtreeTable string, oldPosition, newPosition int64) error

func UpdateNodePositionsSequential

func UpdateNodePositionsSequential(ctx context.Context, db DBQuerier, mtreeTable string, startPosition int64) error

Types

type DBQuerier

type DBQuerier interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
	SendBatch(context.Context, *pgx.Batch) pgx.BatchResults
}

type Templates

type Templates struct {
	EstimateRowCount     *template.Template
	GetPrimaryKey        *template.Template
	GetColumnTypes       *template.Template
	GetColumns           *template.Template
	CheckUserPrivileges  *template.Template
	SpockNodeAndSubInfo  *template.Template
	SpockRepSetInfo      *template.Template
	EnsurePgcrypto       *template.Template
	GetSpockNodeNames    *template.Template
	CheckSchemaExists    *template.Template
	GetTablesInSchema    *template.Template
	GetViewsInSchema     *template.Template
	GetFunctionsInSchema *template.Template
	GetIndicesInSchema   *template.Template
	CheckRepSetExists    *template.Template
	GetTablesInRepSet    *template.Template
	GetPkeyColumnTypes   *template.Template

	CreateMetadataTable             *template.Template
	GetPkeyOffsets                  *template.Template
	CreateSimpleMtreeTable          *template.Template
	CreateIndex                     *template.Template
	CreateCompositeType             *template.Template
	DropCompositeType               *template.Template
	CreateCompositeMtreeTable       *template.Template
	InsertCompositeBlockRanges      *template.Template
	CreateXORFunction               *template.Template
	GetPkeyType                     *template.Template
	UpdateMetadata                  *template.Template
	InsertBlockRanges               *template.Template
	InsertBlockRangesBatchSimple    *template.Template
	InsertBlockRangesBatchComposite *template.Template
	TDBlockHashSQL                  *template.Template
	MtreeLeafHashSQL                *template.Template
	UpdateLeafHashes                *template.Template
	UpdateLeafHashesBatch           *template.Template

	GetDirtyAndNewBlocks  *template.Template
	ClearDirtyFlags       *template.Template
	BuildParentNodes      *template.Template
	GetRootNode           *template.Template
	GetNodeChildren       *template.Template
	GetLeafRanges         *template.Template
	GetLeafRangesExpanded *template.Template
	GetRowCountEstimate   *template.Template
	GetMaxValComposite    *template.Template
	UpdateMaxVal          *template.Template
	GetMaxValSimple       *template.Template
	GetCountComposite     *template.Template
	GetCountSimple        *template.Template

	DeleteParentNodes             *template.Template
	GetMaxNodePosition            *template.Template
	UpdateBlockRangeEnd           *template.Template
	UpdateNodePositionsTemp       *template.Template
	DeleteBlock                   *template.Template
	UpdateNodePositionsSequential *template.Template
	FindBlocksToSplit             *template.Template
	FindBlocksToMerge             *template.Template
	FindBlocksToMergeExpanded     *template.Template
	GetBlockCountComposite        *template.Template
	GetBlockCountSimple           *template.Template
	GetBlockSizeFromMetadata      *template.Template
	GetMaxNodeLevel               *template.Template

	DropXORFunction                  *template.Template
	DropMetadataTable                *template.Template
	DropMtreeTable                   *template.Template
	GetBlockRowCount                 *template.Template
	GetBlockWithCount                *template.Template
	GetBlockWithCountExpanded        *template.Template
	UpdateNodePosition               *template.Template
	GetMaxColumnSize                 *template.Template
	UpdateBlockRangeStart            *template.Template
	GetMinValComposite               *template.Template
	GetMinValSimple                  *template.Template
	GetDirtyAndNewBlocksExpanded     *template.Template
	FindBlocksToSplitExpanded        *template.Template
	ResetPositionsByStart            *template.Template
	ResetPositionsByStartFromTemp    *template.Template
	ResetPositionsByStartExpanded    *template.Template
	GetBulkSplitPoints               *template.Template
	UpdateBlockRangeStartComposite   *template.Template
	UpdateBlockRangeEndComposite     *template.Template
	UpdateAllLeafNodePositionsToTemp *template.Template
	MarkBlockDirty                   *template.Template
	CreateCDCMetadataTable           *template.Template
	UpdateCDCMetadata                *template.Template
	AlterPublicationAddTable         *template.Template
	CreatePublication                *template.Template
	CreateReplicationSlot            *template.Template
	DropPublication                  *template.Template
	DropReplicationSlot              *template.Template
	DropCDCMetadataTable             *template.Template
	GetCDCMetadata                   *template.Template
	UpdateMtreeCounters              *template.Template
	GetReplicationSlotPID            *template.Template
	TerminateBackend                 *template.Template
	CheckPIDExists                   *template.Template
	CreateSchema                     *template.Template
	AlterPublicationDropTable        *template.Template
	DeleteMetadata                   *template.Template
	RemoveTableFromCDCMetadata       *template.Template
	GetSpockOriginLSNForNode         *template.Template
	GetSpockSlotLSNForNode           *template.Template
	EnsureHashVersionColumn          *template.Template
	GetHashVersion                   *template.Template
	MarkAllLeavesDirty               *template.Template
	UpdateHashVersion                *template.Template
	GetReplicationOriginByName       *template.Template
	CreateReplicationOrigin          *template.Template
	SetupReplicationOriginSession    *template.Template
	ResetReplicationOriginSession    *template.Template
	SetupReplicationOriginXact       *template.Template
	ResetReplicationOriginXact       *template.Template
}

Directories

Path Synopsis
Package mocks is a generated GoMock package.
Package mocks is a generated GoMock package.

Jump to

Keyboard shortcuts

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