Searching All Subscriptions takes five seconds #459

Closed
opened 2026-11-13 19:37:04 -08:00 by rays · 2 comments
Owner

A search on All Subscriptions (filter all, sort published) takes 4.5-5 s, the page and its count each scanning every entry's title and description with lower(...) LIKE '%q%' (entries_where in crates/ipx/src/db.rs, the search clause near line 1279). Seen 2026-11-13 17:29 and 17:30 UTC from the iPhone, trace 52e4d7cff272d32d7913f30a0940e1ca: step entries_in/page 4977 ms, count_in 4962 ms, everything else under 60 ms.

Query: $Q spans '{resource.deployment.environment.name="production" && resource.service.name="ipx" && name="step" && duration > 200ms} | select(span.of)' 7d

Ways out: a pg_trgm GIN index on lower(title) and lower(description) on Postgres (SQLite keeps the scan), and running the page and the count concurrently, or skipping the count for a search, so the two scans are not paid one after the other. Check with EXPLAIN (ANALYZE, BUFFERS) on production first.

A search on All Subscriptions (filter all, sort published) takes 4.5-5 s, the page and its count each scanning every entry's title and description with `lower(...) LIKE '%q%'` (entries_where in crates/ipx/src/db.rs, the search clause near line 1279). Seen 2026-11-13 17:29 and 17:30 UTC from the iPhone, trace 52e4d7cff272d32d7913f30a0940e1ca: step entries_in/page 4977 ms, count_in 4962 ms, everything else under 60 ms. Query: `$Q spans '{resource.deployment.environment.name="production" && resource.service.name="ipx" && name="step" && duration > 200ms} | select(span.of)' 7d` Ways out: a pg_trgm GIN index on lower(title) and lower(description) on Postgres (SQLite keeps the scan), and running the page and the count concurrently, or skipping the count for a search, so the two scans are not paid one after the other. Check with EXPLAIN (ANALYZE, BUFFERS) on production first.
rays added the bug label 2026-11-13 19:37:04 -08:00
Author
Owner

EXPLAIN (ANALYZE, BUFFERS) on production, 2026-11-14, the count as ipx sends it for '%apple%':

  • account 2 (154 subscriptions): 5.1 s, a parallel seq scan of entries filtering lower(title) and lower(description).
  • account 3 (29 subscriptions): 675 ms, through entries_seen per feed.
  • descriptions alone: 3.9 s, 554k buffers (about 4.3 GB, mostly TOAST, the HTML of every item); titles alone: 0.2 s, 90k buffers.

pg_trgm is available on the server but not installed. Choices:

  1. pg_trgm GIN on lower(title) and lower(description): same substring meaning as now (#296), fast; but a trigram index over ~4 GB of HTML is several GB on the shared Postgres, and every scan's inserts pay to update it.
  2. pg_trgm GIN on lower(title) only, and search descriptions only for the newest items (or not at all): small index, but a word only in an older item's text stops matching.
  3. Full-text (tsvector GIN on the text without markup): much smaller and fast, but matches words, not substrings: 'app' would no longer find 'apple'.
    Waiting on the owner's choice.
EXPLAIN (ANALYZE, BUFFERS) on production, 2026-11-14, the count as ipx sends it for '%apple%': - account 2 (154 subscriptions): 5.1 s, a parallel seq scan of entries filtering lower(title) and lower(description). - account 3 (29 subscriptions): 675 ms, through entries_seen per feed. - descriptions alone: 3.9 s, 554k buffers (about 4.3 GB, mostly TOAST, the HTML of every item); titles alone: 0.2 s, 90k buffers. pg_trgm is available on the server but not installed. Choices: 1. pg_trgm GIN on lower(title) and lower(description): same substring meaning as now (#296), fast; but a trigram index over ~4 GB of HTML is several GB on the shared Postgres, and every scan's inserts pay to update it. 2. pg_trgm GIN on lower(title) only, and search descriptions only for the newest items (or not at all): small index, but a word only in an older item's text stops matching. 3. Full-text (tsvector GIN on the text without markup): much smaller and fast, but matches words, not substrings: 'app' would no longer find 'apple'. Waiting on the owner's choice.
Author
Owner

Fixed in b046e66 (trigram on plain text, the owner's choice), deployed. The backfill made 674,269 items' search text in 13 minutes; VACUUM (ANALYZE) entries after it, with the owner's leave, cleared the backfill's dead entries from entries_unsearched. Live through the API: 'kubernetes' 25-95 ms, was about 5 s. A word in about one item in nine ('apple', 75,000 matches) still takes about 1.9 s: the count and the page re-check every match's text (a trigram match is a candidate). Filed apart.

Fixed in b046e66 (trigram on plain text, the owner's choice), deployed. The backfill made 674,269 items' search text in 13 minutes; VACUUM (ANALYZE) entries after it, with the owner's leave, cleared the backfill's dead entries from entries_unsearched. Live through the API: 'kubernetes' 25-95 ms, was about 5 s. A word in about one item in nine ('apple', 75,000 matches) still takes about 1.9 s: the count and the page re-check every match's text (a trigram match is a candidate). Filed apart.
rays closed this issue 2026-11-16 18:05:06 -08:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: rays/ipx#459