Forum OpenACS Development: Re: Problems with indexes on foreign key columns

Collapse
Posted by Jon Griffin on
Jeff,
Are you sure that this is a problem in PG? I thought that it automatically created a key for any foreign references?
Collapse
Posted by Jeff Davis on
Jon, it creates triggers automatically but not indexes (except for unique constraints or primary keys). The performance problems I found were on postgres (and its a well known problem on oracle).

anyway here is an example...


oatest4=# create table a ( i integer primary key, j integer not null);
NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index 'a_pkey' for table 'a'
CREATE
oatest4=# \d a
          Table "a"
 Column |  Type   | Modifiers 
--------+---------+-----------
 i      | integer | not null
 j      | integer | not null
Primary key: a_pkey

oatest4=# create table b(k integer references a(i));
NOTICE:  CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
CREATE
oatest4=# \d b
          Table "b"
 Column |  Type   | Modifiers 
--------+---------+-----------
 k      | integer | 
Triggers: RI_ConstraintTrigger_7737891

oatest4=# create table c(k  integer unique references a(i));
NOTICE:  CREATE TABLE / UNIQUE will create implicit index 'c_k_key' for table 'c'
NOTICE:  CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
CREATE
oatest4=# \d c
          Table "c"
 Column |  Type   | Modifiers 
--------+---------+-----------
 k      | integer | 
Unique keys: c_k_key
Triggers: RI_ConstraintTrigger_7737906