Thread: [HACKERS] Silent bug in transformIndexConstraint

[HACKERS] Silent bug in transformIndexConstraint

From
Serge Rielau
Date:
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.

Re: [HACKERS] Silent bug in transformIndexConstraint

From
Serge Rielau
Date:
Never mind. I take that back. The problem is not in community code.

Cheers
Serge