BUG (fixed) in CREATE TABLE ADD CONSTRAINT...(v-7.0.2)

From: jozzano <jozzano(at)exa(dot)unicen(dot)edu(dot)ar>
To: pgsql-hackers(at)postgresql(dot)org
Subject: BUG (fixed) in CREATE TABLE ADD CONSTRAINT...(v-7.0.2)
Date: 2001-07-20 09:23:16
Message-ID: 22811077.995620996783.JavaMail.webmail@mail.exa.unicen.edu.ar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi !
My system is i686/Linux Mandrake 7.0/Postgresql v-7.0.2.
I found a bug in the sql command ALTER TABLE ADD CONSTRAINT..., when I tried to add a composite foreign key constraint
(a FK with more than one attribute). The problem is in the file identified by
$Header: /home/projects/pgsql/cvsroot/pgsql/src/backend/commands/command.c,v 1.71 2000/04/12 17:14:57 momjian Exp $
in the code lines #1139 to #1150, when the function AlterTableAddConstraint() tries to construct the vector of the triggers tgargs.
>From the position 4 and forward, it must collect the pairs of fk_attrs and pk_attrs (interleaved), but the current code put first all
fk_attrs and then all the pk_attrs, leading to an error.
I fixed the bug and tested the update and now it works well. I send you a "diff -c command.c command.fixed.c" (with the diff :
GNU diffutils version 2.7) and the output is:

*** command.c Sun May 6 21:13:06 2001
--- command.fixed.c Mon Jul 9 19:58:21 2001
***************
*** 19,24 ****
--- 19,25 ----
* manipulating code in the commands/ directory, should go
* someplace closer to the lib/catalog code.
*
+ *
*-------------------------------------------------------------------------
*/
#include "postgres.h"
***************
*** 1138,1152 ****
{
Ident *fk_at = lfirst(list);

! trig.tgargs[count++] = fk_at->name;
}
foreach(list, fkconstraint->pk_attrs)
{
Ident *pk_at = lfirst(list);

! trig.tgargs[count++] = pk_at->name;
}
! trig.tgnargs = count;

scan = heap_beginscan(rel, false, SnapshotNow, 0, NULL);
AssertState(scan != NULL);
--- 1139,1156 ----
{
Ident *fk_at = lfirst(list);

! trig.tgargs[count] = fk_at->name;
! count+=2;
}
+ count = 5;
foreach(list, fkconstraint->pk_attrs)
{
Ident *pk_at = lfirst(list);

! trig.tgargs[count] = pk_at->name;
! count+=2;
}
! trig.tgnargs = (count-1);

scan = heap_beginscan(rel, false, SnapshotNow, 0, NULL);
AssertState(scan != NULL);
***************
*** 1220,1223 ****
LockRelation(rel, lockstmt->mode);

heap_close(rel, NoLock); /* close rel, keep lock */
! }
--- 1224,1227 ----
LockRelation(rel, lockstmt->mode);

heap_close(rel, NoLock); /* close rel, keep lock */
! }

I wish it would help you. If its necessary, drop me a line. Regards
Jose Luis Ozzano.

(P.D.: I attached the messaje in a file edited in LINUX. Maybe you have problems to read the original text)
>From pgsql-hackers-owner(at)postgresql(dot)org Fri Jul 20 13:55:40 2001
Received: from postgresql.org.org (webmail.postgresql.org [216.126.85.28])
by postgresql.org (8.11.3/8.11.1) with SMTP id f6KGs6a95467
for <pgsql-hackers(at)postgresql(dot)org>; Fri, 20 Jul 2001 12:54:06 -0400 (EDT)
(envelope-from pgsql-hackers-owner(at)postgresql(dot)org)
Received: from news.tht.net (news.hub.org [216.126.91.242])
by postgresql.org (8.11.3/8.11.1) with ESMTP id f6IDVAa53796;
Wed, 18 Jul 2001 09:31:10 -0400 (EDT)
(envelope-from news(at)news(dot)tht(dot)net)
Received: (from news(at)localhost)
by news.tht.net (8.11.4/8.11.4) id f6IDMm486418;
Wed, 18 Jul 2001 09:22:48 -0400 (EDT)
(envelope-from news)
Message-ID: <3B558D0C(dot)E046E8A6(at)wafishermn(dot)com>
From: Justin Koivisto <justink(at)wafishermn(dot)com>
X-Mailer: Mozilla 4.73 [en] (X11; U; Linux 2.4.5 i686)
X-Accept-Language: en
MIME-Version: 1.0
X-Newsgroups: php.general,alt.php,ba.php,de.comp.lang.php,fr.comp.infosystemes.www.auteurs.php,comp.lang.perl.tk,comp.databases.postgresql.general,comp.databases.postgresql.hackers,comp.databases.postgresql.questions,mailing.database.mysql
Subject: Re: All computers in the world MUST sync with ATOMIC clock before 12:00
AM 21 July 2001!!!
References: <3B54F80B(dot)C5DC2979(at)yahoo(dot)com>
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Lines: 1
Date: Wed, 18 Jul 2001 13:22:47 GMT
X-Complaints-To: abuse(at)onvoy(dot)com
Organization: Onvoy
To: pgsql-hackers(at)postgresql(dot)org(dot)pgsql-general@postgresql.org
X-Archive-Number: 200107/577
X-Sequence-Number: 11396

Just another way to get your name on the top 10 lists, eh?

Browse pgsql-hackers by date

  From Date Subject
Next Message jozzano 2001-07-20 09:27:19 BUG (fixed) in CREATE TABLE ADD CONSTRAINT...(v-7.0.2)
Previous Message Alessio Bragadini 2001-07-20 08:10:32 Re: OID wraparound (was Re: pg_depend)