Skip to content

Releases: Fenoman/pg_query_stack

1.1.1

22 Feb 04:00

Choose a tag to compare

Fix SIGSEGV (dangling pointer) and optimize hot path to ~55ns per query

Fix:

  • Always copy sourceText — short queries into 512-byte inline buffer, long queries into TopTransactionContext via MemoryContextAlloc
  • Add overflow_depth counter to prevent pop of wrong frames at deep recursion
  • Skip pfree in xact callback — TopTransactionContext handles cleanup (O(1))
  • Remove PG_TRY from ExecutorStart/End — push after hook call (pg_stat_statements pattern)
  • Use strnlen to avoid scanning beyond 512KB truncation limit

Performance impact (1000 TPS, ~20 queries/tx):

  • Original version (List+pstrdup): ~900ns/query
  • Previous version (raw pointer): ~10ns/query (unsafe, SIGSEGV)
  • Current version (inline ≤511B): ~55ns/query (safe)
  • Current version (heap >511B): ~250ns/query (safe)
  • Memory: 52KB per backend (100 × 528B static array)

1.1.0

27 Nov 14:39

Choose a tag to compare

Major performance optimization: reduce overhead from 7-10% to near-zero

Performance improvements:
  - Replace PostgreSQL List with static array for zero-allocation query tracking
  - Store pointer to sourceText instead of copying query string on each call
  - Remove memory context switching on hot execution path
  - Add GUC pg_query_stack.enabled for complete runtime disable (zero overhead)

Benchmark results (pgbench -c 10 -j 4 -T 30):
  - Without extension: ~195k TPS
  - Before optimization: ~181k TPS (7.3% overhead)
  - After optimization: ~194k TPS (~0% overhead)

Bug fixes:
  - Fix memory leak in pg_list_reverse_copy (now deep copies with proper cleanup)
  - Fix double-free in SRF function (removed explicit list free, rely on memory context)
  - Fix OOM handling by wrapping all allocations in single PG_TRY block
  - Properly clean up truncated copies in transaction callback

1.0.6

23 Jul 11:55

Choose a tag to compare

Add comprehensive test suite and improve memory management for pg_query_stack

Core improvements:

  • Fix memory leaks by implementing proper cleanup with pg_stack_list_free_deep()
  • Remove separate MemoryContext, use TopTransactionContext directly
  • Add query length limit (MAX_QUERY_TEXT_LENGTH: 512KB) to prevent memory overflow
  • Reduce MAX_QUERY_STACK_DEPTH from 1000 to 100 for better resource usage
  • Add OOM handling with PG_TRY/PG_CATCH blocks
  • Improve NULL safety checks throughout the code

Test suite additions:

  • Add 14 regression tests covering all extension features
  • Include automated test scripts (run_tests.sh, run_single_test.sh)
  • Add TESTING.md documentation with detailed test descriptions

1.0.5

31 May 18:56

Choose a tag to compare

Fix memory leaks, exception handling, and add parallel worker support

  • Fix transaction callback to clear stack before deleting memory context
  • Skip processing in parallel workers with IsParallelWorker() check
  • Fix C89 compatibility by declaring variables at block start
  • Add null checks in pg_stack_free() for safer memory deallocation
  • Include access/parallel.h for proper function declarations

Addresses all compiler warnings and improves overall robustness.

1.0.4

21 May 20:41

Choose a tag to compare

Introduced size guard (MAX_QUERY_STACK_DEPTH = 1000)

  • When the depth hits the limit we drop the deepest frame before pushing a new one (ExecutorStart).
  • Keeps per-backend memory bounded even with runaway recursion.

Memory‐safety fixes

  • pg_stack_free() now pfree()-s both the QueryStackEntry and its query_text.
  • Limiter path frees the trimmed tail entry.
  • Query_Stack_Depth counter added to avoid repeated list_length() scans and guarantee O(1) checks.

Signal/exception robustness

  • volatile bool stack_pushed + balanced pop in PG_CATCH ensure no dangling

1.0.3

03 Dec 07:35

Choose a tag to compare

Small fixes and refactor. Use own MemoryContext

1.0.2

02 Dec 01:01

Choose a tag to compare

Fix another segfault

1.0.1

24 Nov 17:22

Choose a tag to compare

Removed SPI and resolved a conflict with a global variable that was causing a segmentation fault
Use XactCallback to clear query stack
Use CurTransactionContext or TopMemoryContext in some situations
Fixed the shadow variable declaration
Make deep copy of query stack
Replace ExecutorFinish hook to ExecutorEnd hook
Copy only the query text, not the whole structure queryDesc

1.0.0

28 Oct 02:33

Choose a tag to compare

Initial release