Skip to content

1.1.1

Latest

Choose a tag to compare

@Fenoman Fenoman released this 22 Feb 04:00

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)