Re: Searching union views not using indices

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michal Taborsky <michal(dot)taborsky(at)mall(dot)cz>
Cc: pgsql-performance(at)postgresql(dot)org
Subject: Re: Searching union views not using indices
Date: 2005-11-04 15:31:34
Message-ID: 13815.1131118294@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Michal Taborsky <michal(dot)taborsky(at)mall(dot)cz> writes:
> We are facing a performance problem with views consisting of several
> unioned tables. The simplified schema is as follows:

Perhaps you should show us the real schema, because I cannot duplicate
your complaint on the toy case you show.

regression=# explain SELECT object_id FROM commonview WHERE link_id=1234567;
QUERY PLAN
------------------------------------------------------------------------------------------------
Subquery Scan commonview (cost=41.40..41.66 rows=13 width=8)
-> Unique (cost=41.40..41.53 rows=13 width=16)
-> Sort (cost=41.40..41.43 rows=13 width=16)
Sort Key: object_id, link_id, loc
-> Append (cost=0.00..41.16 rows=13 width=16)
-> Subquery Scan "*SELECT* 1" (cost=0.00..17.12 rows=5 width=16)
-> Index Scan using fooi on foo (cost=0.00..17.07 rows=5 width=16)
Index Cond: (link_id = 1234567)
-> Subquery Scan "*SELECT* 2" (cost=0.00..24.04 rows=8 width=16)
-> Index Scan using bari on bar (cost=0.00..23.96 rows=8 width=16)
Index Cond: (link_id = 1234567)
(11 rows)

(I had to add indexes on link_id to the example, of course.)

As noted by others, you probably want to be using UNION ALL not UNION,
but that's not the crux of the issue.

regards, tom lane

In response to

Responses

Browse pgsql-performance by date

  From Date Subject
Next Message Tom Lane 2005-11-04 15:36:34 Re: insert performance for win32
Previous Message Merlin Moncure 2005-11-04 15:31:11 Re: insert performance for win32