Troque os numeric por float ou, se possível, por inteiros mesmo. Usar NUMERIC em operações e/ou índices é uma lástima.
2008/9/26 Marcio Clemes <[EMAIL PROTECTED]> > a coluna codRegistro não está no indice. > > ------------------------------ > *De:* [EMAIL PROTECTED] [mailto: > [EMAIL PROTECTED] *Em nome de *Rodrigo Monteiro > *Enviada em:* quinta-feira, 25 de setembro de 2008 17:28 > *Para:* Comunidade PostgreSQL Brasileira > *Assunto:* Re: [pgbr-geral]Banco de dados cresce 1,3GB por mês > > > EXPLAIN ANALYZE DA QUERY > " > select sum(TotItem) as Total, sum(Quantidade * CustoContabil) as Custo, > sum(Desconto) as Desconto > > from Leitura_Estoque > > where CodEmitente = 1 and CodRegistro = 3 > > and DtMovto between '01/01/2008' and '31/08/2008' > > and CodEstabelec = 3 > > " > > *"Aggregate (cost=268121.88..268121.89 rows=1 width=40) (actual > time=21242.903..21242.904 rows=1 loops=1)" > " -> Index Scan using idx_dtmovtole on leitura_estoque > (cost=0.00..260023.00 rows=1079850 width=40) (actual time=56.412..18274.442 > rows=1003086 loops=1)" > " Index Cond: ((dtmovto >= '2008-01-01'::date) AND (dtmovto <= > '2008-01-31'::date))" > " Filter: ((codemitente = 1::numeric) AND (codregistro = 3::numeric) AND > (codestabelec = 3::numeric))" > "Total runtime: 21242.989 ms" > * > > > > Thu, 25 Sep 2008 14:22:56 -0300, "Rodrigo Monteiro" escreveu:> > > boa > tarde a todos > > Acredito que o tempo de resposta do sql que postarei abaixo esta acima do > normal (em testes comparativos com Sql Server e Oracle) > > > > > > abaixo a estrutura de uma tabela com a leitura das vendas de uma empresa > > ================================================================================ > > > CREATE TABLE leitura_estoque > > ( > > codregistro numeric(4) NOT NULL, > > codemitente numeric(4) NOT NULL, > > codestabelec numeric(4) NOT NULL, > > codproduto numeric(7) NOT NULL, > > documento varchar(20) NOT NULL, > > codtpdocto varchar(10) NOT NULL, > > numitem numeric(3), > > guiche numeric(3), > > equipamento numeric(4), > > dtmovto date, > > quantidade numeric(15,4) NOT NULL DEFAULT 0, > > preco numeric(15,4) NOT NULL DEFAULT 0, > > desconto numeric(12,2), > > vendedor numeric(9), > > coddepto numeric(4), > > tributacao numeric(4), > > aliqtributacao numeric(5,2), > > hora time, > > custocontabil numeric(12,2), > > idregistro numeric(9) NOT NULL, > > seqleitura numeric(9) NOT NULL, > > cupom varchar(6), > > aliqreducao numeric(5,2), > > pontos numeric(9,2) DEFAULT 0, > > funcao numeric(4), > > piscofins numeric(1), > > lucratividade numeric(15,2) NOT NULL DEFAULT 0, > > totitem numeric(15,4) NOT NULL DEFAULT 0, > > CONSTRAINT leitura_estoque_pk PRIMARY KEY (seqleitura), > > CONSTRAINT leitura_estoque_estabelec_fk FOREIGN KEY (codemitente, > codestabelec) > > REFERENCES estabelecimento (codemitente, codestabelec) MATCH SIMPLE > > ON UPDATE NO ACTION ON DELETE NO ACTION > > ) > > WITH OIDS TABLESPACE "GST_TSAux1"; > > ALTER TABLE leitura_estoque OWNER TO postgres; > > > > > > -- Index: idx_leitura_estoque_produto > > > > -- DROP INDEX idx_leitura_estoque_produto; > > > > CREATE INDEX idx_leitura_estoque_produto > > ON leitura_estoque > > USING btree > > (codemitente, codestabelec, dtmovto, codproduto); > > > > -- Index: idx_leitura_estoque_produtopdv > > > > -- DROP INDEX idx_leitura_estoque_produtopdv; > > > > CREATE INDEX idx_leitura_estoque_produtopdv > > ON leitura_estoque > > USING btree > > (codemitente, codestabelec, dtmovto, equipamento, codproduto); > > > > > > > > -- Trigger: trg_altcusto on leitura_estoque > > > > -- DROP TRIGGER trg_altcusto ON leitura_estoque; > > > > CREATE TRIGGER trg_altcusto > > AFTER UPDATE > > ON leitura_estoque > > FOR EACH ROW > > EXECUTE PROCEDURE stpr_altcustovenda(); > > > > -- Trigger: trg_leitura_estoque on leitura_estoque > > > > -- DROP TRIGGER trg_leitura_estoque ON leitura_estoque; > > > > CREATE TRIGGER trg_leitura_estoque > > AFTER INSERT OR UPDATE OR DELETE > > ON leitura_estoque > > FOR EACH ROW > > EXECUTE PROCEDURE stpr_prodresumo(); > > > > -- Trigger: trg_leitura_estoque_ultvenda on leitura_estoque > > > > -- DROP TRIGGER trg_leitura_estoque_ultvenda ON leitura_estoque; > > > > CREATE TRIGGER trg_leitura_estoque_ultvenda > > AFTER INSERT > > ON leitura_estoque > > FOR EACH ROW > > EXECUTE PROCEDURE stpr_leitura_estoque_ultvenda(); > > > > ================================================================================ > > > ABAIXO O RESULTADO DO VACUUM PARA ESTA TABELA > > INFO: vacuuming "public.leitura_estoque" > > INFO: index "leitura_estoque_pk" now contains 95739453 row versions in > 397771 pages > > DETAIL: 157614 index row versions were removed. > > 265 index pages have been deleted, 0 are currently reusable. > > CPU 10.02s/21.19u sec elapsed 196.57 sec. > > INFO: index "idx_leitura_estoque_produto" now contains 95742096 row > versions in 735192 pages > > DETAIL: 157614 index row versions were removed. > > 30 index pages have been deleted, 0 are currently reusable. > > CPU 22.84s/25.90u sec elapsed 1679.85 sec. > > INFO: index "idx_leitura_estoque_produtopdv" now contains 95747773 row > versions in 963391 pages > > DETAIL: 157614 index row versions were removed. > > 3 index pages have been deleted, 0 are currently reusable. > > CPU 28.82s/25.80u sec elapsed 1915.30 sec. > > INFO: "leitura_estoque": removed 157614 row versions in 16495 pages > > DETAIL: CPU 1.06s/0.58u sec elapsed 104.05 sec. > > INFO: "leitura_estoque": found 157614 removable, 95736585 nonremovable row > versions in 4069552 pages > > DETAIL: 0 dead row versions cannot be removed yet. > > There were 0 unused item pointers. > > 0 pages are entirely empty. > > CPU 100.55s/82.69u sec elapsed 4715.99 sec. > > INFO: analyzing "public.leitura_estoque" > > INFO: "leitura_estoque": scanned 3000 of 4070155 pages, containing 70572 > live rows and 0 dead rows; 3000 rows in sample, 95746326 estimated total > rows > > > > Query returned successfully with no result in 4732938 ms. > > ================================================================================= > > > > > ABAIXO A sql query > > > > select sum(TotItem) as Total, sum(Quantidade * CustoContabil) as Custo, > sum(Desconto) as Desconto > > from Leitura_Estoque > > where CodEmitente = 1 and CodRegistro = 3 > > and DtMovto between '01/01/2008' and '31/08/2008' > > and CodEstabelec = 3 > > > > ================================================================================= > > > > > <- em 10 minutos e 66 segundos ----> em um IBM com 8 GB de memória, 2 > processadores Zion: 4.2 Ghz > > > > _______________________________________________ > pgbr-geral mailing list > [email protected] > https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral > > -- William Leite Araújo Analista de Banco de Dados - QualiConsult
_______________________________________________ pgbr-geral mailing list [email protected] https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
