{"id":3345,"date":"2026-11-28T16:14:15","date_gmt":"2026-11-28T16:14:15","guid":{"rendered":"https:\/\/danieldreitberg.com\/?p=3345"},"modified":"2026-11-28T16:14:15","modified_gmt":"2026-11-28T16:14:15","slug":"dr-ai-4379270d0b082381dbdd","status":"publish","type":"post","link":"https:\/\/danieldreitberg.com\/index.php\/2026\/11\/28\/dr-ai-4379270d0b082381dbdd\/","title":{"rendered":"Read a Query Plan Without Calling It a Runtime Measurement"},"content":{"rendered":"<p>A performance review starts going wrong when a generated summary calls an estimated query cost a runtime measurement. PostgreSQL\u2019s ordinary EXPLAIN output describes the plan the optimizer selected. That plan is useful for understanding the expected scan and join behavior, but it cannot tell you what elapsed time a real execution just took, because that execution did not happen.<\/p>\n<p>Reference: <a href=\"https:\/\/www.postgresql.org\/docs\/current\/sql-explain.html\">PostgreSQL EXPLAIN documentation<\/a>. EXPLAIN shows a query plan, and the ANALYZE option actually executes the statement.<\/p>\n<h2>Compare Plan vs Execution<\/h2>\n<p>Start by reading the plan\u2019s node types, estimated rows and relative costs. The cost values use the planner\u2019s own units, not milliseconds. On a safe fixture, run <code>EXPLAIN (ANALYZE)<\/code> on the same read-only SELECT if you want observed row counts and execution timings. Save the query, fixture and output together so a reader can see what was estimated, what actually ran, and what the numbers describe.<\/p>\n<h2>Verify Row Counts<\/h2>\n<p>Use a toy set of story records with an uneven distribution of categories. Ask for one category and compare estimated and actual rows at the relevant scan or filter node, taking its loop count into account. If the two figures diverge, investigate what the plan assumes about the data. The gap is a clue, not proof that statistics are stale; skew, correlated columns and other factors can also affect estimates.<\/p>\n<p>Do not run ANALYZE on an unreviewed write merely to get a richer plan: the option really executes the statement. For this check, stick to a read-only fixture and do not use one instrumented run to promise production latency. If the article needs a performance claim, distinguish rows processed from the time a reader experiences, note the conditions, and repeat the measurement separately. A database execution time excludes the trip to a reader\u2019s browser, which can involve many other services. Otherwise, say only what the plan supports: what PostgreSQL expected to do.<\/p>\n<p><!-- drai-run:4379270d0b082381dbdd --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>An AI performance note should say which kind of evidence it used.<\/p>\n","protected":false},"author":5,"featured_media":3346,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[1],"tags":[],"_links":{"self":[{"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/posts\/3345"}],"collection":[{"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/comments?post=3345"}],"version-history":[{"count":1,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/posts\/3345\/revisions"}],"predecessor-version":[{"id":3347,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/posts\/3345\/revisions\/3347"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/media\/3346"}],"wp:attachment":[{"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/media?parent=3345"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/categories?post=3345"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/danieldreitberg.com\/index.php\/wp-json\/wp\/v2\/tags?post=3345"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}