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 1g0FCj-0001R9-8h for pgsql-general@arkaria.postgresql.org; Thu, 13 Sep 2018 00:09:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1g0FCg-0002d3-Ml for pgsql-general@arkaria.postgresql.org; Thu, 13 Sep 2018 00:09:50 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0FCg-0002c7-BT for pgsql-general@lists.postgresql.org; Thu, 13 Sep 2018 00:09:50 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1g0FCe-0002Zf-1n for pgsql-general@lists.postgresql.org; Thu, 13 Sep 2018 00:09:49 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w8D09lSl032334; Wed, 12 Sep 2018 20:09:47 -0400 From: Tom Lane To: Ben Chobot cc: pgsql-general@lists.postgresql.org Subject: Re: constraint exclusion with a tsrange type In-reply-to: References: Comments: In-reply-to Ben Chobot message dated "Wed, 12 Sep 2018 16:41:30 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <32332.1536797387.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 12 Sep 2018 20:09:47 -0400 Message-ID: <32333.1536797387@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Ben Chobot writes: > Hey everybody, I'm having trouble getting constraint exclusion to work o= n 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_wi= ndow); > 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_wi= ndow); > # explain select * from t where tsrange('2018-1-5','2018-1-6') @> observ= ed_window; Nope, sorry, there's no logic in there about ranges. You'd have to break this down into something involving simple timestamp comparison operators for constraint exclusion to be able to prove anything. Might be a reasonable future extension, perhaps... regards, tom lane