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
PostgreSQL分区约束行为异常_Postgresql - Fatal编程技术网

PostgreSQL分区约束行为异常

PostgreSQL分区约束行为异常,postgresql,Postgresql,我将一个表划分为两列,expired和type\u id。 expired是一个布尔值,type\u id按范围划分。 表格示例: mos_active_1 ... mos_active_15 mos_expired_1 ... mos_expired_15 我的约束设置如下: ADD CONSTRAINT mos_active_1_check CHECK (expired = false AND type_id < 100 ) ... ADD CONSTRAINT mos_expire

我将一个表划分为两列,
expired
type\u id
expired
是一个布尔值,
type\u id
按范围划分。 表格示例:

mos_active_1
...
mos_active_15
mos_expired_1
...
mos_expired_15
我的约束设置如下:

ADD CONSTRAINT mos_active_1_check CHECK (expired = false AND type_id < 100 )
...
ADD CONSTRAINT mos_expired_1_check CHECK (expired = true AND type_id < 100 )
严重不足
SELECT*from mos,其中expired=false,type_id=34
不起作用
EXPLAIN
显示查询了
mos\u expired\u 1
mos\u active\u 1

Result  (cost=0.00..2464.71 rows=5863 width=150)
  ->  Append  (cost=0.00..2464.71 rows=5863 width=150)
        ->  Seq Scan on mos  (cost=0.00..11.50 rows=1 width=627)
              Filter: ((NOT expired) AND (type_id = 34))
        ->  Index Scan using index_mos_expired_1_on_type_id_and_region_id on mos_expired_1 mos  (cost=0.00..8.27 rows=1 width=627)
              Index Cond: (type_id = 34)
              Filter: (NOT expired)
        ->  Bitmap Heap Scan on mos_active_1 mos  (cost=113.68..2444.95 rows=5861 width=150)
              Recheck Cond: (type_id = 34)
              Filter: (NOT expired)
              ->  Bitmap Index Scan on index_mos_active_1_on_type_id  (cost=0.00..112.22 rows=5861 width=0)
                    Index Cond: (type_id = 34)
(除了实际的mos表创建之外)

我真的很想知道我是否遗漏了什么,或者这是查询计划器的问题

更新:我能够用一个简单得多的例子重现同样的问题,只有两个表有一个基于过期的约束:

CREATE TABLE mos (type_id   INTEGER UNIQUE, expired boolean);
CREATE TABLE mos_expired_1 ( CHECK ( expired = true  ) ) INHERITS (mos);
CREATE TABLE mos_active_1 ( CHECK ( expired = false ) ) INHERITS (mos);
INSERT INTO mos_expired_1 (type_id,expired) VALUES(1, true);
INSERT INTO mos_active_1 (type_id,expired) VALUES(2, false);
EXPLAIN SELECT * from mos where expired = false;
EXPLAIN SELECT * from mos where expired = true;

在PostgreSQL中,布尔约束排除似乎不起作用。当您使用
integer
enum
时,它运行良好

整数:

CREATE TABLE mos (type_id INTEGER UNIQUE, expired int);
CREATE TABLE mos_expired_1 ( CHECK ( expired = 0 ) ) INHERITS (mos);
CREATE TABLE mos_active_1 ( CHECK ( expired = 1 ) ) INHERITS (mos); 
INSERT INTO mos_expired_1 (type_id,expired) VALUES(1, 0);
INSERT INTO mos_active_1 (type_id,expired) VALUES(2, 1); 
analyze;

EXPLAIN SELECT * from mos where expired = 0;
                                 QUERY PLAN                                  
-----------------------------------------------------------------------------
 Result  (cost=0.00..37.76 rows=12 width=8)
   ->  Append  (cost=0.00..37.76 rows=12 width=8)
         ->  Seq Scan on mos  (cost=0.00..36.75 rows=11 width=8)
               Filter: (expired = 0)
         ->  Seq Scan on mos_expired_1 mos  (cost=0.00..1.01 rows=1 width=8)
               Filter: (expired = 0)
(6 rows)

EXPLAIN SELECT * from mos where expired = 1;
                                 QUERY PLAN                                 
----------------------------------------------------------------------------
 Result  (cost=0.00..37.76 rows=12 width=8)
   ->  Append  (cost=0.00..37.76 rows=12 width=8)
         ->  Seq Scan on mos  (cost=0.00..36.75 rows=11 width=8)
               Filter: (expired = 1)
         ->  Seq Scan on mos_active_1 mos  (cost=0.00..1.01 rows=1 width=8)
               Filter: (expired = 1)
(6 rows)
枚举:


我不知道这是不是一只虫子。我想它在任何地方都没有记录。

我肯定可以复制,即使是在最新的版本上。试着在PostgreSQL邮件列表上提问,他们非常非常好。哇,很好,我没想到。我在postgresql邮件列表上发布了相同的问题,让我们看看这是否真的是一个bug。
CREATE TABLE mos (type_id INTEGER UNIQUE, expired int);
CREATE TABLE mos_expired_1 ( CHECK ( expired = 0 ) ) INHERITS (mos);
CREATE TABLE mos_active_1 ( CHECK ( expired = 1 ) ) INHERITS (mos); 
INSERT INTO mos_expired_1 (type_id,expired) VALUES(1, 0);
INSERT INTO mos_active_1 (type_id,expired) VALUES(2, 1); 
analyze;

EXPLAIN SELECT * from mos where expired = 0;
                                 QUERY PLAN                                  
-----------------------------------------------------------------------------
 Result  (cost=0.00..37.76 rows=12 width=8)
   ->  Append  (cost=0.00..37.76 rows=12 width=8)
         ->  Seq Scan on mos  (cost=0.00..36.75 rows=11 width=8)
               Filter: (expired = 0)
         ->  Seq Scan on mos_expired_1 mos  (cost=0.00..1.01 rows=1 width=8)
               Filter: (expired = 0)
(6 rows)

EXPLAIN SELECT * from mos where expired = 1;
                                 QUERY PLAN                                 
----------------------------------------------------------------------------
 Result  (cost=0.00..37.76 rows=12 width=8)
   ->  Append  (cost=0.00..37.76 rows=12 width=8)
         ->  Seq Scan on mos  (cost=0.00..36.75 rows=11 width=8)
               Filter: (expired = 1)
         ->  Seq Scan on mos_active_1 mos  (cost=0.00..1.01 rows=1 width=8)
               Filter: (expired = 1)
(6 rows)
CREATE TYPE mybool AS ENUM ('true', 'false');                                     
CREATE TABLE mos (type_id INTEGER UNIQUE, expired mybool);
CREATE TABLE mos_expired_1 ( CHECK ( expired = 'true' ) ) INHERITS (mos);
CREATE TABLE mos_active_1 ( CHECK ( expired = 'false' ) ) INHERITS (mos);
INSERT INTO mos_expired_1 (type_id,expired) VALUES(1, 'true');
INSERT INTO mos_active_1 (type_id,expired) VALUES(2, 'false');
analyze;

EXPLAIN SELECT * from mos where expired = 'true';
                                 QUERY PLAN                                  
-----------------------------------------------------------------------------
 Result  (cost=0.00..37.76 rows=12 width=8)
   ->  Append  (cost=0.00..37.76 rows=12 width=8)
         ->  Seq Scan on mos  (cost=0.00..36.75 rows=11 width=8)
               Filter: (expired = 'true'::mybool)
         ->  Seq Scan on mos_expired_1 mos  (cost=0.00..1.01 rows=1 width=8)
               Filter: (expired = 'true'::mybool)
(6 rows)

EXPLAIN SELECT * from mos where expired = 'false';
                                 QUERY PLAN                                 
----------------------------------------------------------------------------
 Result  (cost=0.00..37.76 rows=12 width=8)
   ->  Append  (cost=0.00..37.76 rows=12 width=8)
         ->  Seq Scan on mos  (cost=0.00..36.75 rows=11 width=8)
               Filter: (expired = 'false'::mybool)
         ->  Seq Scan on mos_active_1 mos  (cost=0.00..1.01 rows=1 width=8)
               Filter: (expired = 'false'::mybool)
(6 rows)