How duckdb/pg_duckdb works
Main Components
a. Core Components:
• PostgreSQL Database Server
• DuckDB Engine Integration
• Query Execution Layer
• Storage Layer
• Extension Management System
• Transaction Management System
b. External Integrations:
• Object Storage (S3, Azure, GCS, R2)
• MotherDuck Integration
• File Format Support (Parquet, CSV, JSON, Iceberg, Delta)
┌─ Client Layer ─────────────────────────────────────┐
• PostgreSQL Clients (psql, applications) │
• ┬───────────────────────────┘
• ↓
┌─ Interface Layer ─────────────────────────────────┐
• PostgreSQL Protocol │
• Extension API Interface │
• ┬───────────────────────────┘
• ↓
┌─ Core Processing Layer ───────────────────────────┐
• ┌─────────────────┐ ┌──────────────────┐ │
• PostgreSQL │ ←──→ │ DuckDB │ │
• Query Engine │ │ Query Engine │ │
• ┘ └──────────────────┘ │
• ┬───────────────────────────┘
• ↓
┌─ Storage Layer ──────────────────────────────────┐
• ┌─────────────┐ ┌──────────┐ ┌───────────────┐ │
• PostgreSQL │ │ DuckDB │ │ Object │ │
• Tables │ │ Tables │ │ Storage │ │
• ┘ └──────────┘ └───────────────┘ │
• ┘
Key Interactions to Highlight
• Query Router: Show how queries are directed to either PostgreSQL or DuckDB engine based on:
• Query type
• Table access method
• Force execution setting
• Data source type
• Data Flow Paths:
• PostgreSQL ↔ DuckDB data exchange
• External storage access paths
• MotherDuck integration path
Important Subsystems to Detail
• Catalog Management (from /include/pgduckdb/catalog/)
• Transaction Management
• Query Planning and Execution
• Type System Integration
• Extension Management
• Background Workers
Technical Details
• Support for various data types
• Transaction boundary handling
• Security and authentication flows
• Extension loading mechanism
• Configuration settings
Specific Implementation Notes
• Catalog structure (pgduckdb_catalog.hpp)
• Transaction management (pgduckdb_transaction.hpp)
• Table access methods (pgduckdb_table_am.hpp)
• Query planning (pgduckdb_planner.hpp)