Skip to content

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

Merged
datlechin merged 9 commits into
mainfrom
perf/metadata-idle-session
Nov 26, 2026
Merged

datlechin merged 9 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, a transaction state read as idle (not unknown), no protected write, automatic commit, no startup commands, already on the read's database and schema, and no statement a person or an agent wrote run on it yet, since a lent read would replace that statement's ROW_COUNT(), FOUND_ROWS() and warnings. 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), instead of reading it again on their own lease. Refresh in the database switcher rereads through the tree. Their schema lists are still read on their own lease: the tree's refresh does not reach the schema service's copy, so reusing it showed a stale list after a refresh.

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. MetadataReadLendingTests also covers a session whose transaction state is unknown or open, and one that ran an authored statement, until a reconnect.
  • ApprovedTargetTests/catalogApprovalHoldsToTheLeasedDriversReport updated on purpose: the pool now dials in the background right after login, which read b.sqlite before the test switched the file, so the count ran in b.sqlite. Its plugin now opens b.sqlite for the session and the moved file for every later dial; the refusal it checks is unchanged.
  • Local, on the head merged with main: ApprovedTargetTests, SchemaServiceTests, MetadataReadLendingTests, MetadataConnectionPool*Tests, DatabaseSwitcherRefreshTests, QuickSwitcherViewModelTests, SchemaLeasingLoadTests, DatabaseTreeMetadataServiceTests, ScopedDriverRoutingTests: 217 passed.

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
…one wrote, which keeps its row count and warnings
…lease again, since the tree's refresh never reaches the schema service's copy
@datlechin
datlechin merged commit 6400623 into main Nov 26, 2026
0 of 3 checks passed
@datlechin
datlechin deleted the perf/metadata-idle-session branch November 27, 2026 16:38
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