Thread: Foreign Key written as a trigger

Foreign Key written as a trigger

From
"George Woodring"
Date:
I have a database that has been upgrade numerous times (Started about
7.1 and is not 7.4.8).  The table has 2 foreign keys on it, but when I
look at the table I see that the FK applied before 7.4.X is written as a
trigger.  Everything seems to work, I was just wondering if there are
any performance reasons to change the trigger to a FK.


issp=> \d notpoll
      Table "public.notpoll"
   Column    |  Type   | Modifiers
-------------+---------+-----------
 notpollid   | integer | not null
 pollgrpid   | integer |
 notgroupsid | integer |
Indexes:
    "notpoll_pkey" primary key, btree (notpollid)
    "notpoll_pollgrpid_key" unique, btree (pollgrpid)
Foreign-key constraints:
    "pollgrp_exists" FOREIGN KEY (pollgrpid) REFERENCES
pollgrpinfo(pollgrpid) ON DELETE CASCADE
Triggers:
    "RI_ConstraintTrigger_2137396" AFTER INSERT OR UPDATE ON notpoll
FROM notgroups NOT DEFERRABLE INITIALLY IMMEDIATE FOR EACH ROW EXECUTE
PROCEDURE "RI_FKey_check_ins"('notgroups_exists', 'notpoll',
'notgroups', 'UNSPECIFIED', 'notgroupsid', 'notgroupsid')


Thanks,
Woody

----------------------------------------
iGLASS Networks
211-A S. Salem St
Apex NC 27502
(919) 387-3550 x813
www.iglass.net

Re: Foreign Key written as a trigger

From
Tom Lane
Date:
"George Woodring" <george.woodring@iglass.net> writes:
> I have a database that has been upgrade numerous times (Started about
> 7.1 and is not 7.4.8).  The table has 2 foreign keys on it, but when I
> look at the table I see that the FK applied before 7.4.X is written as a
> trigger.  Everything seems to work, I was just wondering if there are
> any performance reasons to change the trigger to a FK.

I don't think it would have any performance impact, but it'd definitely
be more future-proof to hide the triggers.  See contrib/adddepend for
a possibly helpful tool.

            regards, tom lane