From: Eyal Halpern Shalev Date: Mon, 15 Apr 2024 23:09:45 +0000 (+0300) Subject: perf(pool): replace SELECT 1 with an empty query X-Git-Tag: pool-3.2.2~1^2~2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=755d7754031b8ad196ab2da00b54234f81a4b5fa;p=thirdparty%2Fpsycopg.git perf(pool): replace SELECT 1 with an empty query --- diff --git a/psycopg_pool/psycopg_pool/pool.py b/psycopg_pool/psycopg_pool/pool.py index 2d17f5ff1..96a97ff20 100644 --- a/psycopg_pool/psycopg_pool/pool.py +++ b/psycopg_pool/psycopg_pool/pool.py @@ -537,11 +537,11 @@ class ConnectionPool(Generic[CT], BasePool): for instance as `!check` callback when a pool is created. """ if conn.autocommit: - conn.execute("SELECT 1") + conn.execute("--ping") else: conn.autocommit = True try: - conn.execute("SELECT 1") + conn.execute("--ping") finally: conn.autocommit = False diff --git a/psycopg_pool/psycopg_pool/pool_async.py b/psycopg_pool/psycopg_pool/pool_async.py index a12f33c35..0a6ad529c 100644 --- a/psycopg_pool/psycopg_pool/pool_async.py +++ b/psycopg_pool/psycopg_pool/pool_async.py @@ -569,7 +569,7 @@ class AsyncConnectionPool(Generic[ACT], BasePool): for instance as `!check` callback when a pool is created. """ if conn.autocommit: - await conn.execute("SELECT 1") + await conn.execute("--ping") else: if True: # ASYNC # NOTE: with Psycopg 3.2 we could use conn.set_autocommit() in @@ -577,13 +577,13 @@ class AsyncConnectionPool(Generic[ACT], BasePool): # previous versions too. await conn.set_autocommit(True) try: - await conn.execute("SELECT 1") + await conn.execute("--ping") finally: await conn.set_autocommit(False) else: conn.autocommit = True try: - conn.execute("SELECT 1") + conn.execute("--ping") finally: conn.autocommit = False