@@ -461,14 +461,47 @@ async def _get_statement(
461461 return statement
462462
463463 async def _introspect_types (self , typeoids , timeout ):
464- return await self .__execute (
464+ if self ._server_caps .jit :
465+ try :
466+ cfgrow , _ = await self .__execute (
467+ """
468+ SELECT
469+ current_setting('jit') AS cur,
470+ set_config('jit', 'off', false) AS new
471+ """ ,
472+ (),
473+ 0 ,
474+ timeout ,
475+ ignore_custom_codec = True ,
476+ )
477+ jit_state = cfgrow [0 ]['cur' ]
478+ except exceptions .UndefinedObjectError :
479+ jit_state = 'off'
480+ else :
481+ jit_state = 'off'
482+
483+ result = await self .__execute (
465484 self ._intro_query ,
466485 (list (typeoids ),),
467486 0 ,
468487 timeout ,
469488 ignore_custom_codec = True ,
470489 )
471490
491+ if jit_state != 'off' :
492+ await self .__execute (
493+ """
494+ SELECT
495+ set_config('jit', $1, false)
496+ """ ,
497+ (jit_state ,),
498+ 0 ,
499+ timeout ,
500+ ignore_custom_codec = True ,
501+ )
502+
503+ return result
504+
472505 async def _introspect_type (self , typename , schema ):
473506 if (
474507 schema == 'pg_catalog'
@@ -2370,7 +2403,7 @@ class _ConnectionProxy:
23702403ServerCapabilities = collections .namedtuple (
23712404 'ServerCapabilities' ,
23722405 ['advisory_locks' , 'notifications' , 'plpgsql' , 'sql_reset' ,
2373- 'sql_close_all' ])
2406+ 'sql_close_all' , 'jit' ])
23742407ServerCapabilities .__doc__ = 'PostgreSQL server capabilities.'
23752408
23762409
@@ -2382,34 +2415,39 @@ def _detect_server_capabilities(server_version, connection_settings):
23822415 plpgsql = False
23832416 sql_reset = True
23842417 sql_close_all = False
2418+ jit = False
23852419 elif hasattr (connection_settings , 'crdb_version' ):
23862420 # CockroachDB detected.
23872421 advisory_locks = False
23882422 notifications = False
23892423 plpgsql = False
23902424 sql_reset = False
23912425 sql_close_all = False
2426+ jit = False
23922427 elif hasattr (connection_settings , 'crate_version' ):
23932428 # CrateDB detected.
23942429 advisory_locks = False
23952430 notifications = False
23962431 plpgsql = False
23972432 sql_reset = False
23982433 sql_close_all = False
2434+ jit = False
23992435 else :
24002436 # Standard PostgreSQL server assumed.
24012437 advisory_locks = True
24022438 notifications = True
24032439 plpgsql = True
24042440 sql_reset = True
24052441 sql_close_all = True
2442+ jit = server_version >= (11 , 0 )
24062443
24072444 return ServerCapabilities (
24082445 advisory_locks = advisory_locks ,
24092446 notifications = notifications ,
24102447 plpgsql = plpgsql ,
24112448 sql_reset = sql_reset ,
2412- sql_close_all = sql_close_all
2449+ sql_close_all = sql_close_all ,
2450+ jit = jit ,
24132451 )
24142452
24152453
0 commit comments