From: Martin Schäfer <Martin.Schaefer@cadcorp.com>
To: Richard Huxton <dev@archonet.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Find out whether a view's column is indexed?
Date: Thu, 10 Jun 2004 14:48:33 +0100
Message-ID: <37936EEC582B394A9E1AA951991A551604C3C0@dev001_pdc.Dev.cadcorp.net> (raw)
I think the information_schema.view_column_usage doesn't tell me which view column is based on which table column, it only says generally which set of table/view columns are used for the view as a whole.
I need a bit more detailed information. If I have two views defined as this:
CREATE VIEW v1 AS SELECT a,b,c FROM t;
CREATE VIEW v2 AS SELECT b AS a,a AS b,c FROM t;
then their entries in view_column_usage is identical, but it is entirely possible that e.g. v1.a is indexed, but v2.a is not indexed.
I can do
EXPLAIN SELECT * FROM v2 WHERE a = 'foo';
and I can see whether a sequential scan or an index scan is performed, but parsing the output of EXPLAIN programmatically is nearly impossible. Anyway the words 'Index Scan' and 'Seq Scan' can change without notice, maybe even from one locale to another.
Martin
> -----Original Message-----
> From: Richard Huxton [mailto:dev@archonet.com]
>
> Martin Schäfer wrote:
> > Is there any way to find out whether a column that's used
> in a view is indexed?
> >
> > The following query:
> >
> > SELECT ic.relname AS index_name
> [snip]
> > lets me find out whether a table column is indexed, but it
> doesn't work for views. Is there anything that can be done
> for views? At least for simple views of the kind 'CREATE VIEW
> v AS SELECT a,b,c FROM t'?
>
> If you're running 7.4 you can look in the information schema, in
> view_column_usage - that will tell you which table-columns a
> view uses.
>
>
> --
> Richard Huxton
> Archonet Ltd
>
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-sql@postgresql.org
Cc: Martin.Schaefer@cadcorp.com, dev@archonet.com
Subject: Re: Find out whether a view's column is indexed?
In-Reply-To: <37936EEC582B394A9E1AA951991A551604C3C0@dev001_pdc.Dev.cadcorp.net>
References: <37936EEC582B394A9E1AA951991A551604C3C0@dev001_pdc.Dev.cadcorp.net>
* 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