1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-12 13:01:09 +03:00

Code simplifications in select.c and where.c.

FossilOrigin-Name: 4f20ac90bce8bd7ba43ef59af5cc4ef7aa282fe8
This commit is contained in:
drh
2015-06-06 18:30:17 +00:00
parent adc57f6834
commit b121dd14ac
4 changed files with 41 additions and 47 deletions

View File

@@ -1,5 +1,5 @@
C Minor\scleanup\sof\sthe\ssqlite3Select()\sprocedure. C Code\ssimplifications\sin\sselect.c\sand\swhere.c.
D 2015-06-06T00:18:01.663 D 2015-06-06T18:30:17.822
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
F Makefile.in 994bab32a3a69e0c35bd148b65cde49879772964 F Makefile.in 994bab32a3a69e0c35bd148b65cde49879772964
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -250,7 +250,7 @@ F src/printf.c 13ce37e5574f9b0682fa86dbcf9faf76b9d82a15
F src/random.c ba2679f80ec82c4190062d756f22d0c358180696 F src/random.c ba2679f80ec82c4190062d756f22d0c358180696
F src/resolve.c 84c571794e3ee5806274d95158a4c0177c6c4708 F src/resolve.c 84c571794e3ee5806274d95158a4c0177c6c4708
F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e F src/rowset.c eccf6af6d620aaa4579bd3b72c1b6395d9e9fa1e
F src/select.c 630623e6536115ec360e07be3cb5e01fab9166f9 F src/select.c d507fe715b12e6aba157fa34b0a5680809e59bac
F src/shell.c 07dda7cd692911d2f22269953418d049f2e2c0ee F src/shell.c 07dda7cd692911d2f22269953418d049f2e2c0ee
F src/sqlite.h.in d165beeceb6b40af60f352a4d4e37e02d9af7df0 F src/sqlite.h.in d165beeceb6b40af60f352a4d4e37e02d9af7df0
F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad F src/sqlite3.rc 992c9f5fb8285ae285d6be28240a7e8d3a7f2bad
@@ -326,7 +326,7 @@ F src/vxworks.h c18586c8edc1bddbc15c004fa16aeb1e1342b4fb
F src/wal.c ce2cb2d06faab54d1bce3e739bec79e063dd9113 F src/wal.c ce2cb2d06faab54d1bce3e739bec79e063dd9113
F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4
F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804 F src/walker.c c253b95b4ee44b21c406e2a1052636c31ea27804
F src/where.c 2db8137f14644e2117c2e2350e08a05e02d6bdab F src/where.c 5cc416ad6d8b6d2027735fcf7c5a6165bb745636
F src/whereInt.h a6f5a762bc1b4b1c76e1cea79976b437ac35a435 F src/whereInt.h a6f5a762bc1b4b1c76e1cea79976b437ac35a435
F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd F test/affinity2.test a6d901b436328bd67a79b41bb0ac2663918fe3bd
@@ -1282,7 +1282,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P be8e3fc70e4c13b28b07985df3457960f58ffddd P f4c90d06bb941453d8110680c7b279e471e8f034
R c9ba4b66998c994d5a4d88f3868eca18 R 042f84cf941d82ab55744b287e51eff7
U drh U drh
Z f5a7ad6c64c16a42ea0d51c96b63ee57 Z f6bc4d318934fdab6d55b7066c6ff342

View File

@@ -1 +1 @@
f4c90d06bb941453d8110680c7b279e471e8f034 4f20ac90bce8bd7ba43ef59af5cc4ef7aa282fe8

View File

@@ -1310,28 +1310,27 @@ static void generateSortTail(
*/ */
#ifdef SQLITE_ENABLE_COLUMN_METADATA #ifdef SQLITE_ENABLE_COLUMN_METADATA
# define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,C,D,E,F) # define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,C,D,E,F)
#else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */
# define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,F)
#endif
static const char *columnTypeImpl( static const char *columnTypeImpl(
NameContext *pNC, NameContext *pNC,
Expr *pExpr, Expr *pExpr,
#ifdef SQLITE_ENABLE_COLUMN_METADATA
const char **pzOrigDb, const char **pzOrigDb,
const char **pzOrigTab, const char **pzOrigTab,
const char **pzOrigCol, const char **pzOrigCol,
#endif
u8 *pEstWidth u8 *pEstWidth
){ ){
char const *zOrigDb = 0;
char const *zOrigTab = 0;
char const *zOrigCol = 0;
#else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */
# define columnType(A,B,C,D,E,F) columnTypeImpl(A,B,F)
static const char *columnTypeImpl(
NameContext *pNC,
Expr *pExpr,
u8 *pEstWidth
){
#endif /* !defined(SQLITE_ENABLE_COLUMN_METADATA) */
char const *zType = 0; char const *zType = 0;
int j; int j;
u8 estWidth = 1; u8 estWidth = 1;
#ifdef SQLITE_ENABLE_COLUMN_METADATA
char const *zOrigDb = 0;
char const *zOrigTab = 0;
char const *zOrigCol = 0;
#endif
if( NEVER(pExpr==0) || pNC->pSrcList==0 ) return 0; if( NEVER(pExpr==0) || pNC->pSrcList==0 ) return 0;
switch( pExpr->op ){ switch( pExpr->op ){

View File

@@ -616,6 +616,11 @@ static void exprAnalyze(SrcList*, WhereClause*, int);
/* /*
** Call exprAnalyze on all terms in a WHERE clause. ** Call exprAnalyze on all terms in a WHERE clause.
**
** Note that exprAnalyze() might add new virtual terms onto the
** end of the WHERE clause. We do not want to analyze these new
** virtual terms, so start analyzing at the end and work forward
** so that the added virtual terms are never processed.
*/ */
static void exprAnalyzeAll( static void exprAnalyzeAll(
SrcList *pTabList, /* the FROM clause */ SrcList *pTabList, /* the FROM clause */
@@ -891,7 +896,7 @@ static void whereCombineDisjuncts(
** **
** CASE 2: ** CASE 2:
** **
** If there are exactly two disjuncts one side has x>A and the other side ** If there are exactly two disjuncts and one side has x>A and the other side
** has x=A (for the same x and A) then add a new virtual conjunct term to the ** has x=A (for the same x and A) then add a new virtual conjunct term to the
** WHERE clause of the form "x>=A". Example: ** WHERE clause of the form "x>=A". Example:
** **
@@ -920,22 +925,22 @@ static void whereCombineDisjuncts(
** is decided elsewhere. This analysis only looks at whether subterms ** is decided elsewhere. This analysis only looks at whether subterms
** appropriate for indexing exist. ** appropriate for indexing exist.
** **
** All examples A through E above satisfy case 2. But if a term ** All examples A through E above satisfy case 3. But if a term
** also satisfies case 1 (such as B) we know that the optimizer will ** also satisfies case 1 (such as B) we know that the optimizer will
** always prefer case 1, so in that case we pretend that case 2 is not ** always prefer case 1, so in that case we pretend that case 3 is not
** satisfied. ** satisfied.
** **
** It might be the case that multiple tables are indexable. For example, ** It might be the case that multiple tables are indexable. For example,
** (E) above is indexable on tables P, Q, and R. ** (E) above is indexable on tables P, Q, and R.
** **
** Terms that satisfy case 2 are candidates for lookup by using ** Terms that satisfy case 3 are candidates for lookup by using
** separate indices to find rowids for each subterm and composing ** separate indices to find rowids for each subterm and composing
** the union of all rowids using a RowSet object. This is similar ** the union of all rowids using a RowSet object. This is similar
** to "bitmap indices" in other database engines. ** to "bitmap indices" in other database engines.
** **
** OTHERWISE: ** OTHERWISE:
** **
** If neither case 1 nor case 2 apply, then leave the eOperator set to ** If none of cases 1, 2, or 3 apply, then leave the eOperator set to
** zero. This term is not useful for search. ** zero. This term is not useful for search.
*/ */
static void exprAnalyzeOrTerm( static void exprAnalyzeOrTerm(
@@ -973,7 +978,7 @@ static void exprAnalyzeOrTerm(
assert( pOrWc->nTerm>=2 ); assert( pOrWc->nTerm>=2 );
/* /*
** Compute the set of tables that might satisfy cases 1 or 2. ** Compute the set of tables that might satisfy cases 1 or 3.
*/ */
indexable = ~(Bitmask)0; indexable = ~(Bitmask)0;
chngToIN = ~(Bitmask)0; chngToIN = ~(Bitmask)0;
@@ -1188,7 +1193,7 @@ static void exprAnalyzeOrTerm(
** relation: ** relation:
** 1. The SQLITE_Transitive optimization must be enabled ** 1. The SQLITE_Transitive optimization must be enabled
** 2. Must be either an == or an IS operator ** 2. Must be either an == or an IS operator
** 3. Not originating the ON clause of an OUTER JOIN ** 3. Not originating in the ON clause of an OUTER JOIN
** 4. The affinities of A and B must be compatible ** 4. The affinities of A and B must be compatible
** 5a. Both operands use the same collating sequence OR ** 5a. Both operands use the same collating sequence OR
** 5b. The overall collating sequence is BINARY ** 5b. The overall collating sequence is BINARY
@@ -1589,8 +1594,8 @@ static int findIndexCol(
** Return true if the DISTINCT expression-list passed as the third argument ** Return true if the DISTINCT expression-list passed as the third argument
** is redundant. ** is redundant.
** **
** A DISTINCT list is redundant if the database contains some subset of ** A DISTINCT list is redundant if any subset of the columns in the
** columns that are unique and non-null. ** DISTINCT list are collectively unique and individually non-null.
*/ */
static int isDistinctRedundant( static int isDistinctRedundant(
Parse *pParse, /* Parsing context */ Parse *pParse, /* Parsing context */
@@ -6689,15 +6694,9 @@ WhereInfo *sqlite3WhereBegin(
} }
#endif #endif
/* Analyze all of the subexpressions. Note that exprAnalyze() might /* Analyze all of the subexpressions. */
** add new virtual terms onto the end of the WHERE clause. We do not
** want to analyze these virtual terms, so start analyzing at the end
** and work forward so that the added virtual terms are never processed.
*/
exprAnalyzeAll(pTabList, &pWInfo->sWC); exprAnalyzeAll(pTabList, &pWInfo->sWC);
if( db->mallocFailed ){ if( db->mallocFailed ) goto whereBeginError;
goto whereBeginError;
}
if( wctrlFlags & WHERE_WANT_DISTINCT ){ if( wctrlFlags & WHERE_WANT_DISTINCT ){
if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){ if( isDistinctRedundant(pParse, pTabList, &pWInfo->sWC, pResultSet) ){
@@ -6713,8 +6712,7 @@ WhereInfo *sqlite3WhereBegin(
/* Construct the WhereLoop objects */ /* Construct the WhereLoop objects */
WHERETRACE(0xffff,("*** Optimizer Start ***\n")); WHERETRACE(0xffff,("*** Optimizer Start ***\n"));
#if defined(WHERETRACE_ENABLED) #if defined(WHERETRACE_ENABLED)
/* Display all terms of the WHERE clause */ if( sqlite3WhereTrace & 0x100 ){ /* Display all terms of the WHERE clause */
if( sqlite3WhereTrace & 0x100 ){
int i; int i;
for(i=0; i<sWLB.pWC->nTerm; i++){ for(i=0; i<sWLB.pWC->nTerm; i++){
whereTermPrint(&sWLB.pWC->a[i], i); whereTermPrint(&sWLB.pWC->a[i], i);
@@ -6726,12 +6724,11 @@ WhereInfo *sqlite3WhereBegin(
rc = whereLoopAddAll(&sWLB); rc = whereLoopAddAll(&sWLB);
if( rc ) goto whereBeginError; if( rc ) goto whereBeginError;
/* Display all of the WhereLoop objects if wheretrace is enabled */ #ifdef WHERETRACE_ENABLED
#ifdef WHERETRACE_ENABLED /* !=0 */ if( sqlite3WhereTrace ){ /* Display all of the WhereLoop objects */
if( sqlite3WhereTrace ){
WhereLoop *p; WhereLoop *p;
int i; int i;
static char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz" static const char zLabel[] = "0123456789abcdefghijklmnopqrstuvwyxz"
"ABCDEFGHIJKLMNOPQRSTUVWYXZ"; "ABCDEFGHIJKLMNOPQRSTUVWYXZ";
for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){ for(p=pWInfo->pLoops, i=0; p; p=p->pNextLoop, i++){
p->cId = zLabel[i%sizeof(zLabel)]; p->cId = zLabel[i%sizeof(zLabel)];
@@ -6753,7 +6750,7 @@ WhereInfo *sqlite3WhereBegin(
if( pParse->nErr || NEVER(db->mallocFailed) ){ if( pParse->nErr || NEVER(db->mallocFailed) ){
goto whereBeginError; goto whereBeginError;
} }
#ifdef WHERETRACE_ENABLED /* !=0 */ #ifdef WHERETRACE_ENABLED
if( sqlite3WhereTrace ){ if( sqlite3WhereTrace ){
sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut); sqlite3DebugPrintf("---- Solution nRow=%d", pWInfo->nRowOut);
if( pWInfo->nOBSat>0 ){ if( pWInfo->nOBSat>0 ){
@@ -6816,7 +6813,7 @@ WhereInfo *sqlite3WhereBegin(
/* If the caller is an UPDATE or DELETE statement that is requesting /* If the caller is an UPDATE or DELETE statement that is requesting
** to use a one-pass algorithm, determine if this is appropriate. ** to use a one-pass algorithm, determine if this is appropriate.
** The one-pass algorithm only works if the WHERE clause constrains ** The one-pass algorithm only works if the WHERE clause constrains
** the statement to update a single row. ** the statement to update or delete a single row.
*/ */
assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 ); assert( (wctrlFlags & WHERE_ONEPASS_DESIRED)==0 || pWInfo->nLevel==1 );
if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0 if( (wctrlFlags & WHERE_ONEPASS_DESIRED)!=0
@@ -6830,7 +6827,6 @@ WhereInfo *sqlite3WhereBegin(
/* Open all tables in the pTabList and any indices selected for /* Open all tables in the pTabList and any indices selected for
** searching those tables. ** searching those tables.
*/ */
notReady = ~(Bitmask)0;
for(ii=0, pLevel=pWInfo->a; ii<nTabList; ii++, pLevel++){ for(ii=0, pLevel=pWInfo->a; ii<nTabList; ii++, pLevel++){
Table *pTab; /* Table to open */ Table *pTab; /* Table to open */
int iDb; /* Index of database containing table/index */ int iDb; /* Index of database containing table/index */
@@ -6919,7 +6915,6 @@ WhereInfo *sqlite3WhereBegin(
} }
} }
if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb); if( iDb>=0 ) sqlite3CodeVerifySchema(pParse, iDb);
notReady &= ~getMask(&pWInfo->sMaskSet, pTabItem->iCursor);
} }
pWInfo->iTop = sqlite3VdbeCurrentAddr(v); pWInfo->iTop = sqlite3VdbeCurrentAddr(v);
if( db->mallocFailed ) goto whereBeginError; if( db->mallocFailed ) goto whereBeginError;