postgres

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Oct 9, 2026 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Overview

Package postgres is the PostgreSQL engine, on pgx v5. It registers itself as "postgres".

User SQL only ever goes through the extended protocol (pgconn.ExecParams), which takes exactly one statement: the server refuses "SELECT 1; SELECT 2" even if it got past the classifier. The simple protocol is used for the console's own constant statements (BEGIN, COMMIT, SET) only.

Tier read sets SET SESSION CHARACTERISTICS AS TRANSACTION READ ONLY and runs every statement inside BEGIN READ ONLY, so a write fails on the server even if it got past the classifier. The statement timeout is the server's statement_timeout and, as a backstop, a client deadline that sends a cancel request (which keeps the connection usable).

Names: a PostgreSQL connection is bound to one database, and tables live in schemas inside it. The db argument of Run, Explain and the catalog methods is the database ("" is the profile's); the session keeps one connection per database, opened on first use. Table names from Tables are "table" for schema public and "schema.table" otherwise. In ColumnInfo, TableInfo and result column origins, the DB field holds the schema, which is the namespace PII rules match ("public.users.email").

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParsePlan

func ParsePlan(raw []byte, sizes map[string]int64) (engine.Plan, error)

ParsePlan normalises the output of EXPLAIN (FORMAT JSON) into an engine.Plan whose Raw is the server's plan unchanged. sizes holds the row counts of tables ("schema.table") from pg_class.reltuples; a full scan of a table found there counts as reading all of it. nil sizes keep PostgreSQL's Plan Rows, which, for a filtered scan, is the number of rows returned, not read.

Mapping:

  • Seq Scan → full; Index Scan / Index Only Scan / Bitmap Heap Scan → lookup when the index condition only has equalities, range otherwise, index when there is no index condition; Tid Scan → lookup; function, VALUES, CTE and subquery scans → full; anything else → unknown.
  • Plan Rows → EstRows (per loop, as PostgreSQL reports it).
  • Sort / Incremental Sort → Sort; hashed Aggregate or SetOp, Materialize, Memoize, Recursive Union → Temp.
  • Nested Loop: the inner side joins the outer pipeline (rows multiply). An inner full scan with no Join Filter and no filter on an outer column → NoJoinCond (a cartesian product).
  • Hash Join / Merge Join: the outer side is the pipeline, the inner side is read once, so it becomes a child group (cost adds).
  • Append members, subquery scans and InitPlans → child groups; SubPlan → a Correlated child group. A child group under a Nested Loop's inner side runs once per outer row, so it is Correlated too.

Types

type Engine

type Engine struct{}

Engine opens PostgreSQL sessions.

func (Engine) Connect

func (Engine) Connect(ctx context.Context, p config.Profile, secret []byte) (engine.Session, error)

Connect opens the connection to the profile's database and applies the session settings of the profile's tier.

type Relation

type Relation struct {
	Schema, Name string
}

Relation is a table, as named in a plan.

func PlanRelations

func PlanRelations(raw []byte) ([]Relation, error)

PlanRelations lists, sorted and without duplicates, the relations a plan reads with a full table or index scan: the ones whose size ParsePlan wants, since PostgreSQL's Plan Rows counts the rows a scan returns, not the rows it reads.

Jump to

Keyboard shortcuts

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