Skip to content

Conversation

@sgaunet
Copy link
Owner

@sgaunet sgaunet commented Dec 7, 2025

This commit fixes the N+1 query pattern in ListTables when include_size=true
by introducing a single optimized query that joins table metadata with statistics.

Changes:

  • Add ListTablesWithStats method that uses single query with JOIN
  • Update App.ListTables to use optimized method when stats requested
  • Add fallback to COUNT(*) for tables with 0 statistics
  • Configure golangci-lint with higher complexity/length limits
  • Update tests to use new optimized method

Performance improvement: 100+ queries reduced to 1-2 queries for large databases

Fixes #21

This commit fixes the N+1 query pattern in ListTables when include_size=true
by introducing a single optimized query that joins table metadata with statistics.

Changes:
- Add ListTablesWithStats method that uses single query with JOIN
- Update App.ListTables to use optimized method when stats requested
- Add fallback to COUNT(*) for tables with 0 statistics
- Configure golangci-lint with higher complexity/length limits
- Update tests to use new optimized method

Performance improvement: 100+ queries reduced to 1-2 queries for large databases

Fixes #21
@sgaunet sgaunet self-assigned this Dec 7, 2025
@sgaunet sgaunet linked an issue Dec 7, 2025 that may be closed by this pull request
6 tasks
@sgaunet sgaunet merged commit b4f5f71 into main Dec 7, 2025
5 checks passed
@sgaunet sgaunet deleted the 21-fix-n1-query-pattern-in-listtables-with-include_size-option branch December 7, 2025 19:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fix N+1 query pattern in ListTables with include_size option

2 participants