Skip to content

fix(postgres): translate entity/id/tenant_id to real columns; register observability env keys#27

Merged
eldonm merged 2 commits into
mainfrom
fix/postgres-translate-entity-column-index
Jul 7, 2026
Merged

fix(postgres): translate entity/id/tenant_id to real columns; register observability env keys#27
eldonm merged 2 commits into
mainfrom
fix/postgres-translate-entity-column-index

Conversation

@eldonm

@eldonm eldonm commented Jul 7, 2026

Copy link
Copy Markdown
Member

Summary

Two focused postgres-backend fixes:

  • Postgres translator hits real columns, not JSONB paths (jvspatial/db/_postgres_translate.py) — queries filtering on entity / id / tenant_id now target the dedicated columns instead of data->>'...' JSONB extraction, so they use the column indexes.
  • Register JVSPATIAL_OBSERVABILITY_ENABLED / JVSPATIAL_SLOW_QUERY_MS in the env allowlist (jvspatial/env_adapter.py) — so the observability/slow-query knobs are recognized configuration rather than rejected/ignored.

Test plan

  • pre-commit run --all-files clean (black, isort, flake8, mypy, detect-secrets).
  • tests/test_env*.py — 22 passed.
  • Postgres integration tests (tests/db/test_postgres_integration.py) skip locally without a test DB; CI runs them against postgres.

🤖 Generated with Claude Code

eldonm added 2 commits July 4, 2026 16:00
…paths

_translate_field_clause built (data #>> '{entity}') for every field
including entity/id/tenant_id, even though these are real top-level
Postgres columns (see _bootstrap_collection DDL + postgres.py's own
_pg_field_extract, which already special-cases them correctly for a
different code path). Every typed <NodeClass>.find(...) auto-injects
an entity discriminator filter, so this blinded every find() call to
the entity btree index and forced a full table scan on the shared
node table.

Reproduced against a live Postgres instance: entity = $1 seq-scanned
at ~298ms on a 2.4k-row table; after this fix it's an Index Scan on
node_entity_idx at ~0.03ms.
…lowlist

Both are real vars consumed directly in database_configurator.py, but
were missing from ALLOWED_ENV_KEYS — every server boot logged "Unknown
JVSPATIAL_* env var ... ignored" even though the var worked correctly.
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Benchmark comparison

Threshold: ±25% (informational, does not block merge)

benchmark baseline (s) current (s) delta status
tests/benchmarks/test_deferred_save_benchmarks.py::test_bench_deferred_save_batched_100 0.056114 0.037174 -33.8% IMPROVED (-33.8%)
tests/benchmarks/test_deferred_save_benchmarks.py::test_bench_immediate_save_100 0.053220 0.038526 -27.6% IMPROVED (-27.6%)
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_batched_saves_500 0.527134 0.432082 -18.0% OK
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_count_empty_query 1.167715 0.918093 -21.4% OK
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_count_filtered 1.268569 1.064342 -16.1% OK
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_find_filtered 1.009164 0.800931 -20.6% OK
tests/benchmarks/test_jsondb_benchmarks.py::test_bench_jsondb_save_throughput 0.001866 0.001538 -17.6% OK
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_count_empty 0.374633 0.254204 -32.1% IMPROVED (-32.1%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_count_fallback_via_regex 0.417655 0.306299 -26.7% IMPROVED (-26.7%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_count_pushdown 0.402586 0.262717 -34.7% IMPROVED (-34.7%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_find_fallback_via_regex 0.399404 0.275657 -31.0% IMPROVED (-31.0%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_find_pushdown 0.351799 0.246087 -30.0% IMPROVED (-30.0%)
tests/benchmarks/test_sqlite_benchmarks.py::test_bench_sqlite_sort_limit_pushdown 0.403209 0.288802 -28.4% IMPROVED (-28.4%)

@eldonm eldonm merged commit 4473f62 into main Jul 7, 2026
6 checks passed
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