- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
版本 - postgres 9.6。
question我不是很清楚我过去问过,那里已经有人回答了,所以我认为最好是发布新问题,提供更清晰的信息,并更具体地说明我的问题。
尝试将事件表与维度表连接起来。事件表是具有检查约束的每日分区(3k 子级)表。事件表有 72 列(我怀疑这是问题所在)。
我简化了查询以演示问题(实际上范围更广,我从两个表中查询字段)。
您可以看到对于这个简单的查询 - 计划 花费了将近 10 秒(我的问题是关于计划时间而不是执行时间)。如果我直接在子表上查询(请不要建议对范围内的所有子表使用联合)查询计划是几毫秒。
explain analyze select campaign_id , spent as spent from events_daily r left join report_campaigns c on r.campaign_id = c.c_id where date >= '20170720' and date < '20170721' ;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------------
Nested Loop Left Join (cost=0.29..28.88 rows=2 width=26) (actual time=0.021..0.021 rows=0 loops=1)
-> Append (cost=0.00..12.25 rows=2 width=26) (actual time=0.003..0.003 rows=0 loops=1)
-> Seq Scan on events_daily r (cost=0.00..0.00 rows=1 width=26) (actual time=0.002..0.002 rows=0 loops=1)
Filter: ((date >= '2017-07-20 00:00:00'::timestamp without time zone) AND (date < '2017-07-21 00:00:00'::timestamp without time zone))
-> Seq Scan on events_daily_20170720 r_1 (cost=0.00..12.25 rows=1 width=26) (actual time=0.000..0.000 rows=0 loops=1)
Filter: ((date >= '2017-07-20 00:00:00'::timestamp without time zone) AND (date < '2017-07-21 00:00:00'::timestamp without time zone))
-> Index Only Scan using report_campaigns_campaign_idx on report_campaigns c (cost=0.29..8.31 rows=1 width=8) (never executed)
Index Cond: (c_id = r.campaign_id)
Heap Fetches: 0
Planning time: 8393.337 ms
Execution time: 0.132 ms
(11 rows)
explain analyze select campaign_id , spent as spent from events_daily_20170720 r left join report_campaigns c on r.campaign_id = c.c_id where date >= '20170720' and date < '20170721' ;
QUERY PLAN
------------------------------------------------------------------------------------------------------------------------------------------------
Nested Loop Left Join (cost=0.29..20.57 rows=1 width=26) (actual time=0.008..0.008 rows=0 loops=1)
-> Seq Scan on events_daily_20170720 r (cost=0.00..12.25 rows=1 width=26) (actual time=0.007..0.007 rows=0 loops=1)
Filter: ((date >= '2017-07-20 00:00:00'::timestamp without time zone) AND (date < '2017-07-21 00:00:00'::timestamp without time zone))
-> Index Only Scan using report_campaigns_campaign_idx on report_campaigns c (cost=0.29..8.31 rows=1 width=8) (never executed)
Index Cond: (c_id = r.campaign_id)
Heap Fetches: 0
Planning time: 0.242 ms
Execution time: 0.059 ms
\d events_daily_20170720
date | timestamp without time zone |
Check constraints:
"events_daily_20170720_date_check" CHECK (date >= '2017-07-20 00:00:00'::timestamp without time zone AND date < '2017-07-21 00:00:00'::timestamp without time zone)
Inherits: events_daily
show constraint_exclusion;
constraint_exclusion
----------------------
on
当运行 ltrace 时,它似乎在每个字段上运行了数千次(暗示它在计划的所有分区表上运行):
strlen("process") = 7
memcpy(0x0b7aac10, "process", 8) = 0x0b7aac10
strlen("channel") = 7
memcpy(0x0b7aac68, "channel", 8) = 0x0b7aac68
strlen("deleted") = 7
memcpy(0x0b7aacc0, "deleted", 8) = 0x0b7aacc0
strlen("old_spent") = 9
memcpy(0x0b7aad18, "old_spent", 10)
最佳答案
问题是你的分区太多了。
作为the documentation警告:
All constraints on all partitions of the master table are examined during constraint exclusion, so large numbers of partitions are likely to increase query planning time considerably. Partitioning using these techniques will work well with up to perhaps a hundred partitions; don't try to use many thousands of partitions.
您应该尝试通过为每个分区使用更长的时间间隔来减少分区的数量。
或者,如果可能,您可以尝试更改应用程序代码以直接访问正确的分区,但这可能会很困难,并且它会消除分区应该带来的许多优势。
关于postgresql - postgres如何调试为什么规划时间过长?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45069283/
我想知道这里是否有人有安装 Postgres-XL 的经验,新的开源多线程版本的 PostgreSQL。我计划将一组 1-2 TB 的数据库从常规 Postgres 9.3 迁移到 XL,并且想知道这
我想创建一个 postgres 备份脚本,但我不想使用 postgres 用户,因为我所在的 unix 系统几乎没有限制。我想要做的是在 crontab 上以 unix 系统(网络)的普通用户身份运行
我正在尝试编写一个 node-postgres 查询,它采用一个整数作为参数在间隔中使用: const query = { text: `SELECT foo
如何在不使用 gui 的情况下停止特定的 Postgres.app 集群。 我想使用 bash/Terminal.app 而不是 gui 我还应该指出,Postgres 应用程序有一个这样的菜单 如果
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
我正在使用 docker 运行 Postgres 图像。它曾经在 Windows10 和 Ubuntu 18.04 上运行没有任何问题。 在 Ubuntu 系统上重新克隆项目后,它在运行 docker
我正在使用 python(比如表 A)将批处理 csv 文件加载到 postgres。我正在使用 pandas 将数据上传到更快的 block 中。 for chunk in pd.read_csv(
所以是的,标题说明了一切,我需要以某种方式将 DB 从源服务器获取到新服务器,但更重要的是旧服务器正在崩溃 :P 有什么方法可以将它全部移动到新服务器并导入它? 旧服务器只是拒绝再运行 Postgre
这主要是出于好奇而提出的问题。我正在浏览 Postgres systemd 单元文件,以了解 systemd 可以做什么。 Postgres 有两个 systemd 单元文件。一个用于代替 syste
从我在 pg_hba.conf 中读到的内容,我推断,为了确保提示我输入 postgres 用户的密码,我应该从当前的“对等”编辑 pg_hba.conf 的前两个条目的方法'到'密码'或'md5',
我已连接到架构 apm。 尝试执行函数并出现以下错误: ERROR: user mapping not found for "postgres" 数据库连接信息说: apm on postgres@
我在 ubuntu 12.04 服务器上,我正在尝试安装 postgresql。截至目前,我已成功安装它但无法配置它。我需要创建一个角色才能继续前进,我在终端中运行了这个命令: root@hostna
我无法以“postgres”用户身份登录到“postgres”数据库。操作系统:REHL 服务器版本 6.3PostgreSQL 版本:8.4有一个数据库“jiradb”用作 JIRA 6.0.8 的
我正在尝试将现有数据库导入 postgres docker 容器。 这就是我的处理方式: docker run --name pg-docker -e POSTGRES_PASSWORD=*****
我们的 Web 应用程序在 postgres 9.3 和 Grails 2.5.3 上运行。当我们重新启动 postgres (/etc/init.d/postgresql restart) 并访问网
我想构建 postgres docker 容器来测试一些问题。我有: postgres 文件的归档文件夹(/var/lib/postgres/data/) 将文件夹放入 docker postgres
我有一个名为“stuff”的表,其中有一个名为“tags”的 json 列,用于存储标签列表,还有一个名为“id”的列,它是表中每一行的主键。我正在使用 postgres 数据库。例如,一行看起来像这
我对 sqlalchemy-psql 中的锁定机制是如何工作的感到非常困惑。我正在运行一个带有 sqlalchemy 和 postgres 的 python-flask 应用程序。由于我有多个线程处理
我(必须)使用 Postgres 8.4 数据库。在这个数据库中,我创建了一个函数: CREATE OR REPLACE FUNCTION counter (mindate timestamptz,m
我已经使用 PostgreSQL 几天了,它运行良好。我一直在通过默认的 postgres 数据库用户和另一个具有权限的用户使用它。 今天中午(在一切正常之后)它停止工作,我再也无法回到数据库中。我会
我是一名优秀的程序员,十分优秀!