- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
将 Postgres 9.1 升级到 9.4 后,我的性能变得极其缓慢。这是运行速度明显更慢的两个查询的示例。
注意:我意识到这些查询可能可以被重写以更有效地工作,但是我主要担心的是在升级到更新版本的 Postgres 之后,它们的运行速度突然慢了 100 倍!我希望在我忽略的地方有一个配置变量。
在进行升级时,我使用了带有 --link 选项的 pg_upgrade 命令。配置文件在 9.4 和 9.1 之间是相同的。它不是在完全相同的硬件上运行,但它们都在 Linode 上运行,我已经尝试为新服务器使用 3 个不同的 Linode,所以我认为这不是硬件问题。
似乎在这两种情况下,9.4 使用的索引与 9.1 不同?
9.1:
EXPLAIN ANALYZE SELECT "id", "title", "timestamp", "parent", "deleted", "sunk", "closed", "sticky", "lastupdate", "views", "oldid", "editedon", "devpost", "hideblue", "totalvotes", "statustag", "forum_category_id", "account_id" FROM "forum_posts" WHERE "parent" = 882269 ORDER BY "timestamp" DESC LIMIT 1;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=63.87..63.87 rows=1 width=78) (actual time=0.020..0.020 rows=0 loops=1)
-> Sort (cost=63.87..63.98 rows=45 width=78) (actual time=0.018..0.018 rows=0 loops=1)
Sort Key: "timestamp"
Sort Method: quicksort Memory: 17kB
-> Index Scan using index_forum_posts_parent on forum_posts (cost=0.00..63.65 rows=45 width=78) (actual time=0.013..0.013 rows=0 loops=1)
Index Cond: (parent = 882269)
Total runtime: 0.074 ms
(7 rows)
9.4:
EXPLAIN ANALYZE SELECT "id", "title", "timestamp", "parent", "deleted", "sunk", "closed", "sticky", "lastupdate", "views", "oldid", "editedon", "devpost", "hideblue", "totalvotes", "statustag", "forum_category_id", "account_id" FROM "forum_posts" WHERE "parent" = 882269 ORDER BY "timestamp" DESC LIMIT 1;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------
Limit (cost=0.42..63.48 rows=1 width=1078) (actual time=920.484..920.484 rows=0 loops=1)
-> Index Scan Backward using forum_posts_timestamp_index on forum_posts (cost=0.42..182622.07 rows=2896 width=1078) (actual time=920.480..920.480 rows=0 loops=1)
Filter: (parent = 882269)
Rows Removed by Filter: 1576382
Planning time: 0.166 ms
Execution time: 920.521 ms
(6 rows)
9.1:
EXPLAIN ANALYZE SELECT "user_library_images"."id", "user_library_images"."imgsrc", "user_library_images"."library_image_id", "user_library_images"."type", "user_library_images"."is_user_uploaded", "user_library_images"."credit", "user_library_images"."orig_dimensions", "user_library_images"."account_id" FROM "user_library_images" INNER JOIN "image_tags" ON "user_library_images"."id" = "image_tags"."user_library_image_id" WHERE ("user_library_images"."account_id" = 769718 AND "image_tags"."tag" ILIKE '%stone%') GROUP BY "user_library_images"."id", "user_library_images"."imgsrc", "user_library_images"."library_image_id", "user_library_images"."type", "user_library_images"."is_user_uploaded", "user_library_images"."credit", "user_library_images"."orig_dimensions", "user_library_images"."account_id" ORDER BY "user_library_images"."id";
Group (cost=2015.46..2015.49 rows=1 width=247) (actual time=0.629..0.652 rows=6 loops=1)
-> Sort (cost=2015.46..2015.47 rows=1 width=247) (actual time=0.626..0.632 rows=6 loops=1)
Sort Key: user_library_images.id, user_library_images.imgsrc, user_library_images.library_image_id, user_library_images.type, user_library_images.is_user_uploaded, user_library_images.credit, user_library_images.orig_dimensions, user_library_images.account_id
Sort Method: quicksort Memory: 19kB
-> Nested Loop (cost=0.00..2015.45 rows=1 width=247) (actual time=0.283..0.603 rows=6 loops=1)
-> Index Scan using index_user_library_images_account on user_library_images (cost=0.00..445.57 rows=285 width=247) (actual time=0.076..0.273 rows=13 loops=1)
Index Cond: (account_id = 769718)
-> Index Scan using index_image_tags_user_library_image on image_tags (cost=0.00..5.50 rows=1 width=4) (actual time=0.020..0.021 rows=0 loops=13)
Index Cond: (user_library_image_id = user_library_images.id)
Filter: (tag ~~* '%stone%'::text)
Total runtime: 0.697 ms
(11 rows)
9.4:
Group (cost=166708.13..166709.46 rows=59 width=1241) (actual time=9677.052..9677.052 rows=0 loops=1)
Group Key: user_library_images.id, user_library_images.imgsrc, user_library_images.library_image_id, user_library_images.type, user_library_images.is_user_uploaded, user_library_images.credit, user_library_images.orig_dimensions, user_library_images.account_id
-> Sort (cost=166708.13..166708.28 rows=59 width=1241) (actual time=9677.049..9677.049 rows=0 loops=1)
Sort Key: user_library_images.id, user_library_images.imgsrc, user_library_images.library_image_id, user_library_images.type, user_library_images.is_user_uploaded, user_library_images.credit, user_library_images.orig_dimensions, user_library_images.account_id
Sort Method: quicksort Memory: 17kB
-> Hash Join (cost=10113.22..166706.39 rows=59 width=1241) (actual time=9677.035..9677.035 rows=0 loops=1)
Hash Cond: (image_tags.user_library_image_id = user_library_images.id)
-> Seq Scan on image_tags (cost=0.00..156488.85 rows=11855 width=4) (actual time=0.301..9592.048 rows=63868 loops=1)
Filter: (tag ~~* '%stone%'::text)
Rows Removed by Filter: 9370406
-> Hash (cost=10045.97..10045.97 rows=5380 width=1241) (actual time=0.047..0.047 rows=4 loops=1)
Buckets: 1024 Batches: 1 Memory Usage: 1kB
-> Bitmap Heap Scan on user_library_images (cost=288.12..10045.97 rows=5380 width=1241) (actual time=0.027..0.037 rows=4 loops=1)
Recheck Cond: (account_id = 769718)
Heap Blocks: exact=4
-> Bitmap Index Scan on index_user_library_images_account (cost=0.00..286.78 rows=5380 width=0) (actual time=0.019..0.019 rows=4 loops=1)
Index Cond: (account_id = 769718)
Planning time: 0.223 ms
Execution time: 9677.109 ms
(19 rows)
====
运行分析脚本后(见下面的答案),问题解决了。作为引用,这是新的 ANALYZE 输出(针对 9.4):
Group (cost=2062.82..2062.91 rows=4 width=248) (actual time=8.775..8.801 rows=7 loops=1)
Group Key: user_library_images.id, user_library_images.imgsrc, user_library_images.library_image_id, user_library_images.type, user_library_images.is_user_uploaded, user_library_images.credit, user_library_images.orig_dimensions, user_library_images.account_id
-> Sort (cost=2062.82..2062.83 rows=4 width=248) (actual time=8.771..8.780 rows=7 loops=1)
Sort Key: user_library_images.id, user_library_images.imgsrc, user_library_images.library_image_id, user_library_images.type, user_library_images.is_user_uploaded, user_library_images.credit, user_library_images.orig_dimensions, user_library_images.account_id
Sort Method: quicksort Memory: 19kB
-> Nested Loop (cost=0.87..2062.78 rows=4 width=248) (actual time=4.156..8.685 rows=7 loops=1)
-> Index Scan using index_user_library_images_account on user_library_images (cost=0.43..469.62 rows=304 width=248) (actual time=0.319..2.528 rows=363 loops=1)
Index Cond: (account_id = 769718)
-> Index Scan using index_image_tags_user_library_image on image_tags (cost=0.43..5.23 rows=1 width=4) (actual time=0.014..0.014 rows=0 loops=363)
Index Cond: (user_library_image_id = user_library_images.id)
Filter: (tag ~~* '%stone%'::text)
Rows Removed by Filter: 2
Planning time: 2.956 ms
Execution time: 8.907 ms
(14 rows)
Limit (cost=65.81..65.81 rows=1 width=77) (actual time=0.256..0.256 rows=0 loops=1)
-> Sort (cost=65.81..65.92 rows=47 width=77) (actual time=0.252..0.252 rows=0 loops=1)
Sort Key: "timestamp"
Sort Method: quicksort Memory: 17kB
-> Index Scan using index_forum_posts_parent on forum_posts (cost=0.43..65.57 rows=47 width=77) (actual time=0.211..0.211 rows=0 loops=1)
Index Cond: (parent = 882269)
Planning time: 2.978 ms
Execution time: 0.380 ms
(8 rows)
最佳答案
pg_upgrade
不会复制(或迁移)数据库的统计信息。
因此您需要分析您的表,以便更新迁移数据库中的统计信息。 pg_upgrade
将创建一个名为 analyze_new_cluster
的批处理文件/shell 脚本,可用于此目的。
或者,您可以手动使用 vacuum analyze
来实现相同的目的。
可以通过查看执行计划来检测丢失的统计信息。预期行数与实际行数相差太大:
(cost=0.00..286.78 rows=5380 width=0) (actual time=0.019..0.019 rows=4 loops=1)
==> 5380 与 4 行
或
(cost=0.00..156488.85 rows=11855 width=4) (actual time=0.301..9592.048 rows=63868 loops=1)
==> 11855 与 63868 行
关于performance - 将 PostgreSQL 从 9.1 升级到 9.4 后性能下降,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28348608/
我想循环遍历 gpx 文件并计算总上升和下降。我有一个函数可以计算两组经纬度点之间的高程差异,我已经设置了 simplexml 来读取和循环遍历 gpx 文件 trkseg 点。 问题是,这不准确(实
我有两个在不同时间段拍摄的数组。如何通过将新玩家标记为上升来检查哪些玩家在列表中上升/下降? 附言- 数组已经根据分数排序。 pastData:[ { playerName:'Jo
我想捕获 ctrl/alt/etc 键的起伏,无论表单上的哪个控件获取 keyup 或 keydown 事件。由于我的表单上有大约 100 个控件,如果我要为每个单独的控件添加代码,那将非常难看。我怎
vector1 = c(2, 2, 2, 2, 2, 2) vector2 = c(2, 2, 3, 3, 3, 3) vector3 = c(2, 2, 1, 2, 2, 2) 我想知道向量中的数字
我不知道如何遵循编译器的建议:consider using a let binding to create a longer lived value。 Playground #![allow(unus
我希望有人能帮助我理解 AngularJS 中的 $scope 遇到的一个恼人的问题。请参阅下面我的代码中的注释: app.controller('MyController', function ($
我有一个 flex 搜索集群,其中有2个节点在2核CPU 8GB ram实例上运行。每个节点都传入了参数“ES_JAVA_OPTS = -Xms3g -Xmx3g”。我有4个索引,每个索引有2个分片和
我正在学习 R(及其通过 quantmod lib 在交易任务中的应用)并定期浏览社区以从这里获得许多新知识和技巧。我对 R 的总体印象和特别是 quantmod lib 的印象 - 它很棒。 在这一
当我们点击屏幕时,我正在绘制纹理正方形。我正在使用相同的纹理。在新 ios 设备中点击几次后,FPS 从 120 下降到 4 左右。每次手指点击时,我都会将点击的点以及纹理和纹理的大小传递给着色器。
只有当对象被点击并且需要从列表中移除时它才会掉落。这是代码: if(event.type == TouchEvent.TOUCH_DOWN){ for(Bottle bottl
我有一个基于SpriteKit的小游戏。 在这个游戏中,我使用了很多带有字母(或字母组合)的节点,用户可以四处移动来构建单词。 这些节点基本上是带有 SKLabelNode 的 SKSpriteNod
我有一个简单的CSS布局 wrapper header left-sidebar / main-content / right-sidebar footer 但我的主要内容似乎下降了(float dr
在标题中,我给出了四个不同的部分,并使用 float 属性使所有内容都显示在一条水平线上。 当我调整浏览器窗口大小时,最后一个 div 位于黑色边框线下方。 如何解决。 http://jsfiddle
CSS: .desc{ text-align: center; color:#60A8D5; padding-top: 17px;
这是一段简单的代码,但我为这个问题尝试过的解决方案都没有奏效。 #ONE { float: left; border: 1
我有一个 SceneKit 设置,其中有一个 Sphere 设置为 Dynamic body。 我能够运行该应用程序并看到球体落在静态 body 地板上。 我想做的是设置场景,这样 sfere 最初就
首先,我的类(class): export class FooBar { ... isFavorite: boolean = false; constructor() { this.isF
我正在尝试删除所有端口上的所有传出 RST 和传入 RST。我正在使用 Debian Linux。我尝试了互联网上列出的所有可能的命令组合,但似乎没有任何效果。 例如,我试过: iptables -A
我正在做这样的事情: fn main() { //[1, 0, 0, 0, 99]; // return [2, 0, 0, 0, 99] //[2, 3, 0, 3, 99]; //
我正在使用 Rusqlite,它可以让你做这样的查询: statement.query_row(params!([1, 2, 3]), ...); params!()定义如下: macro_rules
我是一名优秀的程序员,十分优秀!