From: drh Date: Tue, 12 Mar 2013 18:34:50 +0000 (+0000) Subject: A proposed fix for the DESC ORDER BY bug of ticket [4dd95f6943fbd18]. X-Git-Tag: version-3.7.16~2^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0fe456bb29e7a50a10b0c3da87ce6f963dc8b177;p=thirdparty%2Fsqlite.git A proposed fix for the DESC ORDER BY bug of ticket [4dd95f6943fbd18]. Seems to work, but lots more testing is needed prior to moving to trunk. FossilOrigin-Name: 614a038ad2fe111687d2bc1c0aa716d7eb8fdd7c --- diff --git a/manifest b/manifest index a6db29d38b..315e25336e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Define\s_BSD_SOURCE\swhen\sbuilding\son\sOpenBSD.\sThis\sis\srequired\sfor\sfchmod(). -D 2013-03-11T13:37:52.519 +C A\sproposed\sfix\sfor\sthe\sDESC\sORDER\sBY\sbug\sof\sticket\s[4dd95f6943fbd18].\nSeems\sto\swork,\sbut\slots\smore\stesting\sis\sneeded\sprior\sto\smoving\sto\strunk. +D 2013-03-12T18:34:50.356 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 9a804abbd3cae82d196e4d33aba13239e32522a5 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -179,7 +179,7 @@ F src/shell.c 7c41bfcd9e5bf9d96b9215f79b03a5b2b44a3bca F src/sqlite.h.in 31045976254225e6bf046a96e87b40fa4c1d55e4 F src/sqlite3.rc fea433eb0a59f4c9393c8e6d76a6e2596b1fe0c0 F src/sqlite3ext.h 7183ab832e23db0f934494f16928da127a571d75 -F src/sqliteInt.h 59477c6ddb25e7ed8d8b67f4c58ded254371182e +F src/sqliteInt.h e390bfafb5d65418555ce2464d5a4ad6e57e8c71 F src/sqliteLimit.h 164b0e6749d31e0daa1a4589a169d31c0dec7b3d F src/status.c bedc37ec1a6bb9399944024d63f4c769971955a9 F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e @@ -252,7 +252,7 @@ F src/vtab.c b05e5f1f4902461ba9f5fc49bb7eb7c3a0741a83 F src/wal.c f5c7b5027d0ed0e9bc9afeb4a3a8dfea762ec7d2 F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6 F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b -F src/where.c 8b7690cae8700b385d8a53a39387cf8054d8cc47 +F src/where.c 3db35b6231f3da4147294f59e7a1d339c987af32 F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@ -1037,7 +1037,10 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac -P 1da15adba8f6eec69c24ec6385d6f1a7905a388f -R 23658f0952d1a2fe0f61c5471a6869f3 -U dan -Z 6b791dcdadf138e4fa4768d3023bd490 +P f9027cb47bdec8dcebf1f038921b28d9e9928c18 +R 095810c67d8046e935e9a69945867a0f +T *branch * desc-orderby-fix-1 +T *sym-desc-orderby-fix-1 * +T -sym-trunk * +U drh +Z 8fce222dd4f4c4a0834625ece5c0e872 diff --git a/manifest.uuid b/manifest.uuid index 7c0fe040be..3380b73d72 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -f9027cb47bdec8dcebf1f038921b28d9e9928c18 \ No newline at end of file +614a038ad2fe111687d2bc1c0aa716d7eb8fdd7c \ No newline at end of file diff --git a/src/sqliteInt.h b/src/sqliteInt.h index e5b4ccac4b..2f15f150f6 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -1931,6 +1931,7 @@ struct WherePlan { u32 wsFlags; /* WHERE_* flags that describe the strategy */ u16 nEq; /* Number of == constraints */ u16 nOBSat; /* Number of ORDER BY terms satisfied */ + u16 iOBSat; /* First ORDER BY term satisfied */ double nRow; /* Estimated number of rows (for EQP) */ union { Index *pIdx; /* Index when WHERE_INDEXED is true */ diff --git a/src/where.c b/src/where.c index aa81dabd47..d281ed3000 100644 --- a/src/where.c +++ b/src/where.c @@ -1834,6 +1834,7 @@ static void bestOrClauseIndex(WhereBestIdx *p){ p->cost.used = used; p->cost.plan.nRow = nRow; p->cost.plan.nOBSat = p->i ? p->aLevel[p->i-1].plan.nOBSat : 0; + p->cost.plan.iOBSat = p->cost.plan.nOBSat; p->cost.plan.wsFlags = flags; p->cost.plan.u.pTerm = pTerm; } @@ -3775,7 +3776,8 @@ static void codeApplyAffinity(Parse *pParse, int base, int n, char *zAff){ static int codeEqualityTerm( Parse *pParse, /* The parsing context */ WhereTerm *pTerm, /* The term of the WHERE clause to be coded */ - WhereLevel *pLevel, /* When level of the FROM clause we are working on */ + WhereLevel *pLevel, /* The level of the FROM clause we are working on */ + int iEq, /* Index of the equality term within this level */ int iTarget /* Attempt to leave results in this register */ ){ Expr *pX = pTerm->pExpr; @@ -3793,8 +3795,15 @@ static int codeEqualityTerm( int eType; int iTab; struct InLoop *pIn; - u8 bRev = (pLevel->plan.wsFlags & WHERE_REVERSE)!=0; + u8 bRev; + if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 ){ + Index *pIdx = pLevel->plan.u.pIdx; + bRev = pIdx->aSortOrder[iEq+pLevel->plan.iOBSat]; + }else{ + bRev = 0; + } + if( pLevel->plan.wsFlags & WHERE_REVERSE ) bRev = 1 - bRev; assert( pX->op==TK_IN ); iReg = iTarget; eType = sqlite3FindInIndex(pParse, pX, 0); @@ -3912,7 +3921,7 @@ static int codeAllEqualityTerms( ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */ testcase( (pTerm->wtFlags & TERM_CODED)!=0 ); testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */ - r1 = codeEqualityTerm(pParse, pTerm, pLevel, regBase+j); + r1 = codeEqualityTerm(pParse, pTerm, pLevel, j, regBase+j); if( r1!=regBase+j ){ if( nReg==1 ){ sqlite3ReleaseTempReg(pParse, regBase); @@ -4189,7 +4198,7 @@ static Bitmask codeOneLoopStart( int iTarget = iReg+j+1; pTerm = &pWC->a[aConstraint[k].iTermOffset]; if( pTerm->eOperator & WO_IN ){ - codeEqualityTerm(pParse, pTerm, pLevel, iTarget); + codeEqualityTerm(pParse, pTerm, pLevel, k, iTarget); addrNotFound = pLevel->addrNxt; }else{ sqlite3ExprCode(pParse, pTerm->pExpr->pRight, iTarget); @@ -4230,7 +4239,7 @@ static Bitmask codeOneLoopStart( assert( pTerm->pExpr!=0 ); assert( omitTable==0 ); testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */ - iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, iReleaseReg); + iRowidReg = codeEqualityTerm(pParse, pTerm, pLevel, 0, iReleaseReg); addrNxt = pLevel->addrNxt; sqlite3VdbeAddOp2(v, OP_MustBeInt, iRowidReg, addrNxt); sqlite3VdbeAddOp3(v, OP_NotExists, iCur, addrNxt, iRowidReg);