pg.ddx.io  pgsql-performance@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Robert Haas <robertmhaas@gmail.com>
To: Matthew Wakeling <matthew@flymine.org>
Cc: pgsql-performance@postgresql.org
Subject: Re: Rewriting using rules for performance
Date: Fri, 3 Apr 2009 09:46:32 -0400
Message-ID: <603c8f070904030646u654f4cbbh92e7b42180fa04d0@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.00.0904031413560.21772@aragorn.flymine.org>
References: <alpine.DEB.2.00.0904031413560.21772@aragorn.flymine.org>

On Fri, Apr 3, 2009 at 9:17 AM, Matthew Wakeling <matthew@flymine.org> wrote:
> So, I have a view. The query that the view uses can be written two different
> ways, to use two different indexes. Then I use the view in another query,
> under some circumstances the first way will be quick, and under other
> circumstances the second way will be quick.
>
> What I want to know is, can I create a view that has both queries, and
> allows the planner to choose which one to use? The documentation seems to
> say so in http://www.postgresql.org/docs/8.3/interactive/querytree.html (the
> rule system "creates zero or more query trees as result"), but doesn't say
> how one would do it.

I think this would be clearer if you gave an actual example of what
you're trying to accomplish, but the short answer is "no".  The rule
system lets you create multiple query trees to perform multiple
actions (for example, when an INSERT command is issued, do the
original insert plus also an update) and it implements views.  But
it's independent of query planning.

On the other hand, the query planner should be figuring out which
index to use without any help from you.  If it's not, something is
wrong.

...Robert



view thread (5+ messages)  latest in thread

Message-ID: <603c8f070904030646u654f4cbbh92e7b42180fa04d0@mail.gmail.com>
Permalink:  ../603c8f070904030646u654f4cbbh92e7b42180fa04d0@mail.gmail.com/
Also on:    postgresql.org/message-id/603c8f070904030646u654f4cbbh92e7b42180fa04d0@mail.gmail.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 using the --to and --cc options:
  reply via email

  To: pgsql-performance@postgresql.org
  Cc: robertmhaas@gmail.com, matthew@flymine.org
  Subject: Re: Rewriting using rules for performance
  In-Reply-To: <603c8f070904030646u654f4cbbh92e7b42180fa04d0@mail.gmail.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