Bounded native inventory queries. Eligibility precedes keyset and LIMIT.
postgres_statement
postgres_statement(scope, request, expiry='TRUE', jobs=None)
jobs: owners an erasing CORE-199 job hides leave the array first.
Source code in src/symfonic/memory/backends/inventory.py
| def postgres_statement(scope, request, expiry='TRUE', jobs=None):
"""``jobs``: owners an erasing CORE-199 job hides leave the array first."""
prefix, values = sql_prefix_condition(scope, "scope_path", 5)
if jobs is not None and prefix == '(scope_path COLLATE "C" = ANY($5::text[]))':
from symfonic.memory.backends.postgres_erase_jobs import live_paths
prefix = f'(scope_path COLLATE "C" = ANY({live_paths(jobs, "$1", "$5")}))'
sql = ('SELECT * FROM memory_nodes WHERE tenant_id COLLATE "C"=$1 '
'AND layer=ANY($2::text[]) '
f"AND id::text COLLATE \"C\">$3 AND {prefix} AND {PUBLISHED_SQL} AND {expiry} "
'ORDER BY id::text COLLATE "C" LIMIT $4')
return sql, [scope.tenant_id, list(request.layers), request.after, request.limit + 1, *values]
|