Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0ElY-0000HD-9k for pgsql-general@arkaria.postgresql.org; Wed, 12 Sep 2018 23:41:48 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g0ElT-0008BM-Vt for pgsql-general@arkaria.postgresql.org; Wed, 12 Sep 2018 23:41:43 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0ElT-0008BF-NA for pgsql-general@lists.postgresql.org; Wed, 12 Sep 2018 23:41:43 +0000 Received: from glow.birch.relay.mailchannels.net ([23.83.209.71]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0ElO-0000KZ-5B for pgsql-general@lists.postgresql.org; Wed, 12 Sep 2018 23:41:42 +0000 X-Sender-Id: a2hosting|x-authuser|bench@silentmedia.com Received: from relay.mailchannels.net (localhost [127.0.0.1]) by relay.mailchannels.net (Postfix) with ESMTP id 88A866820E6 for ; Wed, 12 Sep 2018 23:41:33 +0000 (UTC) Received: from a2ss24.a2hosting.com (unknown [100.96.30.62]) (Authenticated sender: a2hosting) by relay.mailchannels.net (Postfix) with ESMTPA id 28970682104 for ; Wed, 12 Sep 2018 23:41:33 +0000 (UTC) X-Sender-Id: a2hosting|x-authuser|bench@silentmedia.com Received: from a2ss24.a2hosting.com (a2ss24.a2hosting.com [75.98.175.117]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384) by 0.0.0.0:2500 (trex/5.16.2); Wed, 12 Sep 2018 23:41:33 +0000 X-MC-Relay: Neutral X-MailChannels-SenderId: a2hosting|x-authuser|bench@silentmedia.com X-MailChannels-Auth-Id: a2hosting X-Power-Lyrical: 6213686c17878d02_1536795693419_3658767840 X-MC-Loop-Signature: 1536795693419:1656265546 X-MC-Ingress-Time: 1536795693418 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=silentmedia.com; s=default; h=To:Date:Message-Id:Subject:Mime-Version: Content-Type:From:Sender:Reply-To:Cc:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=eP3akvjPZHKPrj7ayBQqxT+D3HOiC3BYyFy73yBWz6A=; b=P7IKWJy48KLKZIxbJcFsRxWcqa MlITtyojPAPgE3j4EaOp4bsg72SDdccdciheODeeY4bSw7GqVT6FCVP162nA0mzZRnu7pIrdgNX2X mG2Mc87K2lY8Ypq2npV/1kNmG/VUp+ULhIDXs5pmRDsEktVTkbiXFgq9hlazEQFl+F0B7HNC477Ml WlDwj2Senwa0pOGlESGM/N9lVM+0fFLotrTW6qF/dJoI9xX7mB54iqeM6MweO0GuscKUDnJLgXUTr 471q1FCN0RdFBVoIQdCWbLsUz/6P1uXAWS4HMJ0mDGtu+eewkKDKz3dNysp2/92DaGAodlyTz73o2 iP194xyw==; Received: from 75-172-66-57.tukw.qwest.net ([75.172.66.57]:53823 helo=[10.2.3.3]) by a2ss24.a2hosting.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.89_1) (envelope-from ) id 1g0ElI-007s1v-0T for pgsql-general@lists.postgresql.org; Wed, 12 Sep 2018 19:41:32 -0400 From: Ben Chobot Content-Type: multipart/alternative; boundary="Apple-Mail=_8FB54A7B-FD26-4D6B-B899-F2DA34110993" Mime-Version: 1.0 (Mac OS X Mail 11.5 \(3445.9.1\)) Subject: constraint exclusion with a tsrange type Message-Id: Date: Wed, 12 Sep 2018 16:41:30 -0700 To: pgsql-general@lists.postgresql.org X-Mailer: Apple Mail (2.3445.9.1) X-AuthUser: bench@silentmedia.com List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk --Apple-Mail=_8FB54A7B-FD26-4D6B-B899-F2DA34110993 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Hey everybody, I'm having trouble getting constraint exclusion to work = on a table partitioned with a tsrange type. I've distilled it down to = this: create table t ( id serial primary key, observed_window tsrange not null ); create index t_window on t(observed_window); create table p1 (like t including all); alter table p1 add check ( tsrange('2018-1-1','2019-2-1') @> = observed_window); alter table p1 inherit t; create table p2 (like t including all); alter table p2 inherit t; alter table p2 add check ( tsrange('2018-2-1','2019-3-1') @> = observed_window); # explain select * from t where tsrange('2018-1-5','2018-1-6') @> = observed_window; QUERY PLAN = --------------------------------------------------------------------------= --------------------- Append (cost=3D0.00..51.75 rows=3D13 width=3D36) -> Seq Scan on t (cost=3D0.00..0.00 rows=3D1 width=3D36) Filter: ('["2018-01-05 00:00:00","2018-01-06 = 00:00:00")'::tsrange @> observed_window) -> Seq Scan on p1 (cost=3D0.00..25.88 rows=3D6 width=3D36) Filter: ('["2018-01-05 00:00:00","2018-01-06 = 00:00:00")'::tsrange @> observed_window) -> Seq Scan on p2 (cost=3D0.00..25.88 rows=3D6 width=3D36) Filter: ('["2018-01-05 00:00:00","2018-01-06 = 00:00:00")'::tsrange @> observed_window) (7 rows) I would have expected that postgres could reason that, because I'm = asking for an observed_window that fits within the tsrange = (2018-1-5,2018-1-6), no matter what it was, it would not be found in p2. = Obviously postgres says I'm wrong, but I don't know why?=20 Constraint exclusion is set to "partition". --Apple-Mail=_8FB54A7B-FD26-4D6B-B899-F2DA34110993 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii
Hey everybody, I'm having trouble getting constraint = exclusion to work on a table partitioned with a tsrange type. I've = distilled it down to this:

create table t = (
  id serial primary key,
  = observed_window tsrange not null
);
create index t_window on t(observed_window);

create table p1 = (like t including all);
alter table p1 add check ( = tsrange('2018-1-1','2019-2-1') @> observed_window);
alter table p1 inherit t;
create table p2 (like t including all);
alter table p2 inherit t;
alter table p2 add check ( = tsrange('2018-2-1','2019-3-1') @> = observed_window);

# explain select * from t where = tsrange('2018-1-5','2018-1-6') @> observed_window;
 =                     =                   =   QUERY PLAN
---------------------------------------------------------------= --------------------------------
 Append  (cost=3D0.00..51.75 rows=3D13 = width=3D36)
   ->  Seq Scan on = t  (cost=3D0.00..0.00 rows=3D1 width=3D36)
  =        Filter: ('["2018-01-05 00:00:00","2018-01-06 = 00:00:00")'::tsrange @> observed_window)
  =  ->  Seq Scan on p1  (cost=3D0.00..25.88 = rows=3D6 width=3D36)
        =  Filter: ('["2018-01-05 00:00:00","2018-01-06 00:00:00")'::tsrange = @> observed_window)
   ->  Seq = Scan on p2  (cost=3D0.00..25.88 rows=3D6 width=3D36)
         Filter: ('["2018-01-05 = 00:00:00","2018-01-06 00:00:00")'::tsrange @> observed_window)
(7 rows)


I would have expected = that postgres could reason that, because I'm asking for an = observed_window that fits within the tsrange (2018-1-5,2018-1-6), no = matter what it was, it would not be found in p2. Obviously postgres says = I'm wrong, but I don't know why? 

Constraint exclusion is set to = "partition".

= --Apple-Mail=_8FB54A7B-FD26-4D6B-B899-F2DA34110993--