<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Ali moradi</title>
    <description>The latest articles on DEV Community by Ali moradi (@alimoradi).</description>
    <link>https://dev.to/alimoradi</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3315795%2Fc848f7e0-a15c-4000-b5ba-cdb835e28fa6.jpg</url>
      <title>DEV Community: Ali moradi</title>
      <link>https://dev.to/alimoradi</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/alimoradi"/>
    <language>en</language>
    <item>
      <title>Slow PostgreSQL Query? Locate the Cost Before the Fix</title>
      <dc:creator>Ali moradi</dc:creator>
      <pubDate>Sun, 15 Nov 2026 15:22:25 +0000</pubDate>
      <link>https://dev.to/alimoradi/slow-postgresql-query-locate-the-cost-before-the-fix-214g</link>
      <guid>https://dev.to/alimoradi/slow-postgresql-query-locate-the-cost-before-the-fix-214g</guid>
      <description>&lt;p&gt;A slow query needs a diagnosis before it needs a fix.&lt;/p&gt;

&lt;p&gt;In one PostgreSQL investigation, a recorded production plan showed &lt;strong&gt;2,070.4 ms of execution time&lt;/strong&gt;. JIT compilation consumed &lt;strong&gt;2,023.5 ms within that total: 97.7%&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The operator-supplied audit summary also reported shared-buffer hits, with zero shared reads or temporary blocks in that sample.&lt;/p&gt;

&lt;p&gt;Compilation was the dominant measured cost. That gave us a hypothesis to test.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz5lj5qhngxhsna25436k.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fz5lj5qhngxhsna25436k.png" alt="A three-step diagnostic workflow: inspect the plan for compilation within execution and buffer activity; test the suspected cost with the same workload and a local JIT comparison; check output contents, ordering, individual timings, and controls." width="800" height="537"&gt;&lt;/a&gt;&lt;br&gt;
&lt;em&gt;The diagnostic workflow. Turning JIT off tests the explanation; broader workload evidence guides a permanent change.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Test the diagnosis
&lt;/h2&gt;

&lt;p&gt;A separate local comparison ran the service operation with JIT enabled and disabled across three pairs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JIT on:&lt;/strong&gt; 603.7 ms median elapsed time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;JIT off:&lt;/strong&gt; 21.7 ms median elapsed time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Result digests:&lt;/strong&gt; matched across all six executions.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These were local service timings, not a production before-and-after comparison.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;The diagnostic workflow. Turning JIT off tests the explanation; broader workload evidence guides a permanent change.&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Keep the conclusion narrow
&lt;/h2&gt;

&lt;p&gt;Only three pairs were measured, JIT-on always ran first, and timings varied substantially. Buffer warming and run order limit attribution of the entire difference. Other workloads did not all improve.&lt;/p&gt;

&lt;p&gt;PostgreSQL's &lt;a href="https://www.postgresql.org/docs/16/jit-decision.html" rel="noopener noreferrer"&gt;JIT guidance&lt;/a&gt; explains the tradeoff: compilation overhead must earn its cost through execution savings.&lt;/p&gt;

&lt;p&gt;For your own investigation:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Inspect planning time, execution time, JIT, and buffer activity with &lt;code&gt;EXPLAIN (ANALYZE, BUFFERS, SETTINGS)&lt;/code&gt;. &lt;code&gt;ANALYZE&lt;/code&gt; executes the statement. &lt;a href="https://www.postgresql.org/docs/16/sql-explain.html" rel="noopener noreferrer"&gt;Reference&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Keep the workload and parameters stable; compare transaction-local JIT settings with balanced run order.&lt;/li&gt;
&lt;li&gt;Retain individual timings and compare output contents and ordering.&lt;/li&gt;
&lt;li&gt;Check representative workloads before persisting a setting.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Locate the cost. Test the diagnosis. Then choose the correction.&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>sql</category>
      <category>performance</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
