| From: | Joris Dobbelsteen <joris(at)familiedobbelsteen(dot)nl> | 
|---|---|
| To: | Leon Mergen <leon(at)solatis(dot)com> | 
| Cc: | Erik Jones <erik(at)myemma(dot)com>, Alban Hertroys <dalroi(at)solfertje(dot)student(dot)utwente(dot)nl>, pgsql-general(at)postgresql(dot)org | 
| Subject: | Re: Conditional JOINs ? | 
| Date: | 2008-03-19 21:23:59 | 
| Message-ID: | 47E1846F.4080804@familiedobbelsteen.nl | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
Leon Mergen wrote:
> On 3/19/08, Erik Jones <erik(at)myemma(dot)com> wrote:
>   
>>  >> Excuse me for bumping this up again, but I still don't understand how
>>  >> to use this approach to sequentially walk through all different child
>>  >> tables in one select, without having to JOIN these tables all the
>>  >> time
>>  >
>>  > Apparently a UNION all solved this problem -- sorry for the noise.
>>
>>
>> If you have the child tables INHERITing from the parent, then a simple
>>
>>  SELECT parent.* FROM parent;
>>
>>  would be equivalent to manually spelling out a UNION ALL that
>>  explicitly lists all of the tables.
>>     
>
> But this will only display the information that is common for all the
> child tables -- if I also want to display all the information that is
> specific for the child tables, as I understand it, I have to use a
> UNION ALL and merge all the child tables together this way.
>
> The EXPLAIN of this query:
>
>  Append  (cost=0.00..2169.52 rows=34376 width=94)
>    ->  Seq Scan ON child1 (cost=0.00..1824.71 rows=34371 width=94)
>    ->  Seq Scan ON child2  (cost=0.00..1.05 rows=5 width=56)
>
> Regards,
>
> Leon Mergen
>
>   
What I think you desire is more in the form of:
SELECT id, foo, bar, NULL AS "baz"
FROM child1
UNION ALL
SELECT id, foo, NULL, baz
FROM child2.
I think if you compare it to I/O volume, the joins will not cause many 
additional  I/Os as long as the indexes on "id" for tables child1 and 
child2 will fit into memory.
- Joris
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Richard Huxton | 2008-03-19 22:40:14 | Re: tsearch2 in postgresql 8.3.1 - invalid byte sequence for encoding "UTF8": 0xc3 | 
| Previous Message | Bjørn T Johansen | 2008-03-19 21:17:00 | Which JDBC version to use with PostgreSQL 8.1.11? |