Skip to content

improvement(search): index permission-import identities by subject - #10199

Merged
waleedlatif1 merged 2 commits into
stagingfrom
fix/validate-permission-import-subject-index
Nov 19, 2026
Merged

waleedlatif1 merged 2 commits into
stagingfrom
fix/validate-permission-import-subject-index

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Search resolves a reader's connector permission grants by subject_token alone (activeConnectorPermissionGrants(), used by loadConnectorPermissionGroupTokens and the connector grant checks). The import branch's only index on that column, kcpii_subject_idx, was keyed (import_id, subject_token), so the lookup had to visit every active import (or scan the whole index) instead of jumping to the reader's identities.
  • Replaces it with the same unique key led by the subject: kcpii_subject_import_idx (subject_token, import_id). Same column set, so uniqueness is unchanged: the identity insert's untargeted ON CONFLICT DO NOTHING and the per-import conflict check (import_id + user_id OR subject_token) behave as before, and the table keeps one secondary index rather than two.
  • kcpig_subject_idx (import_id, user_id, group_key) on the grant table already matches the follow-on join (import_id + user_id, group_key IS NOT NULL), so it is unchanged.
  • Migration 0461 follows 0446's replace pattern: replay-safe recovery of an INVALID build, embedded COMMIT, CREATE UNIQUE INDEX CONCURRENTLY IF NOT EXISTS first, then DROP INDEX CONCURRENTLY IF EXISTS on the old one, so uniqueness never lapses. No code reads the index by name, and both index shapes serve the deployed app's queries, so it is backward-compatible with the running version. check:migrations passes with no annotation.

Plain EXPLAIN (ANALYZE) on a throwaway local database with 20k connectors (40k imports, 400k identities, 1.2M import grants), same query shape as the search path:

old (import_id, subject_token) new (subject_token, import_id)
Plan hash join over all 20k active imports, 20k index probes bitmap scan of the reader's 48 identities, then PK lookups
Buffers ~460k ~1.6k
Execution 111 ms 0.9 ms

Release notes

Knowledge search

  • Permission-aware search over connectors that use uploaded permission snapshots now looks up a reader's access directly instead of scanning every snapshot, so it stays fast as more snapshots are uploaded.

@vercel

vercel Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated
docs Skipped Skipped Nov 19, 2026 3:05am UTC

Request Review

@greptile-apps

greptile-apps Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issues were found.

Summary

This PR speeds up permission-aware search by putting subject_token first in the permission-import identity index while keeping the same uniqueness rule.

  • Permission searches find a reader's imported identities by subject first.

No new actionable issues found.

Reviews (2) · Last reviewed commit: "improvement(search): format migration sn..." · Reviewed by Greptile

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

This PR changes a database schema or migrates data. Ultrareviews find 2.4x more serious bugs than standard reviews. Comment @cubic-dev-ai ultrareview to run one.

Turn on auto-fix | Re-trigger cubic

@waleedlatif1
waleedlatif1 merged commit f9c4d7b into staging Nov 19, 2026
58 of 59 checks passed
@waleedlatif1
waleedlatif1 deleted the fix/validate-permission-import-subject-index branch November 19, 2026 03:07
@waleedlatif1

Copy link
Copy Markdown
Collaborator Author

@greptile

This branch was previously deployed

1 inactive deployment
Preview — 541a1b9a Deployed Nov 19, 2026 by vercel[bot]
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