Skip to content

perf(db): implement composite B-Tree database indexes for filtering and pagination (#105) - #138

Merged
Decuayer merged 1 commit into
mainfrom
feat/SDDC-69-composite-db-indexes
Aug 31, 2026
Merged

perf(db): implement composite B-Tree database indexes for filtering and pagination (#105)#138
Decuayer merged 1 commit into
mainfrom
feat/SDDC-69-composite-db-indexes

Conversation

@Decuayer

@Decuayer Decuayer commented Aug 31, 2026

Copy link
Copy Markdown
Owner

🎯 Jira / Task Reference


📝 Summary of Changes

Implements composite B-Tree database indexes across the Incidents, Teams, and Users tables in accordance with NFR-01, NFR-02, and Section 4.2 of the Design Document:

  • Incidents Index: (CreatedAt DESC, Status, Category) (IX_Incidents_CreatedAt_Status_Category) to optimize chronological incident queue pagination and multi-parameter status/category filtering.
  • Teams Index: (Status, TeamName) (IX_Teams_Status_TeamName) for fast idle team lookup and name prefix searching.
  • Users Index: (RoleType, Department, FirstName, LastName) (IX_Users_RoleType_Department_FirstName_LastName) to optimize directory filtering by organizational unit and role-based searching.
  • EF Core Migration: Generated and applied 20260831152146_AddCompositeIndexesForFilteringAndPagination.cs.
  • Automated Tests: Added metadata constraint unit tests in DbContextConstraintTests.cs validating index names, property sequences, and descending ordering.

🏷️ Type of Change

  • 🚀 Feature: New functionality or operational workflow
  • 🐛 Bug Fix: Non-breaking fix for an identified defect
  • ♻️ Refactor: Code restructuring without behavior alteration
  • Performance: Speed, query, or memory consumption optimization
  • 🛠️ Chore / Infra: Dependencies, Docker, CI/CD, or tooling updates
  • 📖 Documentation: README, API specs, or code documentation updates
  • ⚠️ Breaking Change: Requires schema migration or API contract changes

🧪 Testing & Verification

Automated Tests

  • Backend unit/integration tests executed: dotnet test (118/118 passed)
  • Linter & formatting passed: dotnet format --verify-no-changes

Manual Test Steps & PostgreSQL Execution Plans

  1. Applied migration via dotnet ef database update.
  2. Verified presence of target indexes in PostgreSQL system catalog via pg_indexes.
  3. Executed EXPLAIN (ANALYZE, BUFFERS) verifying switch from Seq Scan to Index Scan:
    • Incidents status/category query: Index Scan using "IX_Incidents_CreatedAt_Status_Category" (~1.26ms)
    • Teams availability query: Index Scan using "IX_Teams_Status_TeamName" (~1.19ms)
    • Users role & department query: Index Scan using "IX_Users_RoleType_Department_FirstName_LastName" (~1.34ms)

📷 Screenshots / Evidence (Required for UI / API changes)

Query Execution Plan / Verification
Incidents Filter Index Scan using "IX_Incidents_CreatedAt_Status_Category" on "Incidents"
Teams Availability Index Scan using "IX_Teams_Status_TeamName" on "Teams"
Users Directory Index Scan using "IX_Users_RoleType_Department_FirstName_LastName" on "Users"

📋 Pre-Merge Checklist

  • My code adheres to the project's Clean Architecture & style guidelines.
  • I have self-reviewed my own code before requesting review.
  • Database migrations are backwards-compatible (if applicable).
  • Sensitive secrets / tokens are NOT committed (verified .env exclusions).
  • Jira status updated to In Review.

- Add composite index IX_Incidents_CreatedAt_Status_Category on (CreatedAt DESC, Status, Category)
- Add composite index IX_Teams_Status_TeamName on (Status, TeamName)
- Add composite index IX_Users_RoleType_Department_FirstName_LastName on (RoleType, Department, FirstName, LastName)
- Generate and apply PostgreSQL migration AddCompositeIndexesForFilteringAndPagination
- Add unit tests verifying EF Core model metadata and descending sort configuration
- Verify EXPLAIN ANALYZE execution plans switch from Seq Scan to Index Scan

Closes #105
Ref: SDDC-69
@Decuayer
Decuayer merged commit 91c02b8 into main Aug 31, 2026
1 check 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.

[SDDC-69] Implement Composite B-Tree Database Indexes for Optimized Server-Side Filtering, Pagination, and Search

1 participant