From: drh Date: Thu, 25 Aug 2016 15:46:25 +0000 (+0000) Subject: Improvements to IN operator code generator comments. Avoid unnecessary X-Git-Tag: version-3.15.0~110^2~39 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ecb87ac88d6cac19eb68cab7c5944fcb1d2a372e;p=thirdparty%2Fsqlite.git Improvements to IN operator code generator comments. Avoid unnecessary Copy operations on the LHS of the IN operator. FossilOrigin-Name: b6344298783a1207cba3f635939ddc9ba922ab67 --- diff --git a/manifest b/manifest index 2c01a256ff..cd1f8ff071 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Corrections\sto\sthe\sIN-operator\snotes. -D 2016-08-25T14:23:59.673 +C Improvements\sto\sIN\soperator\scode\sgenerator\scomments.\s\sAvoid\sunnecessary\nCopy\soperations\son\sthe\sLHS\sof\sthe\sIN\soperator. +D 2016-08-25T15:46:25.026 F Makefile.in cfd8fb987cd7a6af046daa87daa146d5aad0e088 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc d66d0395c38571aab3804f8db0fa20707ae4609a @@ -338,7 +338,7 @@ F src/ctime.c e77f3dc297b4b65c96da78b4ae4272fdfae863d7 F src/date.c 95c9a8d00767e7221a8e9a31f4e913fc8029bf6b F src/dbstat.c 19ee7a4e89979d4df8e44cfac7a8f905ec89b77d F src/delete.c 76c084f0265f4a3cd1ecf17eee112a94f1ccbc05 -F src/expr.c 866bcb6e85806beb0f96e651e9d17811e1ecbda5 +F src/expr.c 1c003fcb9c5a6f8c54f6392378225d578be2a086 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb F src/fkey.c e2be0968c1adc679c87e467aa5b4f167588f38a8 F src/func.c 29cc9acb170ec1387b9f63eb52cd85f8de96c771 @@ -1521,7 +1521,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 d256b2caeb9e3eb5dd88bb569ec71f91e9991c81 -R e83420368d9fa99d84d7c5701ecba45b +P 25033ee94538289ba7e0147da30a18300047123f +R e1cedb5c8edd4d27c5fcda8527491fbe U drh -Z a8948efc181e8ffaf5af6c9f4ff55b46 +Z c3029179ef3a13ce81541f0730bc01a8 diff --git a/manifest.uuid b/manifest.uuid index b1c505cee1..f23c36e283 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -25033ee94538289ba7e0147da30a18300047123f \ No newline at end of file +b6344298783a1207cba3f635939ddc9ba922ab67 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index 16f74d785e..385e808917 100644 --- a/src/expr.c +++ b/src/expr.c @@ -2637,16 +2637,19 @@ int sqlite3ExprCheckIN(Parse *pParse, Expr *pIn){ ** x IN (SELECT ...) ** x IN (value, value, ...) ** -** The left-hand side (LHS) is a scalar expression. The right-hand side (RHS) -** is an array of zero or more values. The expression is true if the LHS is -** contained within the RHS. The value of the expression is unknown (NULL) -** if the LHS is NULL or if the LHS is not contained within the RHS and the -** RHS contains one or more NULL values. +** The left-hand side (LHS) is a scalar or vector expression. The +** right-hand side (RHS) is an array of zero or more values. The IN operator +** is true if the LHS is contained within the RHS. The result is false +** if the LHS is definitely not in the RHS. The result is NULL if the presence +** of the LHS in the RHS cannot be determined due to NULLs. ** ** This routine generates code that jumps to destIfFalse if the LHS is not ** contained within the RHS. If due to NULLs we cannot determine if the LHS ** is contained in the RHS then jump to destIfNull. If the LHS is contained ** within the RHS then fall through. +** +** See the separate in-operator.md documentation file in the canonical +** SQLite source tree for additional information. */ static void sqlite3ExprCodeIN( Parse *pParse, /* Parsing and code generating context */ @@ -2660,22 +2663,18 @@ static void sqlite3ExprCodeIN( Vdbe *v; /* Statement under construction */ int *aiMap = 0; /* Map from vector field to index column */ char *zAff = 0; /* Affinity string for comparisons */ - int nVector; /* Size of vectors for this IN(...) op */ - int iDummy; /* Dummy parameter to exprCodeVector() */ - Expr *pLeft = pExpr->pLeft; - int i; + int nVector; /* Size of vectors for this IN operator */ + int iDummy; /* Dummy parameter to exprCodeVector() */ + Expr *pLeft = pExpr->pLeft; /* The LHS of the IN operator */ + int i; /* loop counter */ if( sqlite3ExprCheckIN(pParse, pExpr) ) return; zAff = exprINAffinity(pParse, pExpr); - if( zAff==0 ) return; nVector = sqlite3ExprVectorSize(pExpr->pLeft); aiMap = (int*)sqlite3DbMallocZero( pParse->db, nVector*(sizeof(int) + sizeof(char)) + 1 ); - if( aiMap==0 ){ - sqlite3DbFree(pParse->db, zAff); - return; - } + if( pParse->db->mallocFailed ) goto end_code_IN_op; /* Attempt to compute the RHS. After this step, if anything other than ** IN_INDEX_NOOP is returned, the table opened ith cursor pExpr->iTable @@ -2691,16 +2690,32 @@ static void sqlite3ExprCodeIN( assert( pParse->nErr || nVector==1 || eType==IN_INDEX_EPH || eType==IN_INDEX_INDEX_ASC || eType==IN_INDEX_INDEX_DESC ); +#ifdef SQLITE_DEBUG + /* Confirm that aiMap[] contains nVector integer values between 0 and + ** nVector-1. */ + for(i=0; i from " IN (...)". If the LHS is a ** vector, then it is stored in an array of nVector registers starting ** at r1. */ - r1 = sqlite3GetTempRange(pParse, nVector); sqlite3ExprCachePush(pParse); r2 = exprCodeVector(pParse, pLeft, &iDummy); - for(i=0; idb, aiMap); sqlite3DbFree(pParse->db, zAff); - VdbeComment((v, "end IN expr")); } #endif /* SQLITE_OMIT_SUBQUERY */