By default, pgx automatically caches queries as prepared statements. While there are some limitations, it generally helps with performance and makes prepared statements an after thought.
Unfortunately, we ran into a footgun with Preload's use of NextUniqueInt. Since NextUniqueInt runs a global counter and increments on every build / exec of the query, it effectively negates any of the prepared statement caching that pgx does and appears to cause an increase in memory usage.
Combined with bob not supporting explicit prepared statements when using the pgx driver (it doesn't implement Preparer), the average user is left with suboptimal performance out of the box.
The relatively simple workaround is to provide static PreloadAs aliases when joining via Preload.
By default, pgx automatically caches queries as prepared statements. While there are some limitations, it generally helps with performance and makes prepared statements an after thought.
Unfortunately, we ran into a footgun with
Preload's use ofNextUniqueInt. SinceNextUniqueIntruns a global counter and increments on every build / exec of the query, it effectively negates any of the prepared statement caching that pgx does and appears to cause an increase in memory usage.Combined with bob not supporting explicit prepared statements when using the pgx driver (it doesn't implement
Preparer), the average user is left with suboptimal performance out of the box.The relatively simple workaround is to provide static
PreloadAsaliases when joining viaPreload.