OpenCoverage

select.c

Absolute File Name:/home/opencoverage/opencoverage/guest-scripts/sqlite/src/src/select.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 file contains C code routines that are called by the parser-
13** to handle SELECT statements in SQLite.-
14*/-
15#include "sqliteInt.h"-
16-
17/*-
18** Trace output macros-
19*/-
20#if SELECTTRACE_ENABLED-
21/***/ int sqlite3SelectTrace = 0;-
22# define SELECTTRACE(K,P,S,X) \-
23 if(sqlite3SelectTrace&(K)) \-
24 sqlite3DebugPrintf("%u/%d/%p: ",(S)->selId,(P)->addrExplain,(S)),\-
25 sqlite3DebugPrintf X-
26#else-
27# define SELECTTRACE(K,P,S,X)-
28#endif-
29-
30-
31/*-
32** An instance of the following object is used to record information about-
33** how to process the DISTINCT keyword, to simplify passing that information-
34** into the selectInnerLoop() routine.-
35*/-
36typedef struct DistinctCtx DistinctCtx;-
37struct DistinctCtx {-
38 u8 isTnct; /* True if the DISTINCT keyword is present */-
39 u8 eTnctType; /* One of the WHERE_DISTINCT_* operators */-
40 int tabTnct; /* Ephemeral table used for DISTINCT processing */-
41 int addrTnct; /* Address of OP_OpenEphemeral opcode for tabTnct */-
42};-
43-
44/*-
45** An instance of the following object is used to record information about-
46** the ORDER BY (or GROUP BY) clause of query is being coded.-
47**-
48** The aDefer[] array is used by the sorter-references optimization. For-
49** example, assuming there is no index that can be used for the ORDER BY,-
50** for the query:-
51**-
52** SELECT a, bigblob FROM t1 ORDER BY a LIMIT 10;-
53**-
54** it may be more efficient to add just the "a" values to the sorter, and-
55** retrieve the associated "bigblob" values directly from table t1 as the-
56** 10 smallest "a" values are extracted from the sorter.-
57**-
58** When the sorter-reference optimization is used, there is one entry in the-
59** aDefer[] array for each database table that may be read as values are-
60** extracted from the sorter.-
61*/-
62typedef struct SortCtx SortCtx;-
63struct SortCtx {-
64 ExprList *pOrderBy; /* The ORDER BY (or GROUP BY clause) */-
65 int nOBSat; /* Number of ORDER BY terms satisfied by indices */-
66 int iECursor; /* Cursor number for the sorter */-
67 int regReturn; /* Register holding block-output return address */-
68 int labelBkOut; /* Start label for the block-output subroutine */-
69 int addrSortIndex; /* Address of the OP_SorterOpen or OP_OpenEphemeral */-
70 int labelDone; /* Jump here when done, ex: LIMIT reached */-
71 int labelOBLopt; /* Jump here when sorter is full */-
72 u8 sortFlags; /* Zero or more SORTFLAG_* bits */-
73#ifdef SQLITE_ENABLE_SORTER_REFERENCES-
74 u8 nDefer; /* Number of valid entries in aDefer[] */-
75 struct DeferredCsr {-
76 Table *pTab; /* Table definition */-
77 int iCsr; /* Cursor number for table */-
78 int nKey; /* Number of PK columns for table pTab (>=1) */-
79 } aDefer[4];-
80#endif-
81 struct RowLoadInfo *pDeferredRowLoad; /* Deferred row loading info or NULL */-
82};-
83#define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */-
84-
85/*-
86** Delete all the content of a Select structure. Deallocate the structure-
87** itself only if bFree is true.-
88*/-
89static void clearSelect(sqlite3 *db, Select *p, int bFree){-
90 while( p ){
pDescription
TRUEevaluated 1123277 times by 436 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 646948 times by 436 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)
  • ...
646948-1123277
91 Select *pPrior = p->pPrior;-
92 sqlite3ExprListDelete(db, p->pEList);-
93 sqlite3SrcListDelete(db, p->pSrc);-
94 sqlite3ExprDelete(db, p->pWhere);-
95 sqlite3ExprListDelete(db, p->pGroupBy);-
96 sqlite3ExprDelete(db, p->pHaving);-
97 sqlite3ExprListDelete(db, p->pOrderBy);-
98 sqlite3ExprDelete(db, p->pLimit);-
99#ifndef SQLITE_OMIT_WINDOWFUNC-
100 if( OK_IF_ALWAYS_TRUE(p->pWinDefn) ){
(p->pWinDefn)Description
TRUEevaluated 125 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1123152 times by 436 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)
  • ...
125-1123152
101 sqlite3WindowListDelete(db, p->pWinDefn);-
102 }
executed 125 times by 1 test: end of block
Executed by:
  • Self test (438)
125
103#endif-
104 if( OK_IF_ALWAYS_TRUE(p->pWith) ) sqlite3WithDelete(db, p->pWith);
executed 1847 times by 1 test: sqlite3WithDelete(db, p->pWith);
Executed by:
  • Self test (438)
(p->pWith)Description
TRUEevaluated 1847 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1121430 times by 436 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)
  • ...
1847-1121430
105 if( bFree ) sqlite3DbFreeNN(db, p);
executed 1123125 times by 436 tests: sqlite3DbFreeNN(db, p);
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)
  • ...
bFreeDescription
TRUEevaluated 1123125 times by 436 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 152 times by 1 test
Evaluated by:
  • Self test (438)
152-1123125
106 p = pPrior;-
107 bFree = 1;-
108 }
executed 1123277 times by 436 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)
  • ...
1123277
109}
executed 646948 times by 436 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)
  • ...
646948
110-
111/*-
112** Initialize a SelectDest structure.-
113*/-
114void sqlite3SelectDestInit(SelectDest *pDest, int eDest, int iParm){-
115 pDest->eDest = (u8)eDest;-
116 pDest->iSDParm = iParm;-
117 pDest->zAffSdst = 0;-
118 pDest->iSdst = 0;-
119 pDest->nSdst = 0;-
120}
executed 97671 times by 9 tests: end of block
Executed by:
  • Self test
  • Self test (101)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (438)
  • Self test (57)
  • Self test (58)
  • Self test (64)
97671
121-
122-
123/*-
124** Allocate a new Select structure and return a pointer to that-
125** structure.-
126*/-
127Select *sqlite3SelectNew(-
128 Parse *pParse, /* Parsing context */-
129 ExprList *pEList, /* which columns to include in the result */-
130 SrcList *pSrc, /* the FROM clause -- which tables to scan */-
131 Expr *pWhere, /* the WHERE clause */-
132 ExprList *pGroupBy, /* the GROUP BY clause */-
133 Expr *pHaving, /* the HAVING clause */-
134 ExprList *pOrderBy, /* the ORDER BY clause */-
135 u32 selFlags, /* Flag parameters, such as SF_Distinct */-
136 Expr *pLimit /* LIMIT value. NULL means not used */-
137){-
138 Select *pNew;-
139 Select standin;-
140 pNew = sqlite3DbMallocRawNN(pParse->db, sizeof(*pNew) );-
141 if( pNew==0 ){
pNew==0Description
TRUEevaluated 152 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 599397 times by 436 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)
  • ...
152-599397
142 assert( pParse->db->mallocFailed );-
143 pNew = &standin;-
144 }
executed 152 times by 1 test: end of block
Executed by:
  • Self test (438)
152
145 if( pEList==0 ){
pEList==0Description
TRUEevaluated 1197 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 598352 times by 436 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)
  • ...
1197-598352
146 pEList = sqlite3ExprListAppend(pParse, 0,-
147 sqlite3Expr(pParse->db,TK_ASTERISK,0));-
148 }
executed 1197 times by 1 test: end of block
Executed by:
  • Self test (438)
1197
149 pNew->pEList = pEList;-
150 pNew->op = TK_SELECT;-
151 pNew->selFlags = selFlags;-
152 pNew->iLimit = 0;-
153 pNew->iOffset = 0;-
154 pNew->selId = ++pParse->nSelect;-
155 pNew->addrOpenEphm[0] = -1;-
156 pNew->addrOpenEphm[1] = -1;-
157 pNew->nSelectRow = 0;-
158 if( pSrc==0 ) pSrc = sqlite3DbMallocZero(pParse->db, sizeof(*pSrc));
executed 376566 times by 59 tests: pSrc = sqlite3DbMallocZero(pParse->db, sizeof(*pSrc));
Executed by:
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (13)
  • Self test (14)
  • Self test (15)
  • Self test (17)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (21)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (3)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • ...
pSrc==0Description
TRUEevaluated 376566 times by 59 tests
Evaluated by:
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (13)
  • Self test (14)
  • Self test (15)
  • Self test (17)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (21)
  • Self test (22)
  • Self test (23)
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (3)
  • Self test (31)
  • Self test (32)
  • Self test (33)
  • ...
FALSEevaluated 222983 times by 436 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)
  • ...
222983-376566
159 pNew->pSrc = pSrc;-
160 pNew->pWhere = pWhere;-
161 pNew->pGroupBy = pGroupBy;-
162 pNew->pHaving = pHaving;-
163 pNew->pOrderBy = pOrderBy;-
164 pNew->pPrior = 0;-
165 pNew->pNext = 0;-
166 pNew->pLimit = pLimit;-
167 pNew->pWith = 0;-
168#ifndef SQLITE_OMIT_WINDOWFUNC-
169 pNew->pWin = 0;-
170 pNew->pWinDefn = 0;-
171#endif-
172 if( pParse->db->mallocFailed ) {
pParse->db->mallocFailedDescription
TRUEevaluated 160 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 599389 times by 436 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)
  • ...
160-599389
173 clearSelect(pParse->db, pNew, pNew!=&standin);-
174 pNew = 0;-
175 }else{
executed 160 times by 1 test: end of block
Executed by:
  • Self test (438)
160
176 assert( pNew->pSrc!=0 || pParse->nErr>0 );-
177 }
executed 599389 times by 436 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)
  • ...
599389
178 assert( pNew!=&standin );-
179 return pNew;
executed 599549 times by 436 tests: return pNew;
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)
  • ...
599549
180}-
181-
182-
183/*-
184** Delete the given Select structure and all of its substructures.-
185*/-
186void sqlite3SelectDelete(sqlite3 *db, Select *p){-
187 if( OK_IF_ALWAYS_TRUE(p) ) clearSelect(db, p, 1);
executed 646788 times by 436 tests: clearSelect(db, p, 1);
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)Description
TRUEevaluated 646788 times by 436 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 1010929 times by 436 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)
  • ...
646788-1010929
188}
executed 1657717 times by 436 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)
  • ...
1657717
189-
190/*-
191** Return a pointer to the right-most SELECT statement in a compound.-
192*/-
193static Select *findRightmost(Select *p){-
194 while( p->pNext ) p = p->pNext;
executed 489 times by 1 test: p = p->pNext;
Executed by:
  • Self test (438)
p->pNextDescription
TRUEevaluated 489 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 38059 times by 1 test
Evaluated by:
  • Self test (438)
489-38059
195 return p;
executed 38059 times by 1 test: return p;
Executed by:
  • Self test (438)
38059
196}-
197-
198/*-
199** Given 1 to 3 identifiers preceding the JOIN keyword, determine the-
200** type of join. Return an integer constant that expresses that type-
201** in terms of the following bit values:-
202**-
203** JT_INNER-
204** JT_CROSS-
205** JT_OUTER-
206** JT_NATURAL-
207** JT_LEFT-
208** JT_RIGHT-
209**-
210** A full outer join is the combination of JT_LEFT and JT_RIGHT.-
211**-
212** If an illegal or unsupported join type is seen, then still return-
213** a join type, but put an error in the pParse structure.-
214*/-
215int sqlite3JoinType(Parse *pParse, Token *pA, Token *pB, Token *pC){-
216 int jointype = 0;-
217 Token *apAll[3];-
218 Token *p;-
219 /* 0123456789 123456789 123456789 123 */-
220 static const char zKeyText[] = "naturaleftouterightfullinnercross";-
221 static const struct {-
222 u8 i; /* Beginning of keyword text in zKeyText[] */-
223 u8 nChar; /* Length of the keyword in characters */-
224 u8 code; /* Join type mask */-
225 } aKeyword[] = {-
226 /* natural */ { 0, 7, JT_NATURAL },-
227 /* left */ { 6, 4, JT_LEFT|JT_OUTER },-
228 /* outer */ { 10, 5, JT_OUTER },-
229 /* right */ { 14, 5, JT_RIGHT|JT_OUTER },-
230 /* full */ { 19, 4, JT_LEFT|JT_RIGHT|JT_OUTER },-
231 /* inner */ { 23, 5, JT_INNER },-
232 /* cross */ { 28, 5, JT_INNER|JT_CROSS },-
233 };-
234 int i, j;-
235 apAll[0] = pA;-
236 apAll[1] = pB;-
237 apAll[2] = pC;-
238 for(i=0; i<3 && apAll[i]; i++){
i<3Description
TRUEevaluated 2694 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 18 times by 1 test
Evaluated by:
  • Self test (438)
apAll[i]Description
TRUEevaluated 1445 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1249 times by 1 test
Evaluated by:
  • Self test (438)
18-2694
239 p = apAll[i];-
240 for(j=0; j<ArraySize(aKeyword); j++){
j<((int)(sizeo...aKeyword[0])))Description
TRUEevaluated 3720 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
4-3720
241 if( p->n==aKeyword[j].nChar
p->n==aKeyword[j].nCharDescription
TRUEevaluated 2214 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1506 times by 1 test
Evaluated by:
  • Self test (438)
1506-2214
242 && sqlite3StrNICmp((char*)p->z, &zKeyText[aKeyword[j].i], p->n)==0 ){
sqlite3_strnic...].i], p->n)==0Description
TRUEevaluated 1441 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 773 times by 1 test
Evaluated by:
  • Self test (438)
773-1441
243 jointype |= aKeyword[j].code;-
244 break;
executed 1441 times by 1 test: break;
Executed by:
  • Self test (438)
1441
245 }-
246 }
executed 2279 times by 1 test: end of block
Executed by:
  • Self test (438)
2279
247 testcase( j==0 || j==1 || j==2 || j==3 || j==4 || j==5 || j==6 );-
248 if( j>=ArraySize(aKeyword) ){
j>=((int)(size...aKeyword[0])))Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1441 times by 1 test
Evaluated by:
  • Self test (438)
4-1441
249 jointype |= JT_ERROR;-
250 break;
executed 4 times by 1 test: break;
Executed by:
  • Self test (438)
4
251 }-
252 }
executed 1441 times by 1 test: end of block
Executed by:
  • Self test (438)
1441
253 if(-
254 (jointype & (JT_INNER|JT_OUTER))==(JT_INNER|JT_OUTER) ||
(jointype & (0...0x0001|0x0020)Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1267 times by 1 test
Evaluated by:
  • Self test (438)
4-1267
255 (jointype & JT_ERROR)!=0
(jointype & 0x0040)!=0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1263 times by 1 test
Evaluated by:
  • Self test (438)
4-1263
256 ){-
257 const char *zSp = " ";-
258 assert( pB!=0 );-
259 if( pC==0 ){ zSp++; }
executed 4 times by 1 test: end of block
Executed by:
  • Self test (438)
pC==0Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
4
260 sqlite3ErrorMsg(pParse, "unknown or unsupported join type: "-
261 "%T %T%s%T", pA, pB, zSp, pC);-
262 jointype = JT_INNER;-
263 }else if( (jointype & JT_OUTER)!=0
executed 8 times by 1 test: end of block
Executed by:
  • Self test (438)
(jointype & 0x0020)!=0Description
TRUEevaluated 499 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 764 times by 1 test
Evaluated by:
  • Self test (438)
8-764
264 && (jointype & (JT_LEFT|JT_RIGHT))!=JT_LEFT ){
(jointype & (0...0010))!=0x0008Description
TRUEevaluated 2 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 497 times by 1 test
Evaluated by:
  • Self test (438)
2-497
265 sqlite3ErrorMsg(pParse, -
266 "RIGHT and FULL OUTER JOINs are not currently supported");-
267 jointype = JT_INNER;-
268 }
executed 2 times by 1 test: end of block
Executed by:
  • Self test (438)
2
269 return jointype;
executed 1271 times by 1 test: return jointype;
Executed by:
  • Self test (438)
1271
270}-
271-
272/*-
273** Return the index of a column in a table. Return -1 if the column-
274** is not contained in the table.-
275*/-
276static int columnIndex(Table *pTab, const char *zCol){-
277 int i;-
278 for(i=0; i<pTab->nCol; i++){
i<pTab->nColDescription
TRUEevaluated 5667 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 936 times by 1 test
Evaluated by:
  • Self test (438)
936-5667
279 if( sqlite3StrICmp(pTab->aCol[i].zName, zCol)==0 ) return i;
executed 2396 times by 1 test: return i;
Executed by:
  • Self test (438)
sqlite3StrICmp...Name, zCol)==0Description
TRUEevaluated 2396 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3271 times by 1 test
Evaluated by:
  • Self test (438)
2396-3271
280 }
executed 3271 times by 1 test: end of block
Executed by:
  • Self test (438)
3271
281 return -1;
executed 936 times by 1 test: return -1;
Executed by:
  • Self test (438)
936
282}-
283-
284/*-
285** Search the first N tables in pSrc, from left to right, looking for a-
286** table that has a column named zCol. -
287**-
288** When found, set *piTab and *piCol to the table index and column index-
289** of the matching column and return TRUE.-
290**-
291** If not found, return FALSE.-
292*/-
293static int tableAndColumnIndex(-
294 SrcList *pSrc, /* Array of tables to search */-
295 int N, /* Number of tables in pSrc->a[] to search */-
296 const char *zCol, /* Name of the column we are looking for */-
297 int *piTab, /* Write index of pSrc->a[] here */-
298 int *piCol /* Write index of pSrc->a[*piTab].pTab->aCol[] here */-
299){-
300 int i; /* For looping over tables in pSrc */-
301 int iCol; /* Index of column matching zCol */-
302-
303 assert( (piTab==0)==(piCol==0) ); /* Both or neither are NULL */-
304 for(i=0; i<N; i++){
i<NDescription
TRUEevaluated 2684 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 695 times by 1 test
Evaluated by:
  • Self test (438)
695-2684
305 iCol = columnIndex(pSrc->a[i].pTab, zCol);-
306 if( iCol>=0 ){
iCol>=0Description
TRUEevaluated 1753 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 931 times by 1 test
Evaluated by:
  • Self test (438)
931-1753
307 if( piTab ){
piTabDescription
TRUEevaluated 1361 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 392 times by 1 test
Evaluated by:
  • Self test (438)
392-1361
308 *piTab = i;-
309 *piCol = iCol;-
310 }
executed 1361 times by 1 test: end of block
Executed by:
  • Self test (438)
1361
311 return 1;
executed 1753 times by 1 test: return 1;
Executed by:
  • Self test (438)
1753
312 }-
313 }
executed 931 times by 1 test: end of block
Executed by:
  • Self test (438)
931
314 return 0;
executed 695 times by 1 test: return 0;
Executed by:
  • Self test (438)
695
315}-
316-
317/*-
318** This function is used to add terms implied by JOIN syntax to the-
319** WHERE clause expression of a SELECT statement. The new term, which-
320** is ANDed with the existing WHERE clause, is of the form:-
321**-
322** (tab1.col1 = tab2.col2)-
323**-
324** where tab1 is the iSrc'th table in SrcList pSrc and tab2 is the -
325** (iSrc+1)'th. Column col1 is column iColLeft of tab1, and col2 is-
326** column iColRight of tab2.-
327*/-
328static void addWhereTerm(-
329 Parse *pParse, /* Parsing context */-
330 SrcList *pSrc, /* List of tables in FROM clause */-
331 int iLeft, /* Index of first table to join in pSrc */-
332 int iColLeft, /* Index of column in first table */-
333 int iRight, /* Index of second table in pSrc */-
334 int iColRight, /* Index of column in second table */-
335 int isOuterJoin, /* True if this is an OUTER join */-
336 Expr **ppWhere /* IN/OUT: The WHERE clause to add to */-
337){-
338 sqlite3 *db = pParse->db;-
339 Expr *pE1;-
340 Expr *pE2;-
341 Expr *pEq;-
342-
343 assert( iLeft<iRight );-
344 assert( pSrc->nSrc>iRight );-
345 assert( pSrc->a[iLeft].pTab );-
346 assert( pSrc->a[iRight].pTab );-
347-
348 pE1 = sqlite3CreateColumnExpr(db, pSrc, iLeft, iColLeft);-
349 pE2 = sqlite3CreateColumnExpr(db, pSrc, iRight, iColRight);-
350-
351 pEq = sqlite3PExpr(pParse, TK_EQ, pE1, pE2);-
352 if( pEq && isOuterJoin ){
pEqDescription
TRUEevaluated 1361 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
isOuterJoinDescription
TRUEevaluated 138 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1223 times by 1 test
Evaluated by:
  • Self test (438)
0-1361
353 ExprSetProperty(pEq, EP_FromJoin);-
354 assert( !ExprHasProperty(pEq, EP_TokenOnly|EP_Reduced) );-
355 ExprSetVVAProperty(pEq, EP_NoReduce);-
356 pEq->iRightJoinTable = (i16)pE2->iTable;-
357 }
executed 138 times by 1 test: end of block
Executed by:
  • Self test (438)
138
358 *ppWhere = sqlite3ExprAnd(db, *ppWhere, pEq);-
359}
executed 1361 times by 1 test: end of block
Executed by:
  • Self test (438)
1361
360-
361/*-
362** Set the EP_FromJoin property on all terms of the given expression.-
363** And set the Expr.iRightJoinTable to iTable for every term in the-
364** expression.-
365**-
366** The EP_FromJoin property is used on terms of an expression to tell-
367** the LEFT OUTER JOIN processing logic that this term is part of the-
368** join restriction specified in the ON or USING clause and not a part-
369** of the more general WHERE clause. These terms are moved over to the-
370** WHERE clause during join processing but we need to remember that they-
371** originated in the ON or USING clause.-
372**-
373** The Expr.iRightJoinTable tells the WHERE clause processing that the-
374** expression depends on table iRightJoinTable even if that table is not-
375** explicitly mentioned in the expression. That information is needed-
376** for cases like this:-
377**-
378** SELECT * FROM t1 LEFT JOIN t2 ON t1.a=t2.b AND t1.x=5-
379**-
380** The where clause needs to defer the handling of the t1.x=5-
381** term until after the t2 loop of the join. In that way, a-
382** NULL t2 row will be inserted whenever t1.x!=5. If we do not-
383** defer the handling of t1.x=5, it will be processed immediately-
384** after the t1 loop and rows with t1.x!=5 will never appear in-
385** the output, which is incorrect.-
386*/-
387static void setJoinExpr(Expr *p, int iTable){-
388 while( p ){
pDescription
TRUEevaluated 2288 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2664 times by 1 test
Evaluated by:
  • Self test (438)
2288-2664
389 ExprSetProperty(p, EP_FromJoin);-
390 assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) );-
391 ExprSetVVAProperty(p, EP_NoReduce);-
392 p->iRightJoinTable = (i16)iTable;-
393 if( p->op==TK_FUNCTION && p->x.pList ){
p->op==157Description
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2284 times by 1 test
Evaluated by:
  • Self test (438)
p->x.pListDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
0-2284
394 int i;-
395 for(i=0; i<p->x.pList->nExpr; i++){
i<p->x.pList->nExprDescription
TRUEevaluated 7 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
4-7
396 setJoinExpr(p->x.pList->a[i].pExpr, iTable);-
397 }
executed 7 times by 1 test: end of block
Executed by:
  • Self test (438)
7
398 }
executed 4 times by 1 test: end of block
Executed by:
  • Self test (438)
4
399 setJoinExpr(p->pLeft, iTable);-
400 p = p->pRight;-
401 }
executed 2288 times by 1 test: end of block
Executed by:
  • Self test (438)
2288
402}
executed 2664 times by 1 test: end of block
Executed by:
  • Self test (438)
2664
403-
404/* Undo the work of setJoinExpr(). In the expression tree p, convert every-
405** term that is marked with EP_FromJoin and iRightJoinTable==iTable into-
406** an ordinary term that omits the EP_FromJoin mark.-
407**-
408** This happens when a LEFT JOIN is simplified into an ordinary JOIN.-
409*/-
410static void unsetJoinExpr(Expr *p, int iTable){-
411 while( p ){
pDescription
TRUEevaluated 557 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 715 times by 1 test
Evaluated by:
  • Self test (438)
557-715
412 if( ExprHasProperty(p, EP_FromJoin)
(((p)->flags&(0x000001))!=0)Description
TRUEevaluated 62 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 495 times by 1 test
Evaluated by:
  • Self test (438)
62-495
413 && (iTable<0 || p->iRightJoinTable==iTable) ){
iTable<0Description
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 59 times by 1 test
Evaluated by:
  • Self test (438)
p->iRightJoinTable==iTableDescription
TRUEevaluated 56 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
3-59
414 ExprClearProperty(p, EP_FromJoin);-
415 }
executed 59 times by 1 test: end of block
Executed by:
  • Self test (438)
59
416 if( p->op==TK_FUNCTION && p->x.pList ){
p->op==157Description
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 543 times by 1 test
Evaluated by:
  • Self test (438)
p->x.pListDescription
TRUEevaluated 14 times by 1 test
Evaluated by:
  • Self test (438)
FALSEnever evaluated
0-543
417 int i;-
418 for(i=0; i<p->x.pList->nExpr; i++){
i<p->x.pList->nExprDescription
TRUEevaluated 26 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test (438)
14-26
419 unsetJoinExpr(p->x.pList->a[i].pExpr, iTable);-
420 }
executed 26 times by 1 test: end of block
Executed by:
  • Self test (438)
26
421 }
executed 14 times by 1 test: end of block
Executed by:
  • Self test (438)
14
422 unsetJoinExpr(p->pLeft, iTable);-
423 p = p->pRight;-
424 }
executed 557 times by 1 test: end of block
Executed by:
  • Self test (438)
557
425}
executed 715 times by 1 test: end of block
Executed by:
  • Self test (438)
715
426-
427/*-
428** This routine processes the join information for a SELECT statement.-
429** ON and USING clauses are converted into extra terms of the WHERE clause.-
430** NATURAL joins also create extra WHERE clause terms.-
431**-
432** The terms of a FROM clause are contained in the Select.pSrc structure.-
433** The left most table is the first entry in Select.pSrc. The right-most-
434** table is the last entry. The join operator is held in the entry to-
435** the left. Thus entry 0 contains the join operator for the join between-
436** entries 0 and 1. Any ON or USING clauses associated with the join are-
437** also attached to the left entry.-
438**-
439** This routine returns the number of errors encountered.-
440*/-
441static int sqliteProcessJoin(Parse *pParse, Select *p){-
442 SrcList *pSrc; /* All tables in the FROM clause */-
443 int i, j; /* Loop counters */-
444 struct SrcList_item *pLeft; /* Left table being joined */-
445 struct SrcList_item *pRight; /* Right table being joined */-
446-
447 pSrc = p->pSrc;-
448 pLeft = &pSrc->a[0];-
449 pRight = &pLeft[1];-
450 for(i=0; i<pSrc->nSrc-1; i++, pRight++, pLeft++){
i<pSrc->nSrc-1Description
TRUEevaluated 79439 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1006823 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)
  • ...
79439-1006823
451 Table *pRightTab = pRight->pTab;-
452 int isOuter;-
453-
454 if( NEVER(pLeft->pTab==0 || pRightTab==0) ) continue;
never executed: continue;
pLeft->pTab==0Description
TRUEnever evaluated
FALSEevaluated 79439 times by 1 test
Evaluated by:
  • Self test (438)
pRightTab==0Description
TRUEnever evaluated
FALSEevaluated 79439 times by 1 test
Evaluated by:
  • Self test (438)
0-79439
455 isOuter = (pRight->fg.jointype & JT_OUTER)!=0;-
456-
457 /* When the NATURAL keyword is present, add WHERE clause terms for-
458 ** every column that the two tables have in common.-
459 */-
460 if( pRight->fg.jointype & JT_NATURAL ){
pRight->fg.jointype & 0x0004Description
TRUEevaluated 587 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 78852 times by 1 test
Evaluated by:
  • Self test (438)
587-78852
461 if( pRight->pOn || pRight->pUsing ){
pRight->pOnDescription
TRUEevaluated 4 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 583 times by 1 test
Evaluated by:
  • Self test (438)
pRight->pUsingDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 580 times by 1 test
Evaluated by:
  • Self test (438)
3-583
462 sqlite3ErrorMsg(pParse, "a NATURAL join may not have "-
463 "an ON or USING clause", 0);-
464 return 1;
executed 7 times by 1 test: return 1;
Executed by:
  • Self test (438)
7
465 }-
466 for(j=0; j<pRightTab->nCol; j++){
j<pRightTab->nColDescription
TRUEevaluated 1218 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 580 times by 1 test
Evaluated by:
  • Self test (438)
580-1218
467 char *zName; /* Name of column in the right table */-
468 int iLeft; /* Matching left table */-
469 int iLeftCol; /* Matching column in the left table */-
470-
471 zName = pRightTab->aCol[j].zName;-
472 if( tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol) ){
tableAndColumn...ft, &iLeftCol)Description
TRUEevaluated 719 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 499 times by 1 test
Evaluated by:
  • Self test (438)
499-719
473 addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, j,-
474 isOuter, &p->pWhere);-
475 }
executed 719 times by 1 test: end of block
Executed by:
  • Self test (438)
719
476 }
executed 1218 times by 1 test: end of block
Executed by:
  • Self test (438)
1218
477 }
executed 580 times by 1 test: end of block
Executed by:
  • Self test (438)
580
478-
479 /* Disallow both ON and USING clauses in the same join-
480 */-
481 if( pRight->pOn && pRight->pUsing ){
pRight->pOnDescription
TRUEevaluated 1885 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 77547 times by 1 test
Evaluated by:
  • Self test (438)
pRight->pUsingDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1882 times by 1 test
Evaluated by:
  • Self test (438)
3-77547
482 sqlite3ErrorMsg(pParse, "cannot have both ON and USING "-
483 "clauses in the same join");-
484 return 1;
executed 3 times by 1 test: return 1;
Executed by:
  • Self test (438)
3
485 }-
486-
487 /* Add the ON clause to the end of the WHERE clause, connected by-
488 ** an AND operator.-
489 */-
490 if( pRight->pOn ){
pRight->pOnDescription
TRUEevaluated 1882 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 77547 times by 1 test
Evaluated by:
  • Self test (438)
1882-77547
491 if( isOuter ) setJoinExpr(pRight->pOn, pRight->iCursor);
executed 347 times by 1 test: setJoinExpr(pRight->pOn, pRight->iCursor);
Executed by:
  • Self test (438)
isOuterDescription
TRUEevaluated 347 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1535 times by 1 test
Evaluated by:
  • Self test (438)
347-1535
492 p->pWhere = sqlite3ExprAnd(pParse->db, p->pWhere, pRight->pOn);-
493 pRight->pOn = 0;-
494 }
executed 1882 times by 1 test: end of block
Executed by:
  • Self test (438)
1882
495-
496 /* Create extra terms on the WHERE clause for each column named-
497 ** in the USING clause. Example: If the two tables to be joined are -
498 ** A and B and the USING clause names X, Y, and Z, then add this-
499 ** to the WHERE clause: A.X=B.X AND A.Y=B.Y AND A.Z=B.Z-
500 ** Report an error if any column mentioned in the USING clause is-
501 ** not contained in both tables to be joined.-
502 */-
503 if( pRight->pUsing ){
pRight->pUsingDescription
TRUEevaluated 613 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 78816 times by 1 test
Evaluated by:
  • Self test (438)
613-78816
504 IdList *pList = pRight->pUsing;-
505 for(j=0; j<pList->nId; j++){
j<pList->nIdDescription
TRUEevaluated 648 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 607 times by 1 test
Evaluated by:
  • Self test (438)
607-648
506 char *zName; /* Name of the term in the USING clause */-
507 int iLeft; /* Table on the left with matching column name */-
508 int iLeftCol; /* Column number of matching column on the left */-
509 int iRightCol; /* Column number of matching column on the right */-
510-
511 zName = pList->a[j].zName;-
512 iRightCol = columnIndex(pRightTab, zName);-
513 if( iRightCol<0
iRightCol<0Description
TRUEevaluated 5 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 643 times by 1 test
Evaluated by:
  • Self test (438)
5-643
514 || !tableAndColumnIndex(pSrc, i+1, zName, &iLeft, &iLeftCol)
!tableAndColum...ft, &iLeftCol)Description
TRUEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 642 times by 1 test
Evaluated by:
  • Self test (438)
1-642
515 ){-
516 sqlite3ErrorMsg(pParse, "cannot join using column %s - column "-
517 "not present in both tables", zName);-
518 return 1;
executed 6 times by 1 test: return 1;
Executed by:
  • Self test (438)
6
519 }-
520 addWhereTerm(pParse, pSrc, iLeft, iLeftCol, i+1, iRightCol,-
521 isOuter, &p->pWhere);-
522 }
executed 642 times by 1 test: end of block
Executed by:
  • Self test (438)
642
523 }
executed 607 times by 1 test: end of block
Executed by:
  • Self test (438)
607
524 }
executed 79423 times by 1 test: end of block
Executed by:
  • Self test (438)
79423
525 return 0;
executed 1006823 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)
  • ...
1006823
526}-
527-
528/*-
529** An instance of this object holds information (beyond pParse and pSelect)-
530** needed to load the next result row that is to be added to the sorter.-
531*/-
532typedef struct RowLoadInfo RowLoadInfo;-
533struct RowLoadInfo {-
534 int regResult; /* Store results in array of registers here */-
535 u8 ecelFlags; /* Flag argument to ExprCodeExprList() */-
536#ifdef SQLITE_ENABLE_SORTER_REFERENCES-
537 ExprList *pExtra; /* Extra columns needed by sorter refs */-
538 int regExtraResult; /* Where to load the extra columns */-
539#endif-
540};-
541-
542/*-
543** This routine does the work of loading query data into an array of-
544** registers so that it can be added to the sorter.-
545*/-
546static void innerLoopLoadRow(-
547 Parse *pParse, /* Statement under construction */-
548 Select *pSelect, /* The query being coded */-
549 RowLoadInfo *pInfo /* Info needed to complete the row load */-
550){-
551 sqlite3ExprCodeExprList(pParse, pSelect->pEList, pInfo->regResult,-
552 0, pInfo->ecelFlags);-
553#ifdef SQLITE_ENABLE_SORTER_REFERENCES-
554 if( pInfo->pExtra ){-
555 sqlite3ExprCodeExprList(pParse, pInfo->pExtra, pInfo->regExtraResult, 0, 0);-
556 sqlite3ExprListDelete(pParse->db, pInfo->pExtra);-
557 }-
558#endif-
559}
executed 374052 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)
  • ...
374052
560-
561/*-
562** Code the OP_MakeRecord instruction that generates the entry to be-
563** added into the sorter.-
564**-
565** Return the register in which the result is stored.-
566*/-
567static int makeSorterRecord(-
568 Parse *pParse,-
569 SortCtx *pSort,-
570 Select *pSelect,-
571 int regBase,-
572 int nBase-
573){-
574 int nOBSat = pSort->nOBSat;-
575 Vdbe *v = pParse->pVdbe;-
576 int regOut = ++pParse->nMem;-
577 if( pSort->pDeferredRowLoad ){
pSort->pDeferredRowLoadDescription
TRUEevaluated 644 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12482 times by 1 test
Evaluated by:
  • Self test (438)
644-12482
578 innerLoopLoadRow(pParse, pSelect, pSort->pDeferredRowLoad);-
579 }
executed 644 times by 1 test: end of block
Executed by:
  • Self test (438)
644
580 sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase+nOBSat, nBase-nOBSat, regOut);-
581 return regOut;
executed 13126 times by 1 test: return regOut;
Executed by:
  • Self test (438)
13126
582}-
583-
584/*-
585** Generate code that will push the record in registers regData-
586** through regData+nData-1 onto the sorter.-
587*/-
588static void pushOntoSorter(-
589 Parse *pParse, /* Parser context */-
590 SortCtx *pSort, /* Information about the ORDER BY clause */-
591 Select *pSelect, /* The whole SELECT statement */-
592 int regData, /* First register holding data to be sorted */-
593 int regOrigData, /* First register holding data before packing */-
594 int nData, /* Number of elements in the regData data array */-
595 int nPrefixReg /* No. of reg prior to regData available for use */-
596){-
597 Vdbe *v = pParse->pVdbe; /* Stmt under construction */-
598 int bSeq = ((pSort->sortFlags & SORTFLAG_UseSorter)==0);-
599 int nExpr = pSort->pOrderBy->nExpr; /* No. of ORDER BY terms */-
600 int nBase = nExpr + bSeq + nData; /* Fields in sorter record */-
601 int regBase; /* Regs for sorter record */-
602 int regRecord = 0; /* Assembled sorter record */-
603 int nOBSat = pSort->nOBSat; /* ORDER BY terms to skip */-
604 int op; /* Opcode to add sorter record to sorter */-
605 int iLimit; /* LIMIT counter */-
606 int iSkip = 0; /* End of the sorter insert loop */-
607-
608 assert( bSeq==0 || bSeq==1 );-
609-
610 /* Three cases:-
611 ** (1) The data to be sorted has already been packed into a Record-
612 ** by a prior OP_MakeRecord. In this case nData==1 and regData-
613 ** will be completely unrelated to regOrigData.-
614 ** (2) All output columns are included in the sort record. In that-
615 ** case regData==regOrigData.-
616 ** (3) Some output columns are omitted from the sort record due to-
617 ** the SQLITE_ENABLE_SORTER_REFERENCE optimization, or due to the-
618 ** SQLITE_ECEL_OMITREF optimization, or due to the -
619 ** SortCtx.pDeferredRowLoad optimiation. In any of these cases-
620 ** regOrigData is 0 to prevent this routine from trying to copy-
621 ** values that might not yet exist.-
622 */-
623 assert( nData==1 || regData==regOrigData || regOrigData==0 );-
624-
625 if( nPrefixReg ){
nPrefixRegDescription
TRUEevaluated 12979 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 147 times by 1 test
Evaluated by:
  • Self test (438)
147-12979
626 assert( nPrefixReg==nExpr+bSeq );-
627 regBase = regData - nPrefixReg;-
628 }else{
executed 12979 times by 1 test: end of block
Executed by:
  • Self test (438)
12979
629 regBase = pParse->nMem + 1;-
630 pParse->nMem += nBase;-
631 }
executed 147 times by 1 test: end of block
Executed by:
  • Self test (438)
147
632 assert( pSelect->iOffset==0 || pSelect->iLimit!=0 );-
633 iLimit = pSelect->iOffset ? pSelect->iOffset+1 : pSelect->iLimit;
pSelect->iOffsetDescription
TRUEevaluated 264 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12862 times by 1 test
Evaluated by:
  • Self test (438)
264-12862
634 pSort->labelDone = sqlite3VdbeMakeLabel(v);-
635 sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, regOrigData,-
636 SQLITE_ECEL_DUP | (regOrigData? SQLITE_ECEL_REF : 0));-
637 if( bSeq ){
bSeqDescription
TRUEevaluated 794 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12332 times by 1 test
Evaluated by:
  • Self test (438)
794-12332
638 sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);-
639 }
executed 794 times by 1 test: end of block
Executed by:
  • Self test (438)
794
640 if( nPrefixReg==0 && nData>0 ){
nPrefixReg==0Description
TRUEevaluated 147 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12979 times by 1 test
Evaluated by:
  • Self test (438)
nData>0Description
TRUEevaluated 99 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 48 times by 1 test
Evaluated by:
  • Self test (438)
48-12979
641 sqlite3ExprCodeMove(pParse, regData, regBase+nExpr+bSeq, nData);-
642 }
executed 99 times by 1 test: end of block
Executed by:
  • Self test (438)
99
643 if( nOBSat>0 ){
nOBSat>0Description
TRUEevaluated 319 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12807 times by 1 test
Evaluated by:
  • Self test (438)
319-12807
644 int regPrevKey; /* The first nOBSat columns of the previous row */-
645 int addrFirst; /* Address of the OP_IfNot opcode */-
646 int addrJmp; /* Address of the OP_Jump opcode */-
647 VdbeOp *pOp; /* Opcode that opens the sorter */-
648 int nKey; /* Number of sorting key columns, including OP_Sequence */-
649 KeyInfo *pKI; /* Original KeyInfo on the sorter table */-
650-
651 regRecord = makeSorterRecord(pParse, pSort, pSelect, regBase, nBase);-
652 regPrevKey = pParse->nMem+1;-
653 pParse->nMem += pSort->nOBSat;-
654 nKey = nExpr - pSort->nOBSat + bSeq;-
655 if( bSeq ){
bSeqDescription
TRUEevaluated 78 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 241 times by 1 test
Evaluated by:
  • Self test (438)
78-241
656 addrFirst = sqlite3VdbeAddOp1(v, OP_IfNot, regBase+nExpr); -
657 }else{
executed 78 times by 1 test: end of block
Executed by:
  • Self test (438)
78
658 addrFirst = sqlite3VdbeAddOp1(v, OP_SequenceTest, pSort->iECursor);-
659 }
executed 241 times by 1 test: end of block
Executed by:
  • Self test (438)
241
660 VdbeCoverage(v);-
661 sqlite3VdbeAddOp3(v, OP_Compare, regPrevKey, regBase, pSort->nOBSat);-
662 pOp = sqlite3VdbeGetOp(v, pSort->addrSortIndex);-
663 if( pParse->db->mallocFailed ) return;
never executed: return;
pParse->db->mallocFailedDescription
TRUEnever evaluated
FALSEevaluated 319 times by 1 test
Evaluated by:
  • Self test (438)
0-319
664 pOp->p2 = nKey + nData;-
665 pKI = pOp->p4.pKeyInfo;-
666 memset(pKI->aSortOrder, 0, pKI->nKeyField); /* Makes OP_Jump testable */-
667 sqlite3VdbeChangeP4(v, -1, (char*)pKI, P4_KEYINFO);-
668 testcase( pKI->nAllField > pKI->nKeyField+2 );-
669 pOp->p4.pKeyInfo = sqlite3KeyInfoFromExprList(pParse,pSort->pOrderBy,nOBSat,-
670 pKI->nAllField-pKI->nKeyField-1);-
671 addrJmp = sqlite3VdbeCurrentAddr(v);-
672 sqlite3VdbeAddOp3(v, OP_Jump, addrJmp+1, 0, addrJmp+1); VdbeCoverage(v);-
673 pSort->labelBkOut = sqlite3VdbeMakeLabel(v);-
674 pSort->regReturn = ++pParse->nMem;-
675 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);-
676 sqlite3VdbeAddOp1(v, OP_ResetSorter, pSort->iECursor);-
677 if( iLimit ){
iLimitDescription
TRUEevaluated 78 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 241 times by 1 test
Evaluated by:
  • Self test (438)
78-241
678 sqlite3VdbeAddOp2(v, OP_IfNot, iLimit, pSort->labelDone);-
679 VdbeCoverage(v);-
680 }
executed 78 times by 1 test: end of block
Executed by:
  • Self test (438)
78
681 sqlite3VdbeJumpHere(v, addrFirst);-
682 sqlite3ExprCodeMove(pParse, regBase, regPrevKey, pSort->nOBSat);-
683 sqlite3VdbeJumpHere(v, addrJmp);-
684 }
executed 319 times by 1 test: end of block
Executed by:
  • Self test (438)
319
685 if( iLimit ){
iLimitDescription
TRUEevaluated 794 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12332 times by 1 test
Evaluated by:
  • Self test (438)
794-12332
686 /* At this point the values for the new sorter entry are stored-
687 ** in an array of registers. They need to be composed into a record-
688 ** and inserted into the sorter if either (a) there are currently-
689 ** less than LIMIT+OFFSET items or (b) the new record is smaller than -
690 ** the largest record currently in the sorter. If (b) is true and there-
691 ** are already LIMIT+OFFSET items in the sorter, delete the largest-
692 ** entry before inserting the new one. This way there are never more -
693 ** than LIMIT+OFFSET items in the sorter.-
694 **-
695 ** If the new record does not need to be inserted into the sorter,-
696 ** jump to the next iteration of the loop. If the pSort->labelOBLopt-
697 ** value is not zero, then it is a label of where to jump. Otherwise,-
698 ** just bypass the row insert logic. See the header comment on the-
699 ** sqlite3WhereOrderByLimitOptLabel() function for additional info.-
700 */-
701 int iCsr = pSort->iECursor;-
702 sqlite3VdbeAddOp2(v, OP_IfNotZero, iLimit, sqlite3VdbeCurrentAddr(v)+4);-
703 VdbeCoverage(v);-
704 sqlite3VdbeAddOp2(v, OP_Last, iCsr, 0);-
705 iSkip = sqlite3VdbeAddOp4Int(v, OP_IdxLE,-
706 iCsr, 0, regBase+nOBSat, nExpr-nOBSat);-
707 VdbeCoverage(v);-
708 sqlite3VdbeAddOp1(v, OP_Delete, iCsr);-
709 }
executed 794 times by 1 test: end of block
Executed by:
  • Self test (438)
794
710 if( regRecord==0 ){
regRecord==0Description
TRUEevaluated 12807 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 319 times by 1 test
Evaluated by:
  • Self test (438)
319-12807
711 regRecord = makeSorterRecord(pParse, pSort, pSelect, regBase, nBase);-
712 }
executed 12807 times by 1 test: end of block
Executed by:
  • Self test (438)
12807
713 if( pSort->sortFlags & SORTFLAG_UseSorter ){
pSort->sortFlags & 0x01Description
TRUEevaluated 12332 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 794 times by 1 test
Evaluated by:
  • Self test (438)
794-12332
714 op = OP_SorterInsert;-
715 }else{
executed 12332 times by 1 test: end of block
Executed by:
  • Self test (438)
12332
716 op = OP_IdxInsert;-
717 }
executed 794 times by 1 test: end of block
Executed by:
  • Self test (438)
794
718 sqlite3VdbeAddOp4Int(v, op, pSort->iECursor, regRecord,-
719 regBase+nOBSat, nBase-nOBSat);-
720 if( iSkip ){
iSkipDescription
TRUEevaluated 794 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12332 times by 1 test
Evaluated by:
  • Self test (438)
794-12332
721 sqlite3VdbeChangeP2(v, iSkip,-
722 pSort->labelOBLopt ? pSort->labelOBLopt : sqlite3VdbeCurrentAddr(v));-
723 }
executed 794 times by 1 test: end of block
Executed by:
  • Self test (438)
794
724}
executed 13126 times by 1 test: end of block
Executed by:
  • Self test (438)
13126
725-
726/*-
727** Add code to implement the OFFSET-
728*/-
729static void codeOffset(-
730 Vdbe *v, /* Generate code into this VM */-
731 int iOffset, /* Register holding the offset counter */-
732 int iContinue /* Jump here to skip the current record */-
733){-
734 if( iOffset>0 ){
iOffset>0Description
TRUEevaluated 538 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 414809 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)
  • ...
538-414809
735 sqlite3VdbeAddOp3(v, OP_IfPos, iOffset, iContinue, 1); VdbeCoverage(v);-
736 VdbeComment((v, "OFFSET"));-
737 }
executed 538 times by 1 test: end of block
Executed by:
  • Self test (438)
538
738}
executed 415347 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)
  • ...
415347
739-
740/*-
741** Add code that will check to make sure the N registers starting at iMem-
742** form a distinct entry. iTab is a sorting index that holds previously-
743** seen combinations of the N values. A new entry is made in iTab-
744** if the current N values are new.-
745**-
746** A jump to addrRepeat is made and the N+1 values are popped from the-
747** stack if the top N elements are not distinct.-
748*/-
749static void codeDistinct(-
750 Parse *pParse, /* Parsing and code generating context */-
751 int iTab, /* A sorting index used to test for distinctness */-
752 int addrRepeat, /* Jump to here if not distinct */-
753 int N, /* Number of elements */-
754 int iMem /* First element */-
755){-
756 Vdbe *v;-
757 int r1;-
758-
759 v = pParse->pVdbe;-
760 r1 = sqlite3GetTempReg(pParse);-
761 sqlite3VdbeAddOp4Int(v, OP_Found, iTab, addrRepeat, iMem, N); VdbeCoverage(v);-
762 sqlite3VdbeAddOp3(v, OP_MakeRecord, iMem, N, r1);-
763 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iTab, r1, iMem, N);-
764 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);-
765 sqlite3ReleaseTempReg(pParse, r1);-
766}
executed 3416 times by 1 test: end of block
Executed by:
  • Self test (438)
3416
767-
768#ifdef SQLITE_ENABLE_SORTER_REFERENCES-
769/*-
770** This function is called as part of inner-loop generation for a SELECT-
771** statement with an ORDER BY that is not optimized by an index. It -
772** determines the expressions, if any, that the sorter-reference -
773** optimization should be used for. The sorter-reference optimization-
774** is used for SELECT queries like:-
775**-
776** SELECT a, bigblob FROM t1 ORDER BY a LIMIT 10-
777**-
778** If the optimization is used for expression "bigblob", then instead of-
779** storing values read from that column in the sorter records, the PK of-
780** the row from table t1 is stored instead. Then, as records are extracted from-
781** the sorter to return to the user, the required value of bigblob is-
782** retrieved directly from table t1. If the values are very large, this -
783** can be more efficient than storing them directly in the sorter records.-
784**-
785** The ExprList_item.bSorterRef flag is set for each expression in pEList -
786** for which the sorter-reference optimization should be enabled. -
787** Additionally, the pSort->aDefer[] array is populated with entries-
788** for all cursors required to evaluate all selected expressions. Finally.-
789** output variable (*ppExtra) is set to an expression list containing-
790** expressions for all extra PK values that should be stored in the-
791** sorter records.-
792*/-
793static void selectExprDefer(-
794 Parse *pParse, /* Leave any error here */-
795 SortCtx *pSort, /* Sorter context */-
796 ExprList *pEList, /* Expressions destined for sorter */-
797 ExprList **ppExtra /* Expressions to append to sorter record */-
798){-
799 int i;-
800 int nDefer = 0;-
801 ExprList *pExtra = 0;-
802 for(i=0; i<pEList->nExpr; i++){-
803 struct ExprList_item *pItem = &pEList->a[i];-
804 if( pItem->u.x.iOrderByCol==0 ){-
805 Expr *pExpr = pItem->pExpr;-
806 Table *pTab = pExpr->y.pTab;-
807 if( pExpr->op==TK_COLUMN && pExpr->iColumn>=0 && pTab && !IsVirtual(pTab)-
808 && (pTab->aCol[pExpr->iColumn].colFlags & COLFLAG_SORTERREF)-
809 ){-
810 int j;-
811 for(j=0; j<nDefer; j++){-
812 if( pSort->aDefer[j].iCsr==pExpr->iTable ) break;-
813 }-
814 if( j==nDefer ){-
815 if( nDefer==ArraySize(pSort->aDefer) ){-
816 continue;-
817 }else{-
818 int nKey = 1;-
819 int k;-
820 Index *pPk = 0;-
821 if( !HasRowid(pTab) ){-
822 pPk = sqlite3PrimaryKeyIndex(pTab);-
823 nKey = pPk->nKeyCol;-
824 }-
825 for(k=0; k<nKey; k++){-
826 Expr *pNew = sqlite3PExpr(pParse, TK_COLUMN, 0, 0);-
827 if( pNew ){-
828 pNew->iTable = pExpr->iTable;-
829 pNew->y.pTab = pExpr->y.pTab;-
830 pNew->iColumn = pPk ? pPk->aiColumn[k] : -1;-
831 pExtra = sqlite3ExprListAppend(pParse, pExtra, pNew);-
832 }-
833 }-
834 pSort->aDefer[nDefer].pTab = pExpr->y.pTab;-
835 pSort->aDefer[nDefer].iCsr = pExpr->iTable;-
836 pSort->aDefer[nDefer].nKey = nKey;-
837 nDefer++;-
838 }-
839 }-
840 pItem->bSorterRef = 1;-
841 }-
842 }-
843 }-
844 pSort->nDefer = (u8)nDefer;-
845 *ppExtra = pExtra;-
846}-
847#endif-
848-
849/*-
850** This routine generates the code for the inside of the inner loop-
851** of a SELECT.-
852**-
853** If srcTab is negative, then the p->pEList expressions-
854** are evaluated in order to get the data for this row. If srcTab is-
855** zero or more, then data is pulled from srcTab and p->pEList is used only -
856** to get the number of columns and the collation sequence for each column.-
857*/-
858static void selectInnerLoop(-
859 Parse *pParse, /* The parser context */-
860 Select *p, /* The complete select statement being coded */-
861 int srcTab, /* Pull data from this table if non-negative */-
862 SortCtx *pSort, /* If not NULL, info on how to process ORDER BY */-
863 DistinctCtx *pDistinct, /* If not NULL, info on how to process DISTINCT */-
864 SelectDest *pDest, /* How to dispose of the results */-
865 int iContinue, /* Jump here to continue with next row */-
866 int iBreak /* Jump here to break out of the inner loop */-
867){-
868 Vdbe *v = pParse->pVdbe;-
869 int i;-
870 int hasDistinct; /* True if the DISTINCT keyword is present */-
871 int eDest = pDest->eDest; /* How to dispose of results */-
872 int iParm = pDest->iSDParm; /* First argument to disposal method */-
873 int nResultCol; /* Number of result columns */-
874 int nPrefixReg = 0; /* Number of extra registers before regResult */-
875 RowLoadInfo sRowLoadInfo; /* Info for deferred row loading */-
876-
877 /* Usually, regResult is the first cell in an array of memory cells-
878 ** containing the current result row. In this case regOrig is set to the-
879 ** same value. However, if the results are being sent to the sorter, the-
880 ** values for any expressions that are also part of the sort-key are omitted-
881 ** from this array. In this case regOrig is set to zero. */-
882 int regResult; /* Start of memory holding current results */-
883 int regOrig; /* Start of memory holding full result (or 0) */-
884-
885 assert( v );-
886 assert( p->pEList!=0 );-
887 hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
pDistinctDescription
TRUEevaluated 252634 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 161304 times by 4 tests
Evaluated by:
  • Self test (103)
  • Self test (104)
  • Self test (34)
  • Self test (438)
161304-252634
888 if( pSort && pSort->pOrderBy==0 ) pSort = 0;
executed 239508 times by 435 tests: pSort = 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)
  • ...
pSortDescription
TRUEevaluated 252634 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 161304 times by 4 tests
Evaluated by:
  • Self test (103)
  • Self test (104)
  • Self test (34)
  • Self test (438)
pSort->pOrderBy==0Description
TRUEevaluated 239508 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 13126 times by 1 test
Evaluated by:
  • Self test (438)
13126-252634
889 if( pSort==0 && !hasDistinct ){
pSort==0Description
TRUEevaluated 400812 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 13126 times by 1 test
Evaluated by:
  • Self test (438)
!hasDistinctDescription
TRUEevaluated 400573 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 239 times by 1 test
Evaluated by:
  • Self test (438)
239-400812
890 assert( iContinue!=0 );-
891 codeOffset(v, p->iOffset, iContinue);-
892 }
executed 400573 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)
  • ...
400573
893-
894 /* Pull the requested columns.-
895 */-
896 nResultCol = p->pEList->nExpr;-
897-
898 if( pDest->iSdst==0 ){
pDest->iSdst==0Description
TRUEevaluated 258532 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 155406 times by 6 tests
Evaluated by:
  • Self test (101)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (438)
  • Self test (64)
155406-258532
899 if( pSort ){
pSortDescription
TRUEevaluated 12979 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 245553 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)
  • ...
12979-245553
900 nPrefixReg = pSort->pOrderBy->nExpr;-
901 if( !(pSort->sortFlags & SORTFLAG_UseSorter) ) nPrefixReg++;
executed 653 times by 1 test: nPrefixReg++;
Executed by:
  • Self test (438)
!(pSort->sortFlags & 0x01)Description
TRUEevaluated 653 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12326 times by 1 test
Evaluated by:
  • Self test (438)
653-12326
902 pParse->nMem += nPrefixReg;-
903 }
executed 12979 times by 1 test: end of block
Executed by:
  • Self test (438)
12979
904 pDest->iSdst = pParse->nMem+1;-
905 pParse->nMem += nResultCol;-
906 }else if( pDest->iSdst+nResultCol > pParse->nMem ){
executed 258532 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)
  • ...
pDest->iSdst+n...> pParse->nMemDescription
TRUEevaluated 17751 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 137655 times by 6 tests
Evaluated by:
  • Self test (101)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (438)
  • Self test (64)
17751-258532
907 /* This is an error condition that can result, for example, when a SELECT-
908 ** on the right-hand side of an INSERT contains more result columns than-
909 ** there are columns in the table on the left. The error will be caught-
910 ** and reported later. But we need to make sure enough memory is allocated-
911 ** to avoid other spurious errors in the meantime. */-
912 pParse->nMem += nResultCol;-
913 }
executed 17751 times by 1 test: end of block
Executed by:
  • Self test (438)
17751
914 pDest->nSdst = nResultCol;-
915 regOrig = regResult = pDest->iSdst;-
916 if( srcTab>=0 ){
srcTab>=0Description
TRUEevaluated 36704 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 377234 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)
  • ...
36704-377234
917 for(i=0; i<nResultCol; i++){
i<nResultColDescription
TRUEevaluated 37043 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 36704 times by 1 test
Evaluated by:
  • Self test (438)
36704-37043
918 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);-
919 VdbeComment((v, "%s", p->pEList->a[i].zName));-
920 }
executed 37043 times by 1 test: end of block
Executed by:
  • Self test (438)
37043
921 }else if( eDest!=SRT_Exists ){
executed 36704 times by 1 test: end of block
Executed by:
  • Self test (438)
eDest!=3Description
TRUEevaluated 374052 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 3182 times by 1 test
Evaluated by:
  • Self test (438)
3182-374052
922#ifdef SQLITE_ENABLE_SORTER_REFERENCES-
923 ExprList *pExtra = 0;-
924#endif-
925 /* If the destination is an EXISTS(...) expression, the actual-
926 ** values returned by the SELECT are not required.-
927 */-
928 u8 ecelFlags; /* "ecel" is an abbreviation of "ExprCodeExprList" */-
929 ExprList *pEList;-
930 if( eDest==SRT_Mem || eDest==SRT_Output || eDest==SRT_Coroutine ){
eDest==10Description
TRUEevaluated 12256 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 361796 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)
  • ...
eDest==9Description
TRUEevaluated 177797 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 183999 times by 9 tests
Evaluated by:
  • Self test
  • Self test (101)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (438)
  • Self test (57)
  • Self test (58)
  • Self test (64)
eDest==13Description
TRUEevaluated 108857 times by 9 tests
Evaluated by:
  • Self test
  • Self test (101)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (438)
  • Self test (57)
  • Self test (58)
  • Self test (64)
FALSEevaluated 75142 times by 1 test
Evaluated by:
  • Self test (438)
12256-361796
931 ecelFlags = SQLITE_ECEL_DUP;-
932 }else{
executed 298910 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)
  • ...
298910
933 ecelFlags = 0;-
934 }
executed 75142 times by 1 test: end of block
Executed by:
  • Self test (438)
75142
935 if( pSort && hasDistinct==0 && eDest!=SRT_EphemTab && eDest!=SRT_Table ){
pSortDescription
TRUEevaluated 13126 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 360926 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)
  • ...
hasDistinct==0Description
TRUEevaluated 13077 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 49 times by 1 test
Evaluated by:
  • Self test (438)
eDest!=12Description
TRUEevaluated 13075 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test (438)
eDest!=14Description
TRUEevaluated 13074 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
1-360926
936 /* For each expression in p->pEList that is a copy of an expression in-
937 ** the ORDER BY clause (pSort->pOrderBy), set the associated -
938 ** iOrderByCol value to one more than the index of the ORDER BY -
939 ** expression within the sort-key that pushOntoSorter() will generate.-
940 ** This allows the p->pEList field to be omitted from the sorted record,-
941 ** saving space and CPU cycles. */-
942 ecelFlags |= (SQLITE_ECEL_OMITREF|SQLITE_ECEL_REF);-
943-
944 for(i=pSort->nOBSat; i<pSort->pOrderBy->nExpr; i++){
i<pSort->pOrderBy->nExprDescription
TRUEevaluated 15890 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 13074 times by 1 test
Evaluated by:
  • Self test (438)
13074-15890
945 int j;-
946 if( (j = pSort->pOrderBy->a[i].u.x.iOrderByCol)>0 ){
(j = pSort->pO...iOrderByCol)>0Description
TRUEevaluated 7948 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 7942 times by 1 test
Evaluated by:
  • Self test (438)
7942-7948
947 p->pEList->a[j-1].u.x.iOrderByCol = i+1-pSort->nOBSat;-
948 }
executed 7948 times by 1 test: end of block
Executed by:
  • Self test (438)
7948
949 }
executed 15890 times by 1 test: end of block
Executed by:
  • Self test (438)
15890
950#ifdef SQLITE_ENABLE_SORTER_REFERENCES-
951 selectExprDefer(pParse, pSort, p->pEList, &pExtra);-
952 if( pExtra && pParse->db->mallocFailed==0 ){-
953 /* If there are any extra PK columns to add to the sorter records,-
954 ** allocate extra memory cells and adjust the OpenEphemeral -
955 ** instruction to account for the larger records. This is only-
956 ** required if there are one or more WITHOUT ROWID tables with-
957 ** composite primary keys in the SortCtx.aDefer[] array. */-
958 VdbeOp *pOp = sqlite3VdbeGetOp(v, pSort->addrSortIndex);-
959 pOp->p2 += (pExtra->nExpr - pSort->nDefer);-
960 pOp->p4.pKeyInfo->nAllField += (pExtra->nExpr - pSort->nDefer);-
961 pParse->nMem += pExtra->nExpr;-
962 }-
963#endif-
964-
965 /* Adjust nResultCol to account for columns that are omitted-
966 ** from the sorter by the optimizations in this branch */-
967 pEList = p->pEList;-
968 for(i=0; i<pEList->nExpr; i++){
i<pEList->nExprDescription
TRUEevaluated 41075 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 13074 times by 1 test
Evaluated by:
  • Self test (438)
13074-41075
969 if( pEList->a[i].u.x.iOrderByCol>0
pEList->a[i].u.x.iOrderByCol>0Description
TRUEevaluated 7865 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 33210 times by 1 test
Evaluated by:
  • Self test (438)
7865-33210
970#ifdef SQLITE_ENABLE_SORTER_REFERENCES-
971 || pEList->a[i].bSorterRef-
972#endif-
973 ){-
974 nResultCol--;-
975 regOrig = 0;-
976 }
executed 7865 times by 1 test: end of block
Executed by:
  • Self test (438)
7865
977 }
executed 41075 times by 1 test: end of block
Executed by:
  • Self test (438)
41075
978-
979 testcase( regOrig );-
980 testcase( eDest==SRT_Set );-
981 testcase( eDest==SRT_Mem );-
982 testcase( eDest==SRT_Coroutine );-
983 testcase( eDest==SRT_Output );-
984 assert( eDest==SRT_Set || eDest==SRT_Mem -
985 || eDest==SRT_Coroutine || eDest==SRT_Output );-
986 }
executed 13074 times by 1 test: end of block
Executed by:
  • Self test (438)
13074
987 sRowLoadInfo.regResult = regResult;-
988 sRowLoadInfo.ecelFlags = ecelFlags;-
989#ifdef SQLITE_ENABLE_SORTER_REFERENCES-
990 sRowLoadInfo.pExtra = pExtra;-
991 sRowLoadInfo.regExtraResult = regResult + nResultCol;-
992 if( pExtra ) nResultCol += pExtra->nExpr;-
993#endif-
994 if( p->iLimit
p->iLimitDescription
TRUEevaluated 13569 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 360483 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)
  • ...
13569-360483
995 && (ecelFlags & SQLITE_ECEL_OMITREF)!=0
(ecelFlags & 0x08)!=0Description
TRUEevaluated 784 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12785 times by 1 test
Evaluated by:
  • Self test (438)
784-12785
996 && nPrefixReg>0
nPrefixReg>0Description
TRUEevaluated 644 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 140 times by 1 test
Evaluated by:
  • Self test (438)
140-644
997 ){-
998 assert( pSort!=0 );-
999 assert( hasDistinct==0 );-
1000 pSort->pDeferredRowLoad = &sRowLoadInfo;-
1001 regOrig = 0;-
1002 }else{
executed 644 times by 1 test: end of block
Executed by:
  • Self test (438)
644
1003 innerLoopLoadRow(pParse, p, &sRowLoadInfo);-
1004 }
executed 373408 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)
  • ...
373408
1005 }-
1006-
1007 /* If the DISTINCT keyword was present on the SELECT statement-
1008 ** and this row has been seen before, then do not make this row-
1009 ** part of the result.-
1010 */-
1011 if( hasDistinct ){
hasDistinctDescription
TRUEevaluated 288 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 413650 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)
  • ...
288-413650
1012 switch( pDistinct->eTnctType ){-
1013 case WHERE_DISTINCT_ORDERED: {
executed 62 times by 1 test: case 2:
Executed by:
  • Self test (438)
62
1014 VdbeOp *pOp; /* No longer required OpenEphemeral instr. */-
1015 int iJump; /* Jump destination */-
1016 int regPrev; /* Previous row content */-
1017-
1018 /* Allocate space for the previous row */-
1019 regPrev = pParse->nMem+1;-
1020 pParse->nMem += nResultCol;-
1021-
1022 /* Change the OP_OpenEphemeral coded earlier to an OP_Null-
1023 ** sets the MEM_Cleared bit on the first register of the-
1024 ** previous value. This will cause the OP_Ne below to always-
1025 ** fail on the first iteration of the loop even if the first-
1026 ** row is all NULLs.-
1027 */-
1028 sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct);-
1029 pOp = sqlite3VdbeGetOp(v, pDistinct->addrTnct);-
1030 pOp->opcode = OP_Null;-
1031 pOp->p1 = 1;-
1032 pOp->p2 = regPrev;-
1033-
1034 iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;-
1035 for(i=0; i<nResultCol; i++){
i<nResultColDescription
TRUEevaluated 118 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 62 times by 1 test
Evaluated by:
  • Self test (438)
62-118
1036 CollSeq *pColl = sqlite3ExprCollSeq(pParse, p->pEList->a[i].pExpr);-
1037 if( i<nResultCol-1 ){
i<nResultCol-1Description
TRUEevaluated 56 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 62 times by 1 test
Evaluated by:
  • Self test (438)
56-62
1038 sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);-
1039 VdbeCoverage(v);-
1040 }else{
executed 56 times by 1 test: end of block
Executed by:
  • Self test (438)
56
1041 sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);-
1042 VdbeCoverage(v);-
1043 }
executed 62 times by 1 test: end of block
Executed by:
  • Self test (438)
62
1044 sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);-
1045 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);-
1046 }
executed 118 times by 1 test: end of block
Executed by:
  • Self test (438)
118
1047 assert( sqlite3VdbeCurrentAddr(v)==iJump || pParse->db->mallocFailed );-
1048 sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1);-
1049 break;
executed 62 times by 1 test: break;
Executed by:
  • Self test (438)
62
1050 }-
1051-
1052 case WHERE_DISTINCT_UNIQUE: {
executed 24 times by 1 test: case 1:
Executed by:
  • Self test (438)
24
1053 sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct);-
1054 break;
executed 24 times by 1 test: break;
Executed by:
  • Self test (438)
24
1055 }-
1056-
1057 default: {
executed 202 times by 1 test: default:
Executed by:
  • Self test (438)
202
1058 assert( pDistinct->eTnctType==WHERE_DISTINCT_UNORDERED );-
1059 codeDistinct(pParse, pDistinct->tabTnct, iContinue, nResultCol,-
1060 regResult);-
1061 break;
executed 202 times by 1 test: break;
Executed by:
  • Self test (438)
202
1062 }-
1063 }-
1064 if( pSort==0 ){
pSort==0Description
TRUEevaluated 239 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 49 times by 1 test
Evaluated by:
  • Self test (438)
49-239
1065 codeOffset(v, p->iOffset, iContinue);-
1066 }
executed 239 times by 1 test: end of block
Executed by:
  • Self test (438)
239
1067 }
executed 288 times by 1 test: end of block
Executed by:
  • Self test (438)
288
1068-
1069 switch( eDest ){-
1070 /* In this mode, write each query result to the key of the temporary-
1071 ** table iParm.-
1072 */-
1073#ifndef SQLITE_OMIT_COMPOUND_SELECT-
1074 case SRT_Union: {
executed 72820 times by 1 test: case 1:
Executed by:
  • Self test (438)
72820
1075 int r1;-
1076 r1 = sqlite3GetTempReg(pParse);-
1077 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);-
1078 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);-
1079 sqlite3ReleaseTempReg(pParse, r1);-
1080 break;
executed 72820 times by 1 test: break;
Executed by:
  • Self test (438)
72820
1081 }-
1082-
1083 /* Construct a record from the query result, but instead of-
1084 ** saving that record, use it as a key to delete elements from-
1085 ** the temporary table iParm.-
1086 */-
1087 case SRT_Except: {
executed 126 times by 1 test: case 2:
Executed by:
  • Self test (438)
126
1088 sqlite3VdbeAddOp3(v, OP_IdxDelete, iParm, regResult, nResultCol);-
1089 break;
executed 126 times by 1 test: break;
Executed by:
  • Self test (438)
126
1090 }-
1091#endif /* SQLITE_OMIT_COMPOUND_SELECT */-
1092-
1093 /* Store the result as data using a unique key.-
1094 */-
1095 case SRT_Fifo:
executed 470 times by 1 test: case 5:
Executed by:
  • Self test (438)
470
1096 case SRT_DistFifo:
executed 49 times by 1 test: case 6:
Executed by:
  • Self test (438)
49
1097 case SRT_Table:
executed 48 times by 1 test: case 14:
Executed by:
  • Self test (438)
48
1098 case SRT_EphemTab: {
executed 866 times by 1 test: case 12:
Executed by:
  • Self test (438)
866
1099 int r1 = sqlite3GetTempRange(pParse, nPrefixReg+1);-
1100 testcase( eDest==SRT_Table );-
1101 testcase( eDest==SRT_EphemTab );-
1102 testcase( eDest==SRT_Fifo );-
1103 testcase( eDest==SRT_DistFifo );-
1104 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1+nPrefixReg);-
1105#ifndef SQLITE_OMIT_CTE-
1106 if( eDest==SRT_DistFifo ){
eDest==6Description
TRUEevaluated 49 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1384 times by 1 test
Evaluated by:
  • Self test (438)
49-1384
1107 /* If the destination is DistFifo, then cursor (iParm+1) is open-
1108 ** on an ephemeral index. If the current row is already present-
1109 ** in the index, do not write it to the output. If not, add the-
1110 ** current row to the index and proceed with writing it to the-
1111 ** output table as well. */-
1112 int addr = sqlite3VdbeCurrentAddr(v) + 4;-
1113 sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, addr, r1, 0);-
1114 VdbeCoverage(v);-
1115 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm+1, r1,regResult,nResultCol);-
1116 assert( pSort==0 );-
1117 }
executed 49 times by 1 test: end of block
Executed by:
  • Self test (438)
49
1118#endif-
1119 if( pSort ){
pSortDescription
TRUEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 1430 times by 1 test
Evaluated by:
  • Self test (438)
3-1430
1120 assert( regResult==regOrig );-
1121 pushOntoSorter(pParse, pSort, p, r1+nPrefixReg, regOrig, 1, nPrefixReg);-
1122 }else{
executed 3 times by 1 test: end of block
Executed by:
  • Self test (438)
3
1123 int r2 = sqlite3GetTempReg(pParse);-
1124 sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, r2);-
1125 sqlite3VdbeAddOp3(v, OP_Insert, iParm, r1, r2);-
1126 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);-
1127 sqlite3ReleaseTempReg(pParse, r2);-
1128 }
executed 1430 times by 1 test: end of block
Executed by:
  • Self test (438)
1430
1129 sqlite3ReleaseTempRange(pParse, r1, nPrefixReg+1);-
1130 break;
executed 1433 times by 1 test: break;
Executed by:
  • Self test (438)
1433
1131 }-
1132-
1133#ifndef SQLITE_OMIT_SUBQUERY-
1134 /* If we are creating a set for an "expr IN (SELECT ...)" construct,-
1135 ** then there should be a single item on the stack. Write this-
1136 ** item into the set table with bogus data.-
1137 */-
1138 case SRT_Set: {
executed 3911 times by 1 test: case 11:
Executed by:
  • Self test (438)
3911
1139 if( pSort ){
pSortDescription
TRUEevaluated 51 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3860 times by 1 test
Evaluated by:
  • Self test (438)
51-3860
1140 /* At first glance you would think we could optimize out the-
1141 ** ORDER BY in this case since the order of entries in the set-
1142 ** does not matter. But there might be a LIMIT clause, in which-
1143 ** case the order does matter */-
1144 pushOntoSorter(-
1145 pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);-
1146 }else{
executed 51 times by 1 test: end of block
Executed by:
  • Self test (438)
51
1147 int r1 = sqlite3GetTempReg(pParse);-
1148 assert( sqlite3Strlen30(pDest->zAffSdst)==nResultCol );-
1149 sqlite3VdbeAddOp4(v, OP_MakeRecord, regResult, nResultCol, -
1150 r1, pDest->zAffSdst, nResultCol);-
1151 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, regResult, nResultCol);-
1152 sqlite3ReleaseTempReg(pParse, r1);-
1153 }
executed 3860 times by 1 test: end of block
Executed by:
  • Self test (438)
3860
1154 break;
executed 3911 times by 1 test: break;
Executed by:
  • Self test (438)
3911
1155 }-
1156-
1157 /* If any row exist in the result set, record that fact and abort.-
1158 */-
1159 case SRT_Exists: {
executed 3207 times by 1 test: case 3:
Executed by:
  • Self test (438)
3207
1160 sqlite3VdbeAddOp2(v, OP_Integer, 1, iParm);-
1161 /* The LIMIT clause will terminate the loop for us */-
1162 break;
executed 3207 times by 1 test: break;
Executed by:
  • Self test (438)
3207
1163 }-
1164-
1165 /* If this is a scalar select that is part of an expression, then-
1166 ** store the results in the appropriate memory cell or array of -
1167 ** memory cells and break out of the scan loop.-
1168 */-
1169 case SRT_Mem: {
executed 12270 times by 1 test: case 10:
Executed by:
  • Self test (438)
12270
1170 if( pSort ){
pSortDescription
TRUEevaluated 112 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12158 times by 1 test
Evaluated by:
  • Self test (438)
112-12158
1171 assert( nResultCol<=pDest->nSdst );-
1172 pushOntoSorter(-
1173 pParse, pSort, p, regResult, regOrig, nResultCol, nPrefixReg);-
1174 }else{
executed 112 times by 1 test: end of block
Executed by:
  • Self test (438)
112
1175 assert( nResultCol==pDest->nSdst );-
1176 assert( regResult==iParm );-
1177 /* The LIMIT clause will jump out of the loop for us */-
1178 }
executed 12158 times by 1 test: end of block
Executed by:
  • Self test (438)
12158
1179 break;
executed 12270 times by 1 test: break;
Executed by:
  • Self test (438)
12270
1180 }-
1181#endif /* #ifndef SQLITE_OMIT_SUBQUERY */-
1182-
1183 case SRT_Coroutine: /* Send data to a co-routine */
executed 141993 times by 9 tests: case 13:
Executed by:
  • Self test
  • Self test (101)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (438)
  • Self test (57)
  • Self test (58)
  • Self test (64)
141993
1184 case SRT_Output: { /* Return the results */
executed 177964 times by 435 tests: case 9:
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)
  • ...
177964
1185 testcase( eDest==SRT_Coroutine );-
1186 testcase( eDest==SRT_Output );-
1187 if( pSort ){
pSortDescription
TRUEevaluated 12960 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 306997 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)
  • ...
12960-306997
1188 pushOntoSorter(pParse, pSort, p, regResult, regOrig, nResultCol,-
1189 nPrefixReg);-
1190 }else if( eDest==SRT_Coroutine ){
executed 12960 times by 1 test: end of block
Executed by:
  • Self test (438)
eDest==13Description
TRUEevaluated 139589 times by 9 tests
Evaluated by:
  • Self test
  • Self test (101)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (438)
  • Self test (57)
  • Self test (58)
  • Self test (64)
FALSEevaluated 167408 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)
  • ...
12960-167408
1191 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);-
1192 }else{
executed 139589 times by 9 tests: end of block
Executed by:
  • Self test
  • Self test (101)
  • Self test (32)
  • Self test (33)
  • Self test (34)
  • Self test (438)
  • Self test (57)
  • Self test (58)
  • Self test (64)
139589
1193 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nResultCol);-
1194 }
executed 167408 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)
  • ...
167408
1195 break;
executed 319957 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)
  • ...
319957
1196 }-
1197-
1198#ifndef SQLITE_OMIT_CTE-
1199 /* Write the results into a priority queue that is order according to-
1200 ** pDest->pOrderBy (in pSO). pDest->iSDParm (in iParm) is the cursor for an-
1201 ** index with pSO->nExpr+2 columns. Build a key using pSO for the first-
1202 ** pSO->nExpr columns, then make sure all keys are unique by adding a-
1203 ** final OP_Sequence column. The last column is the record as a blob.-
1204 */-
1205 case SRT_DistQueue:
executed 6 times by 1 test: case 8:
Executed by:
  • Self test (438)
6
1206 case SRT_Queue: {
executed 28 times by 1 test: case 7:
Executed by:
  • Self test (438)
28
1207 int nKey;-
1208 int r1, r2, r3;-
1209 int addrTest = 0;-
1210 ExprList *pSO;-
1211 pSO = pDest->pOrderBy;-
1212 assert( pSO );-
1213 nKey = pSO->nExpr;-
1214 r1 = sqlite3GetTempReg(pParse);-
1215 r2 = sqlite3GetTempRange(pParse, nKey+2);-
1216 r3 = r2+nKey+1;-
1217 if( eDest==SRT_DistQueue ){
eDest==8Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test (438)
6-28
1218 /* If the destination is DistQueue, then cursor (iParm+1) is open-
1219 ** on a second ephemeral index that holds all values every previously-
1220 ** added to the queue. */-
1221 addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0, -
1222 regResult, nResultCol);-
1223 VdbeCoverage(v);-
1224 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test (438)
6
1225 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3);-
1226 if( eDest==SRT_DistQueue ){
eDest==8Description
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test (438)
6-28
1227 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r3);-
1228 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);-
1229 }
executed 6 times by 1 test: end of block
Executed by:
  • Self test (438)
6
1230 for(i=0; i<nKey; i++){
i<nKeyDescription
TRUEevaluated 44 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 34 times by 1 test
Evaluated by:
  • Self test (438)
34-44
1231 sqlite3VdbeAddOp2(v, OP_SCopy,-
1232 regResult + pSO->a[i].u.x.iOrderByCol - 1,-
1233 r2+i);-
1234 }
executed 44 times by 1 test: end of block
Executed by:
  • Self test (438)
44
1235 sqlite3VdbeAddOp2(v, OP_Sequence, iParm, r2+nKey);-
1236 sqlite3VdbeAddOp3(v, OP_MakeRecord, r2, nKey+2, r1);-
1237 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, r1, r2, nKey+2);-
1238 if( addrTest ) sqlite3VdbeJumpHere(v, addrTest);
executed 6 times by 1 test: sqlite3VdbeJumpHere(v, addrTest);
Executed by:
  • Self test (438)
addrTestDescription
TRUEevaluated 6 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 28 times by 1 test
Evaluated by:
  • Self test (438)
6-28
1239 sqlite3ReleaseTempReg(pParse, r1);-
1240 sqlite3ReleaseTempRange(pParse, r2, nKey+2);-
1241 break;
executed 34 times by 1 test: break;
Executed by:
  • Self test (438)
34
1242 }-
1243#endif /* SQLITE_OMIT_CTE */-
1244-
1245-
1246-
1247#if !defined(SQLITE_OMIT_TRIGGER)-
1248 /* Discard the results. This is used for SELECT statements inside-
1249 ** the body of a TRIGGER. The purpose of such selects is to call-
1250 ** user-defined functions that have side effects. We do not care-
1251 ** about the actual results of the select.-
1252 */-
1253 default: {
executed 180 times by 1 test: default:
Executed by:
  • Self test (438)
180
1254 assert( eDest==SRT_Discard );-
1255 break;
executed 180 times by 1 test: break;
Executed by:
  • Self test (438)
180
1256 }-
1257#endif-
1258 }-
1259-
1260 /* Jump to the end of the loop if the LIMIT is reached. Except, if-
1261 ** there is a sorter, in which case the sorter has already limited-
1262 ** the output for us.-
1263 */-
1264 if( pSort==0 && p->iLimit ){
pSort==0Description
TRUEevaluated 400812 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 13126 times by 1 test
Evaluated by:
  • Self test (438)
p->iLimitDescription
TRUEevaluated 16016 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 384796 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)
  • ...
13126-400812
1265 sqlite3VdbeAddOp2(v, OP_DecrJumpZero, p->iLimit, iBreak); VdbeCoverage(v);-
1266 }
executed 16016 times by 1 test: end of block
Executed by:
  • Self test (438)
16016
1267}
executed 413938 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)
  • ...
413938
1268-
1269/*-
1270** Allocate a KeyInfo object sufficient for an index of N key columns and-
1271** X extra columns.-
1272*/-
1273KeyInfo *sqlite3KeyInfoAlloc(sqlite3 *db, int N, int X){-
1274 int nExtra = (N+X)*(sizeof(CollSeq*)+1) - sizeof(CollSeq*);-
1275 KeyInfo *p = sqlite3DbMallocRawNN(db, sizeof(KeyInfo) + nExtra);-
1276 if( p ){
pDescription
TRUEevaluated 173203 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 84 times by 1 test
Evaluated by:
  • Self test (438)
84-173203
1277 p->aSortOrder = (u8*)&p->aColl[N+X];-
1278 p->nKeyField = (u16)N;-
1279 p->nAllField = (u16)(N+X);-
1280 p->enc = ENC(db);-
1281 p->db = db;-
1282 p->nRef = 1;-
1283 memset(&p[1], 0, nExtra);-
1284 }else{
executed 173203 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)
  • ...
173203
1285 sqlite3OomFault(db);-
1286 }
executed 84 times by 1 test: end of block
Executed by:
  • Self test (438)
84
1287 return p;
executed 173287 times by 435 tests: return p;
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)
  • ...
173287
1288}-
1289-
1290/*-
1291** Deallocate a KeyInfo object-
1292*/-
1293void sqlite3KeyInfoUnref(KeyInfo *p){-
1294 if( p ){
pDescription
TRUEevaluated 214655 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 408 times by 1 test
Evaluated by:
  • Self test (438)
408-214655
1295 assert( p->nRef>0 );-
1296 p->nRef--;-
1297 if( p->nRef==0 ) sqlite3DbFreeNN(p->db, p);
executed 172835 times by 435 tests: sqlite3DbFreeNN(p->db, p);
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->nRef==0Description
TRUEevaluated 172835 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 41820 times by 10 tests
Evaluated by:
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
41820-172835
1298 }
executed 214655 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)
  • ...
214655
1299}
executed 215063 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)
  • ...
215063
1300-
1301/*-
1302** Make a new pointer to a KeyInfo object-
1303*/-
1304KeyInfo *sqlite3KeyInfoRef(KeyInfo *p){-
1305 if( p ){
pDescription
TRUEevaluated 41820 times by 10 tests
Evaluated by:
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test (438)
14-41820
1306 assert( p->nRef>0 );-
1307 p->nRef++;-
1308 }
executed 41820 times by 10 tests: end of block
Executed by:
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
41820
1309 return p;
executed 41834 times by 10 tests: return p;
Executed by:
  • Self test (24)
  • Self test (26)
  • Self test (27)
  • Self test (28)
  • Self test (29)
  • Self test (42)
  • Self test (438)
  • Self test (44)
  • Self test (46)
  • Self test (47)
41834
1310}-
1311-
1312#ifdef SQLITE_DEBUG-
1313/*-
1314** Return TRUE if a KeyInfo object can be change. The KeyInfo object-
1315** can only be changed if this is just a single reference to the object.-
1316**-
1317** This routine is used only inside of assert() statements.-
1318*/-
1319int sqlite3KeyInfoIsWriteable(KeyInfo *p){ return p->nRef==1; }-
1320#endif /* SQLITE_DEBUG */-
1321-
1322/*-
1323** Given an expression list, generate a KeyInfo structure that records-
1324** the collating sequence for each expression in that expression list.-
1325**-
1326** If the ExprList is an ORDER BY or GROUP BY clause then the resulting-
1327** KeyInfo structure is appropriate for initializing a virtual index to-
1328** implement that clause. If the ExprList is the result set of a SELECT-
1329** then the KeyInfo structure is appropriate for initializing a virtual-
1330** index to implement a DISTINCT test.-
1331**-
1332** Space to hold the KeyInfo structure is obtained from malloc. The calling-
1333** function is responsible for seeing that this structure is eventually-
1334** freed.-
1335*/-
1336KeyInfo *sqlite3KeyInfoFromExprList(-
1337 Parse *pParse, /* Parsing context */-
1338 ExprList *pList, /* Form the KeyInfo object from this ExprList */-
1339 int iStart, /* Begin with this column of pList */-
1340 int nExtra /* Add this many extra columns to the end */-
1341){-
1342 int nExpr;-
1343 KeyInfo *pInfo;-
1344 struct ExprList_item *pItem;-
1345 sqlite3 *db = pParse->db;-
1346 int i;-
1347-
1348 nExpr = pList->nExpr;-
1349 pInfo = sqlite3KeyInfoAlloc(db, nExpr-iStart, nExtra+1);-
1350 if( pInfo ){
pInfoDescription
TRUEevaluated 67713 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 80 times by 1 test
Evaluated by:
  • Self test (438)
80-67713
1351 assert( sqlite3KeyInfoIsWriteable(pInfo) );-
1352 for(i=iStart, pItem=pList->a+iStart; i<nExpr; i++, pItem++){
i<nExprDescription
TRUEevaluated 72197 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 67713 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)
  • ...
67713-72197
1353 pInfo->aColl[i-iStart] = sqlite3ExprNNCollSeq(pParse, pItem->pExpr);-
1354 pInfo->aSortOrder[i-iStart] = pItem->sortOrder;-
1355 }
executed 72197 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)
  • ...
72197
1356 }
executed 67713 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)
  • ...
67713
1357 return pInfo;
executed 67793 times by 435 tests: return pInfo;
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)
  • ...
67793
1358}-
1359-
1360/*-
1361** Name of the connection operator, used for error messages.-
1362*/-
1363static const char *selectOpName(int id){-
1364 char *z;-
1365 switch( id ){-
1366 case TK_ALL: z = "UNION ALL"; break;
executed 362 times by 1 test: break;
Executed by:
  • Self test (438)
executed 362 times by 1 test: case 124:
Executed by:
  • Self test (438)
362
1367 case TK_INTERSECT: z = "INTERSECT"; break;
executed 187 times by 1 test: break;
Executed by:
  • Self test (438)
executed 187 times by 1 test: case 126:
Executed by:
  • Self test (438)
187
1368 case TK_EXCEPT: z = "EXCEPT"; break;
executed 197 times by 1 test: break;
Executed by:
  • Self test (438)
executed 197 times by 1 test: case 125:
Executed by:
  • Self test (438)
197
1369 default: z = "UNION"; break;
executed 36500 times by 1 test: break;
Executed by:
  • Self test (438)
executed 36500 times by 1 test: default:
Executed by:
  • Self test (438)
36500
1370 }-
1371 return z;
executed 37246 times by 1 test: return z;
Executed by:
  • Self test (438)
37246
1372}-
1373-
1374#ifndef SQLITE_OMIT_EXPLAIN-
1375/*-
1376** Unless an "EXPLAIN QUERY PLAN" command is being processed, this function-
1377** is a no-op. Otherwise, it adds a single row of output to the EQP result,-
1378** where the caption is of the form:-
1379**-
1380** "USE TEMP B-TREE FOR xxx"-
1381**-
1382** where xxx is one of "DISTINCT", "ORDER BY" or "GROUP BY". Exactly which-
1383** is determined by the zUsage argument.-
1384*/-
1385static void explainTempTable(Parse *pParse, const char *zUsage){-
1386 ExplainQueryPlan((pParse, 0, "USE TEMP B-TREE FOR %s", zUsage));-
1387}
executed 15429 times by 1 test: end of block
Executed by:
  • Self test (438)
15429
1388-
1389/*-
1390** Assign expression b to lvalue a. A second, no-op, version of this macro-
1391** is provided when SQLITE_OMIT_EXPLAIN is defined. This allows the code-
1392** in sqlite3Select() to assign values to structure member variables that-
1393** only exist if SQLITE_OMIT_EXPLAIN is not defined without polluting the-
1394** code with #ifndef directives.-
1395*/-
1396# define explainSetInteger(a, b) a = b-
1397-
1398#else-
1399/* No-op versions of the explainXXX() functions and macros. */-
1400# define explainTempTable(y,z)-
1401# define explainSetInteger(y,z)-
1402#endif-
1403-
1404-
1405/*-
1406** If the inner loop was generated using a non-null pOrderBy argument,-
1407** then the results were placed in a sorter. After the loop is terminated-
1408** we need to run the sorter and output the results. The following-
1409** routine generates the code needed to do that.-
1410*/-
1411static void generateSortTail(-
1412 Parse *pParse, /* Parsing context */-
1413 Select *p, /* The SELECT statement */-
1414 SortCtx *pSort, /* Information on the ORDER BY clause */-
1415 int nColumn, /* Number of columns of data */-
1416 SelectDest *pDest /* Write the sorted results here */-
1417){-
1418 Vdbe *v = pParse->pVdbe; /* The prepared statement */-
1419 int addrBreak = pSort->labelDone; /* Jump here to exit loop */-
1420 int addrContinue = sqlite3VdbeMakeLabel(v); /* Jump here for next cycle */-
1421 int addr; /* Top of output loop. Jump for Next. */-
1422 int addrOnce = 0;-
1423 int iTab;-
1424 ExprList *pOrderBy = pSort->pOrderBy;-
1425 int eDest = pDest->eDest;-
1426 int iParm = pDest->iSDParm;-
1427 int regRow;-
1428 int regRowid;-
1429 int iCol;-
1430 int nKey; /* Number of key columns in sorter record */-
1431 int iSortTab; /* Sorter cursor to read from */-
1432 int i;-
1433 int bSeq; /* True if sorter record includes seq. no. */-
1434 int nRefKey = 0;-
1435 struct ExprList_item *aOutEx = p->pEList->a;-
1436-
1437 assert( addrBreak<0 );-
1438 if( pSort->labelBkOut ){
pSort->labelBkOutDescription
TRUEevaluated 319 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12807 times by 1 test
Evaluated by:
  • Self test (438)
319-12807
1439 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);-
1440 sqlite3VdbeGoto(v, addrBreak);-
1441 sqlite3VdbeResolveLabel(v, pSort->labelBkOut);-
1442 }
executed 319 times by 1 test: end of block
Executed by:
  • Self test (438)
319
1443-
1444#ifdef SQLITE_ENABLE_SORTER_REFERENCES-
1445 /* Open any cursors needed for sorter-reference expressions */-
1446 for(i=0; i<pSort->nDefer; i++){-
1447 Table *pTab = pSort->aDefer[i].pTab;-
1448 int iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);-
1449 sqlite3OpenTable(pParse, pSort->aDefer[i].iCsr, iDb, pTab, OP_OpenRead);-
1450 nRefKey = MAX(nRefKey, pSort->aDefer[i].nKey);-
1451 }-
1452#endif-
1453-
1454 iTab = pSort->iECursor;-
1455 if( eDest==SRT_Output || eDest==SRT_Coroutine || eDest==SRT_Mem ){
eDest==9Description
TRUEevaluated 10556 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2570 times by 1 test
Evaluated by:
  • Self test (438)
eDest==13Description
TRUEevaluated 2404 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 166 times by 1 test
Evaluated by:
  • Self test (438)
eDest==10Description
TRUEevaluated 112 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 54 times by 1 test
Evaluated by:
  • Self test (438)
54-10556
1456 regRowid = 0;-
1457 regRow = pDest->iSdst;-
1458 }else{
executed 13072 times by 1 test: end of block
Executed by:
  • Self test (438)
13072
1459 regRowid = sqlite3GetTempReg(pParse);-
1460 regRow = sqlite3GetTempRange(pParse, nColumn);-
1461 }
executed 54 times by 1 test: end of block
Executed by:
  • Self test (438)
54
1462 nKey = pOrderBy->nExpr - pSort->nOBSat;-
1463 if( pSort->sortFlags & SORTFLAG_UseSorter ){
pSort->sortFlags & 0x01Description
TRUEevaluated 12332 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 794 times by 1 test
Evaluated by:
  • Self test (438)
794-12332
1464 int regSortOut = ++pParse->nMem;-
1465 iSortTab = pParse->nTab++;-
1466 if( pSort->labelBkOut ){
pSort->labelBkOutDescription
TRUEevaluated 241 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12091 times by 1 test
Evaluated by:
  • Self test (438)
241-12091
1467 addrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v);-
1468 }
executed 241 times by 1 test: end of block
Executed by:
  • Self test (438)
241
1469 sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut, -
1470 nKey+1+nColumn+nRefKey);-
1471 if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
executed 241 times by 1 test: sqlite3VdbeJumpHere(v, addrOnce);
Executed by:
  • Self test (438)
addrOnceDescription
TRUEevaluated 241 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12091 times by 1 test
Evaluated by:
  • Self test (438)
241-12091
1472 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);-
1473 VdbeCoverage(v);-
1474 codeOffset(v, p->iOffset, addrContinue);-
1475 sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);-
1476 bSeq = 0;-
1477 }else{
executed 12332 times by 1 test: end of block
Executed by:
  • Self test (438)
12332
1478 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);-
1479 codeOffset(v, p->iOffset, addrContinue);-
1480 iSortTab = iTab;-
1481 bSeq = 1;-
1482 }
executed 794 times by 1 test: end of block
Executed by:
  • Self test (438)
794
1483 for(i=0, iCol=nKey+bSeq-1; i<nColumn; i++){
i<nColumnDescription
TRUEevaluated 41155 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 13126 times by 1 test
Evaluated by:
  • Self test (438)
13126-41155
1484#ifdef SQLITE_ENABLE_SORTER_REFERENCES-
1485 if( aOutEx[i].bSorterRef ) continue;-
1486#endif-
1487 if( aOutEx[i].u.x.iOrderByCol==0 ) iCol++;
executed 33290 times by 1 test: iCol++;
Executed by:
  • Self test (438)
aOutEx[i].u.x.iOrderByCol==0Description
TRUEevaluated 33290 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 7865 times by 1 test
Evaluated by:
  • Self test (438)
7865-33290
1488 }
executed 41155 times by 1 test: end of block
Executed by:
  • Self test (438)
41155
1489#ifdef SQLITE_ENABLE_SORTER_REFERENCES-
1490 if( pSort->nDefer ){-
1491 int iKey = iCol+1;-
1492 int regKey = sqlite3GetTempRange(pParse, nRefKey);-
1493-
1494 for(i=0; i<pSort->nDefer; i++){-
1495 int iCsr = pSort->aDefer[i].iCsr;-
1496 Table *pTab = pSort->aDefer[i].pTab;-
1497 int nKey = pSort->aDefer[i].nKey;-
1498-
1499 sqlite3VdbeAddOp1(v, OP_NullRow, iCsr);-
1500 if( HasRowid(pTab) ){-
1501 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iKey++, regKey);-
1502 sqlite3VdbeAddOp3(v, OP_SeekRowid, iCsr, -
1503 sqlite3VdbeCurrentAddr(v)+1, regKey);-
1504 }else{-
1505 int k;-
1506 int iJmp;-
1507 assert( sqlite3PrimaryKeyIndex(pTab)->nKeyCol==nKey );-
1508 for(k=0; k<nKey; k++){-
1509 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iKey++, regKey+k);-
1510 }-
1511 iJmp = sqlite3VdbeCurrentAddr(v);-
1512 sqlite3VdbeAddOp4Int(v, OP_SeekGE, iCsr, iJmp+2, regKey, nKey);-
1513 sqlite3VdbeAddOp4Int(v, OP_IdxLE, iCsr, iJmp+3, regKey, nKey);-
1514 sqlite3VdbeAddOp1(v, OP_NullRow, iCsr);-
1515 }-
1516 }-
1517 sqlite3ReleaseTempRange(pParse, regKey, nRefKey);-
1518 }-
1519#endif-
1520 for(i=nColumn-1; i>=0; i--){
i>=0Description
TRUEevaluated 41155 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 13126 times by 1 test
Evaluated by:
  • Self test (438)
13126-41155
1521#ifdef SQLITE_ENABLE_SORTER_REFERENCES-
1522 if( aOutEx[i].bSorterRef ){-
1523 sqlite3ExprCode(pParse, aOutEx[i].pExpr, regRow+i);-
1524 }else-
1525#endif-
1526 {-
1527 int iRead;-
1528 if( aOutEx[i].u.x.iOrderByCol ){
aOutEx[i].u.x.iOrderByColDescription
TRUEevaluated 7865 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 33290 times by 1 test
Evaluated by:
  • Self test (438)
7865-33290
1529 iRead = aOutEx[i].u.x.iOrderByCol-1;-
1530 }else{
executed 7865 times by 1 test: end of block
Executed by:
  • Self test (438)
7865
1531 iRead = iCol--;-
1532 }
executed 33290 times by 1 test: end of block
Executed by:
  • Self test (438)
33290
1533 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i);-
1534 VdbeComment((v, "%s", aOutEx[i].zName?aOutEx[i].zName : aOutEx[i].zSpan));-
1535 }-
1536 }
executed 41155 times by 1 test: end of block
Executed by:
  • Self test (438)
41155
1537 switch( eDest ){-
1538 case SRT_Table:
executed 1 time by 1 test: case 14:
Executed by:
  • Self test (438)
1
1539 case SRT_EphemTab: {
executed 2 times by 1 test: case 12:
Executed by:
  • Self test (438)
2
1540 sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);-
1541 sqlite3VdbeAddOp3(v, OP_Insert, iParm, regRow, regRowid);-
1542 sqlite3VdbeChangeP5(v, OPFLAG_APPEND);-
1543 break;
executed 3 times by 1 test: break;
Executed by:
  • Self test (438)
3
1544 }-
1545#ifndef SQLITE_OMIT_SUBQUERY-
1546 case SRT_Set: {
executed 51 times by 1 test: case 11:
Executed by:
  • Self test (438)
51
1547 assert( nColumn==sqlite3Strlen30(pDest->zAffSdst) );-
1548 sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, nColumn, regRowid,-
1549 pDest->zAffSdst, nColumn);-
1550 sqlite3VdbeAddOp4Int(v, OP_IdxInsert, iParm, regRowid, regRow, nColumn);-
1551 break;
executed 51 times by 1 test: break;
Executed by:
  • Self test (438)
51
1552 }-
1553 case SRT_Mem: {
executed 112 times by 1 test: case 10:
Executed by:
  • Self test (438)
112
1554 /* The LIMIT clause will terminate the loop for us */-
1555 break;
executed 112 times by 1 test: break;
Executed by:
  • Self test (438)
112
1556 }-
1557#endif-
1558 default: {
executed 12960 times by 1 test: default:
Executed by:
  • Self test (438)
12960
1559 assert( eDest==SRT_Output || eDest==SRT_Coroutine ); -
1560 testcase( eDest==SRT_Output );-
1561 testcase( eDest==SRT_Coroutine );-
1562 if( eDest==SRT_Output ){
eDest==9Description
TRUEevaluated 10556 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 2404 times by 1 test
Evaluated by:
  • Self test (438)
2404-10556
1563 sqlite3VdbeAddOp2(v, OP_ResultRow, pDest->iSdst, nColumn);-
1564 }else{
executed 10556 times by 1 test: end of block
Executed by:
  • Self test (438)
10556
1565 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);-
1566 }
executed 2404 times by 1 test: end of block
Executed by:
  • Self test (438)
2404
1567 break;
executed 12960 times by 1 test: break;
Executed by:
  • Self test (438)
12960
1568 }-
1569 }-
1570 if( regRowid ){
regRowidDescription
TRUEevaluated 54 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 13072 times by 1 test
Evaluated by:
  • Self test (438)
54-13072
1571 if( eDest==SRT_Set ){
eDest==11Description
TRUEevaluated 51 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 3 times by 1 test
Evaluated by:
  • Self test (438)
3-51
1572 sqlite3ReleaseTempRange(pParse, regRow, nColumn);-
1573 }else{
executed 51 times by 1 test: end of block
Executed by:
  • Self test (438)
51
1574 sqlite3ReleaseTempReg(pParse, regRow);-
1575 }
executed 3 times by 1 test: end of block
Executed by:
  • Self test (438)
3
1576 sqlite3ReleaseTempReg(pParse, regRowid);-
1577 }
executed 54 times by 1 test: end of block
Executed by:
  • Self test (438)
54
1578 /* The bottom of the loop-
1579 */-
1580 sqlite3VdbeResolveLabel(v, addrContinue);-
1581 if( pSort->sortFlags & SORTFLAG_UseSorter ){
pSort->sortFlags & 0x01Description
TRUEevaluated 12332 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 794 times by 1 test
Evaluated by:
  • Self test (438)
794-12332
1582 sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr); VdbeCoverage(v);-
1583 }else{
executed 12332 times by 1 test: end of block
Executed by:
  • Self test (438)
12332
1584 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); VdbeCoverage(v);-
1585 }
executed 794 times by 1 test: end of block
Executed by:
  • Self test (438)
794
1586 if( pSort->regReturn ) sqlite3VdbeAddOp1(v, OP_Return, pSort->regReturn);
executed 319 times by 1 test: sqlite3VdbeAddOp1(v, 66, pSort->regReturn);
Executed by:
  • Self test (438)
pSort->regReturnDescription
TRUEevaluated 319 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 12807 times by 1 test
Evaluated by:
  • Self test (438)
319-12807
1587 sqlite3VdbeResolveLabel(v, addrBreak);-
1588}
executed 13126 times by 1 test: end of block
Executed by:
  • Self test (438)
13126
1589-
1590/*-
1591** Return a pointer to a string containing the 'declaration type' of the-
1592** expression pExpr. The string may be treated as static by the caller.-
1593**-
1594** Also try to estimate the size of the returned value and return that-
1595** result in *pEstWidth.-
1596**-
1597** The declaration type is the exact datatype definition extracted from the-
1598** original CREATE TABLE statement if the expression is a column. The-
1599** declaration type for a ROWID field is INTEGER. Exactly when an expression-
1600** is considered a column can be complex in the presence of subqueries. The-
1601** result-set expression in all of the following SELECT statements is -
1602** considered a column by this function.-
1603**-
1604** SELECT col FROM tbl;-
1605** SELECT (SELECT col FROM tbl;-
1606** SELECT (SELECT col FROM tbl);-
1607** SELECT abc FROM (SELECT col AS abc FROM tbl);-
1608** -
1609** The declaration type for any expression other than a column is NULL.-
1610**-
1611** This routine has either 3 or 6 parameters depending on whether or not-
1612** the SQLITE_ENABLE_COLUMN_METADATA compile-time option is used.-
1613*/-
1614#ifdef SQLITE_ENABLE_COLUMN_METADATA-
1615# define columnType(A,B,C,D,E) columnTypeImpl(A,B,C,D,E)-
1616#else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */-
1617# define columnType(A,B,C,D,E) columnTypeImpl(A,B)-
1618#endif-
1619static const char *columnTypeImpl(-
1620 NameContext *pNC, -
1621#ifndef SQLITE_ENABLE_COLUMN_METADATA-
1622 Expr *pExpr-
1623#else-
1624 Expr *pExpr,-
1625 const char **pzOrigDb,-
1626 const char **pzOrigTab,-
1627 const char **pzOrigCol-
1628#endif-
1629){-
1630 char const *zType = 0;-
1631 int j;-
1632#ifdef SQLITE_ENABLE_COLUMN_METADATA-
1633 char const *zOrigDb = 0;-
1634 char const *zOrigTab = 0;-
1635 char const *zOrigCol = 0;-
1636#endif-
1637-
1638 assert( pExpr!=0 );-
1639 assert( pNC->pSrcList!=0 );-
1640 assert( pExpr->op!=TK_AGG_COLUMN ); /* This routine runes before aggregates-
1641 ** are processed */-
1642 switch( pExpr->op ){-
1643 case TK_COLUMN: {
executed 230681 times by 435 tests: case 158:
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)
  • ...
230681
1644 /* The expression is a column. Locate the table the column is being-
1645 ** extracted from in NameContext.pSrcList. This table may be real-
1646 ** database table or a subquery.-
1647 */-
1648 Table *pTab = 0; /* Table structure column is extracted from */-
1649 Select *pS = 0; /* Select the column is extracted from */-
1650 int iCol = pExpr->iColumn; /* Index of column in pTab */-
1651 while( pNC && !pTab ){
pNCDescription
TRUEevaluated 461367 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 8 times by 1 test
Evaluated by:
  • Self test (438)
!pTabDescription
TRUEevaluated 230694 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 230673 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)
  • ...
8-461367
1652 SrcList *pTabList = pNC->pSrcList;-
1653 for(j=0;j<pTabList->nSrc && pTabList->a[j].iCursor!=pExpr->iTable;j++);
executed 96337 times by 1 test: ;
Executed by:
  • Self test (438)
j<pTabList->nSrcDescription
TRUEevaluated 327010 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 21 times by 1 test
Evaluated by:
  • Self test (438)
pTabList->a[j]...=pExpr->iTableDescription
TRUEevaluated 96337 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 230673 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)
  • ...
21-327010
1654 if( j<pTabList->nSrc ){
j<pTabList->nSrcDescription
TRUEevaluated 230673 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 21 times by 1 test
Evaluated by:
  • Self test (438)
21-230673
1655 pTab = pTabList->a[j].pTab;-
1656 pS = pTabList->a[j].pSelect;-
1657 }else{
executed 230673 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)
  • ...
230673
1658 pNC = pNC->pNext;-
1659 }
executed 21 times by 1 test: end of block
Executed by:
  • Self test (438)
21
1660 }-
1661-
1662 if( pTab==0 ){
pTab==0Description
TRUEevaluated 8 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 230673 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)
  • ...
8-230673
1663 /* At one time, code such as "SELECT new.x" within a trigger would-
1664 ** cause this condition to run. Since then, we have restructured how-
1665 ** trigger code is generated and so this condition is no longer -
1666 ** possible. However, it can still be true for statements like-
1667 ** the following:-
1668 **-
1669 ** CREATE TABLE t1(col INTEGER);-
1670 ** SELECT (SELECT t1.col) FROM FROM t1;-
1671 **-
1672 ** when columnType() is called on the expression "t1.col" in the -
1673 ** sub-select. In this case, set the column type to NULL, even-
1674 ** though it should really be "INTEGER".-
1675 **-
1676 ** This is not a problem, as the column type of "t1.col" is never-
1677 ** used. When columnType() is called on the expression -
1678 ** "(SELECT t1.col)", the correct type is returned (see the TK_SELECT-
1679 ** branch below. */-
1680 break;
executed 8 times by 1 test: break;
Executed by:
  • Self test (438)
8
1681 }-
1682-
1683 assert( pTab && pExpr->y.pTab==pTab );-
1684 if( pS ){
pSDescription
TRUEevaluated 4706 times by 2 tests
Evaluated by:
  • Self test (438)
  • Self test (47)
FALSEevaluated 225967 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)
  • ...
4706-225967
1685 /* The "table" is actually a sub-select or a view in the FROM clause-
1686 ** of the SELECT statement. Return the declaration type and origin-
1687 ** data for the result-set column of the sub-select.-
1688 */-
1689 if( iCol>=0 && iCol<pS->pEList->nExpr ){
iCol>=0Description
TRUEevaluated 4704 times by 2 tests
Evaluated by:
  • Self test (438)
  • Self test (47)
FALSEevaluated 2 times by 1 test
Evaluated by:
  • Self test (438)
iCol<pS->pEList->nExprDescription
TRUEevaluated 4703 times by 2 tests
Evaluated by:
  • Self test (438)
  • Self test (47)
FALSEevaluated 1 time by 1 test
Evaluated by:
  • Self test (438)
1-4704
1690 /* If iCol is less than zero, then the expression requests the-
1691 ** rowid of the sub-select or view. This expression is legal (see -
1692 ** test case misc2.2.2) - it always evaluates to NULL.-
1693 */-
1694 NameContext sNC;-
1695 Expr *p = pS->pEList->a[iCol].pExpr;-
1696 sNC.pSrcList = pS->pSrc;-
1697 sNC.pNext = pNC;-
1698 sNC.pParse = pNC->pParse;-
1699 zType = columnType(&sNC, p,&zOrigDb,&zOrigTab,&zOrigCol); -
1700 }
executed 4703 times by 2 tests: end of block
Executed by:
  • Self test (438)
  • Self test (47)
4703
1701 }else{
executed 4706 times by 2 tests: end of block
Executed by:
  • Self test (438)
  • Self test (47)
4706
1702 /* A real table or a CTE table */-
1703 assert( !pS );-
1704#ifdef SQLITE_ENABLE_COLUMN_METADATA-
1705 if( iCol<0 ) iCol = pTab->iPKey;-
1706 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );-
1707 if( iCol<0 ){-
1708 zType = "INTEGER";-
1709 zOrigCol = "rowid";-
1710 }else{-
1711 zOrigCol = pTab->aCol[iCol].zName;-
1712 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);-
1713 }-
1714 zOrigTab = pTab->zName;-
1715 if( pNC->pParse && pTab->pSchema ){-
1716 int iDb = sqlite3SchemaToIndex(pNC->pParse->db, pTab->pSchema);-
1717 zOrigDb = pNC->pParse->db->aDb[iDb].zDbSName;-
1718 }-
1719#else-
1720 assert( iCol==XN_ROWID || (iCol>=0 && iCol<pTab->nCol) );-
1721 if( iCol<0 ){
iCol<0Description
TRUEevaluated 34924 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 191043 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)
  • ...
34924-191043
1722 zType = "INTEGER";-
1723 }else{
executed 34924 times by 1 test: end of block
Executed by:
  • Self test (438)
34924
1724 zType = sqlite3ColumnType(&pTab->aCol[iCol],0);-
1725 }
executed 191043 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)
  • ...
191043
1726#endif-
1727 }-
1728 break;
executed 230673 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)
  • ...
230673
1729 }-
1730#ifndef SQLITE_OMIT_SUBQUERY-
1731 case TK_SELECT: {
executed 283 times by 1 test: case 127:
Executed by:
  • Self test (438)
283
1732 /* The expression is a sub-select. Return the declaration type and-
1733 ** origin info for the single column in the result set of the SELECT-
1734 ** statement.-
1735 */-
1736 NameContext sNC;-
1737 Select *pS = pExpr->x.pSelect;-
1738 Expr *p = pS->pEList->a[0].pExpr;-
1739 assert( ExprHasProperty(pExpr, EP_xIsSelect) );-
1740 sNC.pSrcList = pS->pSrc;-
1741 sNC.pNext = pNC;-
1742 sNC.pParse = pNC->pParse;-
1743 zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol); -
1744 break;
executed 283 times by 1 test: break;
Executed by:
  • Self test (438)
283
1745 }-
1746#endif-
1747 }-
1748-
1749#ifdef SQLITE_ENABLE_COLUMN_METADATA -
1750 if( pzOrigDb ){-
1751 assert( pzOrigTab && pzOrigCol );-
1752 *pzOrigDb = zOrigDb;-
1753 *pzOrigTab = zOrigTab;-
1754 *pzOrigCol = zOrigCol;-
1755 }-
1756#endif-
1757 return zType;
executed 352134 times by 435 tests: return zType;
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)
  • ...
352134
1758}-
1759-
1760/*-
1761** Generate code that will tell the VDBE the declaration types of columns-
1762** in the result set.-
1763*/-
1764static void generateColumnTypes(-
1765 Parse *pParse, /* Parser context */-
1766 SrcList *pTabList, /* List of tables */-
1767 ExprList *pEList /* Expressions defining the result set */-
1768){-
1769#ifndef SQLITE_OMIT_DECLTYPE-
1770 Vdbe *v = pParse->pVdbe;-
1771 int i;-
1772 NameContext sNC;-
1773 sNC.pSrcList = pTabList;-
1774 sNC.pParse = pParse;-
1775 sNC.pNext = 0;-
1776 for(i=0; i<pEList->nExpr; i++){
i<pEList->nExprDescription
TRUEevaluated 337405 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 177049 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)
  • ...
177049-337405
1777 Expr *p = pEList->a[i].pExpr;-
1778 const char *zType;-
1779#ifdef SQLITE_ENABLE_COLUMN_METADATA-
1780 const char *zOrigDb = 0;-
1781 const char *zOrigTab = 0;-
1782 const char *zOrigCol = 0;-
1783 zType = columnType(&sNC, p, &zOrigDb, &zOrigTab, &zOrigCol);-
1784-
1785 /* The vdbe must make its own copy of the column-type and other -
1786 ** column specific strings, in case the schema is reset before this-
1787 ** virtual machine is deleted.-
1788 */-
1789 sqlite3VdbeSetColName(v, i, COLNAME_DATABASE, zOrigDb, SQLITE_TRANSIENT);-
1790 sqlite3VdbeSetColName(v, i, COLNAME_TABLE, zOrigTab, SQLITE_TRANSIENT);-
1791 sqlite3VdbeSetColName(v, i, COLNAME_COLUMN, zOrigCol, SQLITE_TRANSIENT);-
1792#else-
1793 zType = columnType(&sNC, p, 0, 0, 0);-
1794#endif-
1795 sqlite3VdbeSetColName(v, i, COLNAME_DECLTYPE, zType, SQLITE_TRANSIENT);-
1796 }
executed 337405 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)
  • ...
337405
1797#endif /* !defined(SQLITE_OMIT_DECLTYPE) */-
1798}
executed 177049 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)
  • ...
177049
1799-
1800-
1801/*-
1802** Compute the column names for a SELECT statement.-
1803**-
1804** The only guarantee that SQLite makes about column names is that if the-
1805** column has an AS clause assigning it a name, that will be the name used.-
1806** That is the only documented guarantee. However, countless applications-
1807** developed over the years have made baseless assumptions about column names-
1808** and will break if those assumptions changes. Hence, use extreme caution-
1809** when modifying this routine to avoid breaking legacy.-
1810**-
1811** See Also: sqlite3ColumnsFromExprList()-
1812**-
1813** The PRAGMA short_column_names and PRAGMA full_column_names settings are-
1814** deprecated. The default setting is short=ON, full=OFF. 99.9% of all-
1815** applications should operate this way. Nevertheless, we need to support the-
1816** other modes for legacy:-
1817**-
1818** short=OFF, full=OFF: Column name is the text of the expression has it-
1819** originally appears in the SELECT statement. In-
1820** other words, the zSpan of the result expression.-
1821**-
1822** short=ON, full=OFF: (This is the default setting). If the result-
1823** refers directly to a table column, then the-
1824** result column name is just the table column-
1825** name: COLUMN. Otherwise use zSpan.-
1826**-
1827** full=ON, short=ANY: If the result refers directly to a table column,-
1828** then the result column name with the table name-
1829** prefix, ex: TABLE.COLUMN. Otherwise use zSpan.-
1830*/-
1831static void generateColumnNames(-
1832 Parse *pParse, /* Parser context */-
1833 Select *pSelect /* Generate column names for this SELECT statement */-
1834){-
1835 Vdbe *v = pParse->pVdbe;-
1836 int i;-
1837 Table *pTab;-
1838 SrcList *pTabList;-
1839 ExprList *pEList;-
1840 sqlite3 *db = pParse->db;-
1841 int fullName; /* TABLE.COLUMN if no AS clause and is a direct table ref */-
1842 int srcName; /* COLUMN or TABLE.COLUMN if no AS clause and is direct */-
1843-
1844#ifndef SQLITE_OMIT_EXPLAIN-
1845 /* If this is an EXPLAIN, skip this step */-
1846 if( pParse->explain ){
pParse->explainDescription
TRUEevaluated 909 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 179402 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)
  • ...
909-179402
1847 return;
executed 909 times by 1 test: return;
Executed by:
  • Self test (438)
909
1848 }-
1849#endif-
1850-
1851 if( pParse->colNamesSet ) return;
executed 2353 times by 1 test: return;
Executed by:
  • Self test (438)
pParse->colNamesSetDescription
TRUEevaluated 2353 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 177049 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)
  • ...
2353-177049
1852 /* Column names are determined by the left-most term of a compound select */-
1853 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
executed 1644 times by 1 test: pSelect = pSelect->pPrior;
Executed by:
  • Self test (438)
pSelect->pPriorDescription
TRUEevaluated 1644 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 177049 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)
  • ...
1644-177049
1854 SELECTTRACE(1,pParse,pSelect,("generating column names\n"));-
1855 pTabList = pSelect->pSrc;-
1856 pEList = pSelect->pEList;-
1857 assert( v!=0 );-
1858 assert( pTabList!=0 );-
1859 pParse->colNamesSet = 1;-
1860 fullName = (db->flags & SQLITE_FullColNames)!=0;-
1861 srcName = (db->flags & SQLITE_ShortColNames)!=0 || fullName;
(db->flags & 0x00000040)!=0Description
TRUEevaluated 177010 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 39 times by 1 test
Evaluated by:
  • Self test (438)
fullNameDescription
TRUEevaluated 25 times by 1 test
Evaluated by:
  • Self test (438)
FALSEevaluated 14 times by 1 test
Evaluated by:
  • Self test (438)
14-177010
1862 sqlite3VdbeSetNumCols(v, pEList->nExpr);-
1863 for(i=0; i<pEList->nExpr; i++){
i<pEList->nExprDescription
TRUEevaluated 337405 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 177049 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)
  • ...
177049-337405
1864 Expr *p = pEList->a[i].pExpr;-
1865-
1866 assert( p!=0 );-
1867 assert( p->op!=TK_AGG_COLUMN ); /* Agg processing has not run yet */-
1868 assert( p->op!=TK_COLUMN || p->y.pTab!=0 ); /* Covering idx not yet coded */-
1869 if( pEList->a[i].zName ){
pEList->a[i].zNameDescription
TRUEevaluated 55015 times by 54 tests
Evaluated by:
  • Self test (10)
  • Self test (101)
  • Self test (104)
  • Self test (105)
  • Self test (11)
  • Self test (12)
  • Self test (13)
  • Self test (14)
  • Self test (15)
  • Self test (16)
  • Self test (17)
  • Self test (18)
  • Self test (19)
  • Self test (2)
  • Self test (20)
  • Self test (21)
  • Self test (22)
  • Self test (23)
  • Self test (27)
  • Self test (3)
  • Self test (30)
  • Self test (35)
  • Self test (36)
  • Self test (37)
  • Self test (4)
  • ...
FALSEevaluated 282390 times by 435 tests
Evaluated by:
  • Self test
  • Self test (10)
  • Self test (100)
  • Self test (101)
  • Self test (103)
  • Self test (104)