OpenCoverage

where.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/sqlite/src/src/where.c
Source codeSwitch to Preprocessed file
LineSourceCount
1/*-
2** 2001 September 15-
3**-
4** The author disclaims copyright to this source code. In place of-
5** a legal notice, here is a blessing:-
6**-
7** May you do good and not evil.-
8** May you find forgiveness for yourself and forgive others.-
9** May you share freely, never taking more than you give.-
10**-
11*************************************************************************-
12** This module contains C code that generates VDBE code used to process-
13** the WHERE clause of SQL statements. This module is responsible for-
14** generating the code that loops through a table looking for applicable-
15** rows. Indices are selected and used to speed the search when doing-
16** so is applicable. Because this module is responsible for selecting-
17** indices, you might also think of this module as the "query optimizer".-
18*/-
19#include "sqliteInt.h"-
20#include "whereInt.h"-
21-
22/*-
23** Extra information appended to the end of sqlite3_index_info but not-
24** visible to the xBestIndex function, at least not directly. The-
25** sqlite3_vtab_collation() interface knows how to reach it, however.-
26**-
27** This object is not an API and can be changed from one release to the-
28** next. As long as allocateIndexInfo() and sqlite3_vtab_collation()-
29** agree on the structure, all will be well.-
30*/-
31typedef struct HiddenIndexInfo HiddenIndexInfo;-
32struct HiddenIndexInfo {-
33 WhereClause *pWC; /* The Where clause being analyzed */-
34 Parse *pParse; /* The parsing context */-
35};-
36-
37/* Forward declaration of methods */-
38static int whereLoopResize(sqlite3*, WhereLoop*, int);-
39-
40/* Test variable that can be set to enable WHERE tracing */-
41#if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)-
42/***/ int sqlite3WhereTrace = 0;-
43#endif-
44-
45-
46/*-
47** Return the estimated number of output rows from a WHERE clause-
48*/-
49LogEst sqlite3WhereOutputRowCount(WhereInfo *pWInfo){-
50 return pWInfo->nRowOut;
executed 489286 times by 435 tests: return pWInfo->nRowOut;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
489286
51}-
52-
53/*-
54** Return one of the WHERE_DISTINCT_xxxxx values to indicate how this-
55** WHERE clause returns outputs for DISTINCT processing.-
56*/-
57int sqlite3WhereIsDistinct(WhereInfo *pWInfo){-
58 return pWInfo->eDistinct;
executed 348 times by 1 test: return pWInfo->eDistinct;
Executed by:
  • Self test (438)
348
59}-
60-
61/*-
62** Return TRUE if the WHERE clause returns rows in ORDER BY order.-
63** Return FALSE if the output needs to be sorted.-
64*/-
65int sqlite3WhereIsOrdered(WhereInfo *pWInfo){-
66 return pWInfo->nOBSat;
executed 80481 times by 435 tests: return pWInfo->nOBSat;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
80481
67}-
68-
69/*-
70** In the ORDER BY LIMIT optimization, if the inner-most loop is known-
71** to emit rows in increasing order, and if the last row emitted by the-
72** inner-most loop did not fit within the sorter, then we can skip all-
73** subsequent rows for the current iteration of the inner loop (because they-
74** will not fit in the sorter either) and continue with the second inner-
75** loop - the loop immediately outside the inner-most.-
76**-
77** When a row does not fit in the sorter (because the sorter already-
78** holds LIMIT+OFFSET rows that are smaller), then a jump is made to the-
79** label returned by this function.-
80**-
81** If the ORDER BY LIMIT optimization applies, the jump destination should-
82** be the continuation for the second-inner-most loop. If the ORDER BY-
83** LIMIT optimization does not apply, then the jump destination should-
84** be the continuation for the inner-most loop.-
85**-
86** It is always safe for this routine to return the continuation of the-
87** inner-most loop, in the sense that a correct answer will result. -
88** Returning the continuation the second inner loop is an optimization-
89** that might make the code run a little faster, but should not change-
90** the final answer.-
91*/-
92int sqlite3WhereOrderByLimitOptLabel(WhereInfo *pWInfo){-
93 WhereLevel *pInner;-
94 if( !pWInfo->bOrderedInnerLoop ){
!pWInfo->bOrderedInnerLoopDescription
TRUEevaluated 57742 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 51 times by 1 test
Evaluated by:
  • Self test (438)
51-57742
95 /* The ORDER BY LIMIT optimization does not apply. Jump to the -
96 ** continuation of the inner-most loop. */-
97 return pWInfo->iContinue;
executed 57742 times by 435 tests: return pWInfo->iContinue;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
57742
98 }-
99 pInner = &pWInfo->a[pWInfo->nLevel-1];-
100 assert( pInner->addrNxt!=0 );-
101 return pInner->addrNxt;
executed 51 times by 1 test: return pInner->addrNxt;
Executed by:
  • Self test (438)
51
102}-
103-
104/*-
105** Return the VDBE address or label to jump to in order to continue-
106** immediately with the next row of a WHERE clause.-
107*/-
108int sqlite3WhereContinueLabel(WhereInfo *pWInfo){-
109 assert( pWInfo->iContinue!=0 );-
110 return pWInfo->iContinue;
executed 248618 times by 435 tests: return pWInfo->iContinue;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
248618
111}-
112-
113/*-
114** Return the VDBE address or label to jump to in order to break-
115** out of a WHERE loop.-
116*/-
117int sqlite3WhereBreakLabel(WhereInfo *pWInfo){-
118 return pWInfo->iBreak;
executed 249683 times by 435 tests: return pWInfo->iBreak;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
249683
119}-
120-
121/*-
122** Return ONEPASS_OFF (0) if an UPDATE or DELETE statement is unable to-
123** operate directly on the rowis returned by a WHERE clause. Return-
124** ONEPASS_SINGLE (1) if the statement can operation directly because only-
125** a single row is to be changed. Return ONEPASS_MULTI (2) if the one-pass-
126** optimization can be used on multiple -
127**-
128** If the ONEPASS optimization is used (if this routine returns true)-
129** then also write the indices of open cursors used by ONEPASS-
130** into aiCur[0] and aiCur[1]. iaCur[0] gets the cursor of the data-
131** table and iaCur[1] gets the cursor used by an auxiliary index.-
132** Either value may be -1, indicating that cursor is not used.-
133** Any cursors returned will have been opened for writing.-
134**-
135** aiCur[0] and aiCur[1] both get -1 if the where-clause logic is-
136** unable to use the ONEPASS optimization.-
137*/-
138int sqlite3WhereOkOnePass(WhereInfo *pWInfo, int *aiCur){-
139 memcpy(aiCur, pWInfo->aiCurOnePass, sizeof(int)*2);-
140#ifdef WHERETRACE_ENABLED-
141 if( sqlite3WhereTrace && pWInfo->eOnePass!=ONEPASS_OFF ){-
142 sqlite3DebugPrintf("%s cursors: %d %d\n",-
143 pWInfo->eOnePass==ONEPASS_SINGLE ? "ONEPASS_SINGLE" : "ONEPASS_MULTI",-
144 aiCur[0], aiCur[1]);-
145 }-
146#endif-
147 return pWInfo->eOnePass;
executed 40356 times by 378 tests: return pWInfo->eOnePass;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • ...
40356
148}-
149-
150/*-
151** Move the content of pSrc into pDest-
152*/-
153static void whereOrMove(WhereOrSet *pDest, WhereOrSet *pSrc){-
154 pDest->n = pSrc->n;-
155 memcpy(pDest->a, pSrc->a, pDest->n*sizeof(pDest->a[0]));-
156}
executed 18177 times by 1 test: end of block
Executed by:
  • Self test (438)
18177
157-
158/*-
159** Try to insert a new prerequisite/cost entry into the WhereOrSet pSet.-
160**-
161** The new entry might overwrite an existing entry, or it might be-
162** appended, or it might be discarded. Do whatever is the right thing-
163** so that pSet keeps the N_OR_COST best entries seen so far.-
164*/-
165static int whereOrInsert(-
166 WhereOrSet *pSet, /* The WhereOrSet to be updated */-
167 Bitmask prereq, /* Prerequisites of the new entry */-
168 LogEst rRun, /* Run-cost of the new entry */-
169 LogEst nOut /* Number of outputs for the new entry */-
170){-
171 u16 i;-
172 WhereOrCost *p;-
173 for(i=pSet->n, p=pSet->a; i>0; i--, p++){
i>0Description
TRUEevaluated 12221 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 33817 times by 1 test
Evaluated by:
  • Self test (438)
12221-33817
174 if( rRun<=p->rRun && (prereq & p->prereq)==prereq ){
rRun<=p->rRunDescription
TRUEevaluated 5875 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 6346 times by 1 test
Evaluated by:
  • Self test (438)
(prereq & p->prereq)==prereqDescription
TRUEevaluated 5840 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 35 times by 1 test
Evaluated by:
  • Self test (438)
35-6346
175 goto whereOrInsert_done;
executed 5840 times by 1 test: goto whereOrInsert_done;
Executed by:
  • Self test (438)
5840
176 }-
177 if( p->rRun<=rRun && (p->prereq & prereq)==p->prereq ){
p->rRun<=rRunDescription
TRUEevaluated 6359 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test (438)
(p->prereq & p...eq)==p->prereqDescription
TRUEevaluated 6321 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 38 times by 1 test
Evaluated by:
  • Self test (438)
22-6359
178 return 0;
executed 6321 times by 1 test: return 0;
Executed by:
  • Self test (438)
6321
179 }-
180 }
executed 60 times by 1 test: end of block
Executed by:
  • Self test (438)
60
181 if( pSet->n<N_OR_COST ){
pSet->n<3Description
TRUEevaluated 33816 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
1-33816
182 p = &pSet->a[pSet->n++];-
183 p->nOut = nOut;-
184 }else{
executed 33816 times by 1 test: end of block
Executed by:
  • Self test (438)
33816
185 p = pSet->a;-
186 for(i=1; i<pSet->n; i++){
i<pSet->nDescription
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
1-2
187 if( p->rRun>pSet->a[i].rRun ) p = pSet->a + i;
never executed: p = pSet->a + i;
p->rRun>pSet->a[i].rRunDescription
TRUEnever evaluated
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test (438)
0-2
188 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test (438)
2
189 if( p->rRun<=rRun ) return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • Self test (438)
p->rRun<=rRunDescription
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
0-1
190 }
never executed: end of block
0
191whereOrInsert_done:
code before this statement executed 33816 times by 1 test: whereOrInsert_done:
Executed by:
  • Self test (438)
33816
192 p->prereq = prereq;-
193 p->rRun = rRun;-
194 if( p->nOut>nOut ) p->nOut = nOut;
executed 4885 times by 1 test: p->nOut = nOut;
Executed by:
  • Self test (438)
p->nOut>nOutDescription
TRUEevaluated 4885 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 34771 times by 1 test
Evaluated by:
  • Self test (438)
4885-34771
195 return 1;
executed 39656 times by 1 test: return 1;
Executed by:
  • Self test (438)
39656
196}-
197-
198/*-
199** Return the bitmask for the given cursor number. Return 0 if-
200** iCursor is not in the set.-
201*/-
202Bitmask sqlite3WhereGetMask(WhereMaskSet *pMaskSet, int iCursor){-
203 int i;-
204 assert( pMaskSet->n<=(int)sizeof(Bitmask)*8 );-
205 for(i=0; i<pMaskSet->n; i++){
i<pMaskSet->nDescription
TRUEevaluated 1973090 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 162712 times by 1 test
Evaluated by:
  • Self test (438)
162712-1973090
206 if( pMaskSet->ix[i]==iCursor ){
pMaskSet->ix[i]==iCursorDescription
TRUEevaluated 1313604 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 659486 times by 1 test
Evaluated by:
  • Self test (438)
659486-1313604
207 return MASKBIT(i);
executed 1313604 times by 435 tests: return (((Bitmask)1)<<(i));
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
1313604
208 }-
209 }
executed 659486 times by 1 test: end of block
Executed by:
  • Self test (438)
659486
210 return 0;
executed 162712 times by 1 test: return 0;
Executed by:
  • Self test (438)
162712
211}-
212-
213/*-
214** Create a new mask for cursor iCursor.-
215**-
216** There is one cursor per table in the FROM clause. The number of-
217** tables in the FROM clause is limited by a test early in the-
218** sqlite3WhereBegin() routine. So we know that the pMaskSet->ix[]-
219** array will never overflow.-
220*/-
221static void createMask(WhereMaskSet *pMaskSet, int iCursor){-
222 assert( pMaskSet->n < ArraySize(pMaskSet->ix) );-
223 pMaskSet->ix[pMaskSet->n++] = iCursor;-
224}
executed 279537 times by 435 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
279537
225-
226/*-
227** Advance to the next WhereTerm that matches according to the criteria-
228** established when the pScan object was initialized by whereScanInit().-
229** Return NULL if there are no more matching WhereTerms.-
230*/-
231static WhereTerm *whereScanNext(WhereScan *pScan){-
232 int iCur; /* The cursor on the LHS of the term */-
233 i16 iColumn; /* The column on the LHS of the term. -1 for IPK */-
234 Expr *pX; /* An expression being tested */-
235 WhereClause *pWC; /* Shorthand for pScan->pWC */-
236 WhereTerm *pTerm; /* The term being tested */-
237 int k = pScan->k; /* Where to start scanning */-
238-
239 assert( pScan->iEquiv<=pScan->nEquiv );-
240 pWC = pScan->pWC;-
241 while(1){-
242 iColumn = pScan->aiColumn[pScan->iEquiv-1];-
243 iCur = pScan->aiCur[pScan->iEquiv-1];-
244 assert( pWC!=0 );-
245 do{-
246 for(pTerm=pWC->a+k; k<pWC->nTerm; k++, pTerm++){
k<pWC->nTermDescription
TRUEevaluated 1340311 times by 368 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • ...
FALSEevaluated 1017582 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
1017582-1340311
247 if( pTerm->leftCursor==iCur
pTerm->leftCursor==iCurDescription
TRUEevaluated 756518 times by 36 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (4)
  • Self test (40)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • ...
FALSEevaluated 583793 times by 360 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • ...
583793-756518
248 && pTerm->u.leftColumn==iColumn
pTerm->u.leftColumn==iColumnDescription
TRUEevaluated 160745 times by 30 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
FALSEevaluated 595773 times by 34 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (40)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • ...
160745-595773
249 && (iColumn!=XN_EXPR
iColumn!=(-2)Description
TRUEevaluated 160665 times by 30 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
FALSEevaluated 80 times by 1 test
Evaluated by:
  • Self test (438)
80-160665
250 || sqlite3ExprCompareSkip(pTerm->pExpr->pLeft,
sqlite3ExprCom...xExpr,iCur)==0Description
TRUEevaluated 58 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test (438)
22-58
251 pScan->pIdxExpr,iCur)==0)
sqlite3ExprCom...xExpr,iCur)==0Description
TRUEevaluated 58 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 22 times by 1 test
Evaluated by:
  • Self test (438)
22-58
252 && (pScan->iEquiv<=1 || !ExprHasProperty(pTerm->pExpr, EP_FromJoin))
pScan->iEquiv<=1Description
TRUEevaluated 153550 times by 30 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
FALSEevaluated 7173 times by 1 test
Evaluated by:
  • Self test (438)
!(((pTerm->pEx...0x000001))!=0)Description
TRUEevaluated 7161 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test (438)
12-153550
253 ){-
254 if( (pTerm->eOperator & WO_EQUIV)!=0
(pTerm->eOperator & 0x0800)!=0Description
TRUEevaluated 14154 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 146557 times by 30 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
14154-146557
255 && pScan->nEquiv<ArraySize(pScan->aiCur)
pScan->nEquiv<...n->aiCur[0])))Description
TRUEevaluated 14154 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
0-14154
256 && (pX = sqlite3ExprSkipCollate(pTerm->pExpr->pRight))->op==TK_COLUMN
(pX = sqlite3E...ght))->op==158Description
TRUEevaluated 14150 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
4-14150
257 ){-
258 int j;-
259 for(j=0; j<pScan->nEquiv; j++){
j<pScan->nEquivDescription
TRUEevaluated 14729 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 7114 times by 1 test
Evaluated by:
  • Self test (438)
7114-14729
260 if( pScan->aiCur[j]==pX->iTable
pScan->aiCur[j]==pX->iTableDescription
TRUEevaluated 7108 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 7621 times by 1 test
Evaluated by:
  • Self test (438)
7108-7621
261 && pScan->aiColumn[j]==pX->iColumn ){
pScan->aiColum...]==pX->iColumnDescription
TRUEevaluated 7036 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 72 times by 1 test
Evaluated by:
  • Self test (438)
72-7036
262 break;
executed 7036 times by 1 test: break;
Executed by:
  • Self test (438)
7036
263 }-
264 }
executed 7693 times by 1 test: end of block
Executed by:
  • Self test (438)
7693
265 if( j==pScan->nEquiv ){
j==pScan->nEquivDescription
TRUEevaluated 7114 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 7036 times by 1 test
Evaluated by:
  • Self test (438)
7036-7114
266 pScan->aiCur[j] = pX->iTable;-
267 pScan->aiColumn[j] = pX->iColumn;-
268 pScan->nEquiv++;-
269 }
executed 7114 times by 1 test: end of block
Executed by:
  • Self test (438)
7114
270 }
executed 14150 times by 1 test: end of block
Executed by:
  • Self test (438)
14150
271 if( (pTerm->eOperator & pScan->opMask)!=0 ){
(pTerm->eOpera...an->opMask)!=0Description
TRUEevaluated 131301 times by 30 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
FALSEevaluated 29410 times by 1 test
Evaluated by:
  • Self test (438)
29410-131301
272 /* Verify the affinity and collating sequence match */-
273 if( pScan->zCollName && (pTerm->eOperator & WO_ISNULL)==0 ){
pScan->zCollNameDescription
TRUEevaluated 69769 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 61532 times by 30 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
(pTerm->eOperator & 0x0100)==0Description
TRUEevaluated 69486 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 283 times by 1 test
Evaluated by:
  • Self test (438)
283-69769
274 CollSeq *pColl;-
275 Parse *pParse = pWC->pWInfo->pParse;-
276 pX = pTerm->pExpr;-
277 if( !sqlite3IndexAffinityOk(pX, pScan->idxaff) ){
!sqlite3IndexA...pScan->idxaff)Description
TRUEevaluated 937 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 68549 times by 1 test
Evaluated by:
  • Self test (438)
937-68549
278 continue;
executed 937 times by 1 test: continue;
Executed by:
  • Self test (438)
937
279 }-
280 assert(pX->pLeft);-
281 pColl = sqlite3BinaryCompareCollSeq(pParse,-
282 pX->pLeft, pX->pRight);-
283 if( pColl==0 ) pColl = pParse->db->pDfltColl;
executed 2149 times by 1 test: pColl = pParse->db->pDfltColl;
Executed by:
  • Self test (438)
pColl==0Description
TRUEevaluated 2149 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 66400 times by 1 test
Evaluated by:
  • Self test (438)
2149-66400
284 if( sqlite3StrICmp(pColl->zName, pScan->zCollName) ){
sqlite3StrICmp...an->zCollName)Description
TRUEevaluated 103 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 68446 times by 1 test
Evaluated by:
  • Self test (438)
103-68446
285 continue;
executed 103 times by 1 test: continue;
Executed by:
  • Self test (438)
103
286 }-
287 }
executed 68446 times by 1 test: end of block
Executed by:
  • Self test (438)
68446
288 if( (pTerm->eOperator & (WO_EQ|WO_IS))!=0
(pTerm->eOpera...02|0x0080))!=0Description
TRUEevaluated 80231 times by 30 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
FALSEevaluated 50030 times by 1 test
Evaluated by:
  • Self test (438)
50030-80231
289 && (pX = pTerm->pExpr->pRight)->op==TK_COLUMN
(pX = pTerm->p...ight)->op==158Description
TRUEevaluated 14737 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 65494 times by 30 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
14737-65494
290 && pX->iTable==pScan->aiCur[0]
pX->iTable==pScan->aiCur[0]Description
TRUEevaluated 6917 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 7820 times by 1 test
Evaluated by:
  • Self test (438)
6917-7820
291 && pX->iColumn==pScan->aiColumn[0]
pX->iColumn==p...n->aiColumn[0]Description
TRUEevaluated 6912 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test (438)
5-6912
292 ){-
293 testcase( pTerm->eOperator & WO_IS );-
294 continue;
executed 6912 times by 1 test: continue;
Executed by:
  • Self test (438)
6912
295 }-
296 pScan->pWC = pWC;-
297 pScan->k = k+1;-
298 return pTerm;
executed 123349 times by 30 tests: return pTerm;
Executed by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
123349
299 }-
300 }
executed 29410 times by 1 test: end of block
Executed by:
  • Self test (438)
29410
301 }
executed 1209010 times by 366 tests: end of block
Executed by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • ...
1209010
302 pWC = pWC->pOuter;-
303 k = 0;-
304 }while( pWC!=0 );
executed 1017582 times by 435 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
pWC!=0Description
TRUEevaluated 124663 times by 2 tests
Evaluated by:
  • Self test (34)
  • Self test (438)
FALSEevaluated 892919 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
124663-1017582
305 if( pScan->iEquiv>=pScan->nEquiv ) break;
executed 885839 times by 435 tests: break;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
pScan->iEquiv>=pScan->nEquivDescription
TRUEevaluated 885839 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 7080 times by 1 test
Evaluated by:
  • Self test (438)
7080-885839
306 pWC = pScan->pOrigWC;-
307 k = 0;-
308 pScan->iEquiv++;-
309 }
executed 7080 times by 1 test: end of block
Executed by:
  • Self test (438)
7080
310 return 0;
executed 885839 times by 435 tests: return 0;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
885839
311}-
312-
313/*-
314** Initialize a WHERE clause scanner object. Return a pointer to the-
315** first match. Return NULL if there are no matches.-
316**-
317** The scanner will be searching the WHERE clause pWC. It will look-
318** for terms of the form "X <op> <expr>" where X is column iColumn of table-
319** iCur. Or if pIdx!=0 then X is column iColumn of index pIdx. pIdx-
320** must be one of the indexes of table iCur.-
321**-
322** The <op> must be one of the operators described by opMask.-
323**-
324** If the search is for X and the WHERE clause contains terms of the-
325** form X=Y then this routine might also return terms of the form-
326** "Y <op> <expr>". The number of levels of transitivity is limited,-
327** but is enough to handle most commonly occurring SQL statements.-
328**-
329** If X is not the INTEGER PRIMARY KEY then X must be compatible with-
330** index pIdx.-
331*/-
332static WhereTerm *whereScanInit(-
333 WhereScan *pScan, /* The WhereScan object being initialized */-
334 WhereClause *pWC, /* The WHERE clause to be scanned */-
335 int iCur, /* Cursor to scan for */-
336 int iColumn, /* Column to scan for */-
337 u32 opMask, /* Operator(s) to scan for */-
338 Index *pIdx /* Must be compatible with this index */-
339){-
340 pScan->pOrigWC = pWC;-
341 pScan->pWC = pWC;-
342 pScan->pIdxExpr = 0;-
343 pScan->idxaff = 0;-
344 pScan->zCollName = 0;-
345 if( pIdx ){
pIdxDescription
TRUEevaluated 540418 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 374621 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
374621-540418
346 int j = iColumn;-
347 iColumn = pIdx->aiColumn[j];-
348 if( iColumn==XN_EXPR ){
iColumn==(-2)Description
TRUEevaluated 151 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 540267 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
151-540267
349 pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;-
350 pScan->zCollName = pIdx->azColl[j];-
351 }else if( iColumn==pIdx->pTable->iPKey ){
executed 151 times by 1 test: end of block
Executed by:
  • Self test (438)
iColumn==pIdx->pTable->iPKeyDescription
TRUEevaluated 212090 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 328177 times by 356 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • ...
151-328177
352 iColumn = XN_ROWID;-
353 }else if( iColumn>=0 ){
executed 212090 times by 435 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
iColumn>=0Description
TRUEevaluated 252094 times by 356 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • ...
FALSEevaluated 76083 times by 333 tests
Evaluated by:
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • Self test (128)
  • Self test (129)
  • Self test (130)
  • ...
76083-252094
354 pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;-
355 pScan->zCollName = pIdx->azColl[j];-
356 }
executed 252094 times by 356 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • Self test (127)
  • ...
252094
357 }else if( iColumn==XN_EXPR ){
executed 540418 times by 435 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
iColumn==(-2)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 374620 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
1-540418
358 return 0;
executed 1 time by 1 test: return 0;
Executed by:
  • Self test (438)
1
359 }-
360 pScan->opMask = opMask;-
361 pScan->k = 0;-
362 pScan->aiCur[0] = iCur;-
363 pScan->aiColumn[0] = iColumn;-
364 pScan->nEquiv = 1;-
365 pScan->iEquiv = 1;-
366 return whereScanNext(pScan);
executed 915038 times by 435 tests: return whereScanNext(pScan);
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
915038
367}-
368-
369/*-
370** Search for a term in the WHERE clause that is of the form "X <op> <expr>"-
371** where X is a reference to the iColumn of table iCur or of index pIdx-
372** if pIdx!=0 and <op> is one of the WO_xx operator codes specified by-
373** the op parameter. Return a pointer to the term. Return 0 if not found.-
374**-
375** If pIdx!=0 then it must be one of the indexes of table iCur. -
376** Search for terms matching the iColumn-th column of pIdx-
377** rather than the iColumn-th column of table iCur.-
378**-
379** The term returned might by Y=<expr> if there is another constraint in-
380** the WHERE clause that specifies that X=Y. Any such constraints will be-
381** identified by the WO_EQUIV bit in the pTerm->eOperator field. The-
382** aiCur[]/iaColumn[] arrays hold X and all its equivalents. There are 11-
383** slots in aiCur[]/aiColumn[] so that means we can look for X plus up to 10-
384** other equivalent values. Hence a search for X will return <expr> if X=A1-
385** and A1=A2 and A2=A3 and ... and A9=A10 and A10=<expr>.-
386**-
387** If there are multiple terms in the WHERE clause of the form "X <op> <expr>"-
388** then try for the one with no dependencies on <expr> - in other words where-
389** <expr> is a constant expression of some kind. Only return entries of-
390** the form "X <op> Y" where Y is a column in another table if no terms of-
391** the form "X <op> <const-expr>" exist. If no terms with a constant RHS-
392** exist, try to return a term that does not use WO_EQUIV.-
393*/-
394WhereTerm *sqlite3WhereFindTerm(-
395 WhereClause *pWC, /* The WHERE clause to be searched */-
396 int iCur, /* Cursor number of LHS */-
397 int iColumn, /* Column number of LHS */-
398 Bitmask notReady, /* RHS must not overlap with this mask */-
399 u32 op, /* Mask of WO_xx values describing operator */-
400 Index *pIdx /* Must be compatible with this index, if not NULL */-
401){-
402 WhereTerm *pResult = 0;-
403 WhereTerm *p;-
404 WhereScan scan;-
405-
406 p = whereScanInit(&scan, pWC, iCur, iColumn, op, pIdx);-
407 op &= WO_EQ|WO_IS;-
408 while( p ){
pDescription
TRUEevaluated 33541 times by 30 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
FALSEevaluated 350807 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
33541-350807
409 if( (p->prereqRight & notReady)==0 ){
(p->prereqRight & notReady)==0Description
TRUEevaluated 30224 times by 30 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
FALSEevaluated 3317 times by 1 test
Evaluated by:
  • Self test (438)
3317-30224
410 if( p->prereqRight==0 && (p->eOperator&op)!=0 ){
p->prereqRight==0Description
TRUEevaluated 29888 times by 30 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
FALSEevaluated 336 times by 1 test
Evaluated by:
  • Self test (438)
(p->eOperator&op)!=0Description
TRUEevaluated 29197 times by 30 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
FALSEevaluated 691 times by 1 test
Evaluated by:
  • Self test (438)
336-29888
411 testcase( p->eOperator & WO_IS );-
412 return p;
executed 29197 times by 30 tests: return p;
Executed by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (30)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (39)
  • Self test (438)
  • Self test (47)
  • Self test (48)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • Self test (92)
  • Self test (93)
  • Self test (94)
  • ...
29197
413 }-
414 if( pResult==0 ) pResult = p;
executed 1025 times by 1 test: pResult = p;
Executed by:
  • Self test (438)
pResult==0Description
TRUEevaluated 1025 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test (438)
2-1025
415 }
executed 1027 times by 1 test: end of block
Executed by:
  • Self test (438)
1027
416 p = whereScanNext(&scan);-
417 }
executed 4344 times by 1 test: end of block
Executed by:
  • Self test (438)
4344
418 return pResult;
executed 350807 times by 435 tests: return pResult;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
350807
419}-
420-
421/*-
422** This function searches pList for an entry that matches the iCol-th column-
423** of index pIdx.-
424**-
425** If such an expression is found, its index in pList->a[] is returned. If-
426** no expression is found, -1 is returned.-
427*/-
428static int findIndexCol(-
429 Parse *pParse, /* Parse context */-
430 ExprList *pList, /* Expression list to search */-
431 int iBase, /* Cursor for table associated with pIdx */-
432 Index *pIdx, /* Index to match column of */-
433 int iCol /* Column of index to match */-
434){-
435 int i;-
436 const char *zColl = pIdx->azColl[iCol];-
437-
438 for(i=0; i<pList->nExpr; i++){
i<pList->nExprDescription
TRUEevaluated 111 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 35 times by 1 test
Evaluated by:
  • Self test (438)
35-111
439 Expr *p = sqlite3ExprSkipCollate(pList->a[i].pExpr);-
440 if( p->op==TK_COLUMN
p->op==158Description
TRUEevaluated 104 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 7 times by 1 test
Evaluated by:
  • Self test (438)
7-104
441 && p->iColumn==pIdx->aiColumn[iCol]
p->iColumn==pI...aiColumn[iCol]Description
TRUEevaluated 37 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 67 times by 1 test
Evaluated by:
  • Self test (438)
37-67
442 && p->iTable==iBase
p->iTable==iBaseDescription
TRUEevaluated 37 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
0-37
443 ){-
444 CollSeq *pColl = sqlite3ExprNNCollSeq(pParse, pList->a[i].pExpr);-
445 if( 0==sqlite3StrICmp(pColl->zName, zColl) ){
0==sqlite3StrI...>zName, zColl)Description
TRUEevaluated 31 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test (438)
6-31
446 return i;
executed 31 times by 1 test: return i;
Executed by:
  • Self test (438)
31
447 }-
448 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test (438)
6
449 }
executed 80 times by 1 test: end of block
Executed by:
  • Self test (438)
80
450-
451 return -1;
executed 35 times by 1 test: return -1;
Executed by:
  • Self test (438)
35
452}-
453-
454/*-
455** Return TRUE if the iCol-th column of index pIdx is NOT NULL-
456*/-
457static int indexColumnNotNull(Index *pIdx, int iCol){-
458 int j;-
459 assert( pIdx!=0 );-
460 assert( iCol>=0 && iCol<pIdx->nColumn );-
461 j = pIdx->aiColumn[iCol];-
462 if( j>=0 ){
j>=0Description
TRUEevaluated 312 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 24 times by 1 test
Evaluated by:
  • Self test (438)
24-312
463 return pIdx->pTable->aCol[j].notNull;
executed 312 times by 1 test: return pIdx->pTable->aCol[j].notNull;
Executed by:
  • Self test (438)
312
464 }else if( j==(-1) ){
j==(-1)Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test (438)
2-22
465 return 1;
executed 22 times by 1 test: return 1;
Executed by:
  • Self test (438)
22
466 }else{-
467 assert( j==(-2) );-
468 return 0; /* Assume an indexed expression can always yield a NULL */
executed 2 times by 1 test: return 0;
Executed by:
  • Self test (438)
2
469-
470 }-
471}-
472-
473/*-
474** Return true if the DISTINCT expression-list passed as the third argument-
475** is redundant.-
476**-
477** A DISTINCT list is redundant if any subset of the columns in the-
478** DISTINCT list are collectively unique and individually non-null.-
479*/-
480static int isDistinctRedundant(-
481 Parse *pParse, /* Parsing context */-
482 SrcList *pTabList, /* The FROM clause */-
483 WhereClause *pWC, /* The WHERE clause */-
484 ExprList *pDistinct /* The result set that needs to be DISTINCT */-
485){-
486 Table *pTab;-
487 Index *pIdx;-
488 int i; -
489 int iBase;-
490-
491 /* If there is more than one table or sub-select in the FROM clause of-
492 ** this query, then it will not be possible to show that the DISTINCT -
493 ** clause is redundant. */-
494 if( pTabList->nSrc!=1 ) return 0;
executed 63 times by 1 test: return 0;
Executed by:
  • Self test (438)
pTabList->nSrc!=1Description
TRUEevaluated 63 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 196 times by 1 test
Evaluated by:
  • Self test (438)
63-196
495 iBase = pTabList->a[0].iCursor;-
496 pTab = pTabList->a[0].pTab;-
497-
498 /* If any of the expressions is an IPK column on table iBase, then return -
499 ** true. Note: The (p->iTable==iBase) part of this test may be false if the-
500 ** current SELECT is a correlated sub-query.-
501 */-
502 for(i=0; i<pDistinct->nExpr; i++){
i<pDistinct->nExprDescription
TRUEevaluated 318 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 189 times by 1 test
Evaluated by:
  • Self test (438)
189-318
503 Expr *p = sqlite3ExprSkipCollate(pDistinct->a[i].pExpr);-
504 if( p->op==TK_COLUMN && p->iTable==iBase && p->iColumn<0 ) return 1;
executed 7 times by 1 test: return 1;
Executed by:
  • Self test (438)
p->op==158Description
TRUEevaluated 274 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 44 times by 1 test
Evaluated by:
  • Self test (438)
p->iTable==iBaseDescription
TRUEevaluated 271 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
p->iColumn<0Description
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 264 times by 1 test
Evaluated by:
  • Self test (438)
3-274
505 }
executed 311 times by 1 test: end of block
Executed by:
  • Self test (438)
311
506-
507 /* Loop through all indices on the table, checking each to see if it makes-
508 ** the DISTINCT qualifier redundant. It does so if:-
509 **-
510 ** 1. The index is itself UNIQUE, and-
511 **-
512 ** 2. All of the columns in the index are either part of the pDistinct-
513 ** list, or else the WHERE clause contains a term of the form "col=X",-
514 ** where X is a constant value. The collation sequences of the-
515 ** comparison and select-list expressions must match those of the index.-
516 **-
517 ** 3. All of those index columns for which the WHERE clause does not-
518 ** contain a "col=X" term are subject to a NOT NULL constraint.-
519 */-
520 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
pIdxDescription
TRUEevaluated 136 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 177 times by 1 test
Evaluated by:
  • Self test (438)
136-177
521 if( !IsUniqueIndex(pIdx) ) continue;
executed 73 times by 1 test: continue;
Executed by:
  • Self test (438)
!((pIdx)->onError!=0)Description
TRUEevaluated 73 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 63 times by 1 test
Evaluated by:
  • Self test (438)
63-73
522 for(i=0; i<pIdx->nKeyCol; i++){
i<pIdx->nKeyColDescription
TRUEevaluated 70 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12 times by 1 test
Evaluated by:
  • Self test (438)
12-70
523 if( 0==sqlite3WhereFindTerm(pWC, iBase, i, ~(Bitmask)0, WO_EQ, pIdx) ){
0==sqlite3Wher... 0x0002, pIdx)Description
TRUEevaluated 66 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
4-66
524 if( findIndexCol(pParse, pDistinct, iBase, pIdx, i)<0 ) break;
executed 35 times by 1 test: break;
Executed by:
  • Self test (438)
findIndexCol(p...se, pIdx, i)<0Description
TRUEevaluated 35 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 31 times by 1 test
Evaluated by:
  • Self test (438)
31-35
525 if( indexColumnNotNull(pIdx, i)==0 ) break;
executed 16 times by 1 test: break;
Executed by:
  • Self test (438)
indexColumnNotNull(pIdx, i)==0Description
TRUEevaluated 16 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 15 times by 1 test
Evaluated by:
  • Self test (438)
15-16
526 }
executed 15 times by 1 test: end of block
Executed by:
  • Self test (438)
15
527 }
executed 19 times by 1 test: end of block
Executed by:
  • Self test (438)
19
528 if( i==pIdx->nKeyCol ){
i==pIdx->nKeyColDescription
TRUEevaluated 12 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 51 times by 1 test
Evaluated by:
  • Self test (438)
12-51
529 /* This index implies that the DISTINCT qualifier is redundant. */-
530 return 1;
executed 12 times by 1 test: return 1;
Executed by:
  • Self test (438)
12
531 }-
532 }
executed 51 times by 1 test: end of block
Executed by:
  • Self test (438)
51
533-
534 return 0;
executed 177 times by 1 test: return 0;
Executed by:
  • Self test (438)
177
535}-
536-
537-
538/*-
539** Estimate the logarithm of the input value to base 2.-
540*/-
541static LogEst estLog(LogEst N){-
542 return N<=10 ? 0 : sqlite3LogEst(N) - 33;
executed 821273 times by 435 tests: return N<=10 ? 0 : sqlite3LogEst(N) - 33;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
N<=10Description
TRUEevaluated 942 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 820331 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
942-821273
543}-
544-
545/*-
546** Convert OP_Column opcodes to OP_Copy in previously generated code.-
547**-
548** This routine runs over generated VDBE code and translates OP_Column-
549** opcodes into OP_Copy when the table is being accessed via co-routine -
550** instead of via table lookup.-
551**-
552** If the bIncrRowid parameter is 0, then any OP_Rowid instructions on-
553** cursor iTabCur are transformed into OP_Null. Or, if bIncrRowid is non-zero,-
554** then each OP_Rowid is transformed into an instruction to increment the-
555** value stored in its output register.-
556*/-
557static void translateColumnToCopy(-
558 Parse *pParse, /* Parsing context */-
559 int iStart, /* Translate from this opcode to the end */-
560 int iTabCur, /* OP_Column/OP_Rowid references to this table */-
561 int iRegister, /* The first column is in this register */-
562 int bIncrRowid /* If non-zero, transform OP_rowid to OP_AddImm(1) */-
563){-
564 Vdbe *v = pParse->pVdbe;-
565 VdbeOp *pOp = sqlite3VdbeGetOp(v, iStart);-
566 int iEnd = sqlite3VdbeCurrentAddr(v);-
567 if( pParse->db->mallocFailed ) return;
never executed: return;
pParse->db->mallocFailedDescription
TRUEnever evaluated
FALSEevaluated 35367 times by 1 test
Evaluated by:
  • Self test (438)
0-35367
568 for(; iStart<iEnd; iStart++, pOp++){
iStart<iEndDescription
TRUEevaluated 229659 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 35367 times by 1 test
Evaluated by:
  • Self test (438)
35367-229659
569 if( pOp->p1!=iTabCur ) continue;
executed 188002 times by 1 test: continue;
Executed by:
  • Self test (438)
pOp->p1!=iTabCurDescription
TRUEevaluated 188002 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 41657 times by 1 test
Evaluated by:
  • Self test (438)
41657-188002
570 if( pOp->opcode==OP_Column ){
pOp->opcode==90Description
TRUEevaluated 40510 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1147 times by 1 test
Evaluated by:
  • Self test (438)
1147-40510
571 pOp->opcode = OP_Copy;-
572 pOp->p1 = pOp->p2 + iRegister;-
573 pOp->p2 = pOp->p3;-
574 pOp->p3 = 0;-
575 }else if( pOp->opcode==OP_Rowid ){
executed 40510 times by 1 test: end of block
Executed by:
  • Self test (438)
pOp->opcode==129Description
TRUEevaluated 9 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1138 times by 1 test
Evaluated by:
  • Self test (438)
9-40510
576 if( bIncrRowid ){
bIncrRowidDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 6 times by 1 test
Evaluated by:
  • Self test (438)
3-6
577 /* Increment the value stored in the P2 operand of the OP_Rowid. */-
578 pOp->opcode = OP_AddImm;-
579 pOp->p1 = pOp->p2;-
580 pOp->p2 = 1;-
581 }else{
executed 3 times by 1 test: end of block
Executed by:
  • Self test (438)
3
582 pOp->opcode = OP_Null;-
583 pOp->p1 = 0;-
584 pOp->p3 = 0;-
585 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test (438)
6
586 }-
587 }
executed 41657 times by 1 test: end of block
Executed by:
  • Self test (438)
41657
588}
executed 35367 times by 1 test: end of block
Executed by:
  • Self test (438)
35367
589-
590/*-
591** Two routines for printing the content of an sqlite3_index_info-
592** structure. Used for testing and debugging only. If neither-
593** SQLITE_TEST or SQLITE_DEBUG are defined, then these routines-
594** are no-ops.-
595*/-
596#if !defined(SQLITE_OMIT_VIRTUALTABLE) && defined(WHERETRACE_ENABLED)-
597static void TRACE_IDX_INPUTS(sqlite3_index_info *p){-
598 int i;-
599 if( !sqlite3WhereTrace ) return;-
600 for(i=0; i<p->nConstraint; i++){-
601 sqlite3DebugPrintf(" constraint[%d]: col=%d termid=%d op=%d usabled=%d\n",-
602 i,-
603 p->aConstraint[i].iColumn,-
604 p->aConstraint[i].iTermOffset,-
605 p->aConstraint[i].op,-
606 p->aConstraint[i].usable);-
607 }-
608 for(i=0; i<p->nOrderBy; i++){-
609 sqlite3DebugPrintf(" orderby[%d]: col=%d desc=%d\n",-
610 i,-
611 p->aOrderBy[i].iColumn,-
612 p->aOrderBy[i].desc);-
613 }-
614}-
615static void TRACE_IDX_OUTPUTS(sqlite3_index_info *p){-
616 int i;-
617 if( !sqlite3WhereTrace ) return;-
618 for(i=0; i<p->nConstraint; i++){-
619 sqlite3DebugPrintf(" usage[%d]: argvIdx=%d omit=%d\n",-
620 i,-
621 p->aConstraintUsage[i].argvIndex,-
622 p->aConstraintUsage[i].omit);-
623 }-
624 sqlite3DebugPrintf(" idxNum=%d\n", p->idxNum);-
625 sqlite3DebugPrintf(" idxStr=%s\n", p->idxStr);-
626 sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed);-
627 sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost);-
628 sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows);-
629}-
630#else-
631#define TRACE_IDX_INPUTS(A)-
632#define TRACE_IDX_OUTPUTS(A)-
633#endif-
634-
635#ifndef SQLITE_OMIT_AUTOMATIC_INDEX-
636/*-
637** Return TRUE if the WHERE clause term pTerm is of a form where it-
638** could be used with an index to access pSrc, assuming an appropriate-
639** index existed.-
640*/-
641static int termCanDriveIndex(-
642 WhereTerm *pTerm, /* WHERE clause term to check */-
643 struct SrcList_item *pSrc, /* Table we are trying to access */-
644 Bitmask notReady /* Tables in outer loops of the join */-
645){-
646 char aff;-
647 if( pTerm->leftCursor!=pSrc->iCursor ) return 0;
executed 305767 times by 360 tests: return 0;
Executed by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • ...
pTerm->leftCur...=pSrc->iCursorDescription
TRUEevaluated 305767 times by 360 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (120)
  • Self test (121)
  • Self test (122)
  • Self test (123)
  • Self test (124)
  • Self test (125)
  • Self test (126)
  • ...
FALSEevaluated 86476 times by 34 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (40)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • ...
86476-305767
648 if( (pTerm->eOperator & (WO_EQ|WO_IS))==0 ) return 0;
executed 18559 times by 3 tests: return 0;
Executed by:
  • Self test (40)
  • Self test (438)
  • Self test (47)
(pTerm->eOpera...02|0x0080))==0Description
TRUEevaluated 18559 times by 3 tests
Evaluated by:
  • Self test (40)
  • Self test (438)
  • Self test (47)
FALSEevaluated 67917 times by 33 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • ...
18559-67917
649 if( (pSrc->fg.jointype & JT_LEFT)
(pSrc->fg.jointype & 0x0008)Description
TRUEevaluated 853 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 67064 times by 33 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • ...
853-67064
650 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
!(((pTerm->pEx...0x000001))!=0)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 850 times by 1 test
Evaluated by:
  • Self test (438)
3-850
651 && (pTerm->eOperator & WO_IS)
(pTerm->eOperator & 0x0080)Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
0-3
652 ){-
653 /* Cannot use an IS term from the WHERE clause as an index driver for-
654 ** the RHS of a LEFT JOIN. Such a term can only be used if it is from-
655 ** the ON clause. */-
656 return 0;
executed 3 times by 1 test: return 0;
Executed by:
  • Self test (438)
3
657 }-
658 if( (pTerm->prereqRight & notReady)!=0 ) return 0;
executed 170 times by 1 test: return 0;
Executed by:
  • Self test (438)
(pTerm->prereq...& notReady)!=0Description
TRUEevaluated 170 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 67744 times by 33 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • ...
170-67744
659 if( pTerm->u.leftColumn<0 ) return 0;
executed 1152 times by 1 test: return 0;
Executed by:
  • Self test (438)
pTerm->u.leftColumn<0Description
TRUEevaluated 1152 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 66592 times by 33 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • ...
1152-66592
660 aff = pSrc->pTab->aCol[pTerm->u.leftColumn].affinity;-
661 if( !sqlite3IndexAffinityOk(pTerm->pExpr, aff) ) return 0;
executed 463 times by 1 test: return 0;
Executed by:
  • Self test (438)
!sqlite3IndexA...m->pExpr, aff)Description
TRUEevaluated 463 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 66129 times by 33 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • ...
463-66129
662 testcase( pTerm->pExpr->op==TK_IS );-
663 return 1;
executed 66129 times by 33 tests: return 1;
Executed by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • ...
66129
664}-
665#endif-
666-
667-
668#ifndef SQLITE_OMIT_AUTOMATIC_INDEX-
669/*-
670** Generate code to construct the Index object for an automatic index-
671** and to set up the WhereLevel object pLevel so that the code generator-
672** makes use of the automatic index.-
673*/-
674static void constructAutomaticIndex(-
675 Parse *pParse, /* The parsing context */-
676 WhereClause *pWC, /* The WHERE clause */-
677 struct SrcList_item *pSrc, /* The FROM clause term to get the next index */-
678 Bitmask notReady, /* Mask of cursors that are not available */-
679 WhereLevel *pLevel /* Write new index here */-
680){-
681 int nKeyCol; /* Number of columns in the constructed index */-
682 WhereTerm *pTerm; /* A single term of the WHERE clause */-
683 WhereTerm *pWCEnd; /* End of pWC->a[] */-
684 Index *pIdx; /* Object describing the transient index */-
685 Vdbe *v; /* Prepared statement under construction */-
686 int addrInit; /* Address of the initialization bypass jump */-
687 Table *pTable; /* The table being indexed */-
688 int addrTop; /* Top of the index fill loop */-
689 int regRecord; /* Register holding an index record */-
690 int n; /* Column counter */-
691 int i; /* Loop counter */-
692 int mxBitCol; /* Maximum column in pSrc->colUsed */-
693 CollSeq *pColl; /* Collating sequence to on a column */-
694 WhereLoop *pLoop; /* The Loop object */-
695 char *zNotUsed; /* Extra space on the end of pIdx */-
696 Bitmask idxCols; /* Bitmap of columns used for indexing */-
697 Bitmask extraCols; /* Bitmap of additional columns */-
698 u8 sentWarning = 0; /* True if a warnning has been issued */-
699 Expr *pPartial = 0; /* Partial Index Expression */-
700 int iContinue = 0; /* Jump here to skip excluded rows */-
701 struct SrcList_item *pTabItem; /* FROM clause term being indexed */-
702 int addrCounter = 0; /* Address where integer counter is initialized */-
703 int regBase; /* Array of registers where record is assembled */-
704-
705 /* Generate code to skip over the creation and initialization of the-
706 ** transient index on 2nd and subsequent iterations of the loop. */-
707 v = pParse->pVdbe;-
708 assert( v!=0 );-
709 addrInit = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);-
710-
711 /* Count the number of columns that will be added to the index-
712 ** and used to match WHERE clause constraints */-
713 nKeyCol = 0;-
714 pTable = pSrc->pTab;-
715 pWCEnd = &pWC->a[pWC->nTerm];-
716 pLoop = pLevel->pWLoop;-
717 idxCols = 0;-
718 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
pTerm<pWCEndDescription
TRUEevaluated 88711 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2859 times by 1 test
Evaluated by:
  • Self test (438)
2859-88711
719 Expr *pExpr = pTerm->pExpr;-
720 assert( !ExprHasProperty(pExpr, EP_FromJoin) /* prereq always non-zero */-
721 || pExpr->iRightJoinTable!=pSrc->iCursor /* for the right-hand */-
722 || pLoop->prereq!=0 ); /* table of a LEFT JOIN */-
723 if( pLoop->prereq==0
pLoop->prereq==0Description
TRUEevaluated 146 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 88565 times by 1 test
Evaluated by:
  • Self test (438)
146-88565
724 && (pTerm->wtFlags & TERM_VIRTUAL)==0
(pTerm->wtFlags & 0x02)==0Description
TRUEevaluated 114 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 32 times by 1 test
Evaluated by:
  • Self test (438)
32-114
725 && !ExprHasProperty(pExpr, EP_FromJoin)
!(((pExpr)->fl...0x000001))!=0)Description
TRUEevaluated 114 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
0-114
726 && sqlite3ExprIsTableConstant(pExpr, pSrc->iCursor) ){
sqlite3ExprIsT...pSrc->iCursor)Description
TRUEevaluated 64 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 50 times by 1 test
Evaluated by:
  • Self test (438)
50-64
727 pPartial = sqlite3ExprAnd(pParse->db, pPartial,-
728 sqlite3ExprDup(pParse->db, pExpr, 0));-
729 }
executed 64 times by 1 test: end of block
Executed by:
  • Self test (438)
64
730 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
termCanDriveIn...Src, notReady)Description
TRUEevaluated 3019 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 85692 times by 1 test
Evaluated by:
  • Self test (438)
3019-85692
731 int iCol = pTerm->u.leftColumn;-
732 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
iCol>=((int)(s...f(Bitmask)*8))Description
TRUEnever evaluated
FALSEevaluated 3019 times by 1 test
Evaluated by:
  • Self test (438)
0-3019
733 testcase( iCol==BMS );-
734 testcase( iCol==BMS-1 );-
735 if( !sentWarning ){
!sentWarningDescription
TRUEevaluated 2859 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 160 times by 1 test
Evaluated by:
  • Self test (438)
160-2859
736 sqlite3_log(SQLITE_WARNING_AUTOINDEX,-
737 "automatic index on %s(%s)", pTable->zName,-
738 pTable->aCol[iCol].zName);-
739 sentWarning = 1;-
740 }
executed 2859 times by 1 test: end of block
Executed by:
  • Self test (438)
2859
741 if( (idxCols & cMask)==0 ){
(idxCols & cMask)==0Description
TRUEevaluated 3006 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test (438)
13-3006
742 if( whereLoopResize(pParse->db, pLoop, nKeyCol+1) ){
whereLoopResiz...op, nKeyCol+1)Description
TRUEnever evaluated
FALSEevaluated 3006 times by 1 test
Evaluated by:
  • Self test (438)
0-3006
743 goto end_auto_index_create;
never executed: goto end_auto_index_create;
0
744 }-
745 pLoop->aLTerm[nKeyCol++] = pTerm;-
746 idxCols |= cMask;-
747 }
executed 3006 times by 1 test: end of block
Executed by:
  • Self test (438)
3006
748 }
executed 3019 times by 1 test: end of block
Executed by:
  • Self test (438)
3019
749 }
executed 88711 times by 1 test: end of block
Executed by:
  • Self test (438)
88711
750 assert( nKeyCol>0 );-
751 pLoop->u.btree.nEq = pLoop->nLTerm = nKeyCol;-
752 pLoop->wsFlags = WHERE_COLUMN_EQ | WHERE_IDX_ONLY | WHERE_INDEXED-
753 | WHERE_AUTO_INDEX;-
754-
755 /* Count the number of additional columns needed to create a-
756 ** covering index. A "covering index" is an index that contains all-
757 ** columns that are needed by the query. With a covering index, the-
758 ** original table never needs to be accessed. Automatic indices must-
759 ** be a covering index because the index will not be updated if the-
760 ** original table changes and the index and table cannot both be used-
761 ** if they go out of sync.-
762 */-
763 extraCols = pSrc->colUsed & (~idxCols | MASKBIT(BMS-1));-
764 mxBitCol = MIN(BMS-1,pTable->nCol);
(((int)(sizeof...(pTable->nCol)Description
TRUEnever evaluated
FALSEevaluated 2859 times by 1 test
Evaluated by:
  • Self test (438)
0-2859
765 testcase( pTable->nCol==BMS-1 );-
766 testcase( pTable->nCol==BMS-2 );-
767 for(i=0; i<mxBitCol; i++){
i<mxBitColDescription
TRUEevaluated 3899 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2859 times by 1 test
Evaluated by:
  • Self test (438)
2859-3899
768 if( extraCols & MASKBIT(i) ) nKeyCol++;
executed 722 times by 1 test: nKeyCol++;
Executed by:
  • Self test (438)
extraCols & ((...tmask)1)<<(i))Description
TRUEevaluated 722 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3177 times by 1 test
Evaluated by:
  • Self test (438)
722-3177
769 }
executed 3899 times by 1 test: end of block
Executed by:
  • Self test (438)
3899
770 if( pSrc->colUsed & MASKBIT(BMS-1) ){
pSrc->colUsed ...tmask)*8))-1))Description
TRUEnever evaluated
FALSEevaluated 2859 times by 1 test
Evaluated by:
  • Self test (438)
0-2859
771 nKeyCol += pTable->nCol - BMS + 1;-
772 }
never executed: end of block
0
773-
774 /* Construct the Index object to describe this index */-
775 pIdx = sqlite3AllocateIndexObject(pParse->db, nKeyCol+1, 0, &zNotUsed);-
776 if( pIdx==0 ) goto end_auto_index_create;
never executed: goto end_auto_index_create;
pIdx==0Description
TRUEnever evaluated
FALSEevaluated 2859 times by 1 test
Evaluated by:
  • Self test (438)
0-2859
777 pLoop->u.btree.pIndex = pIdx;-
778 pIdx->zName = "auto-index";-
779 pIdx->pTable = pTable;-
780 n = 0;-
781 idxCols = 0;-
782 for(pTerm=pWC->a; pTerm<pWCEnd; pTerm++){
pTerm<pWCEndDescription
TRUEevaluated 88711 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2859 times by 1 test
Evaluated by:
  • Self test (438)
2859-88711
783 if( termCanDriveIndex(pTerm, pSrc, notReady) ){
termCanDriveIn...Src, notReady)Description
TRUEevaluated 3019 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 85692 times by 1 test
Evaluated by:
  • Self test (438)
3019-85692
784 int iCol = pTerm->u.leftColumn;-
785 Bitmask cMask = iCol>=BMS ? MASKBIT(BMS-1) : MASKBIT(iCol);
iCol>=((int)(s...f(Bitmask)*8))Description
TRUEnever evaluated
FALSEevaluated 3019 times by 1 test
Evaluated by:
  • Self test (438)
0-3019
786 testcase( iCol==BMS-1 );-
787 testcase( iCol==BMS );-
788 if( (idxCols & cMask)==0 ){
(idxCols & cMask)==0Description
TRUEevaluated 3006 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 13 times by 1 test
Evaluated by:
  • Self test (438)
13-3006
789 Expr *pX = pTerm->pExpr;-
790 idxCols |= cMask;-
791 pIdx->aiColumn[n] = pTerm->u.leftColumn;-
792 pColl = sqlite3BinaryCompareCollSeq(pParse, pX->pLeft, pX->pRight);-
793 pIdx->azColl[n] = pColl ? pColl->zName : sqlite3StrBINARY;
pCollDescription
TRUEevaluated 3005 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
1-3005
794 n++;-
795 }
executed 3006 times by 1 test: end of block
Executed by:
  • Self test (438)
3006
796 }
executed 3019 times by 1 test: end of block
Executed by:
  • Self test (438)
3019
797 }
executed 88711 times by 1 test: end of block
Executed by:
  • Self test (438)
88711
798 assert( (u32)n==pLoop->u.btree.nEq );-
799-
800 /* Add additional columns needed to make the automatic index into-
801 ** a covering index */-
802 for(i=0; i<mxBitCol; i++){
i<mxBitColDescription
TRUEevaluated 3899 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2859 times by 1 test
Evaluated by:
  • Self test (438)
2859-3899
803 if( extraCols & MASKBIT(i) ){
extraCols & ((...tmask)1)<<(i))Description
TRUEevaluated 722 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3177 times by 1 test
Evaluated by:
  • Self test (438)
722-3177
804 pIdx->aiColumn[n] = i;-
805 pIdx->azColl[n] = sqlite3StrBINARY;-
806 n++;-
807 }
executed 722 times by 1 test: end of block
Executed by:
  • Self test (438)
722
808 }
executed 3899 times by 1 test: end of block
Executed by:
  • Self test (438)
3899
809 if( pSrc->colUsed & MASKBIT(BMS-1) ){
pSrc->colUsed ...tmask)*8))-1))Description
TRUEnever evaluated
FALSEevaluated 2859 times by 1 test
Evaluated by:
  • Self test (438)
0-2859
810 for(i=BMS-1; i<pTable->nCol; i++){
i<pTable->nColDescription
TRUEnever evaluated
FALSEnever evaluated
0
811 pIdx->aiColumn[n] = i;-
812 pIdx->azColl[n] = sqlite3StrBINARY;-
813 n++;-
814 }
never executed: end of block
0
815 }
never executed: end of block
0
816 assert( n==nKeyCol );-
817 pIdx->aiColumn[n] = XN_ROWID;-
818 pIdx->azColl[n] = sqlite3StrBINARY;-
819-
820 /* Create the automatic index */-
821 assert( pLevel->iIdxCur>=0 );-
822 pLevel->iIdxCur = pParse->nTab++;-
823 sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);-
824 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);-
825 VdbeComment((v, "for %s", pTable->zName));-
826-
827 /* Fill the automatic index with content */-
828 pTabItem = &pWC->pWInfo->pTabList->a[pLevel->iFrom];-
829 if( pTabItem->fg.viaCoroutine ){
pTabItem->fg.viaCoroutineDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2856 times by 1 test
Evaluated by:
  • Self test (438)
3-2856
830 int regYield = pTabItem->regReturn;-
831 addrCounter = sqlite3VdbeAddOp2(v, OP_Integer, 0, 0);-
832 sqlite3VdbeAddOp3(v, OP_InitCoroutine, regYield, 0, pTabItem->addrFillSub);-
833 addrTop = sqlite3VdbeAddOp1(v, OP_Yield, regYield);-
834 VdbeCoverage(v);-
835 VdbeComment((v, "next row of %s", pTabItem->pTab->zName));-
836 }else{
executed 3 times by 1 test: end of block
Executed by:
  • Self test (438)
3
837 addrTop = sqlite3VdbeAddOp1(v, OP_Rewind, pLevel->iTabCur); VdbeCoverage(v);-
838 }
executed 2856 times by 1 test: end of block
Executed by:
  • Self test (438)
2856
839 if( pPartial ){
pPartialDescription
TRUEevaluated 59 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2800 times by 1 test
Evaluated by:
  • Self test (438)
59-2800
840 iContinue = sqlite3VdbeMakeLabel(v);-
841 sqlite3ExprIfFalse(pParse, pPartial, iContinue, SQLITE_JUMPIFNULL);-
842 pLoop->wsFlags |= WHERE_PARTIALIDX;-
843 }
executed 59 times by 1 test: end of block
Executed by:
  • Self test (438)
59
844 regRecord = sqlite3GetTempReg(pParse);-
845 regBase = sqlite3GenerateIndexKey(-
846 pParse, pIdx, pLevel->iTabCur, regRecord, 0, 0, 0, 0-
847 );-
848 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);-
849 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);-
850 if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
executed 59 times by 1 test: sqlite3VdbeResolveLabel(v, iContinue);
Executed by:
  • Self test (438)
pPartialDescription
TRUEevaluated 59 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2800 times by 1 test
Evaluated by:
  • Self test (438)
59-2800
851 if( pTabItem->fg.viaCoroutine ){
pTabItem->fg.viaCoroutineDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2856 times by 1 test
Evaluated by:
  • Self test (438)
3-2856
852 sqlite3VdbeChangeP2(v, addrCounter, regBase+n);-
853 testcase( pParse->db->mallocFailed );-
854 translateColumnToCopy(pParse, addrTop, pLevel->iTabCur,-
855 pTabItem->regResult, 1);-
856 sqlite3VdbeGoto(v, addrTop);-
857 pTabItem->fg.viaCoroutine = 0;-
858 }else{
executed 3 times by 1 test: end of block
Executed by:
  • Self test (438)
3
859 sqlite3VdbeAddOp2(v, OP_Next, pLevel->iTabCur, addrTop+1); VdbeCoverage(v);-
860 }
executed 2856 times by 1 test: end of block
Executed by:
  • Self test (438)
2856
861 sqlite3VdbeChangeP5(v, SQLITE_STMTSTATUS_AUTOINDEX);-
862 sqlite3VdbeJumpHere(v, addrTop);-
863 sqlite3ReleaseTempReg(pParse, regRecord);-
864 -
865 /* Jump here when skipping the initialization */-
866 sqlite3VdbeJumpHere(v, addrInit);-
867-
868end_auto_index_create:
code before this statement executed 2859 times by 1 test: end_auto_index_create:
Executed by:
  • Self test (438)
2859
869 sqlite3ExprDelete(pParse->db, pPartial);-
870}
executed 2859 times by 1 test: end of block
Executed by:
  • Self test (438)
2859
871#endif /* SQLITE_OMIT_AUTOMATIC_INDEX */-
872-
873#ifndef SQLITE_OMIT_VIRTUALTABLE-
874/*-
875** Allocate and populate an sqlite3_index_info structure. It is the -
876** responsibility of the caller to eventually release the structure-
877** by passing the pointer returned by this function to sqlite3_free().-
878*/-
879static sqlite3_index_info *allocateIndexInfo(-
880 Parse *pParse, /* The parsing context */-
881 WhereClause *pWC, /* The WHERE clause being analyzed */-
882 Bitmask mUnusable, /* Ignore terms with these prereqs */-
883 struct SrcList_item *pSrc, /* The FROM clause term that is the vtab */-
884 ExprList *pOrderBy, /* The ORDER BY clause */-
885 u16 *pmNoOmit /* Mask of terms not to omit */-
886){-
887 int i, j;-
888 int nTerm;-
889 struct sqlite3_index_constraint *pIdxCons;-
890 struct sqlite3_index_orderby *pIdxOrderBy;-
891 struct sqlite3_index_constraint_usage *pUsage;-
892 struct HiddenIndexInfo *pHidden;-
893 WhereTerm *pTerm;-
894 int nOrderBy;-
895 sqlite3_index_info *pIdxInfo;-
896 u16 mNoOmit = 0;-
897-
898 /* Count the number of possible WHERE clause constraints referring-
899 ** to this virtual table */-
900 for(i=nTerm=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
i<pWC->nTermDescription
TRUEevaluated 23178 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 11464 times by 1 test
Evaluated by:
  • Self test (438)
11464-23178
901 if( pTerm->leftCursor != pSrc->iCursor ) continue;
executed 2900 times by 1 test: continue;
Executed by:
  • Self test (438)
pTerm->leftCur... pSrc->iCursorDescription
TRUEevaluated 2900 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 20278 times by 1 test
Evaluated by:
  • Self test (438)
2900-20278
902 if( pTerm->prereqRight & mUnusable ) continue;
executed 31 times by 1 test: continue;
Executed by:
  • Self test (438)
pTerm->prereqRight & mUnusableDescription
TRUEevaluated 31 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 20247 times by 1 test
Evaluated by:
  • Self test (438)
31-20247
903 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );-
904 testcase( pTerm->eOperator & WO_IN );-
905 testcase( pTerm->eOperator & WO_ISNULL );-
906 testcase( pTerm->eOperator & WO_IS );-
907 testcase( pTerm->eOperator & WO_ALL );-
908 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
executed 4 times by 1 test: continue;
Executed by:
  • Self test (438)
(pTerm->eOpera... ~(0x0800))==0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 20243 times by 1 test
Evaluated by:
  • Self test (438)
4-20243
909 if( pTerm->wtFlags & TERM_VNULL ) continue;
never executed: continue;
pTerm->wtFlags & 0x00Description
TRUEnever evaluated
FALSEevaluated 20243 times by 1 test
Evaluated by:
  • Self test (438)
0-20243
910 assert( pTerm->u.leftColumn>=(-1) );-
911 nTerm++;-
912 }
executed 20243 times by 1 test: end of block
Executed by:
  • Self test (438)
20243
913-
914 /* If the ORDER BY clause contains only columns in the current -
915 ** virtual table then allocate space for the aOrderBy part of-
916 ** the sqlite3_index_info structure.-
917 */-
918 nOrderBy = 0;-
919 if( pOrderBy ){
pOrderByDescription
TRUEevaluated 174 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 11290 times by 1 test
Evaluated by:
  • Self test (438)
174-11290
920 int n = pOrderBy->nExpr;-
921 for(i=0; i<n; i++){
i<nDescription
TRUEevaluated 187 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 113 times by 1 test
Evaluated by:
  • Self test (438)
113-187
922 Expr *pExpr = pOrderBy->a[i].pExpr;-
923 if( pExpr->op!=TK_COLUMN || pExpr->iTable!=pSrc->iCursor ) break;
executed 61 times by 1 test: break;
Executed by:
  • Self test (438)
pExpr->op!=158Description
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 161 times by 1 test
Evaluated by:
  • Self test (438)
pExpr->iTable!=pSrc->iCursorDescription
TRUEevaluated 35 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 126 times by 1 test
Evaluated by:
  • Self test (438)
26-161
924 }
executed 126 times by 1 test: end of block
Executed by:
  • Self test (438)
126
925 if( i==n){
i==nDescription
TRUEevaluated 113 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 61 times by 1 test
Evaluated by:
  • Self test (438)
61-113
926 nOrderBy = n;-
927 }
executed 113 times by 1 test: end of block
Executed by:
  • Self test (438)
113
928 }
executed 174 times by 1 test: end of block
Executed by:
  • Self test (438)
174
929-
930 /* Allocate the sqlite3_index_info structure-
931 */-
932 pIdxInfo = sqlite3DbMallocZero(pParse->db, sizeof(*pIdxInfo)-
933 + (sizeof(*pIdxCons) + sizeof(*pUsage))*nTerm-
934 + sizeof(*pIdxOrderBy)*nOrderBy + sizeof(*pHidden) );-
935 if( pIdxInfo==0 ){
pIdxInfo==0Description
TRUEnever evaluated
FALSEevaluated 11464 times by 1 test
Evaluated by:
  • Self test (438)
0-11464
936 sqlite3ErrorMsg(pParse, "out of memory");-
937 return 0;
never executed: return 0;
0
938 }-
939-
940 /* Initialize the structure. The sqlite3_index_info structure contains-
941 ** many fields that are declared "const" to prevent xBestIndex from-
942 ** changing them. We have to do some funky casting in order to-
943 ** initialize those fields.-
944 */-
945 pHidden = (struct HiddenIndexInfo*)&pIdxInfo[1];-
946 pIdxCons = (struct sqlite3_index_constraint*)&pHidden[1];-
947 pIdxOrderBy = (struct sqlite3_index_orderby*)&pIdxCons[nTerm];-
948 pUsage = (struct sqlite3_index_constraint_usage*)&pIdxOrderBy[nOrderBy];-
949 *(int*)&pIdxInfo->nConstraint = nTerm;-
950 *(int*)&pIdxInfo->nOrderBy = nOrderBy;-
951 *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint = pIdxCons;-
952 *(struct sqlite3_index_orderby**)&pIdxInfo->aOrderBy = pIdxOrderBy;-
953 *(struct sqlite3_index_constraint_usage**)&pIdxInfo->aConstraintUsage =-
954 pUsage;-
955-
956 pHidden->pWC = pWC;-
957 pHidden->pParse = pParse;-
958 for(i=j=0, pTerm=pWC->a; i<pWC->nTerm; i++, pTerm++){
i<pWC->nTermDescription
TRUEevaluated 23178 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 11464 times by 1 test
Evaluated by:
  • Self test (438)
11464-23178
959 u16 op;-
960 if( pTerm->leftCursor != pSrc->iCursor ) continue;
executed 2900 times by 1 test: continue;
Executed by:
  • Self test (438)
pTerm->leftCur... pSrc->iCursorDescription
TRUEevaluated 2900 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 20278 times by 1 test
Evaluated by:
  • Self test (438)
2900-20278
961 if( pTerm->prereqRight & mUnusable ) continue;
executed 31 times by 1 test: continue;
Executed by:
  • Self test (438)
pTerm->prereqRight & mUnusableDescription
TRUEevaluated 31 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 20247 times by 1 test
Evaluated by:
  • Self test (438)
31-20247
962 assert( IsPowerOfTwo(pTerm->eOperator & ~WO_EQUIV) );-
963 testcase( pTerm->eOperator & WO_IN );-
964 testcase( pTerm->eOperator & WO_IS );-
965 testcase( pTerm->eOperator & WO_ISNULL );-
966 testcase( pTerm->eOperator & WO_ALL );-
967 if( (pTerm->eOperator & ~(WO_EQUIV))==0 ) continue;
executed 4 times by 1 test: continue;
Executed by:
  • Self test (438)
(pTerm->eOpera... ~(0x0800))==0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 20243 times by 1 test
Evaluated by:
  • Self test (438)
4-20243
968 if( pTerm->wtFlags & TERM_VNULL ) continue;
never executed: continue;
pTerm->wtFlags & 0x00Description
TRUEnever evaluated
FALSEevaluated 20243 times by 1 test
Evaluated by:
  • Self test (438)
0-20243
969 if( (pSrc->fg.jointype & JT_LEFT)!=0
(pSrc->fg.join...e & 0x0008)!=0Description
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 20219 times by 1 test
Evaluated by:
  • Self test (438)
24-20219
970 && !ExprHasProperty(pTerm->pExpr, EP_FromJoin)
!(((pTerm->pEx...0x000001))!=0)Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 19 times by 1 test
Evaluated by:
  • Self test (438)
5-19
971 && (pTerm->eOperator & (WO_IS|WO_ISNULL))
(pTerm->eOpera...x0080|0x0100))Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test (438)
2-3
972 ){-
973 /* An "IS" term in the WHERE clause where the virtual table is the rhs-
974 ** of a LEFT JOIN. Do not pass this term to the virtual table-
975 ** implementation, as this can lead to incorrect results from SQL such-
976 ** as:-
977 **-
978 ** "LEFT JOIN vtab WHERE vtab.col IS NULL" */-
979 testcase( pTerm->eOperator & WO_ISNULL );-
980 testcase( pTerm->eOperator & WO_IS );-
981 continue;
executed 3 times by 1 test: continue;
Executed by:
  • Self test (438)
3
982 }-
983 assert( pTerm->u.leftColumn>=(-1) );-
984 pIdxCons[j].iColumn = pTerm->u.leftColumn;-
985 pIdxCons[j].iTermOffset = i;-
986 op = pTerm->eOperator & WO_ALL;-
987 if( op==WO_IN ) op = WO_EQ;
executed 22 times by 1 test: op = 0x0002;
Executed by:
  • Self test (438)
op==0x0001Description
TRUEevaluated 22 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 20218 times by 1 test
Evaluated by:
  • Self test (438)
22-20218
988 if( op==WO_AUX ){
op==0x0040Description
TRUEevaluated 139 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 20101 times by 1 test
Evaluated by:
  • Self test (438)
139-20101
989 pIdxCons[j].op = pTerm->eMatchOp;-
990 }else if( op & (WO_ISNULL|WO_IS) ){
executed 139 times by 1 test: end of block
Executed by:
  • Self test (438)
op & (0x0100|0x0080)Description
TRUEevaluated 15 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 20086 times by 1 test
Evaluated by:
  • Self test (438)
15-20086
991 if( op==WO_ISNULL ){
op==0x0100Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 10 times by 1 test
Evaluated by:
  • Self test (438)
5-10
992 pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_ISNULL;-
993 }else{
executed 5 times by 1 test: end of block
Executed by:
  • Self test (438)
5
994 pIdxCons[j].op = SQLITE_INDEX_CONSTRAINT_IS;-
995 }
executed 10 times by 1 test: end of block
Executed by:
  • Self test (438)
10
996 }else{-
997 pIdxCons[j].op = (u8)op;-
998 /* The direct assignment in the previous line is possible only because-
999 ** the WO_ and SQLITE_INDEX_CONSTRAINT_ codes are identical. The-
1000 ** following asserts verify this fact. */-
1001 assert( WO_EQ==SQLITE_INDEX_CONSTRAINT_EQ );-
1002 assert( WO_LT==SQLITE_INDEX_CONSTRAINT_LT );-
1003 assert( WO_LE==SQLITE_INDEX_CONSTRAINT_LE );-
1004 assert( WO_GT==SQLITE_INDEX_CONSTRAINT_GT );-
1005 assert( WO_GE==SQLITE_INDEX_CONSTRAINT_GE );-
1006 assert( pTerm->eOperator&(WO_IN|WO_EQ|WO_LT|WO_LE|WO_GT|WO_GE|WO_AUX) );-
1007-
1008 if( op & (WO_LT|WO_LE|WO_GT|WO_GE)
op & ((0x0002<...02<<(57 -53)))Description
TRUEevaluated 245 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 19841 times by 1 test
Evaluated by:
  • Self test (438)
245-19841
1009 && sqlite3ExprIsVector(pTerm->pExpr->pRight)
sqlite3ExprIsV...pExpr->pRight)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 241 times by 1 test
Evaluated by:
  • Self test (438)
4-241
1010 ){-
1011 if( i<16 ) mNoOmit |= (1 << i);
executed 4 times by 1 test: mNoOmit |= (1 << i);
Executed by:
  • Self test (438)
i<16Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
0-4
1012 if( op==WO_LT ) pIdxCons[j].op = WO_LE;
executed 3 times by 1 test: pIdxCons[j].op = (0x0002<<(55 -53));
Executed by:
  • Self test (438)
op==(0x0002<<(56 -53))Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
1-3
1013 if( op==WO_GT ) pIdxCons[j].op = WO_GE;
never executed: pIdxCons[j].op = (0x0002<<(57 -53));
op==(0x0002<<(54 -53))Description
TRUEnever evaluated
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
0-4
1014 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test (438)
4
1015 }
executed 20086 times by 1 test: end of block
Executed by:
  • Self test (438)
20086
1016-
1017 j++;-
1018 }
executed 20240 times by 1 test: end of block
Executed by:
  • Self test (438)
20240
1019 for(i=0; i<nOrderBy; i++){
i<nOrderByDescription
TRUEevaluated 125 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 11464 times by 1 test
Evaluated by:
  • Self test (438)
125-11464
1020 Expr *pExpr = pOrderBy->a[i].pExpr;-
1021 pIdxOrderBy[i].iColumn = pExpr->iColumn;-
1022 pIdxOrderBy[i].desc = pOrderBy->a[i].sortOrder;-
1023 }
executed 125 times by 1 test: end of block
Executed by:
  • Self test (438)
125
1024-
1025 *pmNoOmit = mNoOmit;-
1026 return pIdxInfo;
executed 11464 times by 1 test: return pIdxInfo;
Executed by:
  • Self test (438)
11464
1027}-
1028-
1029/*-
1030** The table object reference passed as the second argument to this function-
1031** must represent a virtual table. This function invokes the xBestIndex()-
1032** method of the virtual table with the sqlite3_index_info object that-
1033** comes in as the 3rd argument to this function.-
1034**-
1035** If an error occurs, pParse is populated with an error message and a-
1036** non-zero value is returned. Otherwise, 0 is returned and the output-
1037** part of the sqlite3_index_info structure is left populated.-
1038**-
1039** Whether or not an error is returned, it is the responsibility of the-
1040** caller to eventually free p->idxStr if p->needToFreeIdxStr indicates-
1041** that this is required.-
1042*/-
1043static int vtabBestIndex(Parse *pParse, Table *pTab, sqlite3_index_info *p){-
1044 sqlite3_vtab *pVtab = sqlite3GetVTable(pParse->db, pTab)->pVtab;-
1045 int rc;-
1046-
1047 TRACE_IDX_INPUTS(p);-
1048 rc = pVtab->pModule->xBestIndex(pVtab, p);-
1049 TRACE_IDX_OUTPUTS(p);-
1050-
1051 if( rc!=SQLITE_OK ){
rc!=0Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12101 times by 1 test
Evaluated by:
  • Self test (438)
1-12101
1052 if( rc==SQLITE_NOMEM ){
rc==7Description
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
0-1
1053 sqlite3OomFault(pParse->db);-
1054 }else if( !pVtab->zErrMsg ){
never executed: end of block
!pVtab->zErrMsgDescription
TRUEnever evaluated
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
0-1
1055 sqlite3ErrorMsg(pParse, "%s", sqlite3ErrStr(rc));-
1056 }else{
never executed: end of block
0
1057 sqlite3ErrorMsg(pParse, "%s", pVtab->zErrMsg);-
1058 }
executed 1 time by 1 test: end of block
Executed by:
  • Self test (438)
1
1059 }-
1060 sqlite3_free(pVtab->zErrMsg);-
1061 pVtab->zErrMsg = 0;-
1062-
1063#if 0-
1064 /* This error is now caught by the caller.-
1065 ** Search for "xBestIndex malfunction" below */-
1066 for(i=0; i<p->nConstraint; i++){-
1067 if( !p->aConstraint[i].usable && p->aConstraintUsage[i].argvIndex>0 ){-
1068 sqlite3ErrorMsg(pParse, -
1069 "table %s: xBestIndex returned an invalid plan", pTab->zName);-
1070 }-
1071 }-
1072#endif-
1073-
1074 return pParse->nErr;
executed 12102 times by 1 test: return pParse->nErr;
Executed by:
  • Self test (438)
12102
1075}-
1076#endif /* !defined(SQLITE_OMIT_VIRTUALTABLE) */-
1077-
1078#ifdef SQLITE_ENABLE_STAT3_OR_STAT4-
1079/*-
1080** Estimate the location of a particular key among all keys in an-
1081** index. Store the results in aStat as follows:-
1082**-
1083** aStat[0] Est. number of rows less than pRec-
1084** aStat[1] Est. number of rows equal to pRec-
1085**-
1086** Return the index of the sample that is the smallest sample that-
1087** is greater than or equal to pRec. Note that this index is not an index-
1088** into the aSample[] array - it is an index into a virtual set of samples-
1089** based on the contents of aSample[] and the number of fields in record -
1090** pRec. -
1091*/-
1092static int whereKeyStats(-
1093 Parse *pParse, /* Database connection */-
1094 Index *pIdx, /* Index to consider domain of */-
1095 UnpackedRecord *pRec, /* Vector of values to consider */-
1096 int roundUp, /* Round up if true. Round down if false */-
1097 tRowcnt *aStat /* OUT: stats written here */-
1098){-
1099 IndexSample *aSample = pIdx->aSample;-
1100 int iCol; /* Index of required stats in anEq[] etc. */-
1101 int i; /* Index of first sample >= pRec */-
1102 int iSample; /* Smallest sample larger than or equal to pRec */-
1103 int iMin = 0; /* Smallest sample not yet tested */-
1104 int iTest; /* Next sample to test */-
1105 int res; /* Result of comparison operation */-
1106 int nField; /* Number of fields in pRec */-
1107 tRowcnt iLower = 0; /* anLt[] + anEq[] of largest sample pRec is > */-
1108-
1109#ifndef SQLITE_DEBUG-
1110 UNUSED_PARAMETER( pParse );-
1111#endif-
1112 assert( pRec!=0 );-
1113 assert( pIdx->nSample>0 );-
1114 assert( pRec->nField>0 && pRec->nField<=pIdx->nSampleCol );-
1115-
1116 /* Do a binary search to find the first sample greater than or equal-
1117 ** to pRec. If pRec contains a single field, the set of samples to search-
1118 ** is simply the aSample[] array. If the samples in aSample[] contain more-
1119 ** than one fields, all fields following the first are ignored.-
1120 **-
1121 ** If pRec contains N fields, where N is more than one, then as well as the-
1122 ** samples in aSample[] (truncated to N fields), the search also has to-
1123 ** consider prefixes of those samples. For example, if the set of samples-
1124 ** in aSample is:-
1125 **-
1126 ** aSample[0] = (a, 5) -
1127 ** aSample[1] = (a, 10) -
1128 ** aSample[2] = (b, 5) -
1129 ** aSample[3] = (c, 100) -
1130 ** aSample[4] = (c, 105)-
1131 **-
1132 ** Then the search space should ideally be the samples above and the -
1133 ** unique prefixes [a], [b] and [c]. But since that is hard to organize, -
1134 ** the code actually searches this set:-
1135 **-
1136 ** 0: (a) -
1137 ** 1: (a, 5) -
1138 ** 2: (a, 10) -
1139 ** 3: (a, 10) -
1140 ** 4: (b) -
1141 ** 5: (b, 5) -
1142 ** 6: (c) -
1143 ** 7: (c, 100) -
1144 ** 8: (c, 105)-
1145 ** 9: (c, 105)-
1146 **-
1147 ** For each sample in the aSample[] array, N samples are present in the-
1148 ** effective sample array. In the above, samples 0 and 1 are based on -
1149 ** sample aSample[0]. Samples 2 and 3 on aSample[1] etc.-
1150 **-
1151 ** Often, sample i of each block of N effective samples has (i+1) fields.-
1152 ** Except, each sample may be extended to ensure that it is greater than or-
1153 ** equal to the previous sample in the array. For example, in the above, -
1154 ** sample 2 is the first sample of a block of N samples, so at first it -
1155 ** appears that it should be 1 field in size. However, that would make it -
1156 ** smaller than sample 1, so the binary search would not work. As a result, -
1157 ** it is extended to two fields. The duplicates that this creates do not -
1158 ** cause any problems.-
1159 */-
1160 nField = pRec->nField;-
1161 iCol = 0;-
1162 iSample = pIdx->nSample * nField;-
1163 do{-
1164 int iSamp; /* Index in aSample[] of test sample */-
1165 int n; /* Number of fields in test sample */-
1166-
1167 iTest = (iMin+iSample)/2;-
1168 iSamp = iTest / nField;-
1169 if( iSamp>0 ){-
1170 /* The proposed effective sample is a prefix of sample aSample[iSamp].-
1171 ** Specifically, the shortest prefix of at least (1 + iTest%nField) -
1172 ** fields that is greater than the previous effective sample. */-
1173 for(n=(iTest % nField) + 1; n<nField; n++){-
1174 if( aSample[iSamp-1].anLt[n-1]!=aSample[iSamp].anLt[n-1] ) break;-
1175 }-
1176 }else{-
1177 n = iTest + 1;-
1178 }-
1179-
1180 pRec->nField = n;-
1181 res = sqlite3VdbeRecordCompare(aSample[iSamp].n, aSample[iSamp].p, pRec);-
1182 if( res<0 ){-
1183 iLower = aSample[iSamp].anLt[n-1] + aSample[iSamp].anEq[n-1];-
1184 iMin = iTest+1;-
1185 }else if( res==0 && n<nField ){-
1186 iLower = aSample[iSamp].anLt[n-1];-
1187 iMin = iTest+1;-
1188 res = -1;-
1189 }else{-
1190 iSample = iTest;-
1191 iCol = n-1;-
1192 }-
1193 }while( res && iMin<iSample );-
1194 i = iSample / nField;-
1195-
1196#ifdef SQLITE_DEBUG-
1197 /* The following assert statements check that the binary search code-
1198 ** above found the right answer. This block serves no purpose other-
1199 ** than to invoke the asserts. */-
1200 if( pParse->db->mallocFailed==0 ){-
1201 if( res==0 ){-
1202 /* If (res==0) is true, then pRec must be equal to sample i. */-
1203 assert( i<pIdx->nSample );-
1204 assert( iCol==nField-1 );-
1205 pRec->nField = nField;-
1206 assert( 0==sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec) -
1207 || pParse->db->mallocFailed -
1208 );-
1209 }else{-
1210 /* Unless i==pIdx->nSample, indicating that pRec is larger than-
1211 ** all samples in the aSample[] array, pRec must be smaller than the-
1212 ** (iCol+1) field prefix of sample i. */-
1213 assert( i<=pIdx->nSample && i>=0 );-
1214 pRec->nField = iCol+1;-
1215 assert( i==pIdx->nSample -
1216 || sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)>0-
1217 || pParse->db->mallocFailed );-
1218-
1219 /* if i==0 and iCol==0, then record pRec is smaller than all samples-
1220 ** in the aSample[] array. Otherwise, if (iCol>0) then pRec must-
1221 ** be greater than or equal to the (iCol) field prefix of sample i.-
1222 ** If (i>0), then pRec must also be greater than sample (i-1). */-
1223 if( iCol>0 ){-
1224 pRec->nField = iCol;-
1225 assert( sqlite3VdbeRecordCompare(aSample[i].n, aSample[i].p, pRec)<=0-
1226 || pParse->db->mallocFailed );-
1227 }-
1228 if( i>0 ){-
1229 pRec->nField = nField;-
1230 assert( sqlite3VdbeRecordCompare(aSample[i-1].n, aSample[i-1].p, pRec)<0-
1231 || pParse->db->mallocFailed );-
1232 }-
1233 }-
1234 }-
1235#endif /* ifdef SQLITE_DEBUG */-
1236-
1237 if( res==0 ){-
1238 /* Record pRec is equal to sample i */-
1239 assert( iCol==nField-1 );-
1240 aStat[0] = aSample[i].anLt[iCol];-
1241 aStat[1] = aSample[i].anEq[iCol];-
1242 }else{-
1243 /* At this point, the (iCol+1) field prefix of aSample[i] is the first -
1244 ** sample that is greater than pRec. Or, if i==pIdx->nSample then pRec-
1245 ** is larger than all samples in the array. */-
1246 tRowcnt iUpper, iGap;-
1247 if( i>=pIdx->nSample ){-
1248 iUpper = sqlite3LogEstToInt(pIdx->aiRowLogEst[0]);-
1249 }else{-
1250 iUpper = aSample[i].anLt[iCol];-
1251 }-
1252-
1253 if( iLower>=iUpper ){-
1254 iGap = 0;-
1255 }else{-
1256 iGap = iUpper - iLower;-
1257 }-
1258 if( roundUp ){-
1259 iGap = (iGap*2)/3;-
1260 }else{-
1261 iGap = iGap/3;-
1262 }-
1263 aStat[0] = iLower + iGap;-
1264 aStat[1] = pIdx->aAvgEq[nField-1];-
1265 }-
1266-
1267 /* Restore the pRec->nField value before returning. */-
1268 pRec->nField = nField;-
1269 return i;-
1270}-
1271#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */-
1272-
1273/*-
1274** If it is not NULL, pTerm is a term that provides an upper or lower-
1275** bound on a range scan. Without considering pTerm, it is estimated -
1276** that the scan will visit nNew rows. This function returns the number-
1277** estimated to be visited after taking pTerm into account.-
1278**-
1279** If the user explicitly specified a likelihood() value for this term,-
1280** then the return value is the likelihood multiplied by the number of-
1281** input rows. Otherwise, this function assumes that an "IS NOT NULL" term-
1282** has a likelihood of 0.50, and any other term a likelihood of 0.25.-
1283*/-
1284static LogEst whereRangeAdjust(WhereTerm *pTerm, LogEst nNew){-
1285 LogEst nRet = nNew;-
1286 if( pTerm ){
pTermDescription
TRUEevaluated 56274 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 25792 times by 1 test
Evaluated by:
  • Self test (438)
25792-56274
1287 if( pTerm->truthProb<=0 ){
pTerm->truthProb<=0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 56269 times by 1 test
Evaluated by:
  • Self test (438)
5-56269
1288 nRet += pTerm->truthProb;-
1289 }else if( (pTerm->wtFlags & TERM_VNULL)==0 ){
executed 5 times by 1 test: end of block
Executed by:
  • Self test (438)
(pTerm->wtFlags & 0x00)==0Description
TRUEevaluated 56269 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
0-56269
1290 nRet -= 20; assert( 20==sqlite3LogEst(4) );-
1291 }
executed 56269 times by 1 test: end of block
Executed by:
  • Self test (438)
56269
1292 }
executed 56274 times by 1 test: end of block
Executed by:
  • Self test (438)
56274
1293 return nRet;
executed 82066 times by 1 test: return nRet;
Executed by:
  • Self test (438)
82066
1294}-
1295-
1296-
1297#ifdef SQLITE_ENABLE_STAT3_OR_STAT4-
1298/*-
1299** Return the affinity for a single column of an index.-
1300*/-
1301char sqlite3IndexColumnAffinity(sqlite3 *db, Index *pIdx, int iCol){-
1302 assert( iCol>=0 && iCol<pIdx->nColumn );-
1303 if( !pIdx->zColAff ){-
1304 if( sqlite3IndexAffinityStr(db, pIdx)==0 ) return SQLITE_AFF_BLOB;-
1305 }-
1306 return pIdx->zColAff[iCol];-
1307}-
1308#endif-
1309-
1310-
1311#ifdef SQLITE_ENABLE_STAT3_OR_STAT4-
1312/* -
1313** This function is called to estimate the number of rows visited by a-
1314** range-scan on a skip-scan index. For example:-
1315**-
1316** CREATE INDEX i1 ON t1(a, b, c);-
1317** SELECT * FROM t1 WHERE a=? AND c BETWEEN ? AND ?;-
1318**-
1319** Value pLoop->nOut is currently set to the estimated number of rows -
1320** visited for scanning (a=? AND b=?). This function reduces that estimate -
1321** by some factor to account for the (c BETWEEN ? AND ?) expression based-
1322** on the stat4 data for the index. this scan will be peformed multiple -
1323** times (once for each (a,b) combination that matches a=?) is dealt with -
1324** by the caller.-
1325**-
1326** It does this by scanning through all stat4 samples, comparing values-
1327** extracted from pLower and pUpper with the corresponding column in each-
1328** sample. If L and U are the number of samples found to be less than or-
1329** equal to the values extracted from pLower and pUpper respectively, and-
1330** N is the total number of samples, the pLoop->nOut value is adjusted-
1331** as follows:-
1332**-
1333** nOut = nOut * ( min(U - L, 1) / N )-
1334**-
1335** If pLower is NULL, or a value cannot be extracted from the term, L is-
1336** set to zero. If pUpper is NULL, or a value cannot be extracted from it,-
1337** U is set to N.-
1338**-
1339** Normally, this function sets *pbDone to 1 before returning. However,-
1340** if no value can be extracted from either pLower or pUpper (and so the-
1341** estimate of the number of rows delivered remains unchanged), *pbDone-
1342** is left as is.-
1343**-
1344** If an error occurs, an SQLite error code is returned. Otherwise, -
1345** SQLITE_OK.-
1346*/-
1347static int whereRangeSkipScanEst(-
1348 Parse *pParse, /* Parsing & code generating context */-
1349 WhereTerm *pLower, /* Lower bound on the range. ex: "x>123" Might be NULL */-
1350 WhereTerm *pUpper, /* Upper bound on the range. ex: "x<455" Might be NULL */-
1351 WhereLoop *pLoop, /* Update the .nOut value of this loop */-
1352 int *pbDone /* Set to true if at least one expr. value extracted */-
1353){-
1354 Index *p = pLoop->u.btree.pIndex;-
1355 int nEq = pLoop->u.btree.nEq;-
1356 sqlite3 *db = pParse->db;-
1357 int nLower = -1;-
1358 int nUpper = p->nSample+1;-
1359 int rc = SQLITE_OK;-
1360 u8 aff = sqlite3IndexColumnAffinity(db, p, nEq);-
1361 CollSeq *pColl;-
1362 -
1363 sqlite3_value *p1 = 0; /* Value extracted from pLower */-
1364 sqlite3_value *p2 = 0; /* Value extracted from pUpper */-
1365 sqlite3_value *pVal = 0; /* Value extracted from record */-
1366-
1367 pColl = sqlite3LocateCollSeq(pParse, p->azColl[nEq]);-
1368 if( pLower ){-
1369 rc = sqlite3Stat4ValueFromExpr(pParse, pLower->pExpr->pRight, aff, &p1);-
1370 nLower = 0;-
1371 }-
1372 if( pUpper && rc==SQLITE_OK ){-
1373 rc = sqlite3Stat4ValueFromExpr(pParse, pUpper->pExpr->pRight, aff, &p2);-
1374 nUpper = p2 ? 0 : p->nSample;-
1375 }-
1376-
1377 if( p1 || p2 ){-
1378 int i;-
1379 int nDiff;-
1380 for(i=0; rc==SQLITE_OK && i<p->nSample; i++){-
1381 rc = sqlite3Stat4Column(db, p->aSample[i].p, p->aSample[i].n, nEq, &pVal);-
1382 if( rc==SQLITE_OK && p1 ){-
1383 int res = sqlite3MemCompare(p1, pVal, pColl);-
1384 if( res>=0 ) nLower++;-
1385 }-
1386 if( rc==SQLITE_OK && p2 ){-
1387 int res = sqlite3MemCompare(p2, pVal, pColl);-
1388 if( res>=0 ) nUpper++;-
1389 }-
1390 }-
1391 nDiff = (nUpper - nLower);-
1392 if( nDiff<=0 ) nDiff = 1;-
1393-
1394 /* If there is both an upper and lower bound specified, and the -
1395 ** comparisons indicate that they are close together, use the fallback-
1396 ** method (assume that the scan visits 1/64 of the rows) for estimating-
1397 ** the number of rows visited. Otherwise, estimate the number of rows-
1398 ** using the method described in the header comment for this function. */-
1399 if( nDiff!=1 || pUpper==0 || pLower==0 ){-
1400 int nAdjust = (sqlite3LogEst(p->nSample) - sqlite3LogEst(nDiff));-
1401 pLoop->nOut -= nAdjust;-
1402 *pbDone = 1;-
1403 WHERETRACE(0x10, ("range skip-scan regions: %u..%u adjust=%d est=%d\n",-
1404 nLower, nUpper, nAdjust*-1, pLoop->nOut));-
1405 }-
1406-
1407 }else{-
1408 assert( *pbDone==0 );-
1409 }-
1410-
1411 sqlite3ValueFree(p1);-
1412 sqlite3ValueFree(p2);-
1413 sqlite3ValueFree(pVal);-
1414-
1415 return rc;-
1416}-
1417#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */-
1418-
1419/*-
1420** This function is used to estimate the number of rows that will be visited-
1421** by scanning an index for a range of values. The range may have an upper-
1422** bound, a lower bound, or both. The WHERE clause terms that set the upper-
1423** and lower bounds are represented by pLower and pUpper respectively. For-
1424** example, assuming that index p is on t1(a):-
1425**-
1426** ... FROM t1 WHERE a > ? AND a < ? ...-
1427** |_____| |_____|-
1428** | |-
1429** pLower pUpper-
1430**-
1431** If either of the upper or lower bound is not present, then NULL is passed in-
1432** place of the corresponding WhereTerm.-
1433**-
1434** The value in (pBuilder->pNew->u.btree.nEq) is the number of the index-
1435** column subject to the range constraint. Or, equivalently, the number of-
1436** equality constraints optimized by the proposed index scan. For example,-
1437** assuming index p is on t1(a, b), and the SQL query is:-
1438**-
1439** ... FROM t1 WHERE a = ? AND b > ? AND b < ? ...-
1440**-
1441** then nEq is set to 1 (as the range restricted column, b, is the second -
1442** left-most column of the index). Or, if the query is:-
1443**-
1444** ... FROM t1 WHERE a > ? AND a < ? ...-
1445**-
1446** then nEq is set to 0.-
1447**-
1448** When this function is called, *pnOut is set to the sqlite3LogEst() of the-
1449** number of rows that the index scan is expected to visit without -
1450** considering the range constraints. If nEq is 0, then *pnOut is the number of -
1451** rows in the index. Assuming no error occurs, *pnOut is adjusted (reduced)-
1452** to account for the range constraints pLower and pUpper.-
1453** -
1454** In the absence of sqlite_stat4 ANALYZE data, or if such data cannot be-
1455** used, a single range inequality reduces the search space by a factor of 4. -
1456** and a pair of constraints (x>? AND x<?) reduces the expected number of-
1457** rows visited by a factor of 64.-
1458*/-
1459static int whereRangeScanEst(-
1460 Parse *pParse, /* Parsing & code generating context */-
1461 WhereLoopBuilder *pBuilder,-
1462 WhereTerm *pLower, /* Lower bound on the range. ex: "x>123" Might be NULL */-
1463 WhereTerm *pUpper, /* Upper bound on the range. ex: "x<455" Might be NULL */-
1464 WhereLoop *pLoop /* Modify the .nOut and maybe .rRun fields */-
1465){-
1466 int rc = SQLITE_OK;-
1467 int nOut = pLoop->nOut;-
1468 LogEst nNew;-
1469-
1470#ifdef SQLITE_ENABLE_STAT3_OR_STAT4-
1471 Index *p = pLoop->u.btree.pIndex;-
1472 int nEq = pLoop->u.btree.nEq;-
1473-
1474 if( p->nSample>0 && nEq<p->nSampleCol-
1475 && OptimizationEnabled(pParse->db, SQLITE_Stat34)-
1476 ){-
1477 if( nEq==pBuilder->nRecValid ){-
1478 UnpackedRecord *pRec = pBuilder->pRec;-
1479 tRowcnt a[2];-
1480 int nBtm = pLoop->u.btree.nBtm;-
1481 int nTop = pLoop->u.btree.nTop;-
1482-
1483 /* Variable iLower will be set to the estimate of the number of rows in -
1484 ** the index that are less than the lower bound of the range query. The-
1485 ** lower bound being the concatenation of $P and $L, where $P is the-
1486 ** key-prefix formed by the nEq values matched against the nEq left-most-
1487 ** columns of the index, and $L is the value in pLower.-
1488 **-
1489 ** Or, if pLower is NULL or $L cannot be extracted from it (because it-
1490 ** is not a simple variable or literal value), the lower bound of the-
1491 ** range is $P. Due to a quirk in the way whereKeyStats() works, even-
1492 ** if $L is available, whereKeyStats() is called for both ($P) and -
1493 ** ($P:$L) and the larger of the two returned values is used.-
1494 **-
1495 ** Similarly, iUpper is to be set to the estimate of the number of rows-
1496 ** less than the upper bound of the range query. Where the upper bound-
1497 ** is either ($P) or ($P:$U). Again, even if $U is available, both values-
1498 ** of iUpper are requested of whereKeyStats() and the smaller used.-
1499 **-
1500 ** The number of rows between the two bounds is then just iUpper-iLower.-
1501 */-
1502 tRowcnt iLower; /* Rows less than the lower bound */-
1503 tRowcnt iUpper; /* Rows less than the upper bound */-
1504 int iLwrIdx = -2; /* aSample[] for the lower bound */-
1505 int iUprIdx = -1; /* aSample[] for the upper bound */-
1506-
1507 if( pRec ){-
1508 testcase( pRec->nField!=pBuilder->nRecValid );-
1509 pRec->nField = pBuilder->nRecValid;-
1510 }-
1511 /* Determine iLower and iUpper using ($P) only. */-
1512 if( nEq==0 ){-
1513 iLower = 0;-
1514 iUpper = p->nRowEst0;-
1515 }else{-
1516 /* Note: this call could be optimized away - since the same values must -
1517 ** have been requested when testing key $P in whereEqualScanEst(). */-
1518 whereKeyStats(pParse, p, pRec, 0, a);-
1519 iLower = a[0];-
1520 iUpper = a[0] + a[1];-
1521 }-
1522-
1523 assert( pLower==0 || (pLower->eOperator & (WO_GT|WO_GE))!=0 );-
1524 assert( pUpper==0 || (pUpper->eOperator & (WO_LT|WO_LE))!=0 );-
1525 assert( p->aSortOrder!=0 );-
1526 if( p->aSortOrder[nEq] ){-
1527 /* The roles of pLower and pUpper are swapped for a DESC index */-
1528 SWAP(WhereTerm*, pLower, pUpper);-
1529 SWAP(int, nBtm, nTop);-
1530 }-
1531-
1532 /* If possible, improve on the iLower estimate using ($P:$L). */-
1533 if( pLower ){-
1534 int n; /* Values extracted from pExpr */-
1535 Expr *pExpr = pLower->pExpr->pRight;-
1536 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, nBtm, nEq, &n);-
1537 if( rc==SQLITE_OK && n ){-
1538 tRowcnt iNew;-
1539 u16 mask = WO_GT|WO_LE;-
1540 if( sqlite3ExprVectorSize(pExpr)>n ) mask = (WO_LE|WO_LT);-
1541 iLwrIdx = whereKeyStats(pParse, p, pRec, 0, a);-
1542 iNew = a[0] + ((pLower->eOperator & mask) ? a[1] : 0);-
1543 if( iNew>iLower ) iLower = iNew;-
1544 nOut--;-
1545 pLower = 0;-
1546 }-
1547 }-
1548-
1549 /* If possible, improve on the iUpper estimate using ($P:$U). */-
1550 if( pUpper ){-
1551 int n; /* Values extracted from pExpr */-
1552 Expr *pExpr = pUpper->pExpr->pRight;-
1553 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, nTop, nEq, &n);-
1554 if( rc==SQLITE_OK && n ){-
1555 tRowcnt iNew;-
1556 u16 mask = WO_GT|WO_LE;-
1557 if( sqlite3ExprVectorSize(pExpr)>n ) mask = (WO_LE|WO_LT);-
1558 iUprIdx = whereKeyStats(pParse, p, pRec, 1, a);-
1559 iNew = a[0] + ((pUpper->eOperator & mask) ? a[1] : 0);-
1560 if( iNew<iUpper ) iUpper = iNew;-
1561 nOut--;-
1562 pUpper = 0;-
1563 }-
1564 }-
1565-
1566 pBuilder->pRec = pRec;-
1567 if( rc==SQLITE_OK ){-
1568 if( iUpper>iLower ){-
1569 nNew = sqlite3LogEst(iUpper - iLower);-
1570 /* TUNING: If both iUpper and iLower are derived from the same-
1571 ** sample, then assume they are 4x more selective. This brings-
1572 ** the estimated selectivity more in line with what it would be-
1573 ** if estimated without the use of STAT3/4 tables. */-
1574 if( iLwrIdx==iUprIdx ) nNew -= 20; assert( 20==sqlite3LogEst(4) );-
1575 }else{-
1576 nNew = 10; assert( 10==sqlite3LogEst(2) );-
1577 }-
1578 if( nNew<nOut ){-
1579 nOut = nNew;-
1580 }-
1581 WHERETRACE(0x10, ("STAT4 range scan: %u..%u est=%d\n",-
1582 (u32)iLower, (u32)iUpper, nOut));-
1583 }-
1584 }else{-
1585 int bDone = 0;-
1586 rc = whereRangeSkipScanEst(pParse, pLower, pUpper, pLoop, &bDone);-
1587 if( bDone ) return rc;-
1588 }-
1589 }-
1590#else-
1591 UNUSED_PARAMETER(pParse);-
1592 UNUSED_PARAMETER(pBuilder);-
1593 assert( pLower || pUpper );-
1594#endif-
1595 assert( pUpper==0 || (pUpper->wtFlags & TERM_VNULL)==0 );-
1596 nNew = whereRangeAdjust(pLower, nOut);-
1597 nNew = whereRangeAdjust(pUpper, nNew);-
1598-
1599 /* TUNING: If there is both an upper and lower limit and neither limit-
1600 ** has an application-defined likelihood(), assume the range is-
1601 ** reduced by an additional 75%. This means that, by default, an open-ended-
1602 ** range query (e.g. col > ?) is assumed to match 1/4 of the rows in the-
1603 ** index. While a closed range (e.g. col BETWEEN ? AND ?) is estimated to-
1604 ** match 1/64 of the index. */ -
1605 if( pLower && pLower->truthProb>0 && pUpper && pUpper->truthProb>0 ){
pLowerDescription
TRUEevaluated 28305 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12728 times by 1 test
Evaluated by:
  • Self test (438)
pLower->truthProb>0Description
TRUEevaluated 28300 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 5 times by 1 test
Evaluated by:
  • Self test (438)
pUpperDescription
TRUEevaluated 15241 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 13059 times by 1 test
Evaluated by:
  • Self test (438)
pUpper->truthProb>0Description
TRUEevaluated 15241 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
0-28305
1606 nNew -= 20;-
1607 }
executed 15241 times by 1 test: end of block
Executed by:
  • Self test (438)
15241
1608-
1609 nOut -= (pLower!=0) + (pUpper!=0);-
1610 if( nNew<10 ) nNew = 10;
executed 2646 times by 1 test: nNew = 10;
Executed by:
  • Self test (438)
nNew<10Description
TRUEevaluated 2646 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 38387 times by 1 test
Evaluated by:
  • Self test (438)
2646-38387
1611 if( nNew<nOut ) nOut = nNew;
executed 40387 times by 1 test: nOut = nNew;
Executed by:
  • Self test (438)
nNew<nOutDescription
TRUEevaluated 40387 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 646 times by 1 test
Evaluated by:
  • Self test (438)
646-40387
1612#if defined(WHERETRACE_ENABLED)-
1613 if( pLoop->nOut>nOut ){-
1614 WHERETRACE(0x10,("Range scan lowers nOut from %d to %d\n",-
1615 pLoop->nOut, nOut));-
1616 }-
1617#endif-
1618 pLoop->nOut = (LogEst)nOut;-
1619 return rc;
executed 41033 times by 1 test: return rc;
Executed by:
  • Self test (438)
41033
1620}-
1621-
1622#ifdef SQLITE_ENABLE_STAT3_OR_STAT4-
1623/*-
1624** Estimate the number of rows that will be returned based on-
1625** an equality constraint x=VALUE and where that VALUE occurs in-
1626** the histogram data. This only works when x is the left-most-
1627** column of an index and sqlite_stat3 histogram data is available-
1628** for that index. When pExpr==NULL that means the constraint is-
1629** "x IS NULL" instead of "x=VALUE".-
1630**-
1631** Write the estimated row count into *pnRow and return SQLITE_OK. -
1632** If unable to make an estimate, leave *pnRow unchanged and return-
1633** non-zero.-
1634**-
1635** This routine can fail if it is unable to load a collating sequence-
1636** required for string comparison, or if unable to allocate memory-
1637** for a UTF conversion required for comparison. The error is stored-
1638** in the pParse structure.-
1639*/-
1640static int whereEqualScanEst(-
1641 Parse *pParse, /* Parsing & code generating context */-
1642 WhereLoopBuilder *pBuilder,-
1643 Expr *pExpr, /* Expression for VALUE in the x=VALUE constraint */-
1644 tRowcnt *pnRow /* Write the revised row estimate here */-
1645){-
1646 Index *p = pBuilder->pNew->u.btree.pIndex;-
1647 int nEq = pBuilder->pNew->u.btree.nEq;-
1648 UnpackedRecord *pRec = pBuilder->pRec;-
1649 int rc; /* Subfunction return code */-
1650 tRowcnt a[2]; /* Statistics */-
1651 int bOk;-
1652-
1653 assert( nEq>=1 );-
1654 assert( nEq<=p->nColumn );-
1655 assert( p->aSample!=0 );-
1656 assert( p->nSample>0 );-
1657 assert( pBuilder->nRecValid<nEq );-
1658-
1659 /* If values are not available for all fields of the index to the left-
1660 ** of this one, no estimate can be made. Return SQLITE_NOTFOUND. */-
1661 if( pBuilder->nRecValid<(nEq-1) ){-
1662 return SQLITE_NOTFOUND;-
1663 }-
1664-
1665 /* This is an optimization only. The call to sqlite3Stat4ProbeSetValue()-
1666 ** below would return the same value. */-
1667 if( nEq>=p->nColumn ){-
1668 *pnRow = 1;-
1669 return SQLITE_OK;-
1670 }-
1671-
1672 rc = sqlite3Stat4ProbeSetValue(pParse, p, &pRec, pExpr, 1, nEq-1, &bOk);-
1673 pBuilder->pRec = pRec;-
1674 if( rc!=SQLITE_OK ) return rc;-
1675 if( bOk==0 ) return SQLITE_NOTFOUND;-
1676 pBuilder->nRecValid = nEq;-
1677-
1678 whereKeyStats(pParse, p, pRec, 0, a);-
1679 WHERETRACE(0x10,("equality scan regions %s(%d): %d\n",-
1680 p->zName, nEq-1, (int)a[1]));-
1681 *pnRow = a[1];-
1682 -
1683 return rc;-
1684}-
1685#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */-
1686-
1687#ifdef SQLITE_ENABLE_STAT3_OR_STAT4-
1688/*-
1689** Estimate the number of rows that will be returned based on-
1690** an IN constraint where the right-hand side of the IN operator-
1691** is a list of values. Example:-
1692**-
1693** WHERE x IN (1,2,3,4)-
1694**-
1695** Write the estimated row count into *pnRow and return SQLITE_OK. -
1696** If unable to make an estimate, leave *pnRow unchanged and return-
1697** non-zero.-
1698**-
1699** This routine can fail if it is unable to load a collating sequence-
1700** required for string comparison, or if unable to allocate memory-
1701** for a UTF conversion required for comparison. The error is stored-
1702** in the pParse structure.-
1703*/-
1704static int whereInScanEst(-
1705 Parse *pParse, /* Parsing & code generating context */-
1706 WhereLoopBuilder *pBuilder,-
1707 ExprList *pList, /* The value list on the RHS of "x IN (v1,v2,v3,...)" */-
1708 tRowcnt *pnRow /* Write the revised row estimate here */-
1709){-
1710 Index *p = pBuilder->pNew->u.btree.pIndex;-
1711 i64 nRow0 = sqlite3LogEstToInt(p->aiRowLogEst[0]);-
1712 int nRecValid = pBuilder->nRecValid;-
1713 int rc = SQLITE_OK; /* Subfunction return code */-
1714 tRowcnt nEst; /* Number of rows for a single term */-
1715 tRowcnt nRowEst = 0; /* New estimate of the number of rows */-
1716 int i; /* Loop counter */-
1717-
1718 assert( p->aSample!=0 );-
1719 for(i=0; rc==SQLITE_OK && i<pList->nExpr; i++){-
1720 nEst = nRow0;-
1721 rc = whereEqualScanEst(pParse, pBuilder, pList->a[i].pExpr, &nEst);-
1722 nRowEst += nEst;-
1723 pBuilder->nRecValid = nRecValid;-
1724 }-
1725-
1726 if( rc==SQLITE_OK ){-
1727 if( nRowEst > nRow0 ) nRowEst = nRow0;-
1728 *pnRow = nRowEst;-
1729 WHERETRACE(0x10,("IN row estimate: est=%d\n", nRowEst));-
1730 }-
1731 assert( pBuilder->nRecValid==nRecValid );-
1732 return rc;-
1733}-
1734#endif /* SQLITE_ENABLE_STAT3_OR_STAT4 */-
1735-
1736-
1737#ifdef WHERETRACE_ENABLED-
1738/*-
1739** Print the content of a WhereTerm object-
1740*/-
1741static void whereTermPrint(WhereTerm *pTerm, int iTerm){-
1742 if( pTerm==0 ){-
1743 sqlite3DebugPrintf("TERM-%-3d NULL\n", iTerm);-
1744 }else{-
1745 char zType[4];-
1746 char zLeft[50];-
1747 memcpy(zType, "...", 4);-
1748 if( pTerm->wtFlags & TERM_VIRTUAL ) zType[0] = 'V';-
1749 if( pTerm->eOperator & WO_EQUIV ) zType[1] = 'E';-
1750 if( ExprHasProperty(pTerm->pExpr, EP_FromJoin) ) zType[2] = 'L';-
1751 if( pTerm->eOperator & WO_SINGLE ){-
1752 sqlite3_snprintf(sizeof(zLeft),zLeft,"left={%d:%d}",-
1753 pTerm->leftCursor, pTerm->u.leftColumn);-
1754 }else if( (pTerm->eOperator & WO_OR)!=0 && pTerm->u.pOrInfo!=0 ){-
1755 sqlite3_snprintf(sizeof(zLeft),zLeft,"indexable=0x%lld", -
1756 pTerm->u.pOrInfo->indexable);-
1757 }else{-
1758 sqlite3_snprintf(sizeof(zLeft),zLeft,"left=%d", pTerm->leftCursor);-
1759 }-
1760 sqlite3DebugPrintf(-
1761 "TERM-%-3d %p %s %-12s prob=%-3d op=0x%03x wtFlags=0x%04x",-
1762 iTerm, pTerm, zType, zLeft, pTerm->truthProb,-
1763 pTerm->eOperator, pTerm->wtFlags);-
1764 if( pTerm->iField ){-
1765 sqlite3DebugPrintf(" iField=%d\n", pTerm->iField);-
1766 }else{-
1767 sqlite3DebugPrintf("\n");-
1768 }-
1769 sqlite3TreeViewExpr(0, pTerm->pExpr, 0);-
1770 }-
1771}-
1772#endif-
1773-
1774#ifdef WHERETRACE_ENABLED-
1775/*-
1776** Show the complete content of a WhereClause-
1777*/-
1778void sqlite3WhereClausePrint(WhereClause *pWC){-
1779 int i;-
1780 for(i=0; i<pWC->nTerm; i++){-
1781 whereTermPrint(&pWC->a[i], i);-
1782 }-
1783}-
1784#endif-
1785-
1786#ifdef WHERETRACE_ENABLED-
1787/*-
1788** Print a WhereLoop object for debugging purposes-
1789*/-
1790static void whereLoopPrint(WhereLoop *p, WhereClause *pWC){-
1791 WhereInfo *pWInfo = pWC->pWInfo;-
1792 int nb = 1+(pWInfo->pTabList->nSrc+3)/4;-
1793 struct SrcList_item *pItem = pWInfo->pTabList->a + p->iTab;-
1794 Table *pTab = pItem->pTab;-
1795 Bitmask mAll = (((Bitmask)1)<<(nb*4)) - 1;-
1796 sqlite3DebugPrintf("%c%2d.%0*llx.%0*llx", p->cId,-
1797 p->iTab, nb, p->maskSelf, nb, p->prereq & mAll);-
1798 sqlite3DebugPrintf(" %12s",-
1799 pItem->zAlias ? pItem->zAlias : pTab->zName);-
1800 if( (p->wsFlags & WHERE_VIRTUALTABLE)==0 ){-
1801 const char *zName;-
1802 if( p->u.btree.pIndex && (zName = p->u.btree.pIndex->zName)!=0 ){-
1803 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){-
1804 int i = sqlite3Strlen30(zName) - 1;-
1805 while( zName[i]!='_' ) i--;-
1806 zName += i;-
1807 }-
1808 sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);-
1809 }else{-
1810 sqlite3DebugPrintf("%20s","");-
1811 }-
1812 }else{-
1813 char *z;-
1814 if( p->u.vtab.idxStr ){-
1815 z = sqlite3_mprintf("(%d,\"%s\",%x)",-
1816 p->u.vtab.idxNum, p->u.vtab.idxStr, p->u.vtab.omitMask);-
1817 }else{-
1818 z = sqlite3_mprintf("(%d,%x)", p->u.vtab.idxNum, p->u.vtab.omitMask);-
1819 }-
1820 sqlite3DebugPrintf(" %-19s", z);-
1821 sqlite3_free(z);-
1822 }-
1823 if( p->wsFlags & WHERE_SKIPSCAN ){-
1824 sqlite3DebugPrintf(" f %05x %d-%d", p->wsFlags, p->nLTerm,p->nSkip);-
1825 }else{-
1826 sqlite3DebugPrintf(" f %05x N %d", p->wsFlags, p->nLTerm);-
1827 }-
1828 sqlite3DebugPrintf(" cost %d,%d,%d\n", p->rSetup, p->rRun, p->nOut);-
1829 if( p->nLTerm && (sqlite3WhereTrace & 0x100)!=0 ){-
1830 int i;-
1831 for(i=0; i<p->nLTerm; i++){-
1832 whereTermPrint(p->aLTerm[i], i);-
1833 }-
1834 }-
1835}-
1836#endif-
1837-
1838/*-
1839** Convert bulk memory into a valid WhereLoop that can be passed-
1840** to whereLoopClear harmlessly.-
1841*/-
1842static void whereLoopInit(WhereLoop *p){-
1843 p->aLTerm = p->aLTermSpace;-
1844 p->nLTerm = 0;-
1845 p->nLSlot = ArraySize(p->aLTermSpace);-
1846 p->wsFlags = 0;-
1847}
executed 1572403 times by 435 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
1572403
1848-
1849/*-
1850** Clear the WhereLoop.u union. Leave WhereLoop.pLTerm intact.-
1851*/-
1852static void whereLoopClearUnion(sqlite3 *db, WhereLoop *p){-
1853 if( p->wsFlags & (WHERE_VIRTUALTABLE|WHERE_AUTO_INDEX) ){
p->wsFlags & (...00|0x00004000)Description
TRUEevaluated 73157 times by 33 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • ...
FALSEevaluated 910094 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
73157-910094
1854 if( (p->wsFlags & WHERE_VIRTUALTABLE)!=0 && p->u.vtab.needFree ){
(p->wsFlags & 0x00000400)!=0Description
TRUEevaluated 22473 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 50684 times by 33 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • ...
p->u.vtab.needFreeDescription
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 22449 times by 1 test
Evaluated by:
  • Self test (438)
24-50684
1855 sqlite3_free(p->u.vtab.idxStr);-
1856 p->u.vtab.needFree = 0;-
1857 p->u.vtab.idxStr = 0;-
1858 }else if( (p->wsFlags & WHERE_AUTO_INDEX)!=0 && p->u.btree.pIndex!=0 ){
executed 24 times by 1 test: end of block
Executed by:
  • Self test (438)
(p->wsFlags & 0x00004000)!=0Description
TRUEevaluated 50684 times by 33 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • ...
FALSEevaluated 22449 times by 1 test
Evaluated by:
  • Self test (438)
p->u.btree.pIndex!=0Description
TRUEevaluated 2859 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 47825 times by 33 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • ...
24-50684
1859 sqlite3DbFree(db, p->u.btree.pIndex->zColAff);-
1860 sqlite3DbFreeNN(db, p->u.btree.pIndex);-
1861 p->u.btree.pIndex = 0;-
1862 }
executed 2859 times by 1 test: end of block
Executed by:
  • Self test (438)
2859
1863 }
executed 73157 times by 33 tests: end of block
Executed by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • ...
73157
1864}
executed 983251 times by 435 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
983251
1865-
1866/*-
1867** Deallocate internal memory used by a WhereLoop object-
1868*/-
1869static void whereLoopClear(sqlite3 *db, WhereLoop *p){-
1870 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
executed 213 times by 1 test: sqlite3DbFreeNN(db, p->aLTerm);
Executed by:
  • Self test (438)
p->aLTerm!=p->aLTermSpaceDescription
TRUEevaluated 213 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 619731 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
213-619731
1871 whereLoopClearUnion(db, p);-
1872 whereLoopInit(p);-
1873}
executed 619944 times by 435 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
619944
1874-
1875/*-
1876** Increase the memory allocation for pLoop->aLTerm[] to be at least n.-
1877*/-
1878static int whereLoopResize(sqlite3 *db, WhereLoop *p, int n){-
1879 WhereTerm **paNew;-
1880 if( p->nLSlot>=n ) return SQLITE_OK;
executed 467794 times by 435 tests: return 0;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
p->nLSlot>=nDescription
TRUEevaluated 467794 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 241 times by 1 test
Evaluated by:
  • Self test (438)
241-467794
1881 n = (n+7)&~7;-
1882 paNew = sqlite3DbMallocRawNN(db, sizeof(p->aLTerm[0])*n);-
1883 if( paNew==0 ) return SQLITE_NOMEM_BKPT;
executed 4 times by 1 test: return 7;
Executed by:
  • Self test (438)
paNew==0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 237 times by 1 test
Evaluated by:
  • Self test (438)
4-237
1884 memcpy(paNew, p->aLTerm, sizeof(p->aLTerm[0])*p->nLSlot);-
1885 if( p->aLTerm!=p->aLTermSpace ) sqlite3DbFreeNN(db, p->aLTerm);
executed 24 times by 1 test: sqlite3DbFreeNN(db, p->aLTerm);
Executed by:
  • Self test (438)
p->aLTerm!=p->aLTermSpaceDescription
TRUEevaluated 24 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 213 times by 1 test
Evaluated by:
  • Self test (438)
24-213
1886 p->aLTerm = paNew;-
1887 p->nLSlot = n;-
1888 return SQLITE_OK;
executed 237 times by 1 test: return 0;
Executed by:
  • Self test (438)
237
1889}-
1890-
1891/*-
1892** Transfer content from the second pLoop into the first.-
1893*/-
1894static int whereLoopXfer(sqlite3 *db, WhereLoop *pTo, WhereLoop *pFrom){-
1895 whereLoopClearUnion(db, pTo);-
1896 if( whereLoopResize(db, pTo, pFrom->nLTerm) ){
whereLoopResiz...pFrom->nLTerm)Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 363305 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
2-363305
1897 memset(&pTo->u, 0, sizeof(pTo->u));-
1898 return SQLITE_NOMEM_BKPT;
executed 2 times by 1 test: return 7;
Executed by:
  • Self test (438)
2
1899 }-
1900 memcpy(pTo, pFrom, WHERE_LOOP_XFER_SZ);-
1901 memcpy(pTo->aLTerm, pFrom->aLTerm, pTo->nLTerm*sizeof(pTo->aLTerm[0]));-
1902 if( pFrom->wsFlags & WHERE_VIRTUALTABLE ){
pFrom->wsFlags & 0x00000400Description
TRUEevaluated 11782 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 351523 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
11782-351523
1903 pFrom->u.vtab.needFree = 0;-
1904 }else if( (pFrom->wsFlags & WHERE_AUTO_INDEX)!=0 ){
executed 11782 times by 1 test: end of block
Executed by:
  • Self test (438)
(pFrom->wsFlag...0x00004000)!=0Description
TRUEevaluated 50670 times by 33 tests
Evaluated by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • ...
FALSEevaluated 300853 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
11782-300853
1905 pFrom->u.btree.pIndex = 0;-
1906 }
executed 50670 times by 33 tests: end of block
Executed by:
  • Self test
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (4)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
  • Self test (48)
  • Self test (5)
  • Self test (57)
  • Self test (58)
  • Self test (72)
  • Self test (73)
  • Self test (91)
  • ...
50670
1907 return SQLITE_OK;
executed 363305 times by 435 tests: return 0;
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
363305
1908}-
1909-
1910/*-
1911** Delete a WhereLoop object-
1912*/-
1913static void whereLoopDelete(sqlite3 *db, WhereLoop *p){-
1914 whereLoopClear(db, p);-
1915 sqlite3DbFreeNN(db, p);-
1916}
executed 314590 times by 435 tests: end of block
Executed by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
314590
1917-
1918/*-
1919** Free a WhereInfo structure-
1920*/-
1921static void whereInfoFree(sqlite3 *db, WhereInfo *pWInfo){-
1922 int i;-
1923 assert( pWInfo!=0 );-
1924 for(i=0; i<pWInfo->nLevel; i++){
i<pWInfo->nLevelDescription
TRUEevaluated 279346 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 332515 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
279346-332515
1925 WhereLevel *pLevel = &pWInfo->a[i];-
1926 if( pLevel->pWLoop && (pLevel->pWLoop->wsFlags & WHERE_IN_ABLE) ){
pLevel->pWLoopDescription
TRUEevaluated 278563 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)
  • Self test (105)
  • Self test (106)
  • Self test (107)
  • Self test (108)
  • Self test (109)
  • Self test (11)
  • Self test (110)
  • Self test (111)
  • Self test (112)
  • Self test (113)
  • Self test (114)
  • Self test (115)
  • Self test (116)
  • Self test (117)
  • Self test (118)
  • Self test (119)
  • Self test (12)
  • Self test (120)
  • Self test (121)
  • ...
FALSEevaluated 783 times by 1 test
Evaluated by:
  • Self test (438)
(pLevel->pWLoo... & 0x00000800)Description
TRUEevaluated 679 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 277884 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)