1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-19 21:43:15 +03:00

Fix WITHOUT ROWID tables so that they correctly deal with PRIMARY KEYs that

contain redundant columns.

FossilOrigin-Name: 0dfef6757056ef0bdea8f049f7469ccf6960e2cb
This commit is contained in:
drh
2014-12-28 22:10:51 +00:00
parent 0ab0e05c6b
commit e385d8876e
4 changed files with 62 additions and 7 deletions

View File

@@ -1713,6 +1713,19 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
pTab->iPKey = -1;
}else{
pPk = sqlite3PrimaryKeyIndex(pTab);
/*
** Remove all redundant columns from the PRIMARY KEY. For example, change
** "PRIMARY KEY(a,b,a,b,c,b,c,d)" into just "PRIMARY KEY(a,b,c,d)". Later
** code assumes the PRIMARY KEY contains no repeated columns.
*/
for(i=j=1; i<pPk->nKeyCol; i++){
if( hasColumn(pPk->aiColumn, j, pPk->aiColumn[i]) ){
pPk->nColumn--;
}else{
pPk->aiColumn[j++] = pPk->aiColumn[i];
}
}
pPk->nKeyCol = j;
}
pPk->isCovering = 1;
assert( pPk!=0 );