Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.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 带分区表的Hibernate_Postgresql_Hibernate_Partitioning_Database Partitioning - Fatal编程技术网

Postgresql 带分区表的Hibernate

Postgresql 带分区表的Hibernate,postgresql,hibernate,partitioning,database-partitioning,Postgresql,Hibernate,Partitioning,Database Partitioning,使用数据库postgresql 9.5 我有一个表employee\u shift,行数110966498,因此为了改进插入,我已将此表按月份划分了20年(2000年1月至2020年12月,迄今为止共有240个分区表)。这是表中的列日期 现在我的插入速度更快(通过本机查询完成),但我现有的DAO层使用的是HQL,它点击employee\u shift表,而不是点击employee\u shift\u 2010\u 10(year\u month),因此我的select语句相对要慢得多,因为它检查

使用数据库postgresql 9.5

我有一个表
employee\u shift
,行数110966498,因此为了改进插入,我已将此表按月份划分了20年(2000年1月至2020年12月,迄今为止共有240个分区表)。这是表中的
日期

现在我的插入速度更快(通过本机查询完成),但我现有的DAO层使用的是HQL,它点击
employee\u shift
表,而不是点击
employee\u shift\u 2010\u 10
(year\u month),因此我的select语句相对要慢得多,因为它检查所有分区

如果我使用select语句使用
date
列,hibernate有没有办法直接点击
employee\u shift\u 2010\u 10


在这种情况下,还有哪些其他选项可以加快选择速度?

可能您没有为继承的表设置约束,或者使用参数化查询

CREATE TABLE a (id serial PRIMARY KEY, ts timestamp);
CREATE INDEX a_ts ON a (ts);

CREATE TABLE a_2010 ( CONSTRAINT data_2011_check CHECK (ts >= '2010-01-01 00:00:00'::timestamp AND ts < '2011-01-01 00:00:00'::timestamp))  INHERITS (a);
CREATE TABLE a_2011 ( CONSTRAINT data_2012_check CHECK (ts >= '2011-01-01 00:00:00'::timestamp AND ts < '2012-01-01 00:00:00'::timestamp))  INHERITS (a);
CREATE TABLE a_2012 ( CONSTRAINT data_2013_check CHECK (ts >= '2012-01-01 00:00:00'::timestamp AND ts < '2013-01-01 00:00:00'::timestamp))  INHERITS (a);
CREATE TABLE a_2013 ( CONSTRAINT data_2014_check CHECK (ts >= '2013-01-01 00:00:00'::timestamp AND ts < '2014-01-01 00:00:00'::timestamp))  INHERITS (a);
CREATE INDEX a_ts_2010 ON a_2010 (ts);
CREATE INDEX a_ts_2011 ON a_2011 (ts);
CREATE INDEX a_ts_2012 ON a_2012 (ts);
CREATE INDEX a_ts_2013 ON a_2013 (ts);
EXPLAIN ANALYZE SELECT * FROM a WHERE ts = '2011-02-01 00:00:00';


                                                       QUERY PLAN                                                        
-------------------------------------------------------------------------------------------------------------------------
 Append  (cost=0.00..14.79 rows=11 width=12) (actual time=0.006..0.006 rows=0 loops=1)
   ->  Seq Scan on a  (cost=0.00..0.00 rows=1 width=12) (actual time=0.003..0.003 rows=0 loops=1)
         Filter: (ts = '2011-02-01 00:00:00'::timestamp without time zone)
   ->  Bitmap Heap Scan on a_2011  (cost=4.23..14.79 rows=10 width=12) (actual time=0.003..0.003 rows=0 loops=1)
         Recheck Cond: (ts = '2011-02-01 00:00:00'::timestamp without time zone)
         ->  Bitmap Index Scan on a_ts_2011  (cost=0.00..4.23 rows=10 width=0) (actual time=0.003..0.003 rows=0 loops=1)
               Index Cond: (ts = '2011-02-01 00:00:00'::timestamp without time zone)
 Planning time: 1.148 ms
 Execution time: 0.046 ms
(9 rows)