Skip to content

Remove libpqtypes, use plain libpq - #95

Draft
arybczak wants to merge 1 commit into
masterfrom
no-libpqtypes
Draft

arybczak wants to merge 1 commit into
masterfrom
no-libpqtypes

Conversation

@arybczak

@arybczak arybczak commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Drop the bundled libpqtypes C library. Queries are now executed with the API of plain libpq and the binary transport format is handled by the code based on postgresql-binary package (with some bugs fixed).

The library now supports decoding of arbitrary composite (row) types (in particular anonymous ones), named composite types are no longer necessary (and thus no longer have to be registered up-front).

Support for enum types is also improved, single values don't need casts anymore when passed as parameters (arrays of enums still do unfortunately).

Benchmark results against master:

  insert:                       OK
    407  ms ±  24 ms, 23% less than baseline
  select parents:               OK
    42.2 ms ± 1.5 ms, 51% less than baseline
  select parents with children: OK
    95.1 ms ± 2.2 ms, 55% less than baseline
  select big array:             OK
    9.37 ms ± 822 μs, 20% more than baseline
  select many rows:             OK
    11.8 ms ± 383 μs, 57% less than baseline

Selection of big arrays of primitive types (4th benchmark, 100000 elements of int4) is now slightly slower, but this is an edge case that we don't really make use of. I actually managed to make this faster than baseline, but the additional code complexity wasn't IMO worth it.

@arybczak arybczak changed the title Remove dependence on libpqtypes Remove libpqtypes, use plain libpq and postgresql-binary Jul 10, 2026
@arybczak
arybczak force-pushed the no-libpqtypes branch 7 times, most recently from ed40028 to b5aaed1 Compare July 12, 2026 01:05
@arybczak
arybczak force-pushed the no-libpqtypes branch 3 times, most recently from 738b5bd to 0f44dcf Compare July 12, 2026 03:41
@arybczak
arybczak force-pushed the no-libpqtypes branch 9 times, most recently from d2fb50f to aa47fec Compare July 20, 2026 06:56
@arybczak arybczak changed the title Remove libpqtypes, use plain libpq and postgresql-binary Remove libpqtypes, use plain libpq Jul 25, 2026
The library shipped a vendored copy of the libpqtypes C library and built its
encoding and decoding of values on the format strings of that library. The
copy was old, hard to maintain and hid the wire format from the Haskell side.

The library now talks to plain libpq and handles the binary wire format
itself, with encoders and decoders derived from the postgresql-binary package
and fixed where that package was wrong. Values decode through a row decoder
that consumes the fields of a result, which replaces the FromRow machinery,
the composite registration and the format strings. Arrays, ranges, network
types, enums and JSON get first class support, and the date and time types
reject the values that the Haskell types cannot represent. Queries run
synchronously in a helper thread, so that an asynchronous exception cancels
them server side.

This is a major release. CHANGELOG.md lists the changes in the public
behavior, and migration-2.0.md walks through the update of downstream code.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant