[英]Postgresql, manually use analyze $table_name after each update both on indexes or on structure to update query planner? Really?
I have been trying queries and indexes for two days to find the fastest solution and only today I discover thanks to this answer that using the " analyze $table_name;
" command the EXPLAIN
and then the query changes completely after adding or removing indexes.我一直在试图查询和索引了两天,找到最快的解决方案,只有今天我发现由于这个答案,在基于“
analyze $table_name;
”命令EXPLAIN
,然后将查询添加或删除索引后完全改变。
My work consists of this:我的工作包括:
Sequential Scan
despite the new indexSequential Scan
analyze $table_name;
" to update the Postgresql query planninganalyze $table_name;
”来更新 Postgresql 查询计划就足够了Is this something I always have to do?这是我总是必须做的事情吗?
Can I set it automatically so that after each modification on the indexes or on the structure under development it is automatically analyzed?我可以自动设置它以便在每次修改索引或正在开发的结构后自动分析吗?
Is this analysis performed automatically in production?此分析是否在生产中自动执行?
Indexes do not have statistics, they rely on the statistics of the same column(s) from the underlying table.索引没有统计信息,它们依赖于基础表中相同列的统计信息。 The exception is functional/expressional indexes, which do have their own statistics since they invent new columns not in the underlying table.
例外是功能/表达式索引,它们确实有自己的统计信息,因为它们创建了不在基础表中的新列。
Unless the index you created was an expresional index (or your stats were already out of date in the first place), there is no reason to analyze the table after the index creation.除非您创建的索引是一个表达式索引(或者您的统计数据首先已经过时),否则没有理由在创建索引后分析表。
There is no mechanism to automatically do an analyze after the creation of an expressional index.没有在创建表达式索引后自动进行分析的机制。 Even if there were, you would probably want to do it manually anyway, as you would like to ensure it has completed before you proceed to testing.
即使有,您也可能希望手动完成,因为您希望在继续测试之前确保它已完成。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.