Unix Technical Forum

How to find out programmatically whether a query on a view will use an index?

This is a discussion on How to find out programmatically whether a query on a view will use an index? within the pgsql Sql forums, part of the PostgreSQL category; --> Hi, I'm using the PostGIS spatial extension. Some of my spatial queries (like live zooming and panning) should only ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 11:52 AM
=?iso-8859-1?Q?Martin_Sch=E4fer?=
 
Posts: n/a
Default How to find out programmatically whether a query on a view will use an index?

Hi,

I'm using the PostGIS spatial extension. Some of my spatial queries (like
live zooming and panning) should only be performed when the column
containing the spatial data is spatially indexed, otherwise the first query
takes almost forever and users will just kill the application out of
frustration.

I can easily find out whether a spatial column in a table is spatially
indexed, using pg_class, pg_index, and pg_opclass. But this doesn't work for
views. I can't find out whether a column in a view, is just an 'exact copy'
of a column in a table (indicating that there's a chance that an index on
the table column could be used for a query on the view column), or whether
the column in the view defines some kind of operation, rendering any
possible index on the table column useless.

From information_schema.view_column_usage I can see which columns of which
tables are referenced by the view, but it doesn't tell me whether an index
on a column in the table would be used for a query on the view.

Using 'EXPLAIN SELECT ...' does tell me whether the spatial index is used,
but the output is not machine readable. I guess the output is localized to
the current locale, so trying to parse the output doesn't seem to be a good
idea. Is there no way to get a machine readable query plan?

Any help appreciated,

Martin

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 11:53 AM
Bruno Wolff III
 
Posts: n/a
Default Re: How to find out programmatically whether a query on a view will use an index?

On Mon, Jan 24, 2005 at 16:34:09 -0000,
Martin Schäfer <Martin.Schaefer@cadcorp.com> wrote:
>
> I'm using the PostGIS spatial extension. Some of my spatial queries (like
> live zooming and panning) should only be performed when the column
> containing the spatial data is spatially indexed, otherwise the first query
> takes almost forever and users will just kill the application out of
> frustration.


If the real problem is long running queries, maybe using a statement timeout
will solve your problem?

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 06:46 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com