Skip to content

Conversation

@erans
Copy link
Owner

@erans erans commented Nov 25, 2025

Summary

Adds 7 missing PostgreSQL catalog tables to improve protocol completeness:

  • pg_collation - Static handler returning 3 standard collations (default, C, POSIX)
  • pg_replication_slots - Empty stub (SQLite has no replication)
  • pg_shdepend - Empty stub (no shared dependencies in SQLite)
  • pg_statistic - Empty stub (internal stats table, pg_stats view already exists)
  • pg_sequence - Dynamic handler querying SQLite's sqlite_sequence table
  • pg_trigger - Dynamic handler querying SQLite's sqlite_master for triggers
  • pg_settings - Static handler with 41 common PostgreSQL configuration settings

Architecture

  • Follows existing CatalogInterceptor pattern
  • Dedicated handler modules for complex tables (pg_sequence, pg_trigger, pg_settings)
  • Inline handlers for simple stubs
  • Full column projection and WHERE clause filtering support

New Files

  • src/catalog/pg_sequence.rs - Dynamic sequence handler
  • src/catalog/pg_trigger.rs - Dynamic trigger handler
  • src/catalog/pg_settings.rs - Static settings handler
  • 7 new integration test files

Test Plan

  • All 473 library tests pass
  • 19 new integration tests pass across 7 test files
  • cargo check - no errors
  • cargo clippy - no new warnings
  • cargo build - successful

🤖 Generated with Claude Code

erans and others added 11 commits November 25, 2025 09:51
Design document for implementing 7 missing pg_catalog tables:
- pg_settings (dedicated handler, dynamic config)
- pg_sequence (dedicated handler, maps sqlite_sequence)
- pg_trigger (dedicated handler, maps SQLite triggers)
- pg_collation (inline static)
- pg_replication_slots (inline stub)
- pg_shdepend (inline stub)
- pg_statistic (inline stub)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Detailed bite-sized implementation plan with:
- 8 tasks covering all 7 catalog tables
- Integration tests for each table
- Complete code samples
- Step-by-step verification commands

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
The alerts_triggered counter was being incremented in both update_stats()
and trigger_alert(), causing double-counting for high-severity events.
Removed the duplicate increment from trigger_alert() since update_stats()
already handles the counting.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Implements pg_collation catalog table with standard PostgreSQL collations
(default, C, POSIX). Includes column projection support and WHERE clause
filtering by collname.

Changes:
- Added handle_pg_collation_query() in query_interceptor.rs with full column
  projection support using extract_selected_columns()
- Added extract_collation_name_filter() for WHERE collname filtering
- Updated has_catalog_tables check to detect pg_collation queries
- Added pg_collation handler in check_table_factor()
- Added pg_collation handling in db_handler.rs query_with_session() and
  query_with_session_cached() for direct DbHandler access
- Added integration test in tests/pg_collation_test.rs

Test Results:
- cargo test --test pg_collation_test: PASSED
- cargo test --lib: 473 tests PASSED
- cargo check: No errors
- cargo clippy: No new warnings
- cargo build: Successful

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Implements PostgreSQL pg_replication_slots view as an always-empty stub.
SQLite has no replication capabilities, so this table correctly returns
zero rows but with the proper schema for PostgreSQL compatibility.

This enables tools that query pg_replication_slots (like pgAdmin, monitoring
tools, and ORMs) to work without errors.

Changes:
- Added handle_pg_replication_slots_query to CatalogInterceptor
- Added pg_replication_slots detection in has_catalog_tables check
- Added handler routing in check_table_factor
- Added direct handling in query_with_session and query_with_session_cached
- Includes all 16 standard pg_replication_slots columns
- Integration tests verify empty result with correct schema

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Implements PostgreSQL pg_shdepend view as an always-empty stub.
SQLite has no shared object dependencies, so this table correctly returns
zero rows but with the proper schema for PostgreSQL compatibility.

This enables tools that query pg_shdepend (like pgAdmin, monitoring
tools, and ORMs) to work without errors.

Changes:
- Added handle_pg_shdepend_query to CatalogInterceptor
- Added pg_shdepend detection in has_catalog_tables check
- Added handler routing in check_table_factor
- Added direct handling in query_with_session and query_with_session_cached
- Includes all 7 standard pg_shdepend columns
- Integration tests verify empty result with correct schema

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Implemented pg_statistic support following the same pattern as pg_shdepend.
This is an internal PostgreSQL statistics table - user-facing interface is
the pg_stats view. Always returns empty results as SQLite doesn't maintain
PostgreSQL-style column statistics internally.

Implementation includes:
- 31 columns: starelid, staattnum, stainherit, stanullfrac, stawidth,
  stadistinct, stakind1-5, staop1-5, stacoll1-5, stanumbers1-5, stavalues1-5
- Handler in query_interceptor.rs with column projection support
- Fallback handlers in db_handler.rs for both query() and query_with_session()
- Comprehensive integration tests verifying empty results and all columns

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Implement dynamic pg_trigger handler that queries SQLite's sqlite_master
for trigger information and maps it to PostgreSQL's pg_trigger schema.

Key features:
- Queries SQLite: SELECT name, tbl_name, sql FROM sqlite_master WHERE type = 'trigger'
- Parses trigger SQL to extract timing (BEFORE/AFTER/INSTEAD OF) and event (INSERT/UPDATE/DELETE)
- Calculates tgtype bitmask matching PostgreSQL conventions:
  - Bit 0: ROW (1) - SQLite triggers are always row-level
  - Bit 1: BEFORE (2)
  - Bit 6: INSTEAD OF (64)
  - Bits 2-4: INSERT (4), DELETE (8), UPDATE (16)
- Generates OIDs for triggers and tables using hash functions
- Supports WHERE clause filtering
- Returns results sorted by trigger name

Implementation:
- Created src/catalog/pg_trigger.rs following pg_sequence.rs pattern
- Reuses parse_trigger_sql() logic from information_schema.triggers
- Integrated into query_interceptor.rs for routing pg_trigger queries
- Added comprehensive test suite with 5 test cases

Tests verify:
- Basic trigger properties (name, tgrelid, tgtype, tgenabled)
- BEFORE/AFTER timing detection
- INSERT/UPDATE/DELETE event detection
- Empty result sets when no triggers exist
- Multiple triggers with proper sorting

All tests passing (5/5).

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Implemented pg_settings as a static handler returning PostgreSQL-like
configuration settings. This table is heavily queried by PostgreSQL clients
during connection setup, especially for SHOW commands.

Features:
- 41 common PostgreSQL settings (version, encoding, DateStyle, etc.)
- Full 17-column schema (name, setting, unit, category, etc.)
- WHERE clause filtering by name (critical for SHOW commands)
- Static data - no SQLite interaction needed

Implementation:
- Created src/catalog/pg_settings.rs with PgSettingsHandler
- Added to query interceptor and db_handler query routing
- Includes comprehensive test suite with 4 test cases

Test coverage:
- Basic query returns 40+ settings
- WHERE name filter works correctly
- All columns return proper values
- Common settings are present

This completes Task 7 from the missing catalog tables implementation plan.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
These files were created but not committed in the original pg_sequence implementation.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@erans erans merged commit c12f355 into main Nov 25, 2025
1 check passed
@erans erans deleted the feature/missing-catalog-tables branch November 25, 2025 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants