Skip to content

fix(schema): add missing FK indexes and constraints#1776

Merged
moshloop merged 1 commit intomainfrom
fix/schema-missing-indexes-and-fk-constraints
Feb 24, 2026
Merged

fix(schema): add missing FK indexes and constraints#1776
moshloop merged 1 commit intomainfrom
fix/schema-missing-indexes-and-fk-constraints

Conversation

@adityathebe
Copy link
Copy Markdown
Member

@adityathebe adityathebe commented Feb 19, 2026

Add 74 missing indexes on foreign key columns across all schema files.
PostgreSQL does not auto-create indexes for FK columns, causing full
sequential scans on joins, cascade deletes, and filtered queries.

Also add two missing FK constraints:

  • logging_backends.agent_id -> agents.id
  • external_roles.scraper_id -> config_scrapers.id

Agent Conversation: https://pi.dev/session/#23fc14d97915172bb47a9799228d080b

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Feb 19, 2026

Benchstat

Base: 92eb3b0c7ecea2104315c1078bec3d8dfbf32074
Head: 3988d940c7ada1a296eb30a2b45a115be253dd16

goos: linux
goarch: amd64
pkg: github.com/flanksource/duty/bench
cpu: AMD EPYC 7763 64-Core Processor                
                                                │ bench-base.txt │          bench-head.txt           │
                                                │     sec/op     │   sec/op     vs base              │
Main/Sample-15000/catalog_changes/Without_RLS-4      5.453m ± 4%   5.613m ± 8%  +2.93% (p=0.002 n=6)
Main/Sample-15000/catalog_changes/With_RLS-4         130.4m ± 0%   128.6m ± 1%  -1.39% (p=0.009 n=6)
Main/Sample-15000/config_changes/Without_RLS-4       5.471m ± 1%   5.538m ± 6%  +1.23% (p=0.041 n=6)
Main/Sample-15000/config_changes/With_RLS-4          128.2m ± 0%   128.8m ± 0%  +0.49% (p=0.015 n=6)
Main/Sample-15000/config_detail/Without_RLS-4        3.947m ± 1%   3.929m ± 2%       ~ (p=0.485 n=6)
Main/Sample-15000/config_detail/With_RLS-4           125.4m ± 0%   125.4m ± 1%       ~ (p=0.699 n=6)
Main/Sample-15000/config_names/Without_RLS-4         12.92m ± 2%   13.08m ± 1%       ~ (p=0.093 n=6)
Main/Sample-15000/config_names/With_RLS-4            125.8m ± 0%   126.6m ± 1%  +0.61% (p=0.002 n=6)
Main/Sample-15000/config_summary/Without_RLS-4       63.43m ± 1%   62.95m ± 1%       ~ (p=0.065 n=6)
Main/Sample-15000/config_summary/With_RLS-4          741.0m ± 0%   735.9m ± 1%  -0.68% (p=0.002 n=6)
Main/Sample-15000/configs/Without_RLS-4              7.387m ± 1%   7.255m ± 4%       ~ (p=0.065 n=6)
Main/Sample-15000/configs/With_RLS-4                 124.6m ± 2%   125.2m ± 1%       ~ (p=0.093 n=6)
Main/Sample-15000/analysis_types/Without_RLS-4       3.921m ± 3%   3.921m ± 2%       ~ (p=0.818 n=6)
Main/Sample-15000/analysis_types/With_RLS-4          3.977m ± 3%   3.923m ± 1%  -1.36% (p=0.002 n=6)
Main/Sample-15000/analyzer_types/Without_RLS-4       3.758m ± 2%   3.745m ± 1%       ~ (p=0.180 n=6)
Main/Sample-15000/analyzer_types/With_RLS-4          3.786m ± 4%   3.768m ± 4%       ~ (p=0.132 n=6)
Main/Sample-15000/change_types/Without_RLS-4         5.553m ± 4%   5.359m ± 3%  -3.50% (p=0.009 n=6)
Main/Sample-15000/change_types/With_RLS-4            5.475m ± 3%   5.416m ± 3%       ~ (p=0.589 n=6)
Main/Sample-15000/config_classes/Without_RLS-4       3.323m ± 1%   3.291m ± 4%       ~ (p=0.180 n=6)
Main/Sample-15000/config_classes/With_RLS-4          123.9m ± 0%   125.5m ± 0%  +1.29% (p=0.002 n=6)
Main/Sample-15000/config_types/Without_RLS-4         4.018m ± 2%   3.992m ± 6%       ~ (p=0.699 n=6)
Main/Sample-15000/config_types/With_RLS-4            125.5m ± 0%   124.5m ± 2%       ~ (p=0.394 n=6)
geomean                                              19.51m        19.46m       -0.28%

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Feb 19, 2026

Warning

Rate limit exceeded

@adityathebe has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 19 minutes and 3 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/schema-missing-indexes-and-fk-constraints

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@adityathebe adityathebe force-pushed the fix/schema-missing-indexes-and-fk-constraints branch from 8933544 to 72c72bb Compare February 19, 2026 10:13
@adityathebe adityathebe requested a review from moshloop February 19, 2026 10:13
Add 74 missing indexes on foreign key columns across all schema files.
PostgreSQL does not auto-create indexes for FK columns, causing full
sequential scans on joins, cascade deletes, and filtered queries.

Also add two missing FK constraints:
- logging_backends.agent_id -> agents.id
- external_roles.scraper_id -> config_scrapers.id

Reference: https://pi.dev/session/#23fc14d97915172bb47a9799228d080b
@adityathebe adityathebe force-pushed the fix/schema-missing-indexes-and-fk-constraints branch from 72c72bb to 3988d94 Compare February 19, 2026 13:04
@moshloop moshloop merged commit 69c8f7a into main Feb 24, 2026
14 checks passed
@moshloop moshloop deleted the fix/schema-missing-indexes-and-fk-constraints branch February 24, 2026 06:03
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