Take collating sequence into account when removing redundant columns from
indexes on WITHOUT ROWID tables. This is the first proof-of-concept fix for ticket [3182d3879020ef3]. More testing needed. FossilOrigin-Name: b34fa5bff40d3d364bd8c80e7de55c606ef3caac47b14b5265ebcb38857eb85e
This commit is contained in:
parent
73c0d272a9
commit
f78d0f426c
18
manifest
18
manifest
@ -1,5 +1,5 @@
|
||||
C Add\sthe\s".recover"\scommand\sto\sthe\sshell\stool.\sFor\srecovering\sas\smuch\sdata\sas\spossible\sfrom\scorrupt\sdatabases.
|
||||
D 2019-04-27T20:30:19.423
|
||||
C Take\scollating\ssequence\sinto\saccount\swhen\sremoving\sredundant\scolumns\sfrom\nindexes\son\sWITHOUT\sROWID\stables.\s\sThis\sis\sthe\sfirst\sproof-of-concept\sfix\nfor\sticket\s[3182d3879020ef3].\sMore\stesting\sneeded.
|
||||
D 2019-04-28T19:27:02.781
|
||||
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
|
||||
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
|
||||
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
|
||||
@ -463,7 +463,7 @@ F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6
|
||||
F src/btree.c ffe7101006aee2ab9e9dec2fc001998e57a8e59419c6ea4072d6c3935d3d50fb
|
||||
F src/btree.h c11446f07ec0e9dc85af8041cb0855c52f5359c8b2a43e47e02a685282504d89
|
||||
F src/btreeInt.h 6111c15868b90669f79081039d19e7ea8674013f907710baa3c814dc3f8bfd3f
|
||||
F src/build.c e9d560fdc39e0f037b1ebd78fde0ff616963646c8d85a7afa18db064c52c5b75
|
||||
F src/build.c 3fedab95ff7a9b3ed51eceb12aaa61de6bbd063dabd276767494cc448a151b7b
|
||||
F src/callback.c 25dda5e1c2334a367b94a64077b1d06b2553369f616261ca6783c48bcb6bda73
|
||||
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
|
||||
F src/ctime.c 109e58d00f62e8e71ee1eb5944ac18b90171c928ab2e082e058056e1137cc20b
|
||||
@ -1821,8 +1821,10 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P 95209072176ff21a91e96d5bd014b35ef100da2b0b93958baf6df4294a8daa85 425d708c3908fe74f69b62e6dd1722a0018088977e12f14b312dad1df0fbb804
|
||||
R f359cf293ea45304e0ddadd16c7a1206
|
||||
T +closed 425d708c3908fe74f69b62e6dd1722a0018088977e12f14b312dad1df0fbb804
|
||||
U dan
|
||||
Z ee7f2d083d1fca64ba3bb33b40a19208
|
||||
P 50fe48458942fa7a6bcc76316c6321f95b23dc34f2f8e0a483826483b2fb16f6
|
||||
R fa5b9567c2bc0a92e3c8181fab56d7f8
|
||||
T *branch * tkt-3182d38790
|
||||
T *sym-tkt-3182d38790 *
|
||||
T -sym-trunk *
|
||||
U drh
|
||||
Z dd82847aa38c87860cc4ec05cc3ab230
|
||||
|
@ -1 +1 @@
|
||||
50fe48458942fa7a6bcc76316c6321f95b23dc34f2f8e0a483826483b2fb16f6
|
||||
b34fa5bff40d3d364bd8c80e7de55c606ef3caac47b14b5265ebcb38857eb85e
|
54
src/build.c
54
src/build.c
@ -1726,10 +1726,46 @@ static void estimateIndexWidth(Index *pIdx){
|
||||
pIdx->szIdxRow = sqlite3LogEst(wIndex*4);
|
||||
}
|
||||
|
||||
/* Return true if value x is found any of the first nCol entries of aiCol[]
|
||||
/* Return true if column number x is any of the first nCol entries of aiCol[].
|
||||
** This is used to determine if the column number x appears in any of the
|
||||
** first nCol entries of an index.
|
||||
*/
|
||||
static int hasColumn(const i16 *aiCol, int nCol, int x){
|
||||
while( nCol-- > 0 ) if( x==*(aiCol++) ) return 1;
|
||||
while( nCol-- > 0 ){
|
||||
assert( aiCol[0]>=0 );
|
||||
if( x==*(aiCol++) ){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
** Return true if any of the first nKey entries of index pIdx1 exactly
|
||||
** match the iCol-th entry of pIdx2.
|
||||
**
|
||||
** The first nKey entries of pIdx1 are guaranteed to be ordinary columns,
|
||||
** not a rowid or expression.
|
||||
**
|
||||
** This routine differs from hasColumn() in that both the column and the
|
||||
** collating sequence must match for this routine, but for hasColumn() only
|
||||
** the column name must match.
|
||||
*/
|
||||
static int isDupColumn(Index *pIdx1, int nKey, Index *pIdx2, int iCol){
|
||||
int i, j;
|
||||
assert( nKey<=pIdx1->nColumn );
|
||||
assert( iCol<MAX(pIdx2->nColumn,pIdx2->nKeyCol) );
|
||||
j = pIdx2->aiColumn[iCol];
|
||||
testcase( j==XN_EXPR );
|
||||
assert( j!=XN_ROWID );
|
||||
for(i=0; i<nKey; i++){
|
||||
assert( pIdx1->aiColumn[i]>=0 || j>=0 );
|
||||
if( pIdx1->aiColumn[i]==j
|
||||
&& sqlite3StrICmp(pIdx1->azColl[i],pIdx2->azColl[iCol])==0
|
||||
){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1835,9 +1871,10 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
||||
** 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]) ){
|
||||
if( isDupColumn(pPk, j, pPk, i) ){
|
||||
pPk->nColumn--;
|
||||
}else{
|
||||
testcase( hasColumn(pPk->aiColumn, j, pPk->aiColumn[i]) );
|
||||
pPk->aiColumn[j++] = pPk->aiColumn[i];
|
||||
}
|
||||
}
|
||||
@ -1867,7 +1904,10 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
||||
int n;
|
||||
if( IsPrimaryKeyIndex(pIdx) ) continue;
|
||||
for(i=n=0; i<nPk; i++){
|
||||
if( !hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) ) n++;
|
||||
if( !isDupColumn(pIdx, pIdx->nKeyCol, pPk, i) ){
|
||||
testcase( hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) );
|
||||
n++;
|
||||
}
|
||||
}
|
||||
if( n==0 ){
|
||||
/* This index is a superset of the primary key */
|
||||
@ -1876,7 +1916,8 @@ static void convertToWithoutRowidTable(Parse *pParse, Table *pTab){
|
||||
}
|
||||
if( resizeIndexObject(db, pIdx, pIdx->nKeyCol+n) ) return;
|
||||
for(i=0, j=pIdx->nKeyCol; i<nPk; i++){
|
||||
if( !hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) ){
|
||||
if( !isDupColumn(pIdx, pIdx->nKeyCol, pPk, i) ){
|
||||
testcase( hasColumn(pIdx->aiColumn, pIdx->nKeyCol, pPk->aiColumn[i]) );
|
||||
pIdx->aiColumn[j] = pPk->aiColumn[i];
|
||||
pIdx->azColl[j] = pPk->azColl[i];
|
||||
j++;
|
||||
@ -3392,9 +3433,10 @@ void sqlite3CreateIndex(
|
||||
for(j=0; j<pPk->nKeyCol; j++){
|
||||
int x = pPk->aiColumn[j];
|
||||
assert( x>=0 );
|
||||
if( hasColumn(pIndex->aiColumn, pIndex->nKeyCol, x) ){
|
||||
if( isDupColumn(pIndex, pIndex->nKeyCol, pPk, j) ){
|
||||
pIndex->nColumn--;
|
||||
}else{
|
||||
testcase( hasColumn(pIndex->aiColumn,pIndex->nKeyCol,x) );
|
||||
pIndex->aiColumn[i] = x;
|
||||
pIndex->azColl[i] = pPk->azColl[j];
|
||||
pIndex->aSortOrder[i] = pPk->aSortOrder[j];
|
||||
|
Loading…
x
Reference in New Issue
Block a user