У меня есть таблица, которая разбита по месяцам и используется для хранения информации журнала Apache.Когда я запускаю EXPLAIN для простого запроса, в котором предложение WHERE содержится в том же поле, что и CHECK раздела, я получаю тот же план, независимо от того, включено или выключено constraint_exclusion.Ниже приведена информация об основной таблице и два примера информации о дочерних таблицах за февраль и март 2010 года. В целом, существует дочерняя таблица для каждого месяца с февраля 2010 года по июнь 2011 года. В среднем каждая дочерняя таблица имеет около 100 миллионов записей.Также ниже приведен вывод EXPLAIN для простого запроса, один раз с включенным constraint_exclusion и один раз с выключенным.К сожалению, ограничения CHECK не используются для уменьшения размера плана.Связано ли это с тем, что типом request_dt является TIMESTAMP WITH TIME ZONE, а ограничения CHECK - DATES?Есть еще мысли?Я еще не создал индексы для request_dt, но, согласно документации, в этом нет необходимости.Я буду добавлять их, но я не думаю, что они должны влиять на использование ограничений CHECK.
Я использую Postgres 8.3.6.
spatial_data=# \d rpt.websvcs_logs
Table "rpt.websvcs_logs"
Column | Type | Modifiers
--------------------------+-----------------------------+---------------
id | bigint |
ins_ts | timestamp without time zone | default now()
server | text |
host | text |
request_dt | timestamp with time zone |
method | text |
url | text |
api_method | text |
api_key | text |
geo_type | text |
geo_name | text |
radius | text |
lat | text |
long | text |
id_param | text |
state | text |
max | text |
sort_by | text |
sort_dir | text |
rpp | text |
page | text |
ver | text |
output | text |
http_ver | text |
status | text |
size | text |
x_forwarded_for | text |
referrer | text |
agent | text |
accept_encoding | text |
processing_time_sec | text |
processing_time_microsec | text |
spatial_data=# \d rpt.websvcs_logs_201102
Table "rpt.websvcs_logs_201102"
Column | Type | Modifiers
--------------------------+-----------------------------+---------------
id | bigint | not null
ins_ts | timestamp without time zone | default now()
server | text |
host | text |
request_dt | timestamp with time zone |
method | text |
url | text |
api_method | text |
api_key | text |
geo_type | text |
geo_name | text |
radius | text |
lat | text |
long | text |
id_param | text |
state | text |
max | text |
sort_by | text |
sort_dir | text |
rpp | text |
page | text |
ver | text |
output | text |
http_ver | text |
status | text |
size | text |
x_forwarded_for | text |
referrer | text |
agent | text |
accept_encoding | text |
processing_time_sec | text |
processing_time_microsec | text |
Indexes:
"pk_websvcs_logs_201102_id" PRIMARY KEY, btree (id)
Check constraints:
"request_dt" CHECK (request_dt >= '2011-02-01'::date AND request_dt < '2011-03-01'::date)
Inherits: rpt.websvcs_logs
spatial_data=# \d rpt.websvcs_logs_201103
Table "rpt.websvcs_logs_201103"
Column | Type | Modifiers
--------------------------+-----------------------------+---------------
id | bigint | not null
ins_ts | timestamp without time zone | default now()
server | text |
host | text |
request_dt | timestamp with time zone |
method | text |
url | text |
api_method | text |
api_key | text |
geo_type | text |
geo_name | text |
radius | text |
lat | text |
long | text |
id_param | text |
state | text |
max | text |
sort_by | text |
sort_dir | text |
rpp | text |
page | text |
ver | text |
output | text |
http_ver | text |
status | text |
size | text |
x_forwarded_for | text |
referrer | text |
agent | text |
accept_encoding | text |
processing_time_sec | text |
processing_time_microsec | text |
Indexes:
"pk_websvcs_logs_201103_id" PRIMARY KEY, btree (id)
Check constraints:
"request_dt" CHECK (request_dt >= '2011-03-01'::date AND request_dt < '2011-04-01'::date)
Inherits: rpt.websvcs_logs
spatial_data=# SET constraint_exclusion = on;
SET
spatial_data=# EXPLAIN SELECT COUNT(*) FROM rpt.websvcs_logs WHERE request_dt = DATE '2011-03-05';
QUERY
PLAN
------------------------------------------------------------------------------------------------------
Aggregate (cost=85738875.50..85738875.52 rows=1 width=0)
-> Append (cost=0.00..85738236.41 rows=255636 width=0)
-> Seq Scan on websvcs_logs (cost=0.00..11.00 rows=1 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201002 websvcs_logs (cost=0.00..564425.36 rows=1387 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201003 websvcs_logs (cost=0.00..1546537.50 rows=4287 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201004 websvcs_logs (cost=0.00..2528697.60 rows=9248 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201005 websvcs_logs (cost=0.00..3164403.20 rows=12885 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201006 websvcs_logs (cost=0.00..4476196.10 rows=12035 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201007 websvcs_logs (cost=0.00..4470579.60 rows=9543 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201008 websvcs_logs (cost=0.00..4881312.70 rows=11071 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201009 websvcs_logs (cost=0.00..4433474.70 rows=11005 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201010 websvcs_logs (cost=0.00..5419184.20 rows=13605 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201011 websvcs_logs (cost=0.00..5562311.50 rows=15424 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201012 websvcs_logs (cost=0.00..5543114.80 rows=14961 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201101 websvcs_logs (cost=0.00..7320972.20 rows=23008 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201102 websvcs_logs (cost=0.00..7413710.90 rows=23898 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201103 websvcs_logs (cost=0.00..8754694.20 rows=27241 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201104 websvcs_logs (cost=0.00..9292596.80 rows=30848 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201105 websvcs_logs (cost=0.00..9148734.80 rows=30727 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201106 websvcs_logs (cost=0.00..1217213.25 rows=4456 width=0)
Filter: (request_dt = '2011-03-05'::date)
spatial_data=# SET constraint_exclusion = off;
SET
spatial_data=# EXPLAIN SELECT COUNT(*) FROM rpt.websvcs_logs WHERE request_dt = DATE '2011-03-05';
QUERY PLAN
------------------------------------------------------------------------------------------------------
Aggregate (cost=85738875.50..85738875.52 rows=1 width=0)
-> Append (cost=0.00..85738236.41 rows=255636 width=0)
-> Seq Scan on websvcs_logs (cost=0.00..11.00 rows=1 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201002 websvcs_logs (cost=0.00..564425.36 rows=1387 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201003 websvcs_logs (cost=0.00..1546537.50 rows=4287 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201004 websvcs_logs (cost=0.00..2528697.60 rows=9248 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201005 websvcs_logs (cost=0.00..3164403.20 rows=12885 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201006 websvcs_logs (cost=0.00..4476196.10 rows=12035 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201007 websvcs_logs (cost=0.00..4470579.60 rows=9543 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201008 websvcs_logs (cost=0.00..4881312.70 rows=11071 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201009 websvcs_logs (cost=0.00..4433474.70 rows=11005 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201010 websvcs_logs (cost=0.00..5419184.20 rows=13605 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201011 websvcs_logs (cost=0.00..5562311.50 rows=15424 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201012 websvcs_logs (cost=0.00..5543114.80 rows=14961 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201101 websvcs_logs (cost=0.00..7320972.20 rows=23008 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201102 websvcs_logs (cost=0.00..7413710.90 rows=23898 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201103 websvcs_logs (cost=0.00..8754694.20 rows=27241 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201104 websvcs_logs (cost=0.00..9292596.80 rows=30848 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201105 websvcs_logs (cost=0.00..9148734.80 rows=30727 width=0)
Filter: (request_dt = '2011-03-05'::date)
-> Seq Scan on websvcs_logs_201106 websvcs_logs (cost=0.00..1217213.25 rows=4456 width=0)
Filter: (request_dt = '2011-03-05'::date)