[HACKERS] Silent bug in transformIndexConstraint - Mailing list pgsql-hackers

From Serge Rielau
Subject [HACKERS] Silent bug in transformIndexConstraint
Date
Msg-id 6d911319-5207-46a4-b6aa-6432bb96c896@rielau.com
Whole thread Raw
Responses Re: [HACKERS] Silent bug in transformIndexConstraint  (Serge Rielau <serge@rielau.com>)
List pgsql-hackers
In parse_utilcmd.c: transformIndexConstraint()
resides the following piece of code:


/*
* For UNIQUE and PRIMARY KEY, we just have a list of column names.
*
* Make sure referenced keys exist.  If we are making a PRIMARY KEY index,
* also make sure they are NOT NULL, if possible. (Although we could leave
* it to DefineIndex to mark the columns NOT NULL, it's more efficient to
* get it right the first time.)
*/
foreach(lc, constraint->keys)
{
char   *key = strVal(lfirst(lc));

The strVal() is wrong since first(lc) returns an IndexElem * and not a Value *
and we should be doing:
char *key = ((IndexElem *) lfirst(lc))->name

The existing code only works by luck because Value.val.str  happens to match the same offset as IndexElem.name.

pgsql-hackers by date:

Previous
From: Mark Rofail
Date:
Subject: Re: [HACKERS] GSoC 2017: Foreign Key Arrays
Next
From: Josh Berkus
Date:
Subject: Re: [HACKERS] Quorum commit for multiple synchronous replication.