Skip to content

Add index on grants table for grantee_address query performance#731

Draft
Copilot wants to merge 2 commits intorj-granteefrom
copilot/sub-pr-730
Draft

Add index on grants table for grantee_address query performance#731
Copilot wants to merge 2 commits intorj-granteefrom
copilot/sub-pr-730

Conversation

Copy link
Contributor

Copilot AI commented Mar 19, 2026

The GET /grantees/:address/users endpoint was doing a full table scan on grants — the table only had a primary key on (user_id, txhash, grantee_address) with no usable index for lookups by grantee_address.

Changes

  • ddl/migrations/0191_grants_grantee_address_idx.sql — adds a partial index covering the query's filter and sort columns:

    CREATE INDEX IF NOT EXISTS idx_grants_grantee_address
    ON grants(grantee_address, is_revoked, created_at DESC)
    WHERE is_current = true;

    The WHERE is_current = true predicate keeps the index small; is_revoked covers the boolean filter; created_at DESC supports ORDER BY … LIMIT … OFFSET pagination without a sort step.

  • sql/01_schema.sql — schema snapshot updated to reflect the new index.


📍 Connect Copilot coding agent with Jira, Azure Boards or Linear to delegate work to Copilot in one click without leaving your project management tool.

Co-authored-by: rickyrombo <3690498+rickyrombo@users.noreply.github.com>
Copilot AI changed the title [WIP] [WIP] Address feedback on indexing for GET /grantees/:address/users endpoint Add index on grants table for grantee_address query performance Mar 19, 2026
Copilot AI requested a review from rickyrombo March 19, 2026 19:48
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.

2 participants