pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Richard Huxton <dev@archonet.com>
To: Rajesh Kumar Mallah <mallah@trade-india.com>
To: pgsql-performance@postgresql.org
Subject: Re: factoring problem with view in 7.3.3
Date: Wed, 23 Jul 2003 15:13:14 +0100
Message-ID: <200307231513.14574.dev@archonet.com> (raw)
In-Reply-To: <200307231551.48444.mallah@trade-india.com>
References: <200307231551.48444.mallah@trade-india.com>

On Wednesday 23 July 2003 11:21, Rajesh Kumar Mallah wrote:
> Hi ,
>
> I have a view which is a union of select of certain feilds from
> indentical tables. The problem is when we query a column on
> which index exists exists foreach of the tables does not use the
> indexes.
>
>
> But when we query individual tables it uses indexes.
>
> tradein_clients=# create view sent_enquiry_eyp_iid_ip_cat1 as
> select rfi_id,sender_uid,receiver_uid,subject,generated from eyp_rfi  UNION
> select rfi_id,sender_uid,receiver_uid,subject,generated from iid_rfi UNION
> select rfi_id,sender_uid,receiver_uid,subject,generated from ip_rfi UNION
> select rfi_id,sender_uid,receiver_uid,subject,generated from catalog_rfi ;
>
> CREATE VIEW
> tradein_clients=#
> tradein_clients=# explain analyze select rfi_id      from
> sent_enquiry_eyp_iid_ip_cat1 where sender_uid = 34866;

[snip query plan showing full selects being done and then filtering on the 
outputs]

I do remember some talk about issues with pushing where clauses down into 
unions on a view (sorry - can't remember when - maybe check the archives). 
Actually, I thought work had been done on that for 7.3.3, but it might have 
been 7.4

If you generally do that particular query (checking agains sender_uid) then 
the simplest solution is to build an SQL query to push the comparison down 
for you:

CREATE my_function(int4) RETURNS SETOF my_type AS '
  SELECT ... FROM eyp_rfi WHERE sender_uid = $1 UNION
  ...etc...
' LANGUAGE 'SQL';

Note that you may get an error about an operator "=$" if you miss the spaces 
around the "=".

HTH

-- 
  Richard Huxton
  Archonet Ltd



view thread (3+ messages)  latest in thread

Message-ID: <200307231513.14574.dev@archonet.com>
Permalink:  ../200307231513.14574.dev@archonet.com/
Also on:    postgresql.org/message-id/200307231513.14574.dev@archonet.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-performance@postgresql.org
  Cc: dev@archonet.com, mallah@trade-india.com
  Subject: Re: factoring problem with view in 7.3.3
  In-Reply-To: <200307231513.14574.dev@archonet.com>
  References: <200307231551.48444.mallah@trade-india.com> <200307231513.14574.dev@archonet.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox