<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Sqlx on FlakM blog</title><link>https://flakm.com/tags/sqlx/</link><description>Recent content in Sqlx on FlakM blog</description><generator>Hugo</generator><language>en</language><copyright>Copyright © 2023, Maciej Flak; all rights reserved.</copyright><lastBuildDate>Mon, 24 Aug 2026 11:39:24 +0200</lastBuildDate><atom:link href="https://flakm.com/tags/sqlx/index.xml" rel="self" type="application/rss+xml"/><item><title>SQLx caches prepared statements per connection</title><link>https://flakm.com/posts/sqlx_caches_til/</link><pubDate>Mon, 24 Aug 2026 11:39:24 +0200</pubDate><guid>https://flakm.com/posts/sqlx_caches_til/</guid><description>&lt;p&gt;Today I learned that &lt;a href="https://docs.rs/sqlx/latest/sqlx/fn.query.html" class="external-link" target="_blank" rel="noopener"&gt;&lt;code&gt;sqlx::query()&lt;/code&gt;&lt;/a&gt; prepares and caches sql statements transparently. The cache belongs to each &lt;em&gt;connection&lt;/em&gt;, so a pool does not have one shared statement cache — it has one per connection. With &lt;code&gt;max_connections: 40&lt;/code&gt;, a statement that is warm on one connection is cold on the other 39.&lt;/p&gt;
&lt;p&gt;Caching is on by default, and for PostgreSQL each connection keeps up to 100 distinct statements in an LRU keyed by the SQL text. The capacity is configurable:&lt;/p&gt;</description></item></channel></rss>