Employee Database Indexing and Query Patterns
Summary
The current model has 17 confirmed indexes. They support tenant/code uniqueness, common Employee status/department queries, child joins, history ordering, audit lookup, and outbox processing. The source does not establish performance guarantees.
Audience
- Backend developers and QA engineers
- Solution architects reviewing query fit
Reference Content
Important index groups
| Group | Confirmed indexes | Notes | Source |
|---|---|---|---|
| Employee root | 3 | Unique tenant/code; tenant/status; tenant/department | Infrastructure/EmployeeDbContext.cs |
| Organization | 2 | Unique tenant/code for Department and Designation | same |
| Child joins | 8 | One Employee-ID index for each child object | initial migration |
| Timeline/audit | 2 | Tenant/time indexes for timeline and audit | context plus second migration |
| Outbox | 2 | Unique event identity; status/time processing | context |
There is no database unique index for Employee email. Email uniqueness is checked by repository/application logic. No dedicated index exists for Employee designation or reporting-manager references, and no search-specific text index is configured.
Query patterns
- Search starts from tenant-filtered
Employees.AsNoTracking(). - Free-text filters use case-normalized containment over display name, employee code, and email.
- Additional filters cover name, code, email, department, designation, manager, status, activity, skill, location, and employment type.
- The provider counts the filtered set, applies normalized sorting, then uses offset pagination with
SkipandTake. - Supported sorting covers display name, employee code, status, joining date, and update time.
- Profile retrieval eager-loads all eight child collections.
- Timeline reads are no-tracking and newest-first.
- Department/designation list queries are no-tracking projections ordered by name or level/name.
Query-fit limitations
The current indexes directly support only a subset of search filters and sorts. Case transformation and substring predicates may not use ordinary indexes efficiently. No benchmark, query-plan baseline, full-text index, keyset pagination, or performance service-level guarantee was found. Optimization decisions require measured production-safe evidence.
Source References
microservices/src/employee-service/Infrastructure/EmployeeDbContext.csmicroservices/src/employee-service/Infrastructure/PostgresEmployeeSearchProvider.csmicroservices/src/employee-service/Infrastructure/Persistence.csmicroservices/src/employee-service/Application/Queries/EmployeeApplicationQueries.csmicroservices/src/employee-service/Infrastructure/Migrations/20260701173627_InitialEmployeeSchema.csmicroservices/src/employee-service/Infrastructure/Migrations/20260701181407_AddTimelineEventFields.cs
Related Articles
See Also
Keywords
- Composite indexes
- Employee search
- No-tracking queries
Revision Information
- Status: Draft
- Last reviewed: 2026-07-15
- Review cycle: Quarterly