Skip to content

symfonic.memory.backends.postgres_erase_visibility

postgres_erase_visibility

Indexed read fences for validated legacy and retirement schemas.

JobsTable

Bases: str

Qualified identifier carrying its freshly validated schema capability.

String behavior preserves existing identifier consumers. Plain identifiers conservatively require retirement support instead of omitting suppression.

erasing

erasing(jobs: str, tenant_sql: str, path_sql: str) -> str

Hide erasing subtrees and all retired tenant paths, including NULL.

Separate probes retain the active partial index. Retirement's validated constraints imply permanent, enabling the unique permanent tenant index. Only a validated erasing-only schema may omit that second probe.

Source code in src/symfonic/memory/backends/postgres_erase_visibility.py
def erasing(jobs: str, tenant_sql: str, path_sql: str) -> str:
    """Hide erasing subtrees and all retired tenant paths, including NULL.

    Separate probes retain the active partial index. Retirement's validated
    constraints imply permanent, enabling the unique permanent tenant index.
    Only a validated erasing-only schema may omit that second probe.
    """
    active = (
        f"EXISTS (SELECT 1 FROM {jobs} j WHERE j.tenant_id={tenant_sql} "
        f"AND j.state='erasing' AND starts_with({path_sql} COLLATE \"C\", j.prefix))"
    )
    if isinstance(jobs, JobsTable) and not jobs.retirement:
        return active
    return (
        f"({active} OR EXISTS (SELECT 1 FROM {jobs} j WHERE j.tenant_id={tenant_sql} "
        "AND j.permanent AND j.state='retired'))"
    )

fenced_claim

fenced_claim(jobs: str) -> str

Judge claim and job in the same statement snapshot.

Source code in src/symfonic/memory/backends/postgres_erase_visibility.py
def fenced_claim(jobs: str) -> str:
    """Judge claim and job in the same statement snapshot."""
    return erasing(jobs, "c.tenant_id", "c.scope_path")

live_paths

live_paths(jobs: str, tenant_sql: str, array_sql: str) -> str

Remove fenced owners before the bounded content seek.

Source code in src/symfonic/memory/backends/postgres_erase_visibility.py
def live_paths(jobs: str, tenant_sql: str, array_sql: str) -> str:
    """Remove fenced owners before the bounded content seek."""
    return (
        f"ARRAY(SELECT p FROM unnest({array_sql}::text[]) AS p "
        f"WHERE NOT {erasing(jobs, tenant_sql, 'p')})"
    )