MagicStack/asyncpg

Avoiding introspection queries for built-in array types

0xD09CD196D188D0B0 opened this issue · 0 comments

Hi, and thanks for all the work on asyncpg! đź‘‹

I’ve noticed that fresh connections usually emit introspection queries even for statements involving simple arrays of integers.

Looking at the code in init_array_codecs, asyncpg seems to initialize only the core codecs for _oid and _text (as mentioned in the comment, “to make type introspection query work”).

cdef init_array_codecs():
# oid[] and text[] are registered as core codecs
# to make type introspection query work
#
register_core_codec(_OIDOID,
<encode_func>&arrayoid_encode,
<decode_func>&arrayoid_decode,
PG_FORMAT_BINARY)
register_core_codec(_TEXTOID,
<encode_func>&arraytext_encode,
<decode_func>&arraytext_decode,
PG_FORMAT_BINARY)
init_array_codecs()

I was wondering: was there a particular reason that asyncpg doesn’t include more built-in types there? From my perspective, types like _int2, _int4, _int8, _float4, _float8, _bool, and _char are very commonly used in queries. Including them might avoid a lot of introspection queries on new connections.

Is this something that could be considered, or are there trade-offs I might be missing?