Skip to content

Course

Data Engineering & Advanced SQL

Read real EXPLAIN plans, design indexes around operators and write cost, and build ETL on COPY, CDC, and MVCC-correct transactions.

13 lessons

Course Q&A

Keep reading

Related articles from the SudoSecurity blog.

Reviews

Enrolled members can rate this course.

No reviews yet.

The Engine Under the Query

How Postgres turns SQL text into a costed plan, and how to read what it decided.

  1. 01Your SQL Is a Specification, Not a PlanPostgres parses, rewrites, and cost-optimizes your SQL against pg_statistic — stale statistics are the real cause of most suddenly-slow plans.12mOpen
  2. 02Reading EXPLAIN Like a MechanicEXPLAIN (ANALYZE, BUFFERS) is a plan tree read inside-out, where estimated-versus-actual rows and hit-versus-read buffers point at the real problem.15mOpen
  3. 03What a Scan Actually CostsSeq scans beat index scans past a fraction of the table because random_page_cost prices heap fetches — tune it for NVMe and VACUUM for index-only scans.14mOpen

Indexing Strategy

B-tree, GIN, GiST, BRIN, composite ordering, and why every index is a write tax.

  1. 01B-tree Is Not Your Only IndexThe operator picks the index type: B-tree for ordering and equality, GIN for containment, GiST for overlap and exclusion constraints, BRIN for physically sorted time-series.15mOpen
  2. 02Composite Indexes and Column OrderComposite B-trees sort lexicographically — equality columns first, range last — and partial and expression indexes target the rows and spellings queries actually use.13mOpen
  3. 03Indexes Are Not FreeEvery index is a write tax on every INSERT and UPDATE; HOT updates, fillfactor, and per-table autovacuum tuning are how you control it.13mOpen

Analytical SQL

CTEs, window functions, grouping sets, and the time-series patterns that replace application code.

  1. 01CTEs and the Optimization FencePostgres 12+ inlines single-use CTEs, but MATERIALIZED still computes a shared intermediate once — and WITH RECURSIVE replaces N+1 hierarchy walks.14mOpen
  2. 02Window Functions Without the Self-JoinsWindow functions keep every row while ranking it inside its partition — the dedup, running-total, and latest-per-key patterns that end self-joins.15mOpen
  3. 03GROUP BY Beyond COUNT(*)GROUPING SETS, FILTER, and WITHIN GROUP aggregates compute pivots, subtotals, and exact percentiles in one scan instead of N queries.13mOpen
  4. 04Time-Series and Gap Analysisgenerate_series scaffolds the missing buckets, LAG plus a running SUM sessionizes gaps-and-islands, and timestamptz plus explicit zones keep reports honest.15mOpen

Moving Data: ETL in Production

COPY staging, incremental sync, replication slots, and the MVCC rules pipelines break.

  1. 01COPY, Staging, and Bulk LoadsCOPY into an UNLOGGED staging table, validate, merge with ON CONFLICT in one transaction — the bulk-load pattern that survives reruns.14mOpen
  2. 02Incremental Sync and Change Data CaptureWatermark syncs drop rows committed out of order and CDC replay is at-least-once — overlap, dedup, and watch pg_replication_slots before it eats the disk.16mOpen
  3. 03MVCC, Transactions, and Pipeline SafetyMVCC's snapshot rules make check-then-write a race; atomic UPDATEs, FOR UPDATE, retry loops on 40001/40P01, and short transactions keep pipelines correct.16mOpen