1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Improved comments. Fix a problem when an indexed expression is used in an

ORDER BY clause.

FossilOrigin-Name: c59eaf2b7cd2596733f349fc0fe979f71fd29bd73152a0c57066e0b69d5b7a4a
This commit is contained in:
drh
2017-04-11 01:01:27 +00:00
parent 2f8b37850c
commit eac5fc0476
4 changed files with 42 additions and 20 deletions

View File

@ -1,5 +1,5 @@
C Merge\schanges\sfrom\strunk. C Improved\scomments.\s\sFix\sa\sproblem\swhen\san\sindexed\sexpression\sis\sused\sin\san\nORDER\sBY\sclause.
D 2017-04-10T23:42:04.790 D 2017-04-11T01:01:27.332
F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb F Makefile.in 1cc758ce3374a32425e4d130c2fe7b026b20de5b8843243de75f087c0a2661fb
F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434
F Makefile.msc a4c0613a18663bda56d8cf76079ab6590a7c3602e54befb4bbdef76bcaa38b6a F Makefile.msc a4c0613a18663bda56d8cf76079ab6590a7c3602e54befb4bbdef76bcaa38b6a
@ -401,7 +401,7 @@ F src/printf.c 8757834f1b54dae512fb25eb1acc8e94a0d15dd2290b58f2563f65973265adb2
F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384
F src/resolve.c 3e518b962d932a997fae373366880fc028c75706 F src/resolve.c 3e518b962d932a997fae373366880fc028c75706
F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac F src/rowset.c 7b7e7e479212e65b723bf40128c7b36dc5afdfac
F src/select.c b24e628a2b76800171f4c86e38b5d93e27f2c40e603b24733aa8e471029e6ecd F src/select.c 9228235fdefe6de138ac01c4c68d07fd95d78780ef85112a76e63e260a6f5897
F src/shell.c 70f4957b988572315e97c56941fdc81fd35907fee36b7b2e7be5ec4c7e9d065d F src/shell.c 70f4957b988572315e97c56941fdc81fd35907fee36b7b2e7be5ec4c7e9d065d
F src/sqlite.h.in 40233103e3e4e10f8a63523498d0259d232e42aba478e2d3fb914799185aced6 F src/sqlite.h.in 40233103e3e4e10f8a63523498d0259d232e42aba478e2d3fb914799185aced6
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
@ -484,7 +484,7 @@ F src/wal.h 06b2a0b599cc0f53ea97f497cf8c6b758c999f71
F src/walker.c b71a992b413b3a022572eccf29ef4b4890223791 F src/walker.c b71a992b413b3a022572eccf29ef4b4890223791
F src/where.c 1d14e18f32231fa7969e718e7b60ef749b0065e2a7e1b6b00883b20732d280f1 F src/where.c 1d14e18f32231fa7969e718e7b60ef749b0065e2a7e1b6b00883b20732d280f1
F src/whereInt.h 7a21ef633e26acbf46df04add2eba6e0a2100c78dc5879049e93f981fc3344df F src/whereInt.h 7a21ef633e26acbf46df04add2eba6e0a2100c78dc5879049e93f981fc3344df
F src/wherecode.c 38d171e309c7b54d5bdc7d8b663ec16249ad8888e01a77f6c55e9350de8e8349 F src/wherecode.c 943e32e9dccd0af802e0683ae11071c8bd808364e5908a5fb66758bd404c8681
F src/whereexpr.c 130cdd1a43af71b19755270fb1224874cf55158c F src/whereexpr.c 130cdd1a43af71b19755270fb1224874cf55158c
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd
@ -1570,7 +1570,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 13a422230dcf4a8a80434af97434d57e456dcaa6bf0c41e6859f37ded6fa96ca e052436d9f54b785facd661adc648512356b831c0547aa8f347ebf4bd8ef1254 P 8978465f335925378d3aa99df6190ce6a1ee6b130205ccc493f2399803844760
R a0a3c2f64645982d19356fee9ed1bee3 R 1b0a9c05391f59848f876fd33c1876bb
U drh U drh
Z 41de53ab744a90538b62b8272746f983 Z 21e604ae631dfab7b9082f6214d51689

View File

@ -1 +1 @@
8978465f335925378d3aa99df6190ce6a1ee6b130205ccc493f2399803844760 c59eaf2b7cd2596733f349fc0fe979f71fd29bd73152a0c57066e0b69d5b7a4a

View File

@ -1530,6 +1530,7 @@ static void generateColumnTypes(
NameContext sNC; NameContext sNC;
sNC.pSrcList = pTabList; sNC.pSrcList = pTabList;
sNC.pParse = pParse; sNC.pParse = pParse;
sNC.pNext = 0;
for(i=0; i<pEList->nExpr; i++){ for(i=0; i<pEList->nExpr; i++){
Expr *p = pEList->a[i].pExpr; Expr *p = pEList->a[i].pExpr;
const char *zType; const char *zType;
@ -1554,6 +1555,19 @@ static void generateColumnTypes(
#endif /* !defined(SQLITE_OMIT_DECLTYPE) */ #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
} }
/*
** Return the Table objecct in the SrcList that has cursor iCursor.
** Or return NULL if no such Table object exists in the SrcList.
*/
static Table *tableWithCursor(SrcList *pList, int iCursor){
int j;
for(j=0; j<pList->nSrc; j++){
if( pList->a[j].iCursor==iCursor ) return pList->a[j].pTab;
}
return 0;
}
/* /*
** Generate code that will tell the VDBE the names of columns ** Generate code that will tell the VDBE the names of columns
** in the result set. This information is used to provide the ** in the result set. This information is used to provide the
@ -1565,7 +1579,8 @@ static void generateColumnNames(
ExprList *pEList /* Expressions defining the result set */ ExprList *pEList /* Expressions defining the result set */
){ ){
Vdbe *v = pParse->pVdbe; Vdbe *v = pParse->pVdbe;
int i, j; int i;
Table *pTab;
sqlite3 *db = pParse->db; sqlite3 *db = pParse->db;
int fullNames, shortNames; int fullNames, shortNames;
@ -1590,15 +1605,11 @@ static void generateColumnNames(
if( pEList->a[i].zName ){ if( pEList->a[i].zName ){
char *zName = pEList->a[i].zName; char *zName = pEList->a[i].zName;
sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT); sqlite3VdbeSetColName(v, i, COLNAME_NAME, zName, SQLITE_TRANSIENT);
}else if( p->op==TK_COLUMN || p->op==TK_AGG_COLUMN ){ }else if( (p->op==TK_COLUMN || p->op==TK_AGG_COLUMN)
Table *pTab; && (pTab = tableWithCursor(pTabList, p->iTable))!=0
){
char *zCol; char *zCol;
int iCol = p->iColumn; int iCol = p->iColumn;
for(j=0; ALWAYS(j<pTabList->nSrc); j++){
if( pTabList->a[j].iCursor==p->iTable ) break;
}
assert( j<pTabList->nSrc );
pTab = pTabList->a[j].pTab;
if( iCol<0 ) iCol = pTab->iPKey; if( iCol<0 ) iCol = pTab->iPKey;
assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) ); assert( iCol==-1 || (iCol>=0 && iCol<pTab->nCol) );
if( iCol<0 ){ if( iCol<0 ){

View File

@ -1039,7 +1039,10 @@ static void codeExprOrVector(Parse *pParse, Expr *p, int iReg, int nReg){
} }
} }
#if 1 /* INDEXEXPRTRANS */ /* An instance of the IdxExprTrans object carries information about a
** mapping from an expression on table columns into a column in an index
** down through the Walker.
*/
typedef struct IdxExprTrans { typedef struct IdxExprTrans {
Expr *pIdxExpr; /* The index expression */ Expr *pIdxExpr; /* The index expression */
int iTabCur; /* The cursor of the corresponding table */ int iTabCur; /* The cursor of the corresponding table */
@ -1047,6 +1050,12 @@ typedef struct IdxExprTrans {
int iIdxCol; /* The column for the index */ int iIdxCol; /* The column for the index */
} IdxExprTrans; } IdxExprTrans;
/* The walker node callback used to transform matching expressions into
** a reference to an index column for an index on an expression.
**
** If pExpr matches, then transform it into a reference to the index column
** that contains the value of pExpr.
*/
static int whereIndexExprTransNode(Walker *p, Expr *pExpr){ static int whereIndexExprTransNode(Walker *p, Expr *pExpr){
IdxExprTrans *pX = p->u.pIdxTrans; IdxExprTrans *pX = p->u.pIdxTrans;
if( sqlite3ExprCompare(pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){ if( sqlite3ExprCompare(pExpr, pX->pIdxExpr, pX->iTabCur)==0 ){
@ -1092,7 +1101,6 @@ static void whereIndexExprTrans(
sqlite3WalkExprList(&w, pWInfo->pResultSet); sqlite3WalkExprList(&w, pWInfo->pResultSet);
} }
} }
#endif
/* /*
** Generate code for the start of the iLevel-th loop in the WHERE clause ** Generate code for the start of the iLevel-th loop in the WHERE clause
@ -1675,9 +1683,12 @@ Bitmask sqlite3WhereCodeOneLoopStart(
iRowidReg, pPk->nKeyCol); VdbeCoverage(v); iRowidReg, pPk->nKeyCol); VdbeCoverage(v);
} }
#if 1 /* INDEXEXPRTANS */ /* If pIdx is an index on one or more expressions, then look through
** all the expressions in pWInfo and try to transform matching expressions
** into reference to index columns.
*/
whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo); whereIndexExprTrans(pIdx, iCur, iIdxCur, pWInfo);
#endif
/* Record the instruction used to terminate the loop. */ /* Record the instruction used to terminate the loop. */
if( pLoop->wsFlags & WHERE_ONEROW ){ if( pLoop->wsFlags & WHERE_ONEROW ){