TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

What's new in the Postgres 16 query planner

265 点作者 clairegiordano超过 1 年前

9 条评论

londons_explore超过 1 年前
I really wish the postgres query planner would gain the ability to replan a query mid way through execution...<p>Frequently the most pathological queries (ie. the dreadfully slow ones) are because the query planner didn&#x27;t have some knowledge required of the data distribution and couldn&#x27;t accurately estimate the cost of some approach to planning the query. This can easily have a 1000x impact on execution time (ie. 1s rather than 1ms).<p>You will never have 100% accurate table stats - there is always some odd joint distribution you will not capture.<p>So instead, allow the query to start, and if progress isn&#x27;t as fast as the planner expects, feed current progress info back to the planner (pages scanned, tuples matching), and replan with that new data. If the updated plan shows it&#x27;s quicker to discard current results and restart with a new approach, do that.<p>Unfortunately, postgres does streaming queries (ie. the first results of a query are sent back to the client before the query is done), which means that significant infrastructural changes would be needed to allow a midway change of plan. Any new plan would need to keep track of which results had already been sent to the client so they aren&#x27;t resent. Postgres also allows a client to, midway through a query, request that the query reverse direction and re-return previous results in reverse order. That adds a lot of complexity.
评论 #39313405 未加载
评论 #39313753 未加载
评论 #39314597 未加载
评论 #39314528 未加载
评论 #39313452 未加载
评论 #39313731 未加载
评论 #39314735 未加载
评论 #39318092 未加载
评论 #39313830 未加载
wiradikusuma超过 1 年前
I use this tool to visualize my queries: <a href="https:&#x2F;&#x2F;explain.dalibo.com&#x2F;" rel="nofollow">https:&#x2F;&#x2F;explain.dalibo.com&#x2F;</a> (there&#x27;s also <a href="https:&#x2F;&#x2F;www.pgexplain.dev&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.pgexplain.dev&#x2F;</a>, last time the output was less nice, but now both look the same)
评论 #39311529 未加载
评论 #39311821 未加载
fabian2k超过 1 年前
Query planner improvements are always welcome, it&#x27;s a very important part of the DB. Though of course most of the time you notice it is when it&#x27;s not doing what you want ;-).<p>One part of this I found rather frustrating is the JIT in newer Postgres versions. The heuristics on when to use appear not robust at all to me. I&#x27;ve seen this for a rather typical ORM-generated query that is pretty straightforward, but pulls in a lot of other tables via joins. It runs in a few milliseconds without the JIT, but the JIT spent 1-1.5 seconds doing its thing on top of that and makes it incredibly slow for tiny amounts of data.<p>I know now to just disable the JIT, but this feature can give a pretty terrible impression to users that don&#x27;t know enough yet to figure out why it&#x27;s slow. I like Postgres a lot, but enabling the JIT just seems far too dangerous as a default setting to me.
评论 #39313165 未加载
评论 #39313575 未加载
评论 #39312796 未加载
评论 #39312632 未加载
评论 #39312633 未加载
评论 #39313746 未加载
twic超过 1 年前
I&#x27;d be interested to know how often these changes have an effect in real queries. The &quot;Use Limit instead of Unique to implement DISTINCT, when possible&quot; change in particular feels like it would only apply to very silly queries.<p>Do the PostgreSQL developers have any source of information about this?
评论 #39313105 未加载
评论 #39313100 未加载
评论 #39313025 未加载
评论 #39312911 未加载
devit超过 1 年前
I think it would be really nice to have a &quot;strict mode&quot; (for app testing), where PostgreSQL returns an error if an index would improve the query asymptotically and it doesn&#x27;t exist (only based on the query itself, not statistics).<p>And a &quot;CREATE INDICES FOR &lt;sql&gt;&quot; command to create the indices (for app upgrades), plus an automatic index creation mode (for interactive and development use).<p>In general, the system should be architected so that asymptotically suboptimal execution never happens.
riku_iki超过 1 年前
Why wouldnt they implement hints..
评论 #39311231 未加载
评论 #39312274 未加载
andybak超过 1 年前
A friend of mine is a Microsoft DBA for mid-sized companies and was proclaiming how you can&#x27;t do anything serious with Postgres. He said he was shocked to discover it didn&#x27;t even have a query planner.<p>Leaving mocking him to one side for a moment - is there any plausibility to his broader claim that MSSQL can handle things at a scale where Postgres would be a poor choice? My gut instinct is that this is nonsense but I&#x27;m not a DBA by a long stretch.
评论 #39313273 未加载
评论 #39315278 未加载
评论 #39313261 未加载
评论 #39314969 未加载
评论 #39313300 未加载
评论 #39316083 未加载
jhoechtl超过 1 年前
Why is this released by citusdata instead on postgresql.org? Is this a paid feature only or an open source addition?
评论 #39313039 未加载
Diggsey超过 1 年前
But when is it going to be able to use indexes to speed up `IS NOT DISTINCT FROM` queries? ;)