Repository navigation
perf(connections): send session setup with the connect instead of in extra round trips - #4578
Merged
Merged
Conversation
…extra round trips PostgreSQL lands on the saved schema inside the connect batch, a reconnect restores it only when something could have moved it, Redis pipelines SELECT with INFO server and keeps the reply for the mode check, its listing pipelines CONFIG GET with INFO keyspace, and ClickHouse reads version and database in one request.
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.
Summary
switchSchemaIfNeededkept them. A schema chosen on the same connection is set besidestatement_timeout. The host names it for the session (the last session's schema), a reconnect (the browsed schema), lanes and pool entries (the lease's schema). ASET search_pathto a missing schema does not fail, and only a batch that ran to the end counts it as set; otherwise it goes alone as before. It also works through poolers that refuse the startupoptionsparameter. The host names no schema when the user's startup commands run, since one of them may move the search path after it.switchSchemaIfNeeded, unless startup commands or a database switch could have moved it, so the schema the connect landed on is not set twice.SELECTandINFO servergo out in one pipeline afterAUTHhas answered (a refused sign-in still stops the rest), and the mode check reads the keptINFO serverreply instead of sending a second one. The database listing sendsCONFIG GET databasesandINFO keyspacein one pipeline when it wants both.SELECT version(), currentDatabase(), so a connect with no database named makes 3 requests instead of 4. The settings and catalog probes stay their own requests, so each still fails alone.Measured with the drivers' scripted servers: a PostgreSQL connect to a saved schema sends 1 Query where it sent 2 (
PostgreSQLConnectRoundTripTests); a ClickHouse connect with no database makes 3 requests where it made 4 (ClickHouseConnectProfileTests); a Redis listing with key counts is 1 pipeline where it was 2 round trips (RedisDatabaseListingTests). The Redis connect drops from 3 round trips afterAUTHto 1 for a non-zero database, and from 2 to 1 for database 0 (from the code path; no hiredis stub here). MySQL is left for a follow-up, noted on the issue.Test plan
PostgreSQLConnectRoundTripTests/initialSchemaRidesTheBatch,initialSchemaGoesAloneAfterAFailedBatch;RedisDatabaseListingTests/countAndKeyspaceShareAPipeline;ClickHouseConnectProfileTests/blankDatabaseCostsNoExtraRequest;DatabaseManagerTests/reconnectOnTheSchemaSendsNoSwitch,reconnectAfterStartupCommandsSwitches;MetadataConnectionPoolSchemaTests/connectionOpensOnTheLeasesSchema. Each fails on main.ClickHouseConnectProfileTestsanswers the opening query, which replacedSELECT version()andSELECT currentDatabase().MetadataConnectionPoolTestsandSessionRecoveryLoopTests: 112 executed, 112 passed (TableProTests 68, ClickHouseDriverTests 10, PostgreSQLDriverTests 11, RedisDriverTests 23).verify.sh pluginspasses.Closes #4544