pganalyze’s Post

View organization page for pganalyze, graphic

1,222 followers

In today's 5mins of #Postgres, we talk about an improvement to the Postgres query planner in the upcoming Postgres 17, when it comes to materialized CTEs, and column statistics as well as sort order available to the upper plan level. Materialized CTEs are actually less likely today - if you recall Postgres 12 changed the default so a simple CTE like "WITH cte_table AS ( ... ) SELECT ... FROM cte_table" will typically pull up the query inside the "cte_table" to the top level, as if it was written as a sub-SELECT. But if you either use the MATERIALIZED keyword explicitly (because you want the planner to treat it as an optimization fence), or if Postgres can't find a way to pull up the CTE, you will see an explicit "CTE Scan" in your query plan. If you do, you might be surprised about the limited information that Postgres previously provided to plan nodes consuming that CTE Scan. Specifically, only row counts and width, but no other information like column statistics or previous sort orders were passed along. This is fixed in Postgres 17 thanks to the work of Jian Guo, Tom Lane and Richard Guo. Watch the full episode, or read the transcript for all the details, including example query plans that will change: https://lnkd.in/dsAJ7mMq

Waiting for Postgres 17: Better Query Plans for Materialized CTE Scans

Waiting for Postgres 17: Better Query Plans for Materialized CTE Scans

pganalyze.com

To view or add a comment, sign in

Explore topics