Teria como criar uma view dessa query pra ser sempre usada com o seq_scan
off?

2015-03-20 8:34 GMT-03:00 Luiz Carlos L. Nogueira Jr. <
[email protected]>:

> SET enable_seqscan TO on;
> explain analyze
> SELECT ppe.id_processo_parte_expediente,
>        ppe.id_pessoa_parte AS id_destinatario
>   FROM tb_proc_parte_expediente ppe
>   where exists (select 1 from tb_processo_expediente pe  where
> pe.id_processo_expediente::integer = ppe.id_processo_expediente::integer);
>
>
> Hash Semi Join  (cost=22122.22..53155.35 rows=724909 width=8) (actual
> time=812.730..2167.514 rows=724909 loops=1)
>   Hash Cond: ((ppe.id_processo_expediente)::integer =
> (pe.id_processo_expediente)::integer)
>   ->  Seq Scan on tb_proc_parte_expediente ppe  (cost=0.00..17441.09
> rows=724909 width=12) (actual time=0.005..321.824 rows=724909 loops=1)
>   ->  Hash  (cost=13160.43..13160.43 rows=716943 width=4) (actual
> time=812.571..812.571 rows=716943 loops=1)
>         Buckets: 131072  Batches: 1  Memory Usage: 25206kB
>         ->  Seq Scan on tb_processo_expediente pe  (cost=0.00..13160.43
> rows=716943 width=4) (actual time=0.007..337.551 rows=716943 loops=1)
> Total runtime: 2438.293 ms
>
> Só funciona com o off
>
> Merge Join  (cost=10.97..149413.09 rows=724909 width=8) (actual
> time=0.034..2247.658 rows=724909 loops=1)
>   Merge Cond: ((pe.id_processo_expediente)::integer =
> (ppe.id_processo_expediente)::integer)
>   ->  Index Only Scan using tb_processo_expediente_pkey on
> tb_processo_expediente pe  (cost=0.42..25786.66 rows=716943 width=4)
> (actual time=0.016..504.585 rows=716943 loops=1)
>         Heap Fetches: 716943
>   ->  Index Scan using idx_tb_processo_parte_expediente2 on
> tb_proc_parte_expediente ppe  (cost=0.42..112777.29 rows=724909 width=12)
> (actual time=0.006..719.597 rows=724909 loops=1)
> Total runtime: 2522.453 ms
>
>
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a