Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在postgreSQL中使用pg_pathman进行表分区后,SQL的运行速度要慢得多_Postgresql_Postgresql 9.6 - Fatal编程技术网

在postgreSQL中使用pg_pathman进行表分区后,SQL的运行速度要慢得多

在postgreSQL中使用pg_pathman进行表分区后,SQL的运行速度要慢得多,postgresql,postgresql-9.6,Postgresql,Postgresql 9.6,在postgreSQL 9.6中使用pg_pathman 1.5进行表分区后,SQL运行速度较慢,分区列为T1中的“创建时间”。列创建时间的数据范围小于一个月,SQL如下: SELECT t1.* FROM T1 t1 JOIN T2 t2 ON t2.answer_question_id = t1.answer_question_id JOIN T3 t3 ON t3.answer_paper_id = t2.answer_paper_id

在postgreSQL 9.6中使用pg_pathman 1.5进行表分区后,SQL运行速度较慢,分区列为T1中的“创建时间”。列创建时间的数据范围小于一个月,SQL如下:

  SELECT
    t1.*
   FROM
     T1 t1
      JOIN T2 t2 ON t2.answer_question_id = t1.answer_question_id
      JOIN T3 t3 ON t3.answer_paper_id = t2.answer_paper_id
      JOIN T4 t4  ON t3.exam_paper_id = t4 .exam_paper_id
     WHERE
    t3.answer_paper_id = 'ab12-4567-7896-efgh'
   AND t1.create_time >= t4 .exam_begin_time AND t1.create_time <= t4 .exam_end_time
 
T1:(id,answer_question_id,create_time )
T2:(id,answer_question_id,answer_paper_id)
T3:(id,answer_paper_id,exam_paper_id )
T4:(id,exam_paper_id,exam_begin_time,exam_end_time)
我在pg_pathman中执行以下操作:

1、 按列创建时间划分的表分区:

 select                                             
    create_range_partitions('T1'::regclass,           
                        'create_time',                      
                        '2018-11-01 00:00:00'::timestamp,
                        interval '3 month',   
                        24,   
                        false) ;
2、 数据迁移:

 select partition_table_concurrently('T1'::regclass,
                             10000,
                             1.0);
 
 

当我执行上面的sql时,它不能自行停止,除非我在pg_pathman分区后手动取消它,但在pg_pathman分区表T1之前,只需要2秒钟就完成了sql的执行,为什么会这样?以及如何解决这个问题?

我想我已经找到了原因,解决方案是,它需要为分区键(列)创建索引,并在SQL的where子句中使用分区列。

Postgres 9.6实际上不支持正确的分区。如果你真的需要它,你至少应该升级到Postgres 12为什么你认为你需要在表上进行分区?是否要提高删除旧数据的效率?分区不是一个性能工具,而是一个“数据管理”选项。我找不到这样一个版本的pg_pathman。你能提供一个链接吗?慢速查询(
EXPLAIN
)的执行计划是什么?你应该将你的Postgres版本升级到12,而不是pg_pathman(对于当前版本,你一开始就不再是pg_pathman了)