mirror of
https://github.com/postgres/postgres.git
synced 2025-07-07 00:36:50 +03:00
Repair the check for redundant UNIQUE and PRIMARY KEY indices.
Also, improve it so that it checks for multi-column constraints. Thanks to Mark Dalphin <mdalphin@amgen.com> for reporting the problem.
This commit is contained in:
@ -5,7 +5,7 @@
|
|||||||
*
|
*
|
||||||
* Copyright (c) 1994, Regents of the University of California
|
* Copyright (c) 1994, Regents of the University of California
|
||||||
*
|
*
|
||||||
* $Id: analyze.c,v 1.116 1999/07/19 00:26:18 tgl Exp $
|
* $Id: analyze.c,v 1.117 1999/08/15 06:46:49 thomas Exp $
|
||||||
*
|
*
|
||||||
*-------------------------------------------------------------------------
|
*-------------------------------------------------------------------------
|
||||||
*/
|
*/
|
||||||
@ -579,6 +579,9 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
|
|||||||
columns = NIL;
|
columns = NIL;
|
||||||
dlist = NIL;
|
dlist = NIL;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Run through each primary element in the table creation clause
|
||||||
|
*/
|
||||||
while (elements != NIL)
|
while (elements != NIL)
|
||||||
{
|
{
|
||||||
element = lfirst(elements);
|
element = lfirst(elements);
|
||||||
@ -588,6 +591,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
|
|||||||
column = (ColumnDef *) element;
|
column = (ColumnDef *) element;
|
||||||
columns = lappend(columns, column);
|
columns = lappend(columns, column);
|
||||||
|
|
||||||
|
/* Special case SERIAL type? */
|
||||||
if (column->is_sequence)
|
if (column->is_sequence)
|
||||||
{
|
{
|
||||||
char *sname;
|
char *sname;
|
||||||
@ -625,6 +629,7 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
|
|||||||
blist = lcons(sequence, NIL);
|
blist = lcons(sequence, NIL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Check for column constraints, if any... */
|
||||||
if (column->constraints != NIL)
|
if (column->constraints != NIL)
|
||||||
{
|
{
|
||||||
clist = column->constraints;
|
clist = column->constraints;
|
||||||
@ -815,28 +820,43 @@ transformCreateStmt(ParseState *pstate, CreateStmt *stmt)
|
|||||||
* or if a SERIAL column was defined along with a table PRIMARY KEY constraint.
|
* or if a SERIAL column was defined along with a table PRIMARY KEY constraint.
|
||||||
* - thomas 1999-05-11
|
* - thomas 1999-05-11
|
||||||
*/
|
*/
|
||||||
if ((pkey != NULL) && (length(lfirst(pkey->indexParams)) == 1))
|
if (pkey != NULL)
|
||||||
{
|
{
|
||||||
dlist = ilist;
|
dlist = ilist;
|
||||||
ilist = NIL;
|
ilist = NIL;
|
||||||
while (dlist != NIL)
|
while (dlist != NIL)
|
||||||
{
|
{
|
||||||
int keep = TRUE;
|
List *pcols, *icols;
|
||||||
|
int plen, ilen;
|
||||||
|
int keep = TRUE;
|
||||||
|
|
||||||
index = lfirst(dlist);
|
index = lfirst(dlist);
|
||||||
|
pcols = pkey->indexParams;
|
||||||
|
icols = index->indexParams;
|
||||||
|
|
||||||
/*
|
plen = length(pcols);
|
||||||
* has a single column argument, so might be a conflicting
|
ilen = length(icols);
|
||||||
* index...
|
|
||||||
*/
|
/* Not the same as the primary key? Then we should look... */
|
||||||
if ((index != pkey)
|
if ((index != pkey) && (ilen == plen))
|
||||||
&& (length(index->indexParams) == 1))
|
|
||||||
{
|
{
|
||||||
char *pname = ((IndexElem *) lfirst(index->indexParams))->name;
|
keep = FALSE;
|
||||||
char *iname = ((IndexElem *) lfirst(index->indexParams))->name;
|
while ((pcols != NIL) && (icols != NIL))
|
||||||
|
{
|
||||||
|
IndexElem *pcol = lfirst(pcols);
|
||||||
|
IndexElem *icol = lfirst(icols);
|
||||||
|
char *pname = pcol->name;
|
||||||
|
char *iname = icol->name;
|
||||||
|
|
||||||
/* same names? then don't keep... */
|
/* different names? then no match... */
|
||||||
keep = (strcmp(iname, pname) != 0);
|
if (strcmp(iname, pname) != 0)
|
||||||
|
{
|
||||||
|
keep = TRUE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
pcols = lnext(pcols);
|
||||||
|
icols = lnext(icols);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keep)
|
if (keep)
|
||||||
|
Reference in New Issue
Block a user