Skip to content

Conversation

itslenny
Copy link
Contributor

@itslenny itslenny commented Oct 3, 2025

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Prefixes are handled via triggers that have to check the object table to determine if prefixes should be removed. This can cause "orphan prefixes" to be left behind under heavy concurrency

What is the new behavior?

Maintain child ref counts in the prefixes table using statement level triggers

Implementation details

Prefix ref counting

  • adds child_objects and child_prefixes columns for reference counting
  • maintains child object counts via statement level triggers with deterministic locking
  • maintains child prefix counts via row level triggers with deterministic locking

Prefix ref backfill

  • initializes new columns with -1 "sentinel value"
  • creates placeholder increment/decrement functions
    • increment - no-op for existing / inserts prefix with -1 value if new
    • decrement - no-op
  • computes ref counts for all -1 (unset) prefixes in batches
  • removes orphan prefixes (ref counts == 0)
  • replaces increment/decrement functions with real implementation
  • final pass of -1 refs (if needed) - this will only be needed with very heavy traffic during migration

DOES NOT check for / fix missing prefixes. This would be an expensive operation for projects with a large number of objects as it would require a full scan of the objects table, and there is no known issue with missing prefixes (only orphan prefixes)

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.

1 participant