[GENERAL] Postgres 8.3 is not using indexes

2008-08-14 Thread Clemens Schwaighofer
Hi,

i just stumbled on something very strange.

I have here a Postgres 8.3 and a Postgres 8.2 installation, as I am in
the process of merging. Both are from the debian/testing tree, both have
the same configuration file.

In my DB where I found out this trouble I have two tables, I do a very
simple join over both. The foreign key in the second table has an index.

Postgres 8.2 gives me this out:

explain SELECT DISTINCT email  FROM email e, email_group eg WHERE
e.email_group_id = eg.email_group_i
 QUERY PLAN
--
 Unique  (cost=65.16..66.81 rows=85 width=27)
   -  Sort  (cost=65.16..65.98 rows=330 width=27)
 Sort Key: e.email
 -  Merge Join  (cost=0.00..51.35 rows=330 width=27)
   Merge Cond: (eg.email_group_id = e.email_group_id)
   -  Index Scan using email_group_pkey on email_group eg
(cost=0.00..12.91 rows=44 width=4)
   -  Index Scan using idx_email_email_group_id on email e
 (cost=0.00..34.21 rows=330 width=31)

Postgres 8.3 returns this:


explain SELECT DISTINCT email  FROM email e, email_group eg WHERE
e.email_group_id = eg.email_group_id;
  QUERY PLAN
---
 Unique  (cost=268688.95..274975.13 rows=51213 width=26)
   -  Sort  (cost=268688.95..271832.04 rows=1257236 width=26)
 Sort Key: e.email
 -  Hash Join  (cost=2.12..85452.48 rows=1257236 width=26)
   Hash Cond: (e.email_group_id = eg.email_group_id)
   -  Seq Scan on email e  (cost=0.00..68163.36
rows=1257236 width=30)
   -  Hash  (cost=1.50..1.50 rows=50 width=4)
 -  Seq Scan on email_group eg  (cost=0.00..1.50
rows=50 width=4)

I have reindexed the tables, vacuum (analyze) the whole DB, checked the
config if there are some settings different. But I am at a loss here.
Why is Postgres not using the indexes in the 8.3 installation.

I tried this on a different DB on the same server and on a different
server and I always get seq_scan back and never the usage of the index.

Any tips why this is so?

-- 
[ Clemens Schwaighofer  -=:~ ]
[ IT Engineer/Manager]
[ E-Graphics Communications, TEQUILA\ Japan IT Group ]
[6-17-2 Ginza Chuo-ku, Tokyo 104-8167, JAPAN ]
[ Tel: +81-(0)3-3545-7706Fax: +81-(0)3-3545-7343 ]
[ http://www.tequila.jp  ]

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Postgres 8.3 is not using indexes

2008-08-14 Thread Peter Eisentraut
Am Thursday, 14. August 2008 schrieb Clemens Schwaighofer:
 Why is Postgres not using the indexes in the 8.3 installation.

Might have something to do with the removal of some implicit casts.  You 
should show us your table definitions.

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Postgres 8.3 is not using indexes

2008-08-14 Thread Gregory Stark
Clemens Schwaighofer [EMAIL PROTECTED] writes:

 Any tips why this is so?

They don't appear to contain the same data. 
If they do have you run analyze recently?

-- 
  Gregory Stark
  EnterpriseDB  http://www.enterprisedb.com
  Ask me about EnterpriseDB's PostGIS support!

-- 
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


Re: [GENERAL] Postgres 8.3 is not using indexes

2008-08-14 Thread Schwaighofer Clemens
On Thu, Aug 14, 2008 at 20:27, Peter Eisentraut [EMAIL PROTECTED] wrote:

 Am Thursday, 14. August 2008 schrieb Clemens Schwaighofer:
  Why is Postgres not using the indexes in the 8.3 installation.

 Might have something to do with the removal of some implicit casts.  You
 should show us your table definitions.


email table:

  Table public.email
 Column |Type |
Modifiers
+-+--
 row_status | integer |
 date_created   | timestamp without time zone | default now()
 date_updated   | timestamp without time zone |
 user_created   | character varying(25)   | default current_user()
 user_updated   | character varying(25)   |
 email_id   | integer | not null default
nextval('email_email_id_seq'::regclass)
 email_group_id | integer | not null
 email  | character varying   |
 status | smallint| default 0
 custom_field_1 | character varying   |
 custom_field_2 | character varying   |
 custom_field_3 | character varying   |
 custom_field_4 | character varying   |
 custom_field_5 | character varying   |
 custom_field_6 | character varying   |
 custom_field_7 | character varying   |
 custom_field_8 | character varying   |
 custom_field_9 | character varying   |
 delete_mark| smallint|
 checked_count  | integer | default 0
 error_count| integer | default 0
 error_flag | smallint| default 0
 key| character varying   |
 type   | character varying   |
Indexes:
email_pkey PRIMARY KEY, btree (email_id)
idx_email_email btree (email)
idx_email_email_group_id btree (email_group_id)
idx_email_status btree (status)
Foreign-key constraints:
email_email_group_id_fkey FOREIGN KEY (email_group_id) REFERENCES
email_group(email_group_id) MATCH FULL ON UPDATE CASCADE ON DELETE CASCADE
Triggers:
trg_email BEFORE INSERT OR UPDATE ON email FOR EACH ROW EXECUTE
PROCEDURE set_generic()
Inherits: generic

email_group table:

   Table public.email_group
   Column   |Type
|  Modifiers
+-+--
 row_status | integer |
 date_created   | timestamp without time zone | default now()
 date_updated   | timestamp without time zone |
 user_created   | character varying(25)   | default current_user()
 user_updated   | character varying(25)   |
 email_group_id | integer | not null default
nextval('email_group_email_group_id_seq'::regclass)
 pre_email_group_id | integer |
 edit_access_id | integer | not null
 name   | character varying   | not null
 group_type | smallint|
 count  | integer |
 bad_count  | integer |
 hidden | smallint| default 0
Indexes:
email_group_pkey PRIMARY KEY, btree (email_group_id)
idx_email_group_edit_access_id btree (edit_access_id)
idx_email_group_pre_email_group_id btree (pre_email_group_id)
Foreign-key constraints:
email_group_edit_access_id_fkey FOREIGN KEY (edit_access_id)
REFERENCES edit_access(edit_access_id) MATCH FULL ON UPDATE CASCADE ON
DELETE RESTRICT
email_group_pre_email_group_id_fkey FOREIGN KEY (pre_email_group_id)
REFERENCES email_group(email_group_id) MATCH FULL ON UPDATE CASCADE ON
DELETE CASCADE
Triggers:
trg_email_group BEFORE INSERT OR UPDATE ON email_group FOR EACH ROW
EXECUTE PROCEDURE set_generic()
Inherits: generic


-- 
[ Clemens Schwaighofer -=:~ ]
[ IT Engineer/Manager ]
[ E-Graphics Communications, TEQUILA\ Japan IT Group ]
[ 6-17-2 Ginza Chuo-ku, Tokyo 104-8167, JAPAN ]
[ Tel: +81-(0)3-3545-7703 Fax: +81-(0)3-3545-7343 ]
[ http://www.tequila.jp ]





This e-mail is intended only for the named person or entity to which 
it is addressed and contains valuable business information that is 
privileged, confidential and/or otherwise protected from disclosure.  
Dissemination, distribution or copying of this e-mail or the 
information herein by anyone other than the intended recipient, or 
an employee or agent responsible for delivering the message to the 
intended recipient, is strictly prohibited.  All contents are the 
copyright property of TBWA Worldwide, its agencies or a client of 
such agencies. If you are not the intended recipient, you are 
nevertheless bound to respect the worldwide legal rights