db=> SELECT COUNT(*) FROM titulo WHERE cd_pessoa = 1; count ------- 220 (1 record) Time: 48,762 ms db=> SELECT COUNT(*) FROM movimento WHERE cd_pessoa = 1; count ------- 221 (1 record) Time: 1158,463 ms db=> EXPLAIN ANALYZE SELECT COUNT(*) FROM movimento WHERE cd_pessoa = 1; QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=279.99..279.99 rows=1 width=0) (actual time=1.263..1.264 rows=1 loops=1) -> Index Scan using idx_movimento_cd_pessoa on movimento (cost=0.00..279.80 rows=74 width=0) (actual time=0.043..0.984 rows=221 loops=1) Index Cond: (cd_pessoa = 1) Total runtime: 1.388 ms (4 records) Time: 6,279 ms db=> EXPLAIN ANALYZE SELECT COUNT(*) FROM titulo WHERE cd_pessoa = 1; QUERY PLAN ----------------------------------------------------------------------------------------------------------------------------------------------------------- Aggregate (cost=6.02..6.02 rows=1 width=0) (actual time=1.105..1.105 rows=1 loops=1) -> Index Scan using idx_titulo_cd_pessoa_id_tipo_dt_vencimento on titulo (cost=0.00..6.01 rows=1 width=0) (actual time=0.040..0.828 rows=220 loops=1) Index Cond: (cd_pessoa = 1) Total runtime: 1.209 ms (4 records) Time: 6,993 ms db=> SELECT COUNT(*) FROM movimento; count -------- 347355 (1 record) Time: 640,686 ms db=> SELECT COUNT(*) FROM titulo; count -------- 347354 (1 record) Time: 3274,281 ms db=> \d movimento Table "public.movimento" Column | Type | Modifiers -------------------+---------------+--------------------------------------------------------------------- cd_movimento | integer | not null default nextval('public.movimento_cd_movimento_seq'::text) cd_pessoa | integer | not null cd_pessoa_usuario | integer | not null cd_pessoa_matriz | integer | not null cd_pessoa_filial | integer | not null dt_movimento | date | not null vl_movimento | numeric(15,2) | not null id_origem | smallint | not null default 0 id_tipo | smallint | not null nr_nota_fiscal | text | Índices: "pk_movimento"chave primária, btree (cd_movimento) "idx_movimento_cd_pessoa" btree (cd_pessoa) "idx_movimento_cd_pessoa_id_tipo" btree (cd_pessoa, id_tipo) Restrições de checagem: "ckc_id_tipo_moviment" CHECK (id_tipo = 1 OR id_tipo = 2) "ckc_id_origem_moviment" CHECK (id_origem = 0 OR id_origem = 1 OR id_origem = 2) Restrições de chave estrangeira: "fk_movimento_filial" FOREIGN KEY (cd_pessoa_matriz, cd_pessoa_filial) REFERENCES filial(cd_pessoa, cd_pessoa_filial) ON UPDATE RESTRICT ON DELETE RESTRICT "fk_movimento_usuario" FOREIGN KEY (cd_pessoa_usuario) REFERENCES usuario(cd_pessoa) ON UPDATE RESTRICT ON DELETE RESTRICT "fk_movimento_pessoa" FOREIGN KEY (cd_pessoa) REFERENCES pessoa(cd_pessoa) ON UPDATE RESTRICT ON DELETE RESTRICT db=> \d titulo Table "public.titulo" Column | Type | Modifiers ----------------+---------------+--------------------------------------------------------------- cd_titulo | integer | not null default nextval('public.titulo_cd_titulo_seq'::text) cd_portador | integer | cd_movimento | integer | not null nr_lote | integer | cd_lote_titulo | integer | vl_titulo | numeric(15,2) | not null vl_acrescimo | numeric(15,2) | vl_desconto | numeric(15,2) | vl_multa | numeric(15,2) | vl_juro | numeric(15,2) | vl_emolumento | numeric(15,2) | vl_pago | numeric(15,2) | dt_vencimento | date | not null ds_observacao | text | nr_banco | text | dt_quitacao | date | id_tipo | smallint | cd_pessoa | integer | Índices: "pk_titulo"chave primária, btree (cd_titulo) "idx_titulo_cd_movimento" btree (cd_movimento) "idx_titulo_cd_pessoa_id_tipo_dt_vencimento" btree (cd_pessoa, id_tipo, dt_vencimento) "idx_titulo_nr_lote" btree (nr_lote) Restrições de chave estrangeira: "fk_titulo_pessoa" FOREIGN KEY (cd_pessoa) REFERENCES pessoa(cd_pessoa) "fk_titulo_lote" FOREIGN KEY (nr_lote) REFERENCES lote(nr_lote) ON UPDATE RESTRICT ON DELETE RESTRICT "fk_titulo_portador" FOREIGN KEY (cd_portador) REFERENCES portador(cd_portador) ON UPDATE RESTRICT ON DELETE RESTRICT "fk_titulo_lote_titulo" FOREIGN KEY (cd_lote_titulo) REFERENCES lote_titulo(cd_lote_titulo) ON UPDATE RESTRICT ON DELETE RESTRICT