请考虑以下对象:
create table invoices_2011 (
invoice_id bigint not null,
invoice_date date not null,
constraint invoice_line_2011_ck1 CHECK (invoice_date >= '2011-01-01' AND
invoice_date < '2012-01-01')
);
create table invoices_2012 (
invoice_id bigint not null,
invoice_date date not null,
constraint invoice_line_2012_ck1 CHECK (invoice_date >= '2012-01-01' AND
invoice_date < '2013-01-01')
);
create table invoices_2013 (
invoice_id bigint not null,
invoice_date date not null,
constraint invoice_line_2013_ck1 CHECK (invoice_date >= '2013-01-01' AND
invoice_date < '2014-01-01')
);
create or replace view invoices as
select * from invoices_2011
union all
select * from invoices_2012
union all
select * from invoices_2013;
如果我查看以下查询的解释计划:
select * from invoices where invoice_date > '2013-10-01';
它表明要扫描的唯一实际物理表是 invoices_2013,这是我所期望的。
但是,当我查看此查询的解释计划时(今天是 10/11/13):
select * from invoices where invoice_date > date_trunc ('month', current_date)
它扫描所有三个表。
有谁知道以检查约束可以利用它的方式强制检查/插值函数的任何方法?