mirror of
https://github.com/sqlite/sqlite.git
synced 2025-07-30 19:03:16 +03:00
Do not de-duplicate columns index columns associated with a WITHOUT ROWID table
if the columns have different collating sequences. This is the fix for ticket [3182d3879020ef3b2]. There is one test case added, but most of the tests are done in TH3. FossilOrigin-Name: 1b1dd4d48cd79a585e1fa7ee79128e9f2a9ee9846339dc56bbd67b75112dcad5
This commit is contained in:
17
manifest
17
manifest
@ -1,5 +1,5 @@
|
||||
C Fix\sa\sbuffer\soverwrite\sin\sshell.c.in\s(part\sof\sthe\snew\s.recover\scode).
|
||||
D 2019-04-29T11:41:46.359
|
||||
C Do\snot\sde-duplicate\scolumns\sindex\scolumns\sassociated\swith\sa\sWITHOUT\sROWID\stable\nif\sthe\scolumns\shave\sdifferent\scollating\ssequences.\s\sThis\sis\sthe\sfix\sfor\nticket\s[3182d3879020ef3b2].\s\sThere\sis\sone\stest\scase\sadded,\sbut\smost\sof\sthe\ntests\sare\sdone\sin\sTH3.
|
||||
D 2019-04-29T13:48:45.899
|
||||
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 2d9ddfeaf8e1dafc7e1fcc8a84e7a8b455199dac3b69037fc73af6279aa8447b
|
||||
F src/callback.c 25dda5e1c2334a367b94a64077b1d06b2553369f616261ca6783c48bcb6bda73
|
||||
F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
|
||||
F src/ctime.c 109e58d00f62e8e71ee1eb5944ac18b90171c928ab2e082e058056e1137cc20b
|
||||
@ -1707,7 +1707,7 @@ F test/with2.test e0030e2f0267a910d6c0e4f46f2dfe941c1cc0d4f659ba69b3597728e7e8f1
|
||||
F test/with3.test 8d26920c88283e0a473ceebd3451554922108ce7b2a6a1157c47eb0a7011212c
|
||||
F test/with4.test 257be66c0c67fee1defbbac0f685c3465e2cad037f21ce65f23f86084f198205
|
||||
F test/withM.test 693b61765f2b387b5e3e24a4536e2e82de15ff64
|
||||
F test/without_rowid1.test b5ec93f7df2c1d684e0923247dac6aca8888e088bf50a9f244c3933e0e813a72
|
||||
F test/without_rowid1.test 7ac016d20317e36a2f142e960679e558e74f6809ce5f27bde668af01782500df
|
||||
F test/without_rowid2.test af260339f79d13cb220288b67cd287fbcf81ad99
|
||||
F test/without_rowid3.test ea4b59dd1b0d7f5f5e4b7cca978cdb905752a9d7c57dc4344a591dba765a3691
|
||||
F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a
|
||||
@ -1821,7 +1821,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
|
||||
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
|
||||
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
|
||||
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
|
||||
P c621fc668c6538f9f5bdac204f012c64998679a61aa8e224d212503820224c09
|
||||
R fab7a84bb2576871c69ae5af2474d189
|
||||
U dan
|
||||
Z 238bfca672a6077522e49009580b426a
|
||||
P 92facbc73a940d2844ac88fafd2d2dadb10886fb0b7c53e23f346d18fa6d6327 740d5ff6cc9bf7b151dfb8b27409e5923cfb2789b5398fe13d89563aff8ffc07
|
||||
R 202811e2e95855247d322c66d5116799
|
||||
T +closed 740d5ff6cc9bf7b151dfb8b27409e5923cfb2789b5398fe13d89563aff8ffc07
|
||||
U drh
|
||||
Z b55be1ccaf3a50c1a3ba7b999ad660d8
|
||||
|
@ -1 +1 @@
|
||||
92facbc73a940d2844ac88fafd2d2dadb10886fb0b7c53e23f346d18fa6d6327
|
||||
1b1dd4d48cd79a585e1fa7ee79128e9f2a9ee9846339dc56bbd67b75112dcad5
|
59
src/build.c
59
src/build.c
@ -1726,10 +1726,51 @@ 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 pIdx exactly
|
||||
** match the iCol-th entry of pPk. pPk is always a WITHOUT ROWID
|
||||
** PRIMARY KEY index. pIdx is an index on the same table. pIdx may
|
||||
** or may not be the same index as pPk.
|
||||
**
|
||||
** The first nKey entries of pIdx 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 *pIdx, int nKey, Index *pPk, int iCol){
|
||||
int i, j;
|
||||
assert( nKey<=pIdx->nColumn );
|
||||
assert( iCol<MAX(pPk->nColumn,pPk->nKeyCol) );
|
||||
assert( pPk->idxType==SQLITE_IDXTYPE_PRIMARYKEY );
|
||||
assert( pPk->pTable->tabFlags & TF_WithoutRowid );
|
||||
assert( pPk->pTable==pIdx->pTable );
|
||||
testcase( pPk==pIdx );
|
||||
j = pPk->aiColumn[iCol];
|
||||
assert( j!=XN_ROWID && j!=XN_EXPR );
|
||||
for(i=0; i<nKey; i++){
|
||||
assert( pIdx->aiColumn[i]>=0 || j>=0 );
|
||||
if( pIdx->aiColumn[i]==j
|
||||
&& sqlite3StrICmp(pIdx->azColl[i], pPk->azColl[iCol])==0
|
||||
){
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -1835,9 +1876,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 +1909,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 +1921,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 +3438,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];
|
||||
|
@ -391,5 +391,13 @@ do_execsql_test 10.6 {
|
||||
SELECT * FROM t1;
|
||||
} {b a 3 b b 4}
|
||||
|
||||
# 2019-04-29 ticket https://www.sqlite.org/src/info/3182d3879020ef3
|
||||
do_execsql_test 11.1 {
|
||||
CREATE TABLE t11(a TEXT PRIMARY KEY, b INT) WITHOUT ROWID;
|
||||
CREATE INDEX t11a ON t11(a COLLATE NOCASE);
|
||||
INSERT INTO t11(a,b) VALUES ('A',1),('a',2);
|
||||
PRAGMA integrity_check;
|
||||
SELECT a FROM t11 ORDER BY a COLLATE binary;
|
||||
} {ok A a}
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user