pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Heni Lolov <hal_bg@yahoo.com>
To: pgsql-admin@postgresql.org
Subject: Indexes and outer join?
Date: Mon, 4 Mar 2002 03:11:04 -0800 (PST)
Message-ID: <20020304111104.2621.qmail@web21005.mail.yahoo.com> (raw)

Hi!
I have the the folowing objects:

CREATE TABLE sao(
	id INT4,
	type VARCHAR,
	ra  INT4,
	de INT4,
	mag INT2
);

create index sao_drm on sao(de,ra,mag);
create index sao_dm on sao(de,mag);
create index sao_i on sao(id);

CREATE TABLE tycho(
	reg_id INT2,
	id INT2,
	ci INT2,
	ra  INT4,
	de INT4,
	mag INT2,
	hip INT4,
	ppm INT4,
	hd INT4,
	bd VARCHAR
);

create index tycho_drm on tycho(de,ra,mag);
create index tycho_dm on tycho(de,mag);
create index tycho_iic on tycho(reg_id,id,ci);
create index tycho_p on tycho(ppm);
create index tycho_h on tycho(hd);
create index tycho_b on tycho(bd);

CREATE VIEW tyc_glup AS 
	SELECT sao.id,sao.type,tycho.ra,tycho.de,tycho.mag 
	FROM tycho LEFT OUTER JOIN sao 
	ON (tycho.ppm=sao.id);

=================================
explain select * 
from tyc_glup 
where de>0 and de<1000000 and ra<100000 and ra>0;

NOTICE:  QUERY PLAN:

Merge Join  (cost=42975.66..44050.21 rows=34159 width=50)
  ->  Sort  (cost=108.53..108.53 rows=26 width=14)
        ->  Index Scan using tycho_drm on tycho  (cost=0.00..107.90 rows=26
width=14)
  ->  Sort  (cost=42867.14..42867.14 rows=258997 width=36)
        ->  Seq Scan on sao  (cost=0.00..4609.97 rows=258997 width=36)

EXPLAIN
=================================
explain select sao.id,sao.type,tycho.ra,tycho.de,tycho.mag from tycho,sao where
tycho.ppm=sao.id;
NOTICE:  QUERY PLAN:

Merge Join  (cost=238805.10..17321566.61 rows=1366358098 width=50)
  ->  Sort  (cost=195937.97..195937.97 rows=1055115 width=14)
        ->  Seq Scan on tycho  (cost=0.00..19099.15 rows=1055115 width=14)
  ->  Sort  (cost=42867.14..42867.14 rows=258997 width=36)
        ->  Seq Scan on sao  (cost=0.00..4609.97 rows=258997 width=36)

EXPLAIN
==================================

So is there any way to force sao_i index use on sao table and how? The tables
are large and the query takes too much time. 

Thanks in advance!

Rumen





__________________________________________________
Do You Yahoo!?
Yahoo! Sports - sign up for Fantasy Baseball
http://sports.yahoo.com



view thread (2+ messages)  latest in thread

Message-ID: <20020304111104.2621.qmail@web21005.mail.yahoo.com>
Permalink:  ../20020304111104.2621.qmail@web21005.mail.yahoo.com/
Also on:    postgresql.org/message-id/20020304111104.2621.qmail@web21005.mail.yahoo.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-admin@postgresql.org
  Cc: hal_bg@yahoo.com
  Subject: Re: Indexes and outer join?
  In-Reply-To: <20020304111104.2621.qmail@web21005.mail.yahoo.com>
  References: <20020304111104.2621.qmail@web21005.mail.yahoo.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