From: drh Date: Fri, 4 Sep 2015 13:02:21 +0000 (+0000) Subject: Merge trunk enhancements, and espeically the fix for allowing strings X-Git-Tag: version-3.9.0~150^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fheads%2Findex-expr;p=thirdparty%2Fsqlite.git Merge trunk enhancements, and espeically the fix for allowing strings as column identifers in CREATE INDEX statements. FossilOrigin-Name: 5ff855293865c244ac632c630e8e7e8d7c05a5f6 --- aac39e1ded6af9ae93fd7315c2622972c240b241 diff --cc manifest index 807699898f,ccdfa438a5..c64c88ffa2 --- a/manifest +++ b/manifest @@@ -1,5 -1,5 +1,5 @@@ - C Merge\senhancements\sfrom\strunk. - D 2015-09-03T14:18:12.100 -C Continue\sto\ssupport\sthe\s(broken)\slegacy\ssyntax\sof\sallowing\sstrings\sfor\ncolumn\snames\sin\sCREATE\sINDEX\sstatements\sand\sin\sUNIQUE\sand\sPRIMARY\sKEY\nconstraints. -D 2015-09-04T12:54:01.394 ++C Merge\strunk\senhancements,\sand\sespeically\sthe\sfix\sfor\sallowing\sstrings\s\nas\scolumn\sidentifers\sin\sCREATE\sINDEX\sstatements. ++D 2015-09-04T13:02:21.922 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in f85066ce844a28b671aaeeff320921cd0ce36239 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@@ -282,7 -284,7 +284,7 @@@ F src/btmutex.c 45a968cc85afed9b5e6cf55 F src/btree.c 4084d9eed2817331f6e6a82230ba30e448cad497 F src/btree.h 969adc948e89e449220ff0ff724c94bb2a52e9f1 F src/btreeInt.h 8177c9ab90d772d6d2c6c517e05bed774b7c92c0 - F src/build.c 77da53936388346bc5864eab54066c6f3988770a -F src/build.c 3f6176b3af04b85715559d435097c556ba473801 ++F src/build.c 5566b3410080a54e5c302c55d3de53fd080cfc7d F src/callback.c 7b44ce59674338ad48b0e84e7b72f935ea4f68b0 F src/complete.c addcd8160b081131005d5bc2d34adf20c1c5c92f F src/ctime.c 5a0b735dc95604766f5dac73973658eef782ee8b @@@ -772,9 -774,9 +774,9 @@@ F test/incrvacuum.test d2a6ddf5e429720b F test/incrvacuum2.test 676c41428765d58f1da7dbe659ef27726d3d30ac F test/incrvacuum3.test 75256fb1377e7c39ef2de62bfc42bbff67be295a F test/incrvacuum_ioerr.test 6ae2f783424e47a0033304808fe27789cf93e635 -F test/index.test 4d990005a67a36984e4f1a5f1bdccea8d08da4ee +F test/index.test fe3c7a1aad82af92623747e9c3f3aa94ccd51238 - F test/index2.test ee83c6b5e3173a3d7137140d945d9a5d4fdfb9d6 - F test/index3.test b6ec456cf3b81d9a32123fe7e449bde434db338b + F test/index2.test f835d5e13ca163bd78c4459ca15fd2e4ed487407 + F test/index3.test fa3e49bbaa4f38091c9c742e36a1abe67c4ef1fc F test/index4.test ab92e736d5946840236cd61ac3191f91a7856bf6 F test/index5.test 8621491915800ec274609e42e02a97d67e9b13e7 F test/index6.test 7102ec371414c42dfb1d5ca37eb4519aa9edc23a @@@ -1381,7 -1382,7 +1383,7 @@@ F tool/vdbe_profile.tcl 67746953071a9f8 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh 48bd54594752d5be3337f12c72f28d2080cb630b F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f - P ff5137a6dd8cb2a9b629b3a244f52665e9c9ebce 847387ec8e6fef283899578fb232b2c23b00ee5b - R e19b7f210220f2833a87a0bc81a47608 -P d648ddd93de039820f5abe064c7bc1318cd9d6b1 -R d6ad877a8d4dd88a7ffbb10ce1648f9a ++P 1ab10cbf27245961b40eda1ce70f35646f0a9966 3d3df79bfaf9dbc7aa711c08a19d2f6dbe744b32 ++R 46fafd1e16150312779d43bb23b81793 U drh - Z 58f787bccb7c921ddef6f60f047a7162 -Z fa2f98c7a26d464055290dbf8522fd2e ++Z 1a60e3fe37bc43a63ce49e32494691dc diff --cc manifest.uuid index f00ef1513a,fac9e66268..e251058808 --- a/manifest.uuid +++ b/manifest.uuid @@@ -1,1 -1,1 +1,1 @@@ - 1ab10cbf27245961b40eda1ce70f35646f0a9966 -3d3df79bfaf9dbc7aa711c08a19d2f6dbe744b32 ++5ff855293865c244ac632c630e8e7e8d7c05a5f6 diff --cc src/build.c index 742efbf972,2ea67447cc..51facddff2 --- a/src/build.c +++ b/src/build.c @@@ -3104,51 -3126,40 +3128,52 @@@ Index *sqlite3CreateIndex sortOrderMask = 0; /* Ignore DESC */ } - /* Scan the names of the columns of the table to be indexed and - ** load the column indices into the Index structure. Report an error - ** if any column is not found. + /* Analyze the list of expressions that form the terms of the index and + ** report any errors. In the common case where the expression is exactly + ** a table column, store that column in aiColumn[]. For general expressions, + ** populate pIndex->aColExpr and store -2 in aiColumn[]. ** - ** TODO: Add a test to make sure that the same column is not named - ** more than once within the same index. Only the first instance of - ** the column will ever be used by the optimizer. Note that using the - ** same column more than once cannot be an error because that would - ** break backwards compatibility - it needs to be a warning. + ** TODO: Issue a warning if two or more columns of the index are identical. + ** TODO: Issue a warning if the table primary key is used as part of the + ** index key. */ for(i=0, pListItem=pList->a; inExpr; i++, pListItem++){ - const char *zColName; - Expr *pCExpr; - int requestedSortOrder; + Expr *pCExpr; /* The i-th index expression */ + int requestedSortOrder; /* ASC or DESC on the i-th expression */ char *zColl; /* Collation sequence name */ + sqlite3StringToId(pListItem->pExpr); + sqlite3ResolveSelfReference(pParse, pTab, NC_IdxExpr, pListItem->pExpr, 0); + if( pParse->nErr ) goto exit_create_index; pCExpr = sqlite3ExprSkipCollate(pListItem->pExpr); - if( pCExpr->op!=TK_ID ){ - sqlite3ErrorMsg(pParse, "indexes on expressions not yet supported"); - continue; - } - zColName = pCExpr->u.zToken; - for(j=0, pTabCol=pTab->aCol; jnCol; j++, pTabCol++){ - if( sqlite3StrICmp(zColName, pTabCol->zName)==0 ) break; - } - if( j>=pTab->nCol ){ - sqlite3ErrorMsg(pParse, "table %s has no column named %s", - pTab->zName, zColName); - pParse->checkSchema = 1; - goto exit_create_index; + if( pCExpr->op!=TK_COLUMN ){ + if( pTab==pParse->pNewTable ){ + sqlite3ErrorMsg(pParse, "expressions prohibited in PRIMARY KEY and " + "UNIQUE constraints"); + goto exit_create_index; + } + if( pIndex->aColExpr==0 ){ + ExprList *pCopy = sqlite3ExprListDup(db, pList, 0); + pIndex->aColExpr = pCopy; + if( !db->mallocFailed ){ + assert( pCopy!=0 ); + pListItem = &pCopy->a[i]; + } + } + j = -2; + pIndex->aiColumn[i] = -2; + pIndex->uniqNotNull = 0; + }else{ + j = pCExpr->iColumn; + assert( j<=0x7fff ); + if( j<0 ){ + j = pTab->iPKey; + }else if( pTab->aCol[j].notNull==0 ){ + pIndex->uniqNotNull = 0; + } + pIndex->aiColumn[i] = (i16)j; } - assert( j<=0x7fff ); - pIndex->aiColumn[i] = (i16)j; + zColl = 0; if( pListItem->pExpr->op==TK_COLLATE ){ int nColl; zColl = pListItem->pExpr->u.zToken;