fix(perf): open tables without waiting behind background schema introspection#1483
Conversation
4ef3399 to
749fa67
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 4ef3399098
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Signed-off-by: Ngô Quốc Đạt <datlechin@gmail.com>
749fa67 to
c0505c0
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c0505c0a20
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
faf4792 to
fa994a3
Compare
fa994a3 to
e058031
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: e05803197c
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
e058031 to
3056d9c
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3056d9c2fc
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| try await DatabaseManager.shared.withMetadataDriver(connectionId: connId) { driver in | ||
| let cols = try await driver.fetchColumns(table: tableName) |
There was a problem hiding this comment.
Keep session-local metadata on the main driver
When the editable table comes from a session-local object (for example a PostgreSQL/MySQL temporary table created on the current connection, or a temp table shadowing a permanent table), this metadata fetch now runs on a separate pooled connection that cannot see the main connection's temp schema. The user query still succeeds on the main driver, but the schema task will either return no metadata or metadata for a different permanent table, so primary keys/editability and phase-2 metadata can be wrong for those results; keep this path on the active driver or fall back when the table is connection-local.
Useful? React with 👍 / 👎.
# Conflicts: # TablePro/Core/Database/DatabaseManager+Health.swift # TablePro/Core/Database/DatabaseManager+Sessions.swift # TablePro/Core/Services/Query/DatabaseTreeMetadataService.swift # TablePro/Core/Services/Query/MetadataConnectionPool.swift # TablePro/Views/Main/MainContentCoordinator.swift # TablePro/Views/Sidebar/DatabaseTreeView.swift
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 46726a6f63
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| count = try await DatabaseManager.shared.withMetadataDriver(connectionId: parent.connectionId, workload: .bulk) { driver in | ||
| let result = try await driver.execute(query: sql) |
There was a problem hiding this comment.
Keep row counts on the session connection
When an editable table is connection-local (for example a PostgreSQL/MySQL temporary table, or a temp table shadowing a permanent table), this new count path runs SELECT COUNT(*) on a pooled metadata connection instead of the session connection that loaded the grid. That separate connection cannot see the same temp objects/session state, so the row-count refresh can fail or report a different table’s count even though the data grid query itself succeeded; the prior implementation executed this count on the active driver.
Useful? React with 👍 / 👎.
Problem
On connections with many tables (300+), opening a table tab showed the executing spinner for 3-4 seconds while the toolbar reported the query itself took ~100ms.
Root cause
Background schema introspection ran on the same physical database connection as user queries. Plugin connections serialize every operation through one queue, so a user SELECT waited behind whatever introspection was in flight. The largest offender is the autocomplete column preload (
fetchAllColumnsover every table) that fires on connect, database switch, and refresh. The toolbar only measured the SELECT's own time once it finally ran, so the spinner covered the whole wait.Fix
Route background introspection onto the existing
MetadataConnectionPoolinstead of the main query connection, so user queries never wait behind it.DatabaseManager.withMetadataDriver(connectionId:workload:)borrows a pooled connection for the connection's active database.Tests
Added coverage that the schema provider's column loading uses the injected metadata source. Existing provider tests cover the driver fallback path.
How to verify
Open a table on a connection with 300+ tables. The spinner should clear at about the query time, even right after connecting while autocomplete is still loading. Watch the gap between the tab-select log line and
[executeUserQuery].Based on #1473 (sidebar database tree), which introduced
MetadataConnectionPool.