From: drh Date: Sat, 28 Dec 2019 13:01:52 +0000 (+0000) Subject: Simplifications to the initialization of the sqlite3_index_info structure X-Git-Tag: version-3.31.0~125 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cfcf4de4a636abd966ee1dd724f639a96c1cc3f8;p=thirdparty%2Fsqlite.git Simplifications to the initialization of the sqlite3_index_info structure that is used to communicate with virtual table modules. Avoid adding unused constraints to the sqlite3_index_info structure. Extra constraints are harmless, but might be confusing to people trying to understand the code. FossilOrigin-Name: 5e6357fc953a955d8ebb5c1fcd72e04e4ae5e8bf5941810015c2fbc50de70535 --- diff --git a/manifest b/manifest index c6cebb057e..6fa51ebc17 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C If\sthe\s".wheretrace\s0x10000"\sbit\sis\sset,\sprint\sWhereTerm.prereqAll\nand\s.prereqRight\sfields\sin\sthe\sWhereTerm\strace\soutput. -D 2019-12-28T12:33:35.974 +C Simplifications\sto\sthe\sinitialization\sof\sthe\ssqlite3_index_info\sstructure\s\nthat\sis\sused\sto\scommunicate\swith\svirtual\stable\smodules.\s\sAvoid\sadding\nunused\sconstraints\sto\sthe\ssqlite3_index_info\sstructure.\s\sExtra\sconstraints\nare\sharmless,\sbut\smight\sbe\sconfusing\sto\speople\strying\sto\sunderstand\sthe\scode. +D 2019-12-28T13:01:52.507 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -614,7 +614,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 15a2845769f51ba132f9cf0b2c7a6887a91fc8437892dbcce9fcdc68b66d60a1 F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a F src/walker.c a137468bf36c92e64d2275caa80c83902e3a0fc59273591b96c6416d3253d05d -F src/where.c 476c0091eb27c99fb481730621838f646fba6d9ebc6e76a97e8caa9b7f08d933 +F src/where.c 230995f73eded5c3b46cdd6dd9b1862930df2bc402f5e8d2b4bfe64779411685 F src/whereInt.h 4a296fd4fa79fdcbc2b5e8c1b898901617655811223e1082b899c23ecb092217 F src/wherecode.c d42d3e0fe93786621b84dec8065e1dc6b324d7c5934df52f141555843b6aef4e F src/whereexpr.c 4b34be1434183e7bb8a05d4bf42bd53ea53021b0b060936fbd12062b4ff6b396 @@ -1853,7 +1853,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 1be2c18f4021e1d0b8412ecb68a599475c717dd97c7db209fc4203358957fd70 -R 1077f4eb4d5b48d5e8fb352c3adc1164 +P a4f330b133a36356681dce7d2a65d8ab792620494d6cd4ef4934a97cf3a8e6fc +R 9d791d568d34e1fbcc680abee9092a25 U drh -Z 26ea5bdabbe48f1cef138e8164f2fb1d +Z 381500a973c5168ce8cc649911e2754b diff --git a/manifest.uuid b/manifest.uuid index 556a07d0a2..745651a863 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a4f330b133a36356681dce7d2a65d8ab792620494d6cd4ef4934a97cf3a8e6fc \ No newline at end of file +5e6357fc953a955d8ebb5c1fcd72e04e4ae5e8bf5941810015c2fbc50de70535 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 0ea0026f48..69784bc1cc 100644 --- a/src/where.c +++ b/src/where.c @@ -605,7 +605,7 @@ static void translateColumnToCopy( ** are no-ops. */ #if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(WHERETRACE_ENABLED) -static void TRACE_IDX_INPUTS(sqlite3_index_info *p){ +static void whereTraceIndexInfoInputs(sqlite3_index_info *p){ int i; if( !sqlite3WhereTrace ) return; for(i=0; inConstraint; i++){ @@ -623,7 +623,7 @@ static void TRACE_IDX_INPUTS(sqlite3_index_info *p){ p->aOrderBy[i].desc); } } -static void TRACE_IDX_OUTPUTS(sqlite3_index_info *p){ +static void whereTraceIndexInfoOutputs(sqlite3_index_info *p){ int i; if( !sqlite3WhereTrace ) return; for(i=0; inConstraint; i++){ @@ -639,8 +639,8 @@ static void TRACE_IDX_OUTPUTS(sqlite3_index_info *p){ sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows); } #else -#define TRACE_IDX_INPUTS(A) -#define TRACE_IDX_OUTPUTS(A) +#define whereTraceIndexInfoInputs(A) +#define whereTraceIndexInfoOutputs(A) #endif #ifndef SQLITE_OMIT_AUTOMATIC_INDEX @@ -950,23 +950,14 @@ static sqlite3_index_info *allocateIndexInfo( sqlite3ErrorMsg(pParse, "out of memory"); return 0; } - - /* Initialize the structure. The sqlite3_index_info structure contains - ** many fields that are declared "const" to prevent xBestIndex from - ** changing them. We have to do some funky casting in order to - ** initialize those fields. - */ pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1]; pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1]; pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm]; pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy]; - *(int*)&pIdxInfo->nConstraint = nTerm; - *(int*)&pIdxInfo->nOrderBy = nOrderBy; - *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons; - *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy; - *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage = - pUsage; - + pIdxInfo->nOrderBy = nOrderBy; + pIdxInfo->aConstraint = pIdxCons; + pIdxInfo->aOrderBy = pIdxOrderBy; + pIdxInfo->aConstraintUsage = pUsage; pHidden->pWC = pWC; pHidden->pParse = pParse; for(i=j=0, pTerm=pWC->a; inTerm; i++, pTerm++){ @@ -1026,6 +1017,7 @@ static sqlite3_index_info *allocateIndexInfo( j++; } + pIdxInfo->nConstraint = j; for(i=0; ia[i].pExpr; pIdxOrderBy[i].iColumn = pExpr->iColumn; @@ -1056,9 +1048,9 @@ static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){ sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab; int rc; - TRACE_IDX_INPUTS(p); + whereTraceIndexInfoInputs(p); rc = pVtab->pModule->xBestIndex(pVtab, p); - TRACE_IDX_OUTPUTS(p); + whereTraceIndexInfoOutputs(p); if( rc!=SQLITE_OK && rc!=SQLITE_CONSTRAINT ){ if( rc==SQLITE_NOMEM ){