Skip to content

perf(connections): use the idle session for the first listing and read each list once - #4575

Open
datlechin wants to merge 4 commits into
mainfrom
perf/metadata-idle-session
Open

datlechin wants to merge 4 commits into
mainfrom
perf/metadata-idle-session

Conversation

@datlechin

@datlechin datlechin commented Nov 25, 2026 •

Copy link
Copy Markdown
Member

Summary

  • A metadata read takes the idle session connection when the pool has no idle connection for it, so the first table list after connect no longer waits for a second handshake. Only an idle session lends itself: no turn held or queued on its gate, nothing in flight, no transaction, automatic commit, no startup commands, and already on the read's database and schema. One lent read at a time, one lease per read, so a user query can still cut in. Bulk reads never take the session.
  • The browse scope's pooled connection is dialed in the background once the session has logged in, never beside the login, so a wrong password still counts as one failed login.
  • A bulk lease (row count, foreign key prefetch, column preload) takes an idle interactive connection before it dials one of its own. An interactive read never queues behind bulk work on that connection; it opens another if it needs one.
  • The quick switcher and the database switcher take the database list from the tree's loaded list (or join its read) and the browsed database's schema list from the schema service's catalog, instead of reading both again on their own lease. Refresh in the database switcher rereads through the tree.

Measured on the unit tests: opening the pool for a catalog read and then a bulk read now dials 1 connection, not 2 (MetadataConnectionPoolSharingTests); the first catalog read on a fresh connection runs on the session, dialing 0 (MetadataReadLendingTests); opening the database switcher after the sidebar listed the databases reads nothing (DatabaseSwitcherRefreshTests). Statement-log timings at +50 ms were not run here.

Left for later, in a comment on the issue: the tree layout's own lists for the browsed scope (C11b of #4459) and the all-schema listing the quick switcher reads for cross-schema search.

Test plan

  • MetadataReadLendingTests and MetadataConnectionPoolSharingTests (new), DatabaseSwitcherRefreshTests/switcherTakesTheTreesList (new): each fails on main.
  • Local run of the suites that own the changed types (ScopedDriverRoutingTests, MetadataConnectionPool*Tests, DatabaseSwitcherRefreshTests, QuickSwitcherViewModelTests, SchemaLeasingLoadTests, DatabaseTreeMetadataServiceTests, SwitchDatabasePooledConnectionTests, DatabaseSwitchLeaseOrderingTests, the new suites): 172 executed, 172 passed after one test setup fix.

Closes #4542

…d each list once

A catalog read takes the idle session connection when the pool has nothing idle for it, the browse scope's pooled connection is dialed after login, a bulk lease borrows an idle interactive connection, and the switchers read the database and schema lists their owners already hold.
@datlechin
datlechin enabled auto-merge (squash) November 26, 2026 01:50
…ssion

# Conflicts:
#	apple/TablePro/Core/Services/Query/SchemaService+CatalogLoad.swift

This branch has not been deployed

No deployments
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.

perf(connections): use the idle session for the first listing and read each list once

1 participant