Repository navigation
Done
Labels
Description
Problem
Several engines spend round trips after login on setup that could ride a request they already send. Each one is a full RTT on every connect, every pool entry and lane, and every reconnect: about 50 ms each at +50 ms, more through an SSH tunnel (estimates from the round-trip count, not measured).
- PostgreSQL: the connect batch already carries
statement_timeout(the statement log showsSET statement_timeout = 60000inside the first Query on every connection). The saved schema is not:SET search_pathgoes alone after the batch. - MySQL family: the query-timeout
SETis its own round trip (two on OceanBase), and an empty Database field restores the last database with a separateUSE. - Redis:
INFO serveris sent twice on connect, and the database listing sendsCONFIG GET databasesandINFO keyspaceone after the other. - ClickHouse: connect makes up to four sequential HTTP requests.
Cause
- PostgreSQL:
runConnectPlanbatches the reads andstatement_timeout(apple/Plugins/PostgreSQLDriverPlugin/LibPQDriverCore.swift:181-213), andapplyQueryTimeoutskips the timeout the plan applied (:618-626). The selected schema is a separateexecuteQueryafter the batch (:157-162), and an emptycurrent_schema()adds one or two more (:148-152). The post-connect action.selectSchemaFromLastSessionsendsswitchSchemaIfNeeded(apple/TablePro/Core/Database/DatabaseManager+Sessions.swift:445-454). A reconnect callsswitchSchemaunconditionally (apple/TablePro/Core/Database/DatabaseManager+Health.swift:390-392). Pool entries open on schema nil (apple/TablePro/Core/Services/Query/MetadataConnectionPool.swift:579-584) andmoveEntrysends the switch on the first lease (:495). - MySQL:
applyQueryTimeoutruns eachqueryTimeoutStatementsitem throughexecuteWithReconnect(apple/Plugins/MySQLDriverPlugin/MySQLPluginDriver.swift:1196-1226,apple/Plugins/MySQLDriverPlugin/MySQLServerFlavor.swift:201-219). The pool repeats it per entry (MetadataConnectionPool.swift:892-909)..selectDatabaseFromLastSessioncallsplugin.switchDatabaseafter connect (DatabaseManager+Sessions.swift:421-431), while pool entries already put the database in the connect (MetadataConnectionPool.swift:768-777). - Redis:
connectrunsopenContextSync(AUTH or a probe, thenSELECTwhen the index is not 0) and thenfetchServerVersionSync, which sendsINFO server(apple/Plugins/RedisDriverPlugin/RedisPluginConnection.swift:149-171,:555-566,:918-930).RedisPluginDriver.connectthen callsverifyServerMode, which sendsINFO serveragain (apple/Plugins/RedisDriverPlugin/RedisPluginDriver.swift:87-100,:169-178).databaseListingawaitsCONFIG GET databases, thenINFO keyspace(apple/Plugins/RedisDriverPlugin/RedisDatabaseListing.swift:57-73). - ClickHouse:
SELECT version(), the settings probe, the catalog probe and, when no database is set,SELECT currentDatabase()each wait for the one before (apple/Plugins/ClickHouseDriverPlugin/ClickHousePlugin.swift:317-343). A failed probe falls back to defaults without failing the connect (:359-370).
Change
- PostgreSQL: pass the target schema into the connect plan and add
SET search_pathto its trailing settings next tostatement_timeout. ASET search_pathto a missing schema does not error, so it cannot roll back the other settings. This also works through poolers that refuse the startupoptionsparameter. Use it for the session, lanes and pool entries, and make the reconnect restore useswitchSchemaIfNeeded. - MySQL: send the timeout
SETpipelined with the first statement the connection runs, using themysql_send_querypipeliningsendWithSelectLimitalready has (apple/Plugins/MySQLDriverPlugin/MariaDBPluginConnection.swift:959-1000), and keep today's handling of a refused variable. Put the saved database in the connect handshake, as pool entries do, and connect without it only when the server answers that the database is unknown. - Redis: read
redis_modefrom theINFO serverreply already fetched for the version and drop the secondINFO. PipelineSELECTandINFO serverafterAUTHanswers (a failedAUTHmust still stop the rest). SendCONFIG GET databasesandINFO keyspacein oneexecutePipeline. - ClickHouse: ask
SELECT version(), currentDatabase()in the first request, which also opens the connection. Keep the settings and catalog probes as their own requests, because each must fail alone without failing the connect. That is 3 requests instead of 4. Parallel requests are not the fix: each opens a new HTTP/1.1 connection with its own TCP and TLS handshake.
Measure
- Count statements per connect with the server's statement log (PostgreSQL
log_statement=all, MySQLgeneral_log, RedisMONITOR, ClickHousesystem.query_log) for a session, a pool entry and a reconnect. Targets: noSET search_pathand no timeoutSETof their own, oneINFO serverper Redis connect. - Connect-to-tables at +50 ms RTT, median of 10, before and after, direct and over SSH.
Part of the performance plan.
Activity
datlechin commentedon Nov 25, 2026
#4578 ships PostgreSQL (the schema in the connect batch for the session, reconnects, lanes and pool entries; the reconnect restore only when something could have moved it), Redis (SELECT and INFO server in one pipeline after AUTH, one INFO server per connect, the listing's two reads in one pipeline) and ClickHouse (version and database in the first request, 3 requests instead of 4). Left for a follow-up:
SETpipelined with the first statement means deferring it into the execute path, besidesendWithSelectLimit's own pipelining, the reconnect and the refused-variable handling; and putting the saved database in the handshake needs a reconnect without it onER_BAD_DB_ERROR. Both are their own driver change.SET.