Boa tarde pessoal, estive seguindo uns modelos de particionamento de
tabelas, tenho uma tabela com uns 50G, que estou usando numa base DW que
está sendo criada.
Porém não sei por que o particionamento não funciona.

Tenho a tabela Pai, a qual uso o campo dta como base para o particionamento
Criei as tabelas filho, com o seguinte comando:
begin;
CREATE TABLE base.filho_2013 (LIKE base.pai INCLUDING ALL) INHERITS
(base.pai);
ALTER TABLE base.filho_2013 no inherit base.pai;
INSERT INTO base.filho_2013 select * from base.pai WHERE dta between
'2013-01-01 00:00:00' and '2013-12-31 23:59:59';
DELETE FROM base.pai where dta BETWEEN '2013-01-01 00:00:00' and
'2013-12-31 23:59:59';
ALTER TABLE base.filho_2013 inherit base.pai;
ALTER TABLE base.filho_2013 ADD CONSTRAINT filho_check_2013 CHECK ( dta
between '2013-01-01 00:00:00' AND '2013-12-31 23:59:59' );
COMMIT;

Fiz isso pra mais outros anos ( 2010,2011,2012,... )
Porém quando faço as consultas ele verifica em todas as tabelas e não as
particionadas.
Ex.:
explain select * from base.pai where dta between '2010-01-01 00:00:00' and
'2010-12-31 23:59:59';

 QUERY PLAN

---------------------------------------------------------------------------------------------------------------------------------------------------------------------
 Append  (cost=0.56..2396451.65 rows=6158379 width=707)
   ->  Index Scan using ix_pai_01 on pai  (cost=0.56..1591444.27 rows=9496
width=699)
         Index Cond: ((dta >= '2010-01-01 00:00:00-03'::timestamp with time
zone) AND (dta <= '2010-12-31 23:59:59-03'::timestamp with time zone))
   ->  Index Scan using ix_filho_2008_01 on filho_2008  (cost=0.43..8.45
rows=1 width=693)
         Index Cond: ((dta >= '2010-01-01 00:00:00-03'::timestamp with time
zone) AND (dta <= '2010-12-31 23:59:59-03'::timestamp with time zone))
   ->  Index Scan using ix_filho_2013_01 on filho_2013
 (cost=0.56..500612.83 rows=1 width=690)
         Index Cond: ((dta >= '2010-01-01 00:00:00-03'::timestamp with time
zone) AND (dta <= '2010-12-31 23:59:59-03'::timestamp with time zone))
   ->  Index Scan using ix_filho_2012_01 on filho_2012  (cost=0.43..8.46
rows=1 width=683)
         Index Cond: ((dta >= '2010-01-01 00:00:00-03'::timestamp with time
zone) AND (dta <= '2010-12-31 23:59:59-03'::timestamp with time zone))
   ->  Index Scan using ix_filho_2011_01 on filho_2011  (cost=0.43..8.46
rows=1 width=674)
         Index Cond: ((dta >= '2010-01-01 00:00:00-03'::timestamp with time
zone) AND (dta <= '2010-12-31 23:59:59-03'::timestamp with time zone))
   ->  Seq Scan on filho_2010  (cost=0.00..304369.18 rows=6148879 width=707)
         Filter: ((dta >= '2010-01-01 00:00:00-03'::timestamp with time
zone) AND (dta <= '2010-12-31 23:59:59-03'::timestamp with time zone))


Que fiz de errado?
Obs.: ainda tem registros na tabela pai.

Bruno E. A. Silva.
Analista de Sistemas.
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a