Repository navigation
fix(autocomplete): skip server-wide schema indexing on servers with many databases - #353
Open
arturonline wants to merge 1 commit into
Open
arturonline wants to merge 1 commit into
arturonline wants to merge 1 commit into
Conversation
…any databases With no database selected, autocomplete indexed every user database on the server. On a SQL Server instance with hundreds of databases that queued hundreds of metadata queries on the single connection executor and processed millions of entries on the UI thread, leaving the app unresponsive for minutes. Past MAX_SERVER_WIDE_INDEX_DATABASES (20) databases, indexing is skipped with a warning; selecting a database indexes just that one, as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Connecting to a SQL Server instance with many databases, without a default database set, makes sqlit unresponsive for minutes. It often has to be killed and restarted.
Reproduced against a real server with 236 user databases (about 280k tables, 209k views, 594k routines and 3M routine parameters in total).
Cause
When no database is selected and the provider supports cross-database queries, the autocomplete schema loader indexes every non-system database on the server (
_load_schema_directly→get_databases→_on_databases_loaded(all_dbs)).For each database it runs 3 metadata queries: tables, views, and routines with parameters. Each query is fast on its own (about 1s per database in total), but:
session.executor, which is the single thread that owns the connection. Anything the user does (expanding a tree node, running a query) waits behind them for several minutes._table_metadata, and every routine is appended to the cache. That is millions of items processed in idle-scheduler batches on the main thread, plus several hundred worker threads spawned at once.The result looks like a hang.
Fix
Add
MAX_SERVER_WIDE_INDEX_DATABASES = 20. When the server-wide database list is longer than this, autocomplete indexing is skipped and a warning is shown:Selecting a database already calls
_load_schema_cache()with that database as the only target, so indexing picks up there with no further changes. Servers with 20 or fewer databases, and connections with a database configured, behave exactly as before.The guard is applied in both loading paths:
_on_databases_loaded(threaded / idle-scheduler path). A selected database always arrives here as a single-item list, so it is never affected._load_schema_cache_async, right after the database list is fetched.Workaround for users on older versions
Set a database on the connection. Autocomplete then indexes only that database.
Tests
New
tests/unit/test_autocomplete_many_databases.py:The new tests pass when run directly. I couldn't run the full suite with pytest in my local environment.
Possible follow-ups (not in this PR)
🤖 Generated with Claude Code