Olá,

Leandro, assim como você questionou, eu também me questionei e resolvi fazer
o teste para ver se ajudava o planejador.

Abaixo a resposta.

explain select t1.campo1,t1.campo2,t1.campo3,null as campo4 from tabela1 t1
union select t2.campo1,t2.campo2,null as campo3,t2.campo4 from tabela2 t2;
                                     QUERY
PLAN
-------------------------------------------------------------------------------------
 Unique  (cost=13.64..16.14 rows=200 width=12)
   ->  Sort  (cost=13.64..14.14 rows=200 width=12)
         Sort Key: campo1, campo2, campo3, campo4
         ->  Append  (cost=0.00..6.00 rows=200 width=12)
               ->  Subquery Scan "*SELECT* 1"  (cost=0.00..3.00 rows=100
width=12)
                     ->  Seq Scan on tabela1 t1  (cost=0.00..2.00 rows=100
width=12)
               ->  Subquery Scan "*SELECT* 2"  (cost=0.00..3.00 rows=100
width=12)
                     ->  Seq Scan on tabela2 t2  (cost=0.00..2.00 rows=100
width=12)
(8 rows)


postgres=# explain select t1.campo1,t1.campo2,t1.campo3,null as campo4 from
tabela1 t1 union select t2.campo1,t2.campo2,null as campo3,t2.campo4 from
tabela2 t2;
                                     QUERY
PLAN
-------------------------------------------------------------------------------------
 Unique  (cost=13.64..16.14 rows=200 width=12)
   ->  Sort  (cost=13.64..14.14 rows=200 width=12)
         Sort Key: campo1, campo2, campo3, campo4
         ->  Append  (cost=0.00..6.00 rows=200 width=12)
               ->  Subquery Scan "*SELECT* 1"  (cost=0.00..3.00 rows=100
width=12)
                     ->  Seq Scan on tabela1 t1  (cost=0.00..2.00 rows=100
width=12)
               ->  Subquery Scan "*SELECT* 2"  (cost=0.00..3.00 rows=100
width=12)
                     ->  Seq Scan on tabela2 t2  (cost=0.00..2.00 rows=100
width=12)
(8 rows)

Foi testado com a claúsula where também e o resultado foi igual para os dois
casos.

Quando a resposta do colega, encontrei um erro, não é possível nomear campos
nulos prefixados com a tabela.
NULL as t1.campo4

Na hora isso passou desapercebido :(

[]s

2008/5/13 Leandro DUTRA <[EMAIL PROTECTED]>:

> 2008/5/12 junior Prado <[EMAIL PROTECTED]>:
> > use o nome da tabela para otimizar a consulta
>
> É uma boa prática para legibilidade, mas ajuda de fato o planejador?
>
> --
> skype:leandro.gfc.dutra?chat Yahoo!: ymsgr:sendIM?lgcdutra
> +55 (11) 3040 7300 r155 gTalk: xmpp:[EMAIL PROTECTED]<[EMAIL PROTECTED]>
> +55 (11) 9406 7191 ICQ/AIM: aim:GoIM?screenname=61287803
> +55 (11) 5685 2219 MSN: msnim:[EMAIL PROTECTED]
> _______________________________________________
> pgbr-geral mailing list
> [email protected]
> https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral
>



-- 
João Paulo
www.dextra.com.br/postgres
PostgreSQL
_______________________________________________
pgbr-geral mailing list
[email protected]
https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

Responder a