pg.ddx.io pgsql-general@postgresql.org mailing list archive
help / color / mirror / Atom feedconstraint exclusion with a tsrange type
2+ messages / 2 participants
[nested] [flat]
* constraint exclusion with a tsrange type
@ 2018-09-12 23:41 Ben Chobot <bench@silentmedia.com>
0 siblings, 1 reply; 2+ messages in thread
From: Ben Chobot @ 2018-09-12 23:41 UTC (permalink / raw)
To: pgsql-general@lists.postgresql.org
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=0.00..51.75 rows=13 width=36)
-> Seq Scan on t (cost=0.00..0.00 rows=1 width=36)
Filter: ('["2018-01-05 00:00:00","2018-01-06 00:00:00")'::tsrange @> observed_window)
-> Seq Scan on p1 (cost=0.00..25.88 rows=6 width=36)
Filter: ('["2018-01-05 00:00:00","2018-01-06 00:00:00")'::tsrange @> observed_window)
-> Seq Scan on p2 (cost=0.00..25.88 rows=6 width=36)
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".
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: constraint exclusion with a tsrange type
@ 2018-09-13 00:09 Tom Lane <tgl@sss.pgh.pa.us>
parent: Ben Chobot <bench@silentmedia.com>
0 siblings, 0 replies; 2+ messages in thread
From: Tom Lane @ 2018-09-13 00:09 UTC (permalink / raw)
To: Ben Chobot <bench@silentmedia.com>; +Cc: pgsql-general@lists.postgresql.org
Ben Chobot <bench@silentmedia.com> writes:
> 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;
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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2018-09-13 00:09 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2018-09-12 23:41 constraint exclusion with a tsrange type Ben Chobot <bench@silentmedia.com>
2018-09-13 00:09 ` Tom Lane <tgl@sss.pgh.pa.us>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox