Absolute File Name: | /home/opencoverage/opencoverage/guest-scripts/sqlite/src/src/window.c |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | static void row_numberStepFunc( | - | ||||||||||||||||||
2 | sqlite3_context *pCtx, | - | ||||||||||||||||||
3 | int nArg, | - | ||||||||||||||||||
4 | sqlite3_value **apArg | - | ||||||||||||||||||
5 | ){ | - | ||||||||||||||||||
6 | i64 *p = (i64*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
7 | if( p
executed 13692 times by 1 test: p)++;(*p)++; Executed by:
executed 13692 times by 1 test: (*p)++; Executed by:
| 0-13692 | ||||||||||||||||||
8 | (void)(nArg); | - | ||||||||||||||||||
9 | (void)(apArg); | - | ||||||||||||||||||
10 | } executed 13692 times by 1 test: end of block Executed by:
| 13692 | ||||||||||||||||||
11 | static void row_numberValueFunc(sqlite3_context *pCtx){ | - | ||||||||||||||||||
12 | i64 *p = (i64*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
13 | sqlite3_result_int64(pCtx, (p ? *p : 0)); | - | ||||||||||||||||||
14 | } executed 13767 times by 1 test: end of block Executed by:
| 13767 | ||||||||||||||||||
15 | - | |||||||||||||||||||
16 | - | |||||||||||||||||||
17 | - | |||||||||||||||||||
18 | - | |||||||||||||||||||
19 | - | |||||||||||||||||||
20 | struct CallCount { | - | ||||||||||||||||||
21 | i64 nValue; | - | ||||||||||||||||||
22 | i64 nStep; | - | ||||||||||||||||||
23 | i64 nTotal; | - | ||||||||||||||||||
24 | }; | - | ||||||||||||||||||
25 | - | |||||||||||||||||||
26 | - | |||||||||||||||||||
27 | - | |||||||||||||||||||
28 | - | |||||||||||||||||||
29 | - | |||||||||||||||||||
30 | - | |||||||||||||||||||
31 | - | |||||||||||||||||||
32 | static void dense_rankStepFunc( | - | ||||||||||||||||||
33 | sqlite3_context *pCtx, | - | ||||||||||||||||||
34 | int nArg, | - | ||||||||||||||||||
35 | sqlite3_value **apArg | - | ||||||||||||||||||
36 | ){ | - | ||||||||||||||||||
37 | struct CallCount *p; | - | ||||||||||||||||||
38 | p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
39 | if( p
executed 23929 times by 1 test: p->nStep = 1; Executed by:
| 0-23929 | ||||||||||||||||||
40 | (void)(nArg); | - | ||||||||||||||||||
41 | (void)(apArg); | - | ||||||||||||||||||
42 | } executed 23929 times by 1 test: end of block Executed by:
| 23929 | ||||||||||||||||||
43 | static void dense_rankValueFunc(sqlite3_context *pCtx){ | - | ||||||||||||||||||
44 | struct CallCount *p; | - | ||||||||||||||||||
45 | p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
46 | if( p
| 0-10703 | ||||||||||||||||||
47 | if( p->nStep
| 122-10581 | ||||||||||||||||||
48 | p->nValue++; | - | ||||||||||||||||||
49 | p->nStep = 0; | - | ||||||||||||||||||
50 | } executed 10581 times by 1 test: end of block Executed by:
| 10581 | ||||||||||||||||||
51 | sqlite3_result_int64(pCtx, p->nValue); | - | ||||||||||||||||||
52 | } executed 10703 times by 1 test: end of block Executed by:
| 10703 | ||||||||||||||||||
53 | } executed 10703 times by 1 test: end of block Executed by:
| 10703 | ||||||||||||||||||
54 | - | |||||||||||||||||||
55 | - | |||||||||||||||||||
56 | - | |||||||||||||||||||
57 | - | |||||||||||||||||||
58 | - | |||||||||||||||||||
59 | - | |||||||||||||||||||
60 | - | |||||||||||||||||||
61 | static void rankStepFunc( | - | ||||||||||||||||||
62 | sqlite3_context *pCtx, | - | ||||||||||||||||||
63 | int nArg, | - | ||||||||||||||||||
64 | sqlite3_value **apArg | - | ||||||||||||||||||
65 | ){ | - | ||||||||||||||||||
66 | struct CallCount *p; | - | ||||||||||||||||||
67 | p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
68 | if( p
| 0-23967 | ||||||||||||||||||
69 | p->nStep++; | - | ||||||||||||||||||
70 | if( p->nValue==0
| 10604-13363 | ||||||||||||||||||
71 | p->nValue = p->nStep; | - | ||||||||||||||||||
72 | } executed 10604 times by 1 test: end of block Executed by:
| 10604 | ||||||||||||||||||
73 | } executed 23967 times by 1 test: end of block Executed by:
| 23967 | ||||||||||||||||||
74 | (void)(nArg); | - | ||||||||||||||||||
75 | (void)(apArg); | - | ||||||||||||||||||
76 | } executed 23967 times by 1 test: end of block Executed by:
| 23967 | ||||||||||||||||||
77 | static void rankValueFunc(sqlite3_context *pCtx){ | - | ||||||||||||||||||
78 | struct CallCount *p; | - | ||||||||||||||||||
79 | p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
80 | if( p
| 0-10731 | ||||||||||||||||||
81 | sqlite3_result_int64(pCtx, p->nValue); | - | ||||||||||||||||||
82 | p->nValue = 0; | - | ||||||||||||||||||
83 | } executed 10731 times by 1 test: end of block Executed by:
| 10731 | ||||||||||||||||||
84 | } executed 10731 times by 1 test: end of block Executed by:
| 10731 | ||||||||||||||||||
85 | - | |||||||||||||||||||
86 | - | |||||||||||||||||||
87 | - | |||||||||||||||||||
88 | - | |||||||||||||||||||
89 | - | |||||||||||||||||||
90 | - | |||||||||||||||||||
91 | - | |||||||||||||||||||
92 | static void percent_rankStepFunc( | - | ||||||||||||||||||
93 | sqlite3_context *pCtx, | - | ||||||||||||||||||
94 | int nArg, | - | ||||||||||||||||||
95 | sqlite3_value **apArg | - | ||||||||||||||||||
96 | ){ | - | ||||||||||||||||||
97 | struct CallCount *p; | - | ||||||||||||||||||
98 | (void)(nArg); | - | ||||||||||||||||||
99 | ((void) (0)) | - | ||||||||||||||||||
100 | ; | - | ||||||||||||||||||
101 | - | |||||||||||||||||||
102 | p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
103 | if( p
| 0-20512 | ||||||||||||||||||
104 | if( p->nTotal==0
| 430-20082 | ||||||||||||||||||
105 | p->nTotal = sqlite3_value_int64(apArg[0]); | - | ||||||||||||||||||
106 | } executed 430 times by 1 test: end of block Executed by:
| 430 | ||||||||||||||||||
107 | p->nStep++; | - | ||||||||||||||||||
108 | if( p->nValue==0
| 10103-10409 | ||||||||||||||||||
109 | p->nValue = p->nStep; | - | ||||||||||||||||||
110 | } executed 10409 times by 1 test: end of block Executed by:
| 10409 | ||||||||||||||||||
111 | } executed 20512 times by 1 test: end of block Executed by:
| 20512 | ||||||||||||||||||
112 | } executed 20512 times by 1 test: end of block Executed by:
| 20512 | ||||||||||||||||||
113 | static void percent_rankValueFunc(sqlite3_context *pCtx){ | - | ||||||||||||||||||
114 | struct CallCount *p; | - | ||||||||||||||||||
115 | p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
116 | if( p
| 0-11268 | ||||||||||||||||||
117 | if( p->nTotal>1
| 433-10835 | ||||||||||||||||||
118 | double r = (double)(p->nValue-1) / (double)(p->nTotal-1); | - | ||||||||||||||||||
119 | sqlite3_result_double(pCtx, r); | - | ||||||||||||||||||
120 | } executed 10835 times by 1 test: else{end of block Executed by:
| 10835 | ||||||||||||||||||
121 | sqlite3_result_double(pCtx, 0.0); | - | ||||||||||||||||||
122 | } executed 433 times by 1 test: end of block Executed by:
| 433 | ||||||||||||||||||
123 | p->nValue = 0; | - | ||||||||||||||||||
124 | } executed 11268 times by 1 test: end of block Executed by:
| 11268 | ||||||||||||||||||
125 | } executed 11268 times by 1 test: end of block Executed by:
| 11268 | ||||||||||||||||||
126 | - | |||||||||||||||||||
127 | - | |||||||||||||||||||
128 | - | |||||||||||||||||||
129 | - | |||||||||||||||||||
130 | - | |||||||||||||||||||
131 | - | |||||||||||||||||||
132 | - | |||||||||||||||||||
133 | static void cume_distStepFunc( | - | ||||||||||||||||||
134 | sqlite3_context *pCtx, | - | ||||||||||||||||||
135 | int nArg, | - | ||||||||||||||||||
136 | sqlite3_value **apArg | - | ||||||||||||||||||
137 | ){ | - | ||||||||||||||||||
138 | struct CallCount *p; | - | ||||||||||||||||||
139 | - | |||||||||||||||||||
140 | ((void) (0)) | - | ||||||||||||||||||
141 | ; (void)(nArg); | - | ||||||||||||||||||
142 | - | |||||||||||||||||||
143 | p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
144 | if( p
| 0-20505 | ||||||||||||||||||
145 | if( p->nTotal==0
| 426-20079 | ||||||||||||||||||
146 | p->nTotal = sqlite3_value_int64(apArg[0]); | - | ||||||||||||||||||
147 | } executed 426 times by 1 test: end of block Executed by:
| 426 | ||||||||||||||||||
148 | p->nStep++; | - | ||||||||||||||||||
149 | } executed 20505 times by 1 test: end of block Executed by:
| 20505 | ||||||||||||||||||
150 | } executed 20505 times by 1 test: end of block Executed by:
| 20505 | ||||||||||||||||||
151 | static void cume_distValueFunc(sqlite3_context *pCtx){ | - | ||||||||||||||||||
152 | struct CallCount *p; | - | ||||||||||||||||||
153 | p = (struct CallCount*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
154 | if( p
| 0-11256 | ||||||||||||||||||
155 | double r = (double)(p->nStep) / (double)(p->nTotal); | - | ||||||||||||||||||
156 | sqlite3_result_double(pCtx, r); | - | ||||||||||||||||||
157 | } executed 10831 times by 1 test: end of block Executed by:
| 10831 | ||||||||||||||||||
158 | } executed 11256 times by 1 test: end of block Executed by:
| 11256 | ||||||||||||||||||
159 | - | |||||||||||||||||||
160 | - | |||||||||||||||||||
161 | - | |||||||||||||||||||
162 | - | |||||||||||||||||||
163 | struct NtileCtx { | - | ||||||||||||||||||
164 | i64 nTotal; | - | ||||||||||||||||||
165 | i64 nParam; | - | ||||||||||||||||||
166 | i64 iRow; | - | ||||||||||||||||||
167 | }; | - | ||||||||||||||||||
168 | - | |||||||||||||||||||
169 | - | |||||||||||||||||||
170 | - | |||||||||||||||||||
171 | - | |||||||||||||||||||
172 | - | |||||||||||||||||||
173 | - | |||||||||||||||||||
174 | - | |||||||||||||||||||
175 | static void ntileStepFunc( | - | ||||||||||||||||||
176 | sqlite3_context *pCtx, | - | ||||||||||||||||||
177 | int nArg, | - | ||||||||||||||||||
178 | sqlite3_value **apArg | - | ||||||||||||||||||
179 | ){ | - | ||||||||||||||||||
180 | struct NtileCtx *p; | - | ||||||||||||||||||
181 | - | |||||||||||||||||||
182 | ((void) (0)) | - | ||||||||||||||||||
183 | ; (void)(nArg); | - | ||||||||||||||||||
184 | p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
185 | if( p
| 0-24115 | ||||||||||||||||||
186 | if( p->nTotal==0
| 3848-20267 | ||||||||||||||||||
187 | p->nParam = sqlite3_value_int64(apArg[0]); | - | ||||||||||||||||||
188 | p->nTotal = sqlite3_value_int64(apArg[1]); | - | ||||||||||||||||||
189 | if( p->nParam<=0
| 3-3845 | ||||||||||||||||||
190 | sqlite3_result_error( | - | ||||||||||||||||||
191 | pCtx, "argument of ntile must be a positive integer", -1 | - | ||||||||||||||||||
192 | ); | - | ||||||||||||||||||
193 | } executed 3 times by 1 test: end of block Executed by:
| 3 | ||||||||||||||||||
194 | } executed 3848 times by 1 test: end of block Executed by:
| 3848 | ||||||||||||||||||
195 | p->iRow++; | - | ||||||||||||||||||
196 | } executed 24115 times by 1 test: end of block Executed by:
| 24115 | ||||||||||||||||||
197 | } executed 24115 times by 1 test: end of block Executed by:
| 24115 | ||||||||||||||||||
198 | static void ntileValueFunc(sqlite3_context *pCtx){ | - | ||||||||||||||||||
199 | struct NtileCtx *p; | - | ||||||||||||||||||
200 | p = (struct NtileCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
201 | if( p
| 0-31791 | ||||||||||||||||||
202 | int nSize = (p->nTotal / p->nParam); | - | ||||||||||||||||||
203 | if( nSize==0
| 13850-14107 | ||||||||||||||||||
204 | sqlite3_result_int64(pCtx, p->iRow); | - | ||||||||||||||||||
205 | } executed 14107 times by 1 test: else{end of block Executed by:
| 14107 | ||||||||||||||||||
206 | i64 nLarge = p->nTotal - p->nParam*nSize; | - | ||||||||||||||||||
207 | i64 iSmall = nLarge*(nSize+1); | - | ||||||||||||||||||
208 | i64 iRow = p->iRow-1; | - | ||||||||||||||||||
209 | - | |||||||||||||||||||
210 | - | |||||||||||||||||||
211 | ((void) (0)) | - | ||||||||||||||||||
212 | ; | - | ||||||||||||||||||
213 | - | |||||||||||||||||||
214 | if( iRow<iSmall
| 3839-10011 | ||||||||||||||||||
215 | sqlite3_result_int64(pCtx, 1 + iRow/(nSize+1)); | - | ||||||||||||||||||
216 | } executed 10011 times by 1 test: else{end of block Executed by:
| 10011 | ||||||||||||||||||
217 | sqlite3_result_int64(pCtx, 1 + nLarge + (iRow-iSmall)/nSize); | - | ||||||||||||||||||
218 | } executed 3839 times by 1 test: end of block Executed by:
| 3839 | ||||||||||||||||||
219 | } | - | ||||||||||||||||||
220 | } | - | ||||||||||||||||||
221 | } executed 31791 times by 1 test: end of block Executed by:
| 31791 | ||||||||||||||||||
222 | - | |||||||||||||||||||
223 | - | |||||||||||||||||||
224 | - | |||||||||||||||||||
225 | - | |||||||||||||||||||
226 | struct LastValueCtx { | - | ||||||||||||||||||
227 | sqlite3_value *pVal; | - | ||||||||||||||||||
228 | int nVal; | - | ||||||||||||||||||
229 | }; | - | ||||||||||||||||||
230 | - | |||||||||||||||||||
231 | - | |||||||||||||||||||
232 | - | |||||||||||||||||||
233 | - | |||||||||||||||||||
234 | static void last_valueStepFunc( | - | ||||||||||||||||||
235 | sqlite3_context *pCtx, | - | ||||||||||||||||||
236 | int nArg, | - | ||||||||||||||||||
237 | sqlite3_value **apArg | - | ||||||||||||||||||
238 | ){ | - | ||||||||||||||||||
239 | struct LastValueCtx *p; | - | ||||||||||||||||||
240 | (void)(nArg); | - | ||||||||||||||||||
241 | p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
242 | if( p
| 0-19965 | ||||||||||||||||||
243 | sqlite3_value_free(p->pVal); | - | ||||||||||||||||||
244 | p->pVal = sqlite3_value_dup(apArg[0]); | - | ||||||||||||||||||
245 | if( p->pVal==0
| 0-19965 | ||||||||||||||||||
246 | sqlite3_result_error_nomem(pCtx); | - | ||||||||||||||||||
247 | } never executed: else{end of block | 0 | ||||||||||||||||||
248 | p->nVal++; | - | ||||||||||||||||||
249 | } executed 19965 times by 1 test: end of block Executed by:
| 19965 | ||||||||||||||||||
250 | } | - | ||||||||||||||||||
251 | } executed 19965 times by 1 test: end of block Executed by:
| 19965 | ||||||||||||||||||
252 | static void last_valueInvFunc( | - | ||||||||||||||||||
253 | sqlite3_context *pCtx, | - | ||||||||||||||||||
254 | int nArg, | - | ||||||||||||||||||
255 | sqlite3_value **apArg | - | ||||||||||||||||||
256 | ){ | - | ||||||||||||||||||
257 | struct LastValueCtx *p; | - | ||||||||||||||||||
258 | (void)(nArg); | - | ||||||||||||||||||
259 | (void)(apArg); | - | ||||||||||||||||||
260 | p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
261 | if( (
| 0-9900 | ||||||||||||||||||
262 | p->nVal--; | - | ||||||||||||||||||
263 | if( p->nVal==0
| 1430-8470 | ||||||||||||||||||
264 | sqlite3_value_free(p->pVal); | - | ||||||||||||||||||
265 | p->pVal = 0; | - | ||||||||||||||||||
266 | } executed 1430 times by 1 test: end of block Executed by:
| 1430 | ||||||||||||||||||
267 | } executed 9900 times by 1 test: end of block Executed by:
| 9900 | ||||||||||||||||||
268 | } executed 9900 times by 1 test: end of block Executed by:
| 9900 | ||||||||||||||||||
269 | static void last_valueValueFunc(sqlite3_context *pCtx){ | - | ||||||||||||||||||
270 | struct LastValueCtx *p; | - | ||||||||||||||||||
271 | p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
272 | if( p
| 0-17829 | ||||||||||||||||||
273 | sqlite3_result_value(pCtx, p->pVal); | - | ||||||||||||||||||
274 | } executed 16742 times by 1 test: end of block Executed by:
| 16742 | ||||||||||||||||||
275 | } executed 17829 times by 1 test: end of block Executed by:
| 17829 | ||||||||||||||||||
276 | static void last_valueFinalizeFunc(sqlite3_context *pCtx){ | - | ||||||||||||||||||
277 | struct LastValueCtx *p; | - | ||||||||||||||||||
278 | p = (struct LastValueCtx*)sqlite3_aggregate_context(pCtx, sizeof(*p)); | - | ||||||||||||||||||
279 | if( p
| 0-4806 | ||||||||||||||||||
280 | sqlite3_result_value(pCtx, p->pVal); | - | ||||||||||||||||||
281 | sqlite3_value_free(p->pVal); | - | ||||||||||||||||||
282 | p->pVal = 0; | - | ||||||||||||||||||
283 | } executed 3941 times by 1 test: end of block Executed by:
| 3941 | ||||||||||||||||||
284 | } executed 4806 times by 1 test: end of block Executed by:
| 4806 | ||||||||||||||||||
285 | static const char row_numberName[] = "row_number"; | - | ||||||||||||||||||
286 | static const char dense_rankName[] = "dense_rank"; | - | ||||||||||||||||||
287 | static const char rankName[] = "rank"; | - | ||||||||||||||||||
288 | static const char percent_rankName[] = "percent_rank"; | - | ||||||||||||||||||
289 | static const char cume_distName[] = "cume_dist"; | - | ||||||||||||||||||
290 | static const char ntileName[] = "ntile"; | - | ||||||||||||||||||
291 | static const char last_valueName[] = "last_value"; | - | ||||||||||||||||||
292 | static const char nth_valueName[] = "nth_value"; | - | ||||||||||||||||||
293 | static const char first_valueName[] = "first_value"; | - | ||||||||||||||||||
294 | static const char leadName[] = "lead"; | - | ||||||||||||||||||
295 | static const char lagName[] = "lag"; | - | ||||||||||||||||||
296 | static void noopStepFunc( | - | ||||||||||||||||||
297 | sqlite3_context *p, | - | ||||||||||||||||||
298 | int n, | - | ||||||||||||||||||
299 | sqlite3_value **a | - | ||||||||||||||||||
300 | ){ | - | ||||||||||||||||||
301 | (void)(p); | - | ||||||||||||||||||
302 | (void)(n); | - | ||||||||||||||||||
303 | (void)(a); | - | ||||||||||||||||||
304 | - | |||||||||||||||||||
305 | ((void) (0)) | - | ||||||||||||||||||
306 | ; | - | ||||||||||||||||||
307 | } never executed: end of block | 0 | ||||||||||||||||||
308 | static void noopValueFunc(sqlite3_context *p){ (void)(p); } executed 40724 times by 1 test: end of block Executed by:
| 40724 | ||||||||||||||||||
309 | void sqlite3WindowFunctions(void){ | - | ||||||||||||||||||
310 | static FuncDef aWindowFuncs[] = { | - | ||||||||||||||||||
311 | { 0, (1|0x10000|0), 0, 0, row_numberStepFunc, row_numberValueFunc, row_numberValueFunc, noopStepFunc, row_numberName, {0} }, | - | ||||||||||||||||||
312 | { 0, (1|0x10000|0), 0, 0, dense_rankStepFunc, dense_rankValueFunc, dense_rankValueFunc, noopStepFunc, dense_rankName, {0} }, | - | ||||||||||||||||||
313 | { 0, (1|0x10000|0), 0, 0, rankStepFunc, rankValueFunc, rankValueFunc, noopStepFunc, rankName, {0} }, | - | ||||||||||||||||||
314 | { 0, (1|0x10000|0x20000), 0, 0, percent_rankStepFunc, percent_rankValueFunc, percent_rankValueFunc, noopStepFunc, percent_rankName, {0} }, | - | ||||||||||||||||||
315 | { 0, (1|0x10000|0x20000), 0, 0, cume_distStepFunc, cume_distValueFunc, cume_distValueFunc, noopStepFunc, cume_distName, {0} }, | - | ||||||||||||||||||
316 | { 1, (1|0x10000|0x20000), 0, 0, ntileStepFunc, ntileValueFunc, ntileValueFunc, noopStepFunc, ntileName, {0} }, | - | ||||||||||||||||||
317 | { 1, (1|0x10000|0), 0, 0, last_valueStepFunc, last_valueFinalizeFunc, last_valueValueFunc, last_valueInvFunc, last_valueName, {0} }, | - | ||||||||||||||||||
318 | { 2, (1|0x10000|0), 0, 0, noopStepFunc, noopValueFunc, noopValueFunc, noopStepFunc, nth_valueName, {0} }, | - | ||||||||||||||||||
319 | { 1, (1|0x10000|0), 0, 0, noopStepFunc, noopValueFunc, noopValueFunc, noopStepFunc, first_valueName, {0} }, | - | ||||||||||||||||||
320 | { 1, (1|0x10000|0), 0, 0, noopStepFunc, noopValueFunc, noopValueFunc, noopStepFunc, leadName, {0} }, | - | ||||||||||||||||||
321 | { 2, (1|0x10000|0), 0, 0, noopStepFunc, noopValueFunc, noopValueFunc, noopStepFunc, leadName, {0} }, | - | ||||||||||||||||||
322 | { 3, (1|0x10000|0), 0, 0, noopStepFunc, noopValueFunc, noopValueFunc, noopStepFunc, leadName, {0} }, | - | ||||||||||||||||||
323 | { 1, (1|0x10000|0), 0, 0, noopStepFunc, noopValueFunc, noopValueFunc, noopStepFunc, lagName, {0} }, | - | ||||||||||||||||||
324 | { 2, (1|0x10000|0), 0, 0, noopStepFunc, noopValueFunc, noopValueFunc, noopStepFunc, lagName, {0} }, | - | ||||||||||||||||||
325 | { 3, (1|0x10000|0), 0, 0, noopStepFunc, noopValueFunc, noopValueFunc, noopStepFunc, lagName, {0} }, | - | ||||||||||||||||||
326 | }; | - | ||||||||||||||||||
327 | sqlite3InsertBuiltinFuncs(aWindowFuncs, ((int)(sizeof(aWindowFuncs)/sizeof(aWindowFuncs[0])))); | - | ||||||||||||||||||
328 | } executed 534 times by 438 tests: end of block Executed by:
| 534 | ||||||||||||||||||
329 | void sqlite3WindowUpdate( | - | ||||||||||||||||||
330 | Parse *pParse, | - | ||||||||||||||||||
331 | Window *pList, | - | ||||||||||||||||||
332 | Window *pWin, | - | ||||||||||||||||||
333 | FuncDef *pFunc | - | ||||||||||||||||||
334 | ){ | - | ||||||||||||||||||
335 | if( pWin->zName
| 13-1909 | ||||||||||||||||||
336 | Window *p; | - | ||||||||||||||||||
337 | for(p=pList; p
| 1-210 | ||||||||||||||||||
338 | if( sqlite3StrICmp(p->zName, pWin->zName)==0
executed 208 times by 1 test: break; Executed by:
| 2-208 | ||||||||||||||||||
339 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
340 | if( p==0
| 1-208 | ||||||||||||||||||
341 | sqlite3ErrorMsg(pParse, "no such window: %s", pWin->zName); | - | ||||||||||||||||||
342 | return; executed 1 time by 1 test: return; Executed by:
| 1 | ||||||||||||||||||
343 | } | - | ||||||||||||||||||
344 | pWin->pPartition = sqlite3ExprListDup(pParse->db, p->pPartition, 0); | - | ||||||||||||||||||
345 | pWin->pOrderBy = sqlite3ExprListDup(pParse->db, p->pOrderBy, 0); | - | ||||||||||||||||||
346 | pWin->pStart = sqlite3ExprDup(pParse->db, p->pStart, 0); | - | ||||||||||||||||||
347 | pWin->pEnd = sqlite3ExprDup(pParse->db, p->pEnd, 0); | - | ||||||||||||||||||
348 | pWin->eStart = p->eStart; | - | ||||||||||||||||||
349 | pWin->eEnd = p->eEnd; | - | ||||||||||||||||||
350 | pWin->eType = p->eType; | - | ||||||||||||||||||
351 | } executed 208 times by 1 test: end of block Executed by:
| 208 | ||||||||||||||||||
352 | if( pFunc->funcFlags & 0x10000
| 861-1269 | ||||||||||||||||||
353 | sqlite3 *db = pParse->db; | - | ||||||||||||||||||
354 | if( pWin->pFilter
| 1-1268 | ||||||||||||||||||
355 | sqlite3ErrorMsg(pParse, | - | ||||||||||||||||||
356 | "FILTER clause may only be used with aggregate window functions" | - | ||||||||||||||||||
357 | ); | - | ||||||||||||||||||
358 | } executed 1 time by 1 test: elseend of block Executed by:
| 1 | ||||||||||||||||||
359 | if( pFunc->zName==row_numberName
| 73-1195 | ||||||||||||||||||
360 | sqlite3ExprDelete(db, pWin->pStart); | - | ||||||||||||||||||
361 | sqlite3ExprDelete(db, pWin->pEnd); | - | ||||||||||||||||||
362 | pWin->pStart = pWin->pEnd = 0; | - | ||||||||||||||||||
363 | pWin->eType = 76; | - | ||||||||||||||||||
364 | pWin->eStart = 87; | - | ||||||||||||||||||
365 | pWin->eEnd = 82; | - | ||||||||||||||||||
366 | } executed 216 times by 1 test: elseend of block Executed by:
| 216 | ||||||||||||||||||
367 | - | |||||||||||||||||||
368 | if( pFunc->zName==dense_rankName
| 139-913 | ||||||||||||||||||
369 | || pFunc->zName==percent_rankName
| 103-663 | ||||||||||||||||||
370 | ){ | - | ||||||||||||||||||
371 | sqlite3ExprDelete(db, pWin->pStart); | - | ||||||||||||||||||
372 | sqlite3ExprDelete(db, pWin->pEnd); | - | ||||||||||||||||||
373 | pWin->pStart = pWin->pEnd = 0; | - | ||||||||||||||||||
374 | pWin->eType = 86; | - | ||||||||||||||||||
375 | pWin->eStart = 87; | - | ||||||||||||||||||
376 | pWin->eEnd = 82; | - | ||||||||||||||||||
377 | } executed 492 times by 1 test: end of block Executed by:
| 492 | ||||||||||||||||||
378 | } executed 1269 times by 1 test: end of block Executed by:
| 1269 | ||||||||||||||||||
379 | pWin->pFunc = pFunc; | - | ||||||||||||||||||
380 | } executed 2130 times by 1 test: end of block Executed by:
| 2130 | ||||||||||||||||||
381 | - | |||||||||||||||||||
382 | - | |||||||||||||||||||
383 | - | |||||||||||||||||||
384 | - | |||||||||||||||||||
385 | - | |||||||||||||||||||
386 | typedef struct WindowRewrite WindowRewrite; | - | ||||||||||||||||||
387 | struct WindowRewrite { | - | ||||||||||||||||||
388 | Window *pWin; | - | ||||||||||||||||||
389 | SrcList *pSrc; | - | ||||||||||||||||||
390 | ExprList *pSub; | - | ||||||||||||||||||
391 | Select *pSubSelect; | - | ||||||||||||||||||
392 | }; | - | ||||||||||||||||||
393 | - | |||||||||||||||||||
394 | - | |||||||||||||||||||
395 | - | |||||||||||||||||||
396 | - | |||||||||||||||||||
397 | - | |||||||||||||||||||
398 | - | |||||||||||||||||||
399 | static int selectWindowRewriteExprCb(Walker *pWalker, Expr *pExpr){ | - | ||||||||||||||||||
400 | struct WindowRewrite *p = pWalker->u.pRewrite; | - | ||||||||||||||||||
401 | Parse *pParse = pWalker->pParse; | - | ||||||||||||||||||
402 | - | |||||||||||||||||||
403 | - | |||||||||||||||||||
404 | - | |||||||||||||||||||
405 | - | |||||||||||||||||||
406 | - | |||||||||||||||||||
407 | - | |||||||||||||||||||
408 | if( p->pSubSelect
| 4-3137 | ||||||||||||||||||
409 | if( pExpr->op!=158
| 1-3 | ||||||||||||||||||
410 | return executed 1 time by 1 test: 0;return 0; Executed by:
executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||
411 | }else{ | - | ||||||||||||||||||
412 | int nSrc = p->pSrc->nSrc; | - | ||||||||||||||||||
413 | int i; | - | ||||||||||||||||||
414 | for(i=0; i<nSrc
| 2-3 | ||||||||||||||||||
415 | if( pExpr->iTable==p->pSrc->a[i].iCursor
executed 1 time by 1 test: break; Executed by:
| 1-2 | ||||||||||||||||||
416 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
417 | if( i==nSrc
executed 2 times by 1 test: 0;return 0; Executed by:
executed 2 times by 1 test: return 0; Executed by:
| 1-2 | ||||||||||||||||||
418 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
419 | } | - | ||||||||||||||||||
420 | - | |||||||||||||||||||
421 | switch( pExpr->op ){ | - | ||||||||||||||||||
422 | - | |||||||||||||||||||
423 | case executed 2127 times by 1 test: 157:case 157: Executed by:
executed 2127 times by 1 test: case 157: Executed by:
| 2127 | ||||||||||||||||||
424 | if( !(((pExpr)->flags&(0x1000000))!=0)
| 1-2126 | ||||||||||||||||||
425 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||||||||
426 | }else{ | - | ||||||||||||||||||
427 | Window *pWin; | - | ||||||||||||||||||
428 | for(pWin=p->pWin; pWin
| 170-2316 | ||||||||||||||||||
429 | if( pExpr->y.pWin==pWin
| 360-1956 | ||||||||||||||||||
430 | - | |||||||||||||||||||
431 | ((void) (0)) | - | ||||||||||||||||||
432 | ; | - | ||||||||||||||||||
433 | return executed 1956 times by 1 test: 1;return 1; Executed by:
executed 1956 times by 1 test: return 1; Executed by:
| 1956 | ||||||||||||||||||
434 | } | - | ||||||||||||||||||
435 | } executed 360 times by 1 test: end of block Executed by:
| 360 | ||||||||||||||||||
436 | } executed 170 times by 1 test: end of block Executed by:
| 170 | ||||||||||||||||||
437 | - | |||||||||||||||||||
438 | - | |||||||||||||||||||
439 | case executed 1 time by 1 test: 159:case 159: Executed by:
executed 1 time by 1 test: case 159: Executed by:
code before this statement executed 170 times by 1 test: case 159: Executed by:
| 1-170 | ||||||||||||||||||
440 | case executed 934 times by 1 test: 158:case 158: Executed by:
executed 934 times by 1 test: {case 158: Executed by:
| 934 | ||||||||||||||||||
441 | Expr *pDup = sqlite3ExprDup(pParse->db, pExpr, 0); | - | ||||||||||||||||||
442 | p->pSub = sqlite3ExprListAppend(pParse, p->pSub, pDup); | - | ||||||||||||||||||
443 | if( p->pSub
| 0-1105 | ||||||||||||||||||
444 | - | |||||||||||||||||||
445 | ((void) (0)) | - | ||||||||||||||||||
446 | ; | - | ||||||||||||||||||
447 | (pExpr)->flags|=(0x008000); | - | ||||||||||||||||||
448 | sqlite3ExprDelete(pParse->db, pExpr); | - | ||||||||||||||||||
449 | (pExpr)->flags&=~(0x008000); | - | ||||||||||||||||||
450 | memset(pExpr, 0, sizeof(Expr)); | - | ||||||||||||||||||
451 | - | |||||||||||||||||||
452 | pExpr->op = 158; | - | ||||||||||||||||||
453 | pExpr->iColumn = p->pSub->nExpr-1; | - | ||||||||||||||||||
454 | pExpr->iTable = p->pWin->iEphCsr; | - | ||||||||||||||||||
455 | } executed 1105 times by 1 test: end of block Executed by:
| 1105 | ||||||||||||||||||
456 | - | |||||||||||||||||||
457 | break; executed 1105 times by 1 test: break; Executed by:
| 1105 | ||||||||||||||||||
458 | } | - | ||||||||||||||||||
459 | - | |||||||||||||||||||
460 | default executed 76 times by 1 test: :default: Executed by:
executed 76 times by 1 test: default: Executed by:
| 76 | ||||||||||||||||||
461 | break; executed 76 times by 1 test: break; Executed by:
| 76 | ||||||||||||||||||
462 | } | - | ||||||||||||||||||
463 | - | |||||||||||||||||||
464 | return executed 1182 times by 1 test: 0;return 0; Executed by:
executed 1182 times by 1 test: return 0; Executed by:
| 1182 | ||||||||||||||||||
465 | } | - | ||||||||||||||||||
466 | static int selectWindowRewriteSelectCb(Walker *pWalker, Select *pSelect){ | - | ||||||||||||||||||
467 | struct WindowRewrite *p = pWalker->u.pRewrite; | - | ||||||||||||||||||
468 | Select *pSave = p->pSubSelect; | - | ||||||||||||||||||
469 | if( pSave==pSelect
| 1 | ||||||||||||||||||
470 | return executed 1 time by 1 test: 0;return 0; Executed by:
executed 1 time by 1 test: return 0; Executed by:
| 1 | ||||||||||||||||||
471 | }else{ | - | ||||||||||||||||||
472 | p->pSubSelect = pSelect; | - | ||||||||||||||||||
473 | sqlite3WalkSelect(pWalker, pSelect); | - | ||||||||||||||||||
474 | p->pSubSelect = pSave; | - | ||||||||||||||||||
475 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
476 | return executed 1 time by 1 test: 1;return 1; Executed by:
executed 1 time by 1 test: return 1; Executed by:
| 1 | ||||||||||||||||||
477 | } | - | ||||||||||||||||||
478 | static void selectWindowRewriteEList( | - | ||||||||||||||||||
479 | Parse *pParse, | - | ||||||||||||||||||
480 | Window *pWin, | - | ||||||||||||||||||
481 | SrcList *pSrc, | - | ||||||||||||||||||
482 | ExprList *pEList, | - | ||||||||||||||||||
483 | ExprList **ppSub | - | ||||||||||||||||||
484 | ){ | - | ||||||||||||||||||
485 | Walker sWalker; | - | ||||||||||||||||||
486 | WindowRewrite sRewrite; | - | ||||||||||||||||||
487 | - | |||||||||||||||||||
488 | memset(&sWalker, 0, sizeof(Walker)); | - | ||||||||||||||||||
489 | memset(&sRewrite, 0, sizeof(WindowRewrite)); | - | ||||||||||||||||||
490 | - | |||||||||||||||||||
491 | sRewrite.pSub = *ppSub; | - | ||||||||||||||||||
492 | sRewrite.pWin = pWin; | - | ||||||||||||||||||
493 | sRewrite.pSrc = pSrc; | - | ||||||||||||||||||
494 | - | |||||||||||||||||||
495 | sWalker.pParse = pParse; | - | ||||||||||||||||||
496 | sWalker.xExprCallback = selectWindowRewriteExprCb; | - | ||||||||||||||||||
497 | sWalker.xSelectCallback = selectWindowRewriteSelectCb; | - | ||||||||||||||||||
498 | sWalker.u.pRewrite = &sRewrite; | - | ||||||||||||||||||
499 | - | |||||||||||||||||||
500 | (void)sqlite3WalkExprList(&sWalker, pEList); | - | ||||||||||||||||||
501 | - | |||||||||||||||||||
502 | *ppSub = sRewrite.pSub; | - | ||||||||||||||||||
503 | } executed 3618 times by 1 test: end of block Executed by:
| 3618 | ||||||||||||||||||
504 | - | |||||||||||||||||||
505 | - | |||||||||||||||||||
506 | - | |||||||||||||||||||
507 | - | |||||||||||||||||||
508 | - | |||||||||||||||||||
509 | static ExprList *exprListAppendList( | - | ||||||||||||||||||
510 | Parse *pParse, | - | ||||||||||||||||||
511 | ExprList *pList, | - | ||||||||||||||||||
512 | ExprList *pAppend | - | ||||||||||||||||||
513 | ){ | - | ||||||||||||||||||
514 | if( pAppend
| 1637-5746 | ||||||||||||||||||
515 | int i; | - | ||||||||||||||||||
516 | int nInit = pList
| 2170-3576 | ||||||||||||||||||
517 | for(i=0; i<pAppend->nExpr
| 5746-7141 | ||||||||||||||||||
518 | Expr *pDup = sqlite3ExprDup(pParse->db, pAppend->a[i].pExpr, 0); | - | ||||||||||||||||||
519 | pList = sqlite3ExprListAppend(pParse, pList, pDup); | - | ||||||||||||||||||
520 | if( pList
executed 7141 times by 1 test: pList->a[nInit+i].sortOrder = pAppend->a[i].sortOrder; Executed by:
| 0-7141 | ||||||||||||||||||
521 | } executed 7141 times by 1 test: end of block Executed by:
| 7141 | ||||||||||||||||||
522 | } executed 5746 times by 1 test: end of block Executed by:
| 5746 | ||||||||||||||||||
523 | return executed 7383 times by 1 test: pList;return pList; Executed by:
executed 7383 times by 1 test: return pList; Executed by:
| 7383 | ||||||||||||||||||
524 | } | - | ||||||||||||||||||
525 | int sqlite3WindowRewrite(Parse *pParse, Select *p){ | - | ||||||||||||||||||
526 | int rc = 0; | - | ||||||||||||||||||
527 | if( p->pWin
| 1809-313444 | ||||||||||||||||||
528 | Vdbe *v = sqlite3GetVdbe(pParse); | - | ||||||||||||||||||
529 | sqlite3 *db = pParse->db; | - | ||||||||||||||||||
530 | Select *pSub = 0; | - | ||||||||||||||||||
531 | SrcList *pSrc = p->pSrc; | - | ||||||||||||||||||
532 | Expr *pWhere = p->pWhere; | - | ||||||||||||||||||
533 | ExprList *pGroupBy = p->pGroupBy; | - | ||||||||||||||||||
534 | Expr *pHaving = p->pHaving; | - | ||||||||||||||||||
535 | ExprList *pSort = 0; | - | ||||||||||||||||||
536 | - | |||||||||||||||||||
537 | ExprList *pSublist = 0; | - | ||||||||||||||||||
538 | Window *pMWin = p->pWin; | - | ||||||||||||||||||
539 | Window *pWin; | - | ||||||||||||||||||
540 | - | |||||||||||||||||||
541 | p->pSrc = 0; | - | ||||||||||||||||||
542 | p->pWhere = 0; | - | ||||||||||||||||||
543 | p->pGroupBy = 0; | - | ||||||||||||||||||
544 | p->pHaving = 0; | - | ||||||||||||||||||
545 | - | |||||||||||||||||||
546 | - | |||||||||||||||||||
547 | - | |||||||||||||||||||
548 | - | |||||||||||||||||||
549 | pSort = sqlite3ExprListDup(db, pMWin->pPartition, 0); | - | ||||||||||||||||||
550 | pSort = exprListAppendList(pParse, pSort, pMWin->pOrderBy); | - | ||||||||||||||||||
551 | if( pSort
| 58-1751 | ||||||||||||||||||
552 | if( sqlite3ExprListCompare(pSort, p->pOrderBy, -1)==0
| 110-206 | ||||||||||||||||||
553 | sqlite3ExprListDelete(db, p->pOrderBy); | - | ||||||||||||||||||
554 | p->pOrderBy = 0; | - | ||||||||||||||||||
555 | } executed 110 times by 1 test: end of block Executed by:
| 110 | ||||||||||||||||||
556 | } executed 316 times by 1 test: end of block Executed by:
| 316 | ||||||||||||||||||
557 | - | |||||||||||||||||||
558 | - | |||||||||||||||||||
559 | - | |||||||||||||||||||
560 | - | |||||||||||||||||||
561 | pMWin->iEphCsr = pParse->nTab++; | - | ||||||||||||||||||
562 | - | |||||||||||||||||||
563 | selectWindowRewriteEList(pParse, pMWin, pSrc, p->pEList, &pSublist); | - | ||||||||||||||||||
564 | selectWindowRewriteEList(pParse, pMWin, pSrc, p->pOrderBy, &pSublist); | - | ||||||||||||||||||
565 | pMWin->nBufferCol = (pSublist
| 435-1374 | ||||||||||||||||||
566 | - | |||||||||||||||||||
567 | - | |||||||||||||||||||
568 | - | |||||||||||||||||||
569 | - | |||||||||||||||||||
570 | pSublist = exprListAppendList(pParse, pSublist, pMWin->pPartition); | - | ||||||||||||||||||
571 | pSublist = exprListAppendList(pParse, pSublist, pMWin->pOrderBy); | - | ||||||||||||||||||
572 | - | |||||||||||||||||||
573 | - | |||||||||||||||||||
574 | - | |||||||||||||||||||
575 | - | |||||||||||||||||||
576 | - | |||||||||||||||||||
577 | for(pWin=pMWin; pWin
| 1809-1956 | ||||||||||||||||||
578 | pWin->iArgCol = (pSublist
| 42-1914 | ||||||||||||||||||
579 | pSublist = exprListAppendList(pParse, pSublist, pWin->pOwner->x.pList); | - | ||||||||||||||||||
580 | if( pWin->pFilter
| 72-1884 | ||||||||||||||||||
581 | Expr *pFilter = sqlite3ExprDup(db, pWin->pFilter, 0); | - | ||||||||||||||||||
582 | pSublist = sqlite3ExprListAppend(pParse, pSublist, pFilter); | - | ||||||||||||||||||
583 | } executed 72 times by 1 test: end of block Executed by:
| 72 | ||||||||||||||||||
584 | pWin->regAccum = ++pParse->nMem; | - | ||||||||||||||||||
585 | pWin->regResult = ++pParse->nMem; | - | ||||||||||||||||||
586 | sqlite3VdbeAddOp2(v, 73, 0, pWin->regAccum); | - | ||||||||||||||||||
587 | } executed 1956 times by 1 test: end of block Executed by:
| 1956 | ||||||||||||||||||
588 | - | |||||||||||||||||||
589 | - | |||||||||||||||||||
590 | - | |||||||||||||||||||
591 | - | |||||||||||||||||||
592 | - | |||||||||||||||||||
593 | - | |||||||||||||||||||
594 | - | |||||||||||||||||||
595 | if( pSublist==0
| 20-1789 | ||||||||||||||||||
596 | pSublist = sqlite3ExprListAppend(pParse, 0, | - | ||||||||||||||||||
597 | sqlite3ExprAlloc(db, 143, &sqlite3IntTokens[0], 0) | - | ||||||||||||||||||
598 | ); | - | ||||||||||||||||||
599 | } executed 20 times by 1 test: end of block Executed by:
| 20 | ||||||||||||||||||
600 | - | |||||||||||||||||||
601 | pSub = sqlite3SelectNew( | - | ||||||||||||||||||
602 | pParse, pSublist, pSrc, pWhere, pGroupBy, pHaving, pSort, 0, 0 | - | ||||||||||||||||||
603 | ); | - | ||||||||||||||||||
604 | p->pSrc = sqlite3SrcListAppend(db, 0, 0, 0); | - | ||||||||||||||||||
605 | - | |||||||||||||||||||
606 | ((void) (0)) | - | ||||||||||||||||||
607 | ; | - | ||||||||||||||||||
608 | if( p->pSrc
| 0-1809 | ||||||||||||||||||
609 | p->pSrc->a[0].pSelect = pSub; | - | ||||||||||||||||||
610 | sqlite3SrcListAssignCursors(pParse, p->pSrc); | - | ||||||||||||||||||
611 | if( sqlite3ExpandSubquery(pParse, &p->pSrc->a[0])
| 0-1809 | ||||||||||||||||||
612 | rc = 7; | - | ||||||||||||||||||
613 | } never executed: else{end of block | 0 | ||||||||||||||||||
614 | pSub->selFlags |= 0x00040; | - | ||||||||||||||||||
615 | p->selFlags &= ~0x00008; | - | ||||||||||||||||||
616 | sqlite3SelectPrep(pParse, pSub, 0); | - | ||||||||||||||||||
617 | } executed 1809 times by 1 test: end of block Executed by:
| 1809 | ||||||||||||||||||
618 | - | |||||||||||||||||||
619 | sqlite3VdbeAddOp2(v, 113, pMWin->iEphCsr, pSublist->nExpr); | - | ||||||||||||||||||
620 | } executed 1809 times by 1 test: else{end of block Executed by:
| 1809 | ||||||||||||||||||
621 | sqlite3SelectDelete(db, pSub); | - | ||||||||||||||||||
622 | } never executed: end of block | 0 | ||||||||||||||||||
623 | if( db->mallocFailed
never executed: rc = 7; | 0-1809 | ||||||||||||||||||
624 | } executed 1809 times by 1 test: end of block Executed by:
| 1809 | ||||||||||||||||||
625 | - | |||||||||||||||||||
626 | return executed 315253 times by 435 tests: rc;return rc; Executed by:
executed 315253 times by 435 tests: return rc; Executed by:
| 315253 | ||||||||||||||||||
627 | } | - | ||||||||||||||||||
628 | - | |||||||||||||||||||
629 | - | |||||||||||||||||||
630 | - | |||||||||||||||||||
631 | - | |||||||||||||||||||
632 | void sqlite3WindowDelete(sqlite3 *db, Window *p){ | - | ||||||||||||||||||
633 | if( p
| 6-2323 | ||||||||||||||||||
634 | sqlite3ExprDelete(db, p->pFilter); | - | ||||||||||||||||||
635 | sqlite3ExprListDelete(db, p->pPartition); | - | ||||||||||||||||||
636 | sqlite3ExprListDelete(db, p->pOrderBy); | - | ||||||||||||||||||
637 | sqlite3ExprDelete(db, p->pEnd); | - | ||||||||||||||||||
638 | sqlite3ExprDelete(db, p->pStart); | - | ||||||||||||||||||
639 | sqlite3DbFree(db, p->zName); | - | ||||||||||||||||||
640 | sqlite3DbFree(db, p); | - | ||||||||||||||||||
641 | } executed 2323 times by 1 test: end of block Executed by:
| 2323 | ||||||||||||||||||
642 | } executed 2329 times by 1 test: end of block Executed by:
| 2329 | ||||||||||||||||||
643 | - | |||||||||||||||||||
644 | - | |||||||||||||||||||
645 | - | |||||||||||||||||||
646 | - | |||||||||||||||||||
647 | void sqlite3WindowListDelete(sqlite3 *db, Window *p){ | - | ||||||||||||||||||
648 | while( p
| 125-126 | ||||||||||||||||||
649 | Window *pNext = p->pNextWin; | - | ||||||||||||||||||
650 | sqlite3WindowDelete(db, p); | - | ||||||||||||||||||
651 | p = pNext; | - | ||||||||||||||||||
652 | } executed 126 times by 1 test: end of block Executed by:
| 126 | ||||||||||||||||||
653 | } executed 125 times by 1 test: end of block Executed by:
| 125 | ||||||||||||||||||
654 | static Expr *sqlite3WindowOffsetExpr(Parse *pParse, Expr *pExpr){ | - | ||||||||||||||||||
655 | if( 0==sqlite3ExprIsConstant(pExpr)
| 2-3750 | ||||||||||||||||||
656 | sqlite3ExprDelete(pParse->db, pExpr); | - | ||||||||||||||||||
657 | pExpr = sqlite3ExprAlloc(pParse->db, 110, 0, 0); | - | ||||||||||||||||||
658 | } executed 2 times by 1 test: end of block Executed by:
| 2 | ||||||||||||||||||
659 | return executed 3752 times by 1 test: pExpr;return pExpr; Executed by:
executed 3752 times by 1 test: return pExpr; Executed by:
| 3752 | ||||||||||||||||||
660 | } | - | ||||||||||||||||||
661 | - | |||||||||||||||||||
662 | - | |||||||||||||||||||
663 | - | |||||||||||||||||||
664 | - | |||||||||||||||||||
665 | Window *sqlite3WindowAlloc( | - | ||||||||||||||||||
666 | Parse *pParse, | - | ||||||||||||||||||
667 | int eType, | - | ||||||||||||||||||
668 | int eStart, | - | ||||||||||||||||||
669 | Expr *pStart, | - | ||||||||||||||||||
670 | int eEnd, | - | ||||||||||||||||||
671 | Expr *pEnd | - | ||||||||||||||||||
672 | ){ | - | ||||||||||||||||||
673 | Window *pWin = 0; | - | ||||||||||||||||||
674 | - | |||||||||||||||||||
675 | - | |||||||||||||||||||
676 | - | |||||||||||||||||||
677 | ((void) (0)) | - | ||||||||||||||||||
678 | ; | - | ||||||||||||||||||
679 | - | |||||||||||||||||||
680 | ((void) (0)) | - | ||||||||||||||||||
681 | - | |||||||||||||||||||
682 | ; | - | ||||||||||||||||||
683 | - | |||||||||||||||||||
684 | ((void) (0)) | - | ||||||||||||||||||
685 | - | |||||||||||||||||||
686 | ; | - | ||||||||||||||||||
687 | - | |||||||||||||||||||
688 | ((void) (0)) | - | ||||||||||||||||||
689 | ; | - | ||||||||||||||||||
690 | - | |||||||||||||||||||
691 | ((void) (0)) | - | ||||||||||||||||||
692 | ; | - | ||||||||||||||||||
693 | - | |||||||||||||||||||
694 | - | |||||||||||||||||||
695 | - | |||||||||||||||||||
696 | - | |||||||||||||||||||
697 | - | |||||||||||||||||||
698 | if( eType==86
| 1-1189 | ||||||||||||||||||
699 | sqlite3ErrorMsg(pParse, "RANGE must use only UNBOUNDED or CURRENT ROW"); | - | ||||||||||||||||||
700 | goto executed 2 times by 1 test: windowAllocErr;goto windowAllocErr; Executed by:
executed 2 times by 1 test: goto windowAllocErr; Executed by:
| 2 | ||||||||||||||||||
701 | } | - | ||||||||||||||||||
702 | if( (eStart==82
| 1-1431 | ||||||||||||||||||
703 | || (eStart==83
| 1-1690 | ||||||||||||||||||
704 | ){ | - | ||||||||||||||||||
705 | sqlite3ErrorMsg(pParse, "unsupported frame delimiter for ROWS"); | - | ||||||||||||||||||
706 | goto executed 4 times by 1 test: windowAllocErr;goto windowAllocErr; Executed by:
executed 4 times by 1 test: goto windowAllocErr; Executed by:
| 4 | ||||||||||||||||||
707 | } | - | ||||||||||||||||||
708 | - | |||||||||||||||||||
709 | pWin = (Window*)sqlite3DbMallocZero(pParse->db, sizeof(Window)); | - | ||||||||||||||||||
710 | if( pWin==0
never executed: windowAllocErr;goto windowAllocErr; never executed: goto windowAllocErr; | 0-1876 | ||||||||||||||||||
711 | pWin->eType = eType; | - | ||||||||||||||||||
712 | pWin->eStart = eStart; | - | ||||||||||||||||||
713 | pWin->eEnd = eEnd; | - | ||||||||||||||||||
714 | pWin->pEnd = sqlite3WindowOffsetExpr(pParse, pEnd); | - | ||||||||||||||||||
715 | pWin->pStart = sqlite3WindowOffsetExpr(pParse, pStart); | - | ||||||||||||||||||
716 | return executed 1876 times by 1 test: pWin;return pWin; Executed by:
executed 1876 times by 1 test: return pWin; Executed by:
| 1876 | ||||||||||||||||||
717 | - | |||||||||||||||||||
718 | windowAllocErr: | - | ||||||||||||||||||
719 | sqlite3ExprDelete(pParse->db, pEnd); | - | ||||||||||||||||||
720 | sqlite3ExprDelete(pParse->db, pStart); | - | ||||||||||||||||||
721 | return executed 6 times by 1 test: 0;return 0; Executed by:
executed 6 times by 1 test: return 0; Executed by:
| 6 | ||||||||||||||||||
722 | } | - | ||||||||||||||||||
723 | - | |||||||||||||||||||
724 | - | |||||||||||||||||||
725 | - | |||||||||||||||||||
726 | - | |||||||||||||||||||
727 | void sqlite3WindowAttach(Parse *pParse, Expr *p, Window *pWin){ | - | ||||||||||||||||||
728 | if( p
| 0-1969 | ||||||||||||||||||
729 | - | |||||||||||||||||||
730 | ((void) (0)) | - | ||||||||||||||||||
731 | ; | - | ||||||||||||||||||
732 | - | |||||||||||||||||||
733 | - | |||||||||||||||||||
734 | - | |||||||||||||||||||
735 | if( (
| 0-1969 | ||||||||||||||||||
736 | p->y.pWin = pWin; | - | ||||||||||||||||||
737 | (p)->flags|=(0x1000000); | - | ||||||||||||||||||
738 | pWin->pOwner = p; | - | ||||||||||||||||||
739 | if( p->flags & 0x000010
| 1-1968 | ||||||||||||||||||
740 | sqlite3ErrorMsg(pParse, | - | ||||||||||||||||||
741 | "DISTINCT is not supported for window functions"); | - | ||||||||||||||||||
742 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||||||||
743 | } executed 1969 times by 1 test: end of block Executed by:
| 1969 | ||||||||||||||||||
744 | } executed 1969 times by 1 test: else{end of block Executed by:
| 1969 | ||||||||||||||||||
745 | sqlite3WindowDelete(pParse->db, pWin); | - | ||||||||||||||||||
746 | } never executed: end of block | 0 | ||||||||||||||||||
747 | } | - | ||||||||||||||||||
748 | - | |||||||||||||||||||
749 | - | |||||||||||||||||||
750 | - | |||||||||||||||||||
751 | - | |||||||||||||||||||
752 | - | |||||||||||||||||||
753 | int sqlite3WindowCompare(Parse *pParse, Window *p1, Window *p2){ | - | ||||||||||||||||||
754 | if( p1->eType!=p2->eType
executed 45 times by 1 test: 1;return 1; Executed by:
executed 45 times by 1 test: return 1; Executed by:
| 45-271 | ||||||||||||||||||
755 | if( p1->eStart!=p2->eStart
executed 32 times by 1 test: 1;return 1; Executed by:
executed 32 times by 1 test: return 1; Executed by:
| 32-239 | ||||||||||||||||||
756 | if( p1->eEnd!=p2->eEnd
executed 24 times by 1 test: 1;return 1; Executed by:
executed 24 times by 1 test: return 1; Executed by:
| 24-215 | ||||||||||||||||||
757 | if( sqlite3ExprCompare(pParse, p1->pStart, p2->pStart, -1)
executed 4 times by 1 test: 1;return 1; Executed by:
executed 4 times by 1 test: return 1; Executed by:
| 4-211 | ||||||||||||||||||
758 | if( sqlite3ExprCompare(pParse, p1->pEnd, p2->pEnd, -1)
executed 4 times by 1 test: 1;return 1; Executed by:
executed 4 times by 1 test: return 1; Executed by:
| 4-207 | ||||||||||||||||||
759 | if( sqlite3ExprListCompare(p1->pPartition, p2->pPartition, -1)
executed 25 times by 1 test: 1;return 1; Executed by:
executed 25 times by 1 test: return 1; Executed by:
| 25-182 | ||||||||||||||||||
760 | if( sqlite3ExprListCompare(p1->pOrderBy, p2->pOrderBy, -1)
executed 25 times by 1 test: 1;return 1; Executed by:
executed 25 times by 1 test: return 1; Executed by:
| 25-157 | ||||||||||||||||||
761 | return executed 157 times by 1 test: 0;return 0; Executed by:
executed 157 times by 1 test: return 0; Executed by:
| 157 | ||||||||||||||||||
762 | } | - | ||||||||||||||||||
763 | - | |||||||||||||||||||
764 | - | |||||||||||||||||||
765 | - | |||||||||||||||||||
766 | - | |||||||||||||||||||
767 | - | |||||||||||||||||||
768 | - | |||||||||||||||||||
769 | - | |||||||||||||||||||
770 | void sqlite3WindowCodeInit(Parse *pParse, Window *pMWin){ | - | ||||||||||||||||||
771 | Window *pWin; | - | ||||||||||||||||||
772 | Vdbe *v = sqlite3GetVdbe(pParse); | - | ||||||||||||||||||
773 | int nPart = (pMWin->pPartition
| 875-934 | ||||||||||||||||||
774 | nPart += (pMWin->pOrderBy
| 78-1731 | ||||||||||||||||||
775 | if( nPart
| 58-1751 | ||||||||||||||||||
776 | pMWin->regPart = pParse->nMem+1; | - | ||||||||||||||||||
777 | pParse->nMem += nPart; | - | ||||||||||||||||||
778 | sqlite3VdbeAddOp3(v, 73, 0, pMWin->regPart, pMWin->regPart+nPart-1); | - | ||||||||||||||||||
779 | } executed 1751 times by 1 test: end of block Executed by:
| 1751 | ||||||||||||||||||
780 | - | |||||||||||||||||||
781 | for(pWin=pMWin; pWin
| 1809-1956 | ||||||||||||||||||
782 | FuncDef *p = pWin->pFunc; | - | ||||||||||||||||||
783 | if( (
| 94-1749 | ||||||||||||||||||
784 | - | |||||||||||||||||||
785 | - | |||||||||||||||||||
786 | - | |||||||||||||||||||
787 | - | |||||||||||||||||||
788 | - | |||||||||||||||||||
789 | - | |||||||||||||||||||
790 | - | |||||||||||||||||||
791 | ExprList *pList = pWin->pOwner->x.pList; | - | ||||||||||||||||||
792 | KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pList, 0, 0); | - | ||||||||||||||||||
793 | pWin->csrApp = pParse->nTab++; | - | ||||||||||||||||||
794 | pWin->regApp = pParse->nMem+1; | - | ||||||||||||||||||
795 | pParse->nMem += 3; | - | ||||||||||||||||||
796 | if( pKeyInfo
| 0-94 | ||||||||||||||||||
797 | - | |||||||||||||||||||
798 | ((void) (0)) | - | ||||||||||||||||||
799 | ; | - | ||||||||||||||||||
800 | pKeyInfo->aSortOrder[0] = 1; | - | ||||||||||||||||||
801 | } executed 44 times by 1 test: end of block Executed by:
| 44 | ||||||||||||||||||
802 | sqlite3VdbeAddOp2(v, 113, pWin->csrApp, 2); | - | ||||||||||||||||||
803 | sqlite3VdbeAppendP4(v, pKeyInfo, (-9)); | - | ||||||||||||||||||
804 | sqlite3VdbeAddOp2(v, 70, 0, pWin->regApp+1); | - | ||||||||||||||||||
805 | } executed 94 times by 1 test: end of block Executed by:
| 94 | ||||||||||||||||||
806 | else if( p->zName==nth_valueName
| 103-1744 | ||||||||||||||||||
807 | - | |||||||||||||||||||
808 | - | |||||||||||||||||||
809 | - | |||||||||||||||||||
810 | ((void) (0)) | - | ||||||||||||||||||
811 | ; | - | ||||||||||||||||||
812 | pWin->regApp = pParse->nMem+1; | - | ||||||||||||||||||
813 | pWin->csrApp = pParse->nTab++; | - | ||||||||||||||||||
814 | pParse->nMem += 2; | - | ||||||||||||||||||
815 | sqlite3VdbeAddOp2(v, 111, pWin->csrApp, pMWin->iEphCsr); | - | ||||||||||||||||||
816 | } executed 221 times by 1 test: end of block Executed by:
| 221 | ||||||||||||||||||
817 | else if( p->zName==leadName
| 107-1519 | ||||||||||||||||||
818 | - | |||||||||||||||||||
819 | ((void) (0)) | - | ||||||||||||||||||
820 | ; | - | ||||||||||||||||||
821 | pWin->csrApp = pParse->nTab++; | - | ||||||||||||||||||
822 | sqlite3VdbeAddOp2(v, 111, pWin->csrApp, pMWin->iEphCsr); | - | ||||||||||||||||||
823 | } executed 229 times by 1 test: end of block Executed by:
| 229 | ||||||||||||||||||
824 | } executed 1956 times by 1 test: end of block Executed by:
| 1956 | ||||||||||||||||||
825 | } executed 1809 times by 1 test: end of block Executed by:
| 1809 | ||||||||||||||||||
826 | static void windowCheckIntValue(Parse *pParse, int reg, int eCond){ | - | ||||||||||||||||||
827 | static const char *azErr[] = { | - | ||||||||||||||||||
828 | "frame starting offset must be a non-negative integer", | - | ||||||||||||||||||
829 | "frame ending offset must be a non-negative integer", | - | ||||||||||||||||||
830 | "second argument to nth_value must be a positive integer" | - | ||||||||||||||||||
831 | }; | - | ||||||||||||||||||
832 | static int aOp[] = { 57, 57, 54 }; | - | ||||||||||||||||||
833 | Vdbe *v = sqlite3GetVdbe(pParse); | - | ||||||||||||||||||
834 | int regZero = sqlite3GetTempReg(pParse); | - | ||||||||||||||||||
835 | - | |||||||||||||||||||
836 | ((void) (0)) | - | ||||||||||||||||||
837 | ; | - | ||||||||||||||||||
838 | sqlite3VdbeAddOp2(v, 70, 0, regZero); | - | ||||||||||||||||||
839 | sqlite3VdbeAddOp2(v, 15, reg, sqlite3VdbeCurrentAddr(v)+2); | - | ||||||||||||||||||
840 | ; | - | ||||||||||||||||||
841 | ; | - | ||||||||||||||||||
842 | ; | - | ||||||||||||||||||
843 | sqlite3VdbeAddOp3(v, aOp[eCond], regZero, sqlite3VdbeCurrentAddr(v)+2, reg); | - | ||||||||||||||||||
844 | ; | - | ||||||||||||||||||
845 | ; | - | ||||||||||||||||||
846 | ; | - | ||||||||||||||||||
847 | sqlite3VdbeAddOp2(v, 69, 1, 2); | - | ||||||||||||||||||
848 | sqlite3VdbeAppendP4(v, (void*)azErr[eCond], (-1)); | - | ||||||||||||||||||
849 | sqlite3ReleaseTempReg(pParse, regZero); | - | ||||||||||||||||||
850 | } executed 901 times by 1 test: end of block Executed by:
| 901 | ||||||||||||||||||
851 | - | |||||||||||||||||||
852 | - | |||||||||||||||||||
853 | - | |||||||||||||||||||
854 | - | |||||||||||||||||||
855 | - | |||||||||||||||||||
856 | static int windowArgCount(Window *pWin){ | - | ||||||||||||||||||
857 | ExprList *pList = pWin->pOwner->x.pList; | - | ||||||||||||||||||
858 | return executed 8183 times by 1 test: (pListreturn (pList ? pList->nExpr : 0); Executed by:
executed 8183 times by 1 test: return (pList ? pList->nExpr : 0); Executed by:
| 2479-8183 | ||||||||||||||||||
859 | } | - | ||||||||||||||||||
860 | static void windowAggStep( | - | ||||||||||||||||||
861 | Parse *pParse, | - | ||||||||||||||||||
862 | Window *pMWin, | - | ||||||||||||||||||
863 | int csr, | - | ||||||||||||||||||
864 | int bInverse, | - | ||||||||||||||||||
865 | int reg, | - | ||||||||||||||||||
866 | int regPartSize | - | ||||||||||||||||||
867 | ){ | - | ||||||||||||||||||
868 | Vdbe *v = sqlite3GetVdbe(pParse); | - | ||||||||||||||||||
869 | Window *pWin; | - | ||||||||||||||||||
870 | for(pWin=pMWin; pWin
| 2410-2609 | ||||||||||||||||||
871 | int flags = pWin->pFunc->funcFlags; | - | ||||||||||||||||||
872 | int regArg; | - | ||||||||||||||||||
873 | int nArg = windowArgCount(pWin); | - | ||||||||||||||||||
874 | - | |||||||||||||||||||
875 | if( csr>=0
| 664-1945 | ||||||||||||||||||
876 | int i; | - | ||||||||||||||||||
877 | for(i=0; i<nArg
| 1945-2388 | ||||||||||||||||||
878 | sqlite3VdbeAddOp3(v, 90, csr, pWin->iArgCol+i, reg+i); | - | ||||||||||||||||||
879 | } executed 2388 times by 1 test: end of block Executed by:
| 2388 | ||||||||||||||||||
880 | regArg = reg; | - | ||||||||||||||||||
881 | if( flags & 0x20000
| 350-1595 | ||||||||||||||||||
882 | if( nArg==0
| 143-207 | ||||||||||||||||||
883 | regArg = regPartSize; | - | ||||||||||||||||||
884 | } executed 207 times by 1 test: else{end of block Executed by:
| 207 | ||||||||||||||||||
885 | sqlite3VdbeAddOp2(v, 79, regPartSize, reg+nArg); | - | ||||||||||||||||||
886 | } executed 143 times by 1 test: end of block Executed by:
| 143 | ||||||||||||||||||
887 | nArg++; | - | ||||||||||||||||||
888 | } executed 350 times by 1 test: end of block Executed by:
| 350 | ||||||||||||||||||
889 | } executed 1945 times by 1 test: else{end of block Executed by:
| 1945 | ||||||||||||||||||
890 | - | |||||||||||||||||||
891 | ((void) (0)) | - | ||||||||||||||||||
892 | ; | - | ||||||||||||||||||
893 | regArg = reg + pWin->iArgCol; | - | ||||||||||||||||||
894 | } executed 664 times by 1 test: end of block Executed by:
| 664 | ||||||||||||||||||
895 | - | |||||||||||||||||||
896 | if( (
| 291-2318 | ||||||||||||||||||
897 | && pWin->eStart!=87
| 113-178 | ||||||||||||||||||
898 | ){ | - | ||||||||||||||||||
899 | int addrIsNull = sqlite3VdbeAddOp1(v, 50, regArg); | - | ||||||||||||||||||
900 | ; | - | ||||||||||||||||||
901 | if( bInverse==0
| 84-94 | ||||||||||||||||||
902 | sqlite3VdbeAddOp2(v, 83, pWin->regApp+1, 1); | - | ||||||||||||||||||
903 | sqlite3VdbeAddOp2(v, 79, regArg, pWin->regApp); | - | ||||||||||||||||||
904 | sqlite3VdbeAddOp3(v, 102, pWin->regApp, 2, pWin->regApp+2); | - | ||||||||||||||||||
905 | sqlite3VdbeAddOp2(v, 133, pWin->csrApp, pWin->regApp+2); | - | ||||||||||||||||||
906 | } executed 94 times by 1 test: else{end of block Executed by:
| 94 | ||||||||||||||||||
907 | sqlite3VdbeAddOp4Int(v, 24, pWin->csrApp, 0, regArg, 1); | - | ||||||||||||||||||
908 | ; | - | ||||||||||||||||||
909 | sqlite3VdbeAddOp1(v, 124, pWin->csrApp); | - | ||||||||||||||||||
910 | sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2); | - | ||||||||||||||||||
911 | } executed 84 times by 1 test: end of block Executed by:
| 84 | ||||||||||||||||||
912 | sqlite3VdbeJumpHere(v, addrIsNull); | - | ||||||||||||||||||
913 | } executed 178 times by 1 test: else if( pWin->regAppend of block Executed by:
| 178-2078 | ||||||||||||||||||
914 | - | |||||||||||||||||||
915 | ((void) (0)) | - | ||||||||||||||||||
916 | - | |||||||||||||||||||
917 | - | |||||||||||||||||||
918 | ; | - | ||||||||||||||||||
919 | - | |||||||||||||||||||
920 | ((void) (0)) | - | ||||||||||||||||||
921 | ; | - | ||||||||||||||||||
922 | sqlite3VdbeAddOp2(v, 83, pWin->regApp+1-bInverse, 1); | - | ||||||||||||||||||
923 | } executed 353 times by 1 test: else if( pWin->pFunc->zName==leadNameend of block Executed by:
| 188-1890 | ||||||||||||||||||
924 | || pWin->pFunc->zName==lagName
| 173-1717 | ||||||||||||||||||
925 | ){ | - | ||||||||||||||||||
926 | - | |||||||||||||||||||
927 | } executed 361 times by 1 test: else{end of block Executed by:
| 361 | ||||||||||||||||||
928 | int addrIf = 0; | - | ||||||||||||||||||
929 | if( pWin->pFilter
| 113-1604 | ||||||||||||||||||
930 | int regTmp; | - | ||||||||||||||||||
931 | - | |||||||||||||||||||
932 | ((void) (0)) | - | ||||||||||||||||||
933 | ; | - | ||||||||||||||||||
934 | - | |||||||||||||||||||
935 | ((void) (0)) | - | ||||||||||||||||||
936 | ; | - | ||||||||||||||||||
937 | if( csr>0
| 19-94 | ||||||||||||||||||
938 | regTmp = sqlite3GetTempReg(pParse); | - | ||||||||||||||||||
939 | sqlite3VdbeAddOp3(v, 90, csr, pWin->iArgCol+nArg,regTmp); | - | ||||||||||||||||||
940 | } executed 94 times by 1 test: else{end of block Executed by:
| 94 | ||||||||||||||||||
941 | regTmp = regArg + nArg; | - | ||||||||||||||||||
942 | } executed 19 times by 1 test: end of block Executed by:
| 19 | ||||||||||||||||||
943 | addrIf = sqlite3VdbeAddOp3(v, 20, regTmp, 0, 1); | - | ||||||||||||||||||
944 | ; | - | ||||||||||||||||||
945 | if( csr>0
| 19-94 | ||||||||||||||||||
946 | sqlite3ReleaseTempReg(pParse, regTmp); | - | ||||||||||||||||||
947 | } executed 94 times by 1 test: end of block Executed by:
| 94 | ||||||||||||||||||
948 | } executed 113 times by 1 test: end of block Executed by:
| 113 | ||||||||||||||||||
949 | if( pWin->pFunc->funcFlags & 0x0020
| 113-1604 | ||||||||||||||||||
950 | CollSeq *pColl; | - | ||||||||||||||||||
951 | - | |||||||||||||||||||
952 | ((void) (0)) | - | ||||||||||||||||||
953 | ; | - | ||||||||||||||||||
954 | pColl = sqlite3ExprNNCollSeq(pParse, pWin->pOwner->x.pList->a[0].pExpr); | - | ||||||||||||||||||
955 | sqlite3VdbeAddOp4(v, 82, 0,0,0, (const char*)pColl, (-2)); | - | ||||||||||||||||||
956 | } executed 113 times by 1 test: end of block Executed by:
| 113 | ||||||||||||||||||
957 | sqlite3VdbeAddOp3(v, bInverse? 154 : 155, | - | ||||||||||||||||||
958 | bInverse, regArg, pWin->regAccum); | - | ||||||||||||||||||
959 | sqlite3VdbeAppendP4(v, pWin->pFunc, (-8)); | - | ||||||||||||||||||
960 | sqlite3VdbeChangeP5(v, (u8)nArg); | - | ||||||||||||||||||
961 | if( addrIf
executed 113 times by 1 test: sqlite3VdbeJumpHere(v, addrIf); Executed by:
| 113-1604 | ||||||||||||||||||
962 | } executed 1717 times by 1 test: end of block Executed by:
| 1717 | ||||||||||||||||||
963 | } | - | ||||||||||||||||||
964 | } executed 2410 times by 1 test: end of block Executed by:
| 2410 | ||||||||||||||||||
965 | - | |||||||||||||||||||
966 | - | |||||||||||||||||||
967 | - | |||||||||||||||||||
968 | - | |||||||||||||||||||
969 | - | |||||||||||||||||||
970 | - | |||||||||||||||||||
971 | - | |||||||||||||||||||
972 | static void windowAggFinal(Parse *pParse, Window *pMWin, int bFinal){ | - | ||||||||||||||||||
973 | Vdbe *v = sqlite3GetVdbe(pParse); | - | ||||||||||||||||||
974 | Window *pWin; | - | ||||||||||||||||||
975 | - | |||||||||||||||||||
976 | for(pWin=pMWin; pWin
| 3187-3460 | ||||||||||||||||||
977 | if( (
| 400-3060 | ||||||||||||||||||
978 | && pWin->eStart!=87
| 122-278 | ||||||||||||||||||
979 | ){ | - | ||||||||||||||||||
980 | sqlite3VdbeAddOp2(v, 73, 0, pWin->regResult); | - | ||||||||||||||||||
981 | sqlite3VdbeAddOp1(v, 32, pWin->csrApp); | - | ||||||||||||||||||
982 | ; | - | ||||||||||||||||||
983 | sqlite3VdbeAddOp3(v, 90, pWin->csrApp, 0, pWin->regResult); | - | ||||||||||||||||||
984 | sqlite3VdbeJumpHere(v, sqlite3VdbeCurrentAddr(v)-2); | - | ||||||||||||||||||
985 | if( bFinal
| 28-94 | ||||||||||||||||||
986 | sqlite3VdbeAddOp1(v, 139, pWin->csrApp); | - | ||||||||||||||||||
987 | } executed 28 times by 1 test: end of block Executed by:
| 28 | ||||||||||||||||||
988 | } executed 122 times by 1 test: else if( pWin->regAppend of block Executed by:
| 122-3052 | ||||||||||||||||||
989 | } executed 286 times by 1 test: else{end of block Executed by:
| 286 | ||||||||||||||||||
990 | if( bFinal
| 1072-1980 | ||||||||||||||||||
991 | sqlite3VdbeAddOp2(v, 158, pWin->regAccum, windowArgCount(pWin)); | - | ||||||||||||||||||
992 | sqlite3VdbeAppendP4(v, pWin->pFunc, (-8)); | - | ||||||||||||||||||
993 | sqlite3VdbeAddOp2(v, 78, pWin->regAccum, pWin->regResult); | - | ||||||||||||||||||
994 | sqlite3VdbeAddOp2(v, 73, 0, pWin->regAccum); | - | ||||||||||||||||||
995 | } executed 1072 times by 1 test: else{end of block Executed by:
| 1072 | ||||||||||||||||||
996 | sqlite3VdbeAddOp3(v, 157, pWin->regAccum, windowArgCount(pWin), | - | ||||||||||||||||||
997 | pWin->regResult); | - | ||||||||||||||||||
998 | sqlite3VdbeAppendP4(v, pWin->pFunc, (-8)); | - | ||||||||||||||||||
999 | } executed 1980 times by 1 test: end of block Executed by:
| 1980 | ||||||||||||||||||
1000 | } | - | ||||||||||||||||||
1001 | } | - | ||||||||||||||||||
1002 | } executed 3187 times by 1 test: end of block Executed by:
| 3187 | ||||||||||||||||||
1003 | - | |||||||||||||||||||
1004 | - | |||||||||||||||||||
1005 | - | |||||||||||||||||||
1006 | - | |||||||||||||||||||
1007 | - | |||||||||||||||||||
1008 | - | |||||||||||||||||||
1009 | static void windowPartitionCache( | - | ||||||||||||||||||
1010 | Parse *pParse, | - | ||||||||||||||||||
1011 | Select *p, | - | ||||||||||||||||||
1012 | WhereInfo *pWInfo, | - | ||||||||||||||||||
1013 | int regFlushPart, | - | ||||||||||||||||||
1014 | int lblFlushPart, | - | ||||||||||||||||||
1015 | int *pRegSize | - | ||||||||||||||||||
1016 | ){ | - | ||||||||||||||||||
1017 | Window *pMWin = p->pWin; | - | ||||||||||||||||||
1018 | Vdbe *v = sqlite3GetVdbe(pParse); | - | ||||||||||||||||||
1019 | int iSubCsr = p->pSrc->a[0].iCursor; | - | ||||||||||||||||||
1020 | int nSub = p->pSrc->a[0].pTab->nCol; | - | ||||||||||||||||||
1021 | int k; | - | ||||||||||||||||||
1022 | - | |||||||||||||||||||
1023 | int reg = pParse->nMem+1; | - | ||||||||||||||||||
1024 | int regRecord = reg+nSub; | - | ||||||||||||||||||
1025 | int regRowid = regRecord+1; | - | ||||||||||||||||||
1026 | - | |||||||||||||||||||
1027 | *pRegSize = regRowid; | - | ||||||||||||||||||
1028 | pParse->nMem += nSub + 2; | - | ||||||||||||||||||
1029 | - | |||||||||||||||||||
1030 | - | |||||||||||||||||||
1031 | - | |||||||||||||||||||
1032 | for(k=0; k<nSub
| 1212-4172 | ||||||||||||||||||
1033 | sqlite3VdbeAddOp3(v, 90, iSubCsr, k, reg+k); | - | ||||||||||||||||||
1034 | } executed 4172 times by 1 test: end of block Executed by:
| 4172 | ||||||||||||||||||
1035 | sqlite3VdbeAddOp3(v, 102, reg, nSub, regRecord); | - | ||||||||||||||||||
1036 | - | |||||||||||||||||||
1037 | - | |||||||||||||||||||
1038 | - | |||||||||||||||||||
1039 | if( pMWin->pPartition
| 583-629 | ||||||||||||||||||
1040 | int addr; | - | ||||||||||||||||||
1041 | ExprList *pPart = pMWin->pPartition; | - | ||||||||||||||||||
1042 | int nPart = pPart->nExpr; | - | ||||||||||||||||||
1043 | int regNewPart = reg + pMWin->nBufferCol; | - | ||||||||||||||||||
1044 | KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0); | - | ||||||||||||||||||
1045 | - | |||||||||||||||||||
1046 | addr = sqlite3VdbeAddOp3(v, 87, regNewPart, pMWin->regPart,nPart); | - | ||||||||||||||||||
1047 | sqlite3VdbeAppendP4(v, (void*)pKeyInfo, (-9)); | - | ||||||||||||||||||
1048 | sqlite3VdbeAddOp3(v, 16, addr+2, addr+4, addr+2); | - | ||||||||||||||||||
1049 | ; | - | ||||||||||||||||||
1050 | sqlite3VdbeAddOp3(v, 78, regNewPart, pMWin->regPart, nPart-1); | - | ||||||||||||||||||
1051 | sqlite3VdbeAddOp2(v, 12, regFlushPart, lblFlushPart); | - | ||||||||||||||||||
1052 | ; | - | ||||||||||||||||||
1053 | } executed 583 times by 1 test: end of block Executed by:
| 583 | ||||||||||||||||||
1054 | - | |||||||||||||||||||
1055 | - | |||||||||||||||||||
1056 | sqlite3VdbeAddOp2(v, 121, pMWin->iEphCsr, regRowid); | - | ||||||||||||||||||
1057 | sqlite3VdbeAddOp3(v, 122, pMWin->iEphCsr, regRecord, regRowid); | - | ||||||||||||||||||
1058 | - | |||||||||||||||||||
1059 | - | |||||||||||||||||||
1060 | sqlite3WhereEnd(pWInfo); | - | ||||||||||||||||||
1061 | - | |||||||||||||||||||
1062 | - | |||||||||||||||||||
1063 | sqlite3VdbeAddOp2(v, 12, regFlushPart, lblFlushPart); | - | ||||||||||||||||||
1064 | ; | - | ||||||||||||||||||
1065 | } executed 1212 times by 1 test: end of block Executed by:
| 1212 | ||||||||||||||||||
1066 | static void windowReturnOneRow( | - | ||||||||||||||||||
1067 | Parse *pParse, | - | ||||||||||||||||||
1068 | Window *pMWin, | - | ||||||||||||||||||
1069 | int regGosub, | - | ||||||||||||||||||
1070 | int addrGosub | - | ||||||||||||||||||
1071 | ){ | - | ||||||||||||||||||
1072 | Vdbe *v = sqlite3GetVdbe(pParse); | - | ||||||||||||||||||
1073 | Window *pWin; | - | ||||||||||||||||||
1074 | for(pWin=pMWin; pWin
| 1709-1811 | ||||||||||||||||||
1075 | FuncDef *pFunc = pWin->pFunc; | - | ||||||||||||||||||
1076 | if( pFunc->zName==nth_valueName
| 158-1653 | ||||||||||||||||||
1077 | || pFunc->zName==first_valueName
| 128-1525 | ||||||||||||||||||
1078 | ){ | - | ||||||||||||||||||
1079 | int csr = pWin->csrApp; | - | ||||||||||||||||||
1080 | int lbl = sqlite3VdbeMakeLabel(v); | - | ||||||||||||||||||
1081 | int tmpReg = sqlite3GetTempReg(pParse); | - | ||||||||||||||||||
1082 | sqlite3VdbeAddOp2(v, 73, 0, pWin->regResult); | - | ||||||||||||||||||
1083 | - | |||||||||||||||||||
1084 | if( pFunc->zName==nth_valueName
| 128-158 | ||||||||||||||||||
1085 | sqlite3VdbeAddOp3(v, 90, pMWin->iEphCsr, pWin->iArgCol+1,tmpReg); | - | ||||||||||||||||||
1086 | windowCheckIntValue(pParse, tmpReg, 2); | - | ||||||||||||||||||
1087 | } executed 158 times by 1 test: else{end of block Executed by:
| 158 | ||||||||||||||||||
1088 | sqlite3VdbeAddOp2(v, 70, 1, tmpReg); | - | ||||||||||||||||||
1089 | } executed 128 times by 1 test: end of block Executed by:
| 128 | ||||||||||||||||||
1090 | sqlite3VdbeAddOp3(v, 96, tmpReg, pWin->regApp, tmpReg); | - | ||||||||||||||||||
1091 | sqlite3VdbeAddOp3(v, 54, pWin->regApp+1, lbl, tmpReg); | - | ||||||||||||||||||
1092 | ; | - | ||||||||||||||||||
1093 | sqlite3VdbeAddOp3(v, 30, csr, 0, tmpReg); | - | ||||||||||||||||||
1094 | ; | - | ||||||||||||||||||
1095 | sqlite3VdbeAddOp3(v, 90, csr, pWin->iArgCol, pWin->regResult); | - | ||||||||||||||||||
1096 | sqlite3VdbeResolveLabel(v, lbl); | - | ||||||||||||||||||
1097 | sqlite3ReleaseTempReg(pParse, tmpReg); | - | ||||||||||||||||||
1098 | } executed 286 times by 1 test: end of block Executed by:
| 286 | ||||||||||||||||||
1099 | else if( pFunc->zName==leadName
| 136-1359 | ||||||||||||||||||
1100 | int nArg = pWin->pOwner->x.pList->nExpr; | - | ||||||||||||||||||
1101 | int iEph = pMWin->iEphCsr; | - | ||||||||||||||||||
1102 | int csr = pWin->csrApp; | - | ||||||||||||||||||
1103 | int lbl = sqlite3VdbeMakeLabel(v); | - | ||||||||||||||||||
1104 | int tmpReg = sqlite3GetTempReg(pParse); | - | ||||||||||||||||||
1105 | - | |||||||||||||||||||
1106 | if( nArg<3
| 10-292 | ||||||||||||||||||
1107 | sqlite3VdbeAddOp2(v, 73, 0, pWin->regResult); | - | ||||||||||||||||||
1108 | } executed 292 times by 1 test: else{end of block Executed by:
| 292 | ||||||||||||||||||
1109 | sqlite3VdbeAddOp3(v, 90, iEph, pWin->iArgCol+2, pWin->regResult); | - | ||||||||||||||||||
1110 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||||||||
1111 | sqlite3VdbeAddOp2(v, 129, iEph, tmpReg); | - | ||||||||||||||||||
1112 | if( nArg<2
| 22-280 | ||||||||||||||||||
1113 | int val = (pFunc->zName==leadName
| 4-18 | ||||||||||||||||||
1114 | sqlite3VdbeAddOp2(v, 83, tmpReg, val); | - | ||||||||||||||||||
1115 | } executed 22 times by 1 test: else{end of block Executed by:
| 22 | ||||||||||||||||||
1116 | int op = (pFunc->zName==leadName
| 132-148 | ||||||||||||||||||
1117 | int tmpReg2 = sqlite3GetTempReg(pParse); | - | ||||||||||||||||||
1118 | sqlite3VdbeAddOp3(v, 90, iEph, pWin->iArgCol+1, tmpReg2); | - | ||||||||||||||||||
1119 | sqlite3VdbeAddOp3(v, op, tmpReg2, tmpReg, tmpReg); | - | ||||||||||||||||||
1120 | sqlite3ReleaseTempReg(pParse, tmpReg2); | - | ||||||||||||||||||
1121 | } executed 280 times by 1 test: end of block Executed by:
| 280 | ||||||||||||||||||
1122 | - | |||||||||||||||||||
1123 | sqlite3VdbeAddOp3(v, 30, csr, lbl, tmpReg); | - | ||||||||||||||||||
1124 | ; | - | ||||||||||||||||||
1125 | sqlite3VdbeAddOp3(v, 90, csr, pWin->iArgCol, pWin->regResult); | - | ||||||||||||||||||
1126 | sqlite3VdbeResolveLabel(v, lbl); | - | ||||||||||||||||||
1127 | sqlite3ReleaseTempReg(pParse, tmpReg); | - | ||||||||||||||||||
1128 | } executed 302 times by 1 test: end of block Executed by:
| 302 | ||||||||||||||||||
1129 | } executed 1811 times by 1 test: end of block Executed by:
| 1811 | ||||||||||||||||||
1130 | sqlite3VdbeAddOp2(v, 12, regGosub, addrGosub); | - | ||||||||||||||||||
1131 | } executed 1709 times by 1 test: end of block Executed by:
| 1709 | ||||||||||||||||||
1132 | static void windowReturnRows( | - | ||||||||||||||||||
1133 | Parse *pParse, | - | ||||||||||||||||||
1134 | Window *pMWin, | - | ||||||||||||||||||
1135 | int regCtr, | - | ||||||||||||||||||
1136 | int regGosub, | - | ||||||||||||||||||
1137 | int addrGosub, | - | ||||||||||||||||||
1138 | int regInvArg, | - | ||||||||||||||||||
1139 | int regInvSize | - | ||||||||||||||||||
1140 | ){ | - | ||||||||||||||||||
1141 | int addr; | - | ||||||||||||||||||
1142 | Vdbe *v = sqlite3GetVdbe(pParse); | - | ||||||||||||||||||
1143 | windowAggFinal(pParse, pMWin, 0); | - | ||||||||||||||||||
1144 | addr = sqlite3VdbeAddOp3(v, 47, regCtr, sqlite3VdbeCurrentAddr(v)+2 ,1); | - | ||||||||||||||||||
1145 | ; | - | ||||||||||||||||||
1146 | sqlite3VdbeAddOp2(v, 11, 0, 0); | - | ||||||||||||||||||
1147 | windowReturnOneRow(pParse, pMWin, regGosub, addrGosub); | - | ||||||||||||||||||
1148 | if( regInvArg
| 85-936 | ||||||||||||||||||
1149 | windowAggStep(pParse, pMWin, pMWin->iEphCsr, 1, regInvArg, regInvSize); | - | ||||||||||||||||||
1150 | } executed 85 times by 1 test: end of block Executed by:
| 85 | ||||||||||||||||||
1151 | sqlite3VdbeAddOp2(v, 5, pMWin->iEphCsr, addr); | - | ||||||||||||||||||
1152 | ; | - | ||||||||||||||||||
1153 | sqlite3VdbeJumpHere(v, addr+1); | - | ||||||||||||||||||
1154 | } executed 1021 times by 1 test: end of block Executed by:
| 1021 | ||||||||||||||||||
1155 | - | |||||||||||||||||||
1156 | - | |||||||||||||||||||
1157 | - | |||||||||||||||||||
1158 | - | |||||||||||||||||||
1159 | - | |||||||||||||||||||
1160 | - | |||||||||||||||||||
1161 | - | |||||||||||||||||||
1162 | static int windowInitAccum(Parse *pParse, Window *pMWin){ | - | ||||||||||||||||||
1163 | Vdbe *v = sqlite3GetVdbe(pParse); | - | ||||||||||||||||||
1164 | int regArg; | - | ||||||||||||||||||
1165 | int nArg = 0; | - | ||||||||||||||||||
1166 | Window *pWin; | - | ||||||||||||||||||
1167 | for(pWin=pMWin; pWin
| 1212-1292 | ||||||||||||||||||
1168 | FuncDef *pFunc = pWin->pFunc; | - | ||||||||||||||||||
1169 | sqlite3VdbeAddOp2(v, 73, 0, pWin->regAccum); | - | ||||||||||||||||||
1170 | nArg = ((
| 62-1230 | ||||||||||||||||||
1171 | if( pFunc->zName==nth_valueName
| 118-1174 | ||||||||||||||||||
1172 | || pFunc->zName==first_valueName
| 103-1071 | ||||||||||||||||||
1173 | ){ | - | ||||||||||||||||||
1174 | sqlite3VdbeAddOp2(v, 70, 0, pWin->regApp); | - | ||||||||||||||||||
1175 | sqlite3VdbeAddOp2(v, 70, 0, pWin->regApp+1); | - | ||||||||||||||||||
1176 | } executed 221 times by 1 test: end of block Executed by:
| 221 | ||||||||||||||||||
1177 | - | |||||||||||||||||||
1178 | if( (
| 8-1200 | ||||||||||||||||||
1179 | - | |||||||||||||||||||
1180 | ((void) (0)) | - | ||||||||||||||||||
1181 | ; | - | ||||||||||||||||||
1182 | sqlite3VdbeAddOp1(v, 139, pWin->csrApp); | - | ||||||||||||||||||
1183 | sqlite3VdbeAddOp2(v, 70, 0, pWin->regApp+1); | - | ||||||||||||||||||
1184 | } executed 84 times by 1 test: end of block Executed by:
| 84 | ||||||||||||||||||
1185 | } executed 1292 times by 1 test: end of block Executed by:
| 1292 | ||||||||||||||||||
1186 | regArg = pParse->nMem+1; | - | ||||||||||||||||||
1187 | pParse->nMem += nArg; | - | ||||||||||||||||||
1188 | return executed 1212 times by 1 test: regArg;return regArg; Executed by:
executed 1212 times by 1 test: return regArg; Executed by:
| 1212 | ||||||||||||||||||
1189 | } | - | ||||||||||||||||||
1190 | static void windowCodeRowExprStep( | - | ||||||||||||||||||
1191 | Parse *pParse, | - | ||||||||||||||||||
1192 | Select *p, | - | ||||||||||||||||||
1193 | WhereInfo *pWInfo, | - | ||||||||||||||||||
1194 | int regGosub, | - | ||||||||||||||||||
1195 | int addrGosub | - | ||||||||||||||||||
1196 | ){ | - | ||||||||||||||||||
1197 | Window *pMWin = p->pWin; | - | ||||||||||||||||||
1198 | Vdbe *v = sqlite3GetVdbe(pParse); | - | ||||||||||||||||||
1199 | int regFlushPart; | - | ||||||||||||||||||
1200 | int lblFlushPart; | - | ||||||||||||||||||
1201 | int lblFlushDone; | - | ||||||||||||||||||
1202 | - | |||||||||||||||||||
1203 | int regArg; | - | ||||||||||||||||||
1204 | int addr; | - | ||||||||||||||||||
1205 | int csrStart = pParse->nTab++; | - | ||||||||||||||||||
1206 | int csrEnd = pParse->nTab++; | - | ||||||||||||||||||
1207 | int regStart; | - | ||||||||||||||||||
1208 | int regEnd; | - | ||||||||||||||||||
1209 | int addrGoto; | - | ||||||||||||||||||
1210 | int addrTop; | - | ||||||||||||||||||
1211 | int addrIfPos1 = 0; | - | ||||||||||||||||||
1212 | int addrIfPos2 = 0; | - | ||||||||||||||||||
1213 | int regSize = 0; | - | ||||||||||||||||||
1214 | - | |||||||||||||||||||
1215 | - | |||||||||||||||||||
1216 | ((void) (0)) | - | ||||||||||||||||||
1217 | - | |||||||||||||||||||
1218 | - | |||||||||||||||||||
1219 | - | |||||||||||||||||||
1220 | - | |||||||||||||||||||
1221 | ; | - | ||||||||||||||||||
1222 | - | |||||||||||||||||||
1223 | ((void) (0)) | - | ||||||||||||||||||
1224 | - | |||||||||||||||||||
1225 | - | |||||||||||||||||||
1226 | - | |||||||||||||||||||
1227 | - | |||||||||||||||||||
1228 | ; | - | ||||||||||||||||||
1229 | - | |||||||||||||||||||
1230 | - | |||||||||||||||||||
1231 | regFlushPart = ++pParse->nMem; | - | ||||||||||||||||||
1232 | lblFlushPart = sqlite3VdbeMakeLabel(v); | - | ||||||||||||||||||
1233 | lblFlushDone = sqlite3VdbeMakeLabel(v); | - | ||||||||||||||||||
1234 | - | |||||||||||||||||||
1235 | regStart = ++pParse->nMem; | - | ||||||||||||||||||
1236 | regEnd = ++pParse->nMem; | - | ||||||||||||||||||
1237 | - | |||||||||||||||||||
1238 | windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, ®Size); | - | ||||||||||||||||||
1239 | - | |||||||||||||||||||
1240 | addrGoto = sqlite3VdbeAddOp0(v, 11); | - | ||||||||||||||||||
1241 | - | |||||||||||||||||||
1242 | - | |||||||||||||||||||
1243 | sqlite3VdbeResolveLabel(v, lblFlushPart); | - | ||||||||||||||||||
1244 | sqlite3VdbeAddOp2(v, 17, 0, sqlite3VdbeCurrentAddr(v)+3); | - | ||||||||||||||||||
1245 | ; | - | ||||||||||||||||||
1246 | ; | - | ||||||||||||||||||
1247 | sqlite3VdbeAddOp2(v, 111, csrStart, pMWin->iEphCsr); | - | ||||||||||||||||||
1248 | sqlite3VdbeAddOp2(v, 111, csrEnd, pMWin->iEphCsr); | - | ||||||||||||||||||
1249 | - | |||||||||||||||||||
1250 | - | |||||||||||||||||||
1251 | - | |||||||||||||||||||
1252 | if( pMWin->pStart
| 314-374 | ||||||||||||||||||
1253 | sqlite3ExprCode(pParse, pMWin->pStart, regStart); | - | ||||||||||||||||||
1254 | windowCheckIntValue(pParse, regStart, 0); | - | ||||||||||||||||||
1255 | } executed 374 times by 1 test: end of block Executed by:
| 374 | ||||||||||||||||||
1256 | if( pMWin->pEnd
| 319-369 | ||||||||||||||||||
1257 | sqlite3ExprCode(pParse, pMWin->pEnd, regEnd); | - | ||||||||||||||||||
1258 | windowCheckIntValue(pParse, regEnd, 1); | - | ||||||||||||||||||
1259 | } executed 369 times by 1 test: end of block Executed by:
| 369 | ||||||||||||||||||
1260 | if( pMWin->pEnd
| 66-369 | ||||||||||||||||||
1261 | - | |||||||||||||||||||
1262 | ((void) (0)) | - | ||||||||||||||||||
1263 | ; | - | ||||||||||||||||||
1264 | - | |||||||||||||||||||
1265 | ((void) (0)) | - | ||||||||||||||||||
1266 | ; | - | ||||||||||||||||||
1267 | sqlite3VdbeAddOp3(v, 57, regStart, sqlite3VdbeCurrentAddr(v)+2, regEnd); | - | ||||||||||||||||||
1268 | ; | - | ||||||||||||||||||
1269 | sqlite3VdbeAddOp2(v, 78, regSize, regStart); | - | ||||||||||||||||||
1270 | sqlite3VdbeAddOp3(v, 97, regStart, regEnd, regEnd); | - | ||||||||||||||||||
1271 | } executed 66 times by 1 test: end of block Executed by:
| 66 | ||||||||||||||||||
1272 | - | |||||||||||||||||||
1273 | if( pMWin->pStart
| 85-374 | ||||||||||||||||||
1274 | - | |||||||||||||||||||
1275 | ((void) (0)) | - | ||||||||||||||||||
1276 | ; | - | ||||||||||||||||||
1277 | - | |||||||||||||||||||
1278 | ((void) (0)) | - | ||||||||||||||||||
1279 | ; | - | ||||||||||||||||||
1280 | sqlite3VdbeAddOp3(v, 55, regStart, sqlite3VdbeCurrentAddr(v)+3, regEnd); | - | ||||||||||||||||||
1281 | ; | - | ||||||||||||||||||
1282 | sqlite3VdbeAddOp2(v, 78, regSize, regStart); | - | ||||||||||||||||||
1283 | sqlite3VdbeAddOp2(v, 78, regSize, regEnd); | - | ||||||||||||||||||
1284 | } executed 85 times by 1 test: end of block Executed by:
| 85 | ||||||||||||||||||
1285 | - | |||||||||||||||||||
1286 | - | |||||||||||||||||||
1287 | regArg = windowInitAccum(pParse, pMWin); | - | ||||||||||||||||||
1288 | - | |||||||||||||||||||
1289 | sqlite3VdbeAddOp2(v, 36, pMWin->iEphCsr, lblFlushDone); | - | ||||||||||||||||||
1290 | ; | - | ||||||||||||||||||
1291 | sqlite3VdbeAddOp2(v, 36, csrStart, lblFlushDone); | - | ||||||||||||||||||
1292 | ; | - | ||||||||||||||||||
1293 | sqlite3VdbeChangeP5(v, 1); | - | ||||||||||||||||||
1294 | sqlite3VdbeAddOp2(v, 36, csrEnd, lblFlushDone); | - | ||||||||||||||||||
1295 | ; | - | ||||||||||||||||||
1296 | sqlite3VdbeChangeP5(v, 1); | - | ||||||||||||||||||
1297 | - | |||||||||||||||||||
1298 | - | |||||||||||||||||||
1299 | - | |||||||||||||||||||
1300 | - | |||||||||||||||||||
1301 | addrTop = sqlite3VdbeCurrentAddr(v); | - | ||||||||||||||||||
1302 | if( pMWin->eEnd==85
| 128-560 | ||||||||||||||||||
1303 | addrIfPos1 = sqlite3VdbeAddOp3(v, 47, regEnd, 0 , 1); | - | ||||||||||||||||||
1304 | ; | - | ||||||||||||||||||
1305 | } executed 128 times by 1 test: end of block Executed by:
| 128 | ||||||||||||||||||
1306 | sqlite3VdbeAddOp2(v, 5, csrEnd, sqlite3VdbeCurrentAddr(v)+2); | - | ||||||||||||||||||
1307 | ; | - | ||||||||||||||||||
1308 | addr = sqlite3VdbeAddOp0(v, 11); | - | ||||||||||||||||||
1309 | windowAggStep(pParse, pMWin, csrEnd, 0, regArg, regSize); | - | ||||||||||||||||||
1310 | if( pMWin->eEnd==87
| 188-500 | ||||||||||||||||||
1311 | sqlite3VdbeAddOp2(v, 11, 0, addrTop); | - | ||||||||||||||||||
1312 | sqlite3VdbeJumpHere(v, addr); | - | ||||||||||||||||||
1313 | addrTop = sqlite3VdbeCurrentAddr(v); | - | ||||||||||||||||||
1314 | } executed 188 times by 1 test: else{end of block Executed by:
| 188 | ||||||||||||||||||
1315 | sqlite3VdbeJumpHere(v, addr); | - | ||||||||||||||||||
1316 | if( pMWin->eEnd==85
| 128-372 | ||||||||||||||||||
1317 | sqlite3VdbeJumpHere(v, addrIfPos1); | - | ||||||||||||||||||
1318 | } executed 128 times by 1 test: end of block Executed by:
| 128 | ||||||||||||||||||
1319 | } executed 500 times by 1 test: end of block Executed by:
| 500 | ||||||||||||||||||
1320 | - | |||||||||||||||||||
1321 | if( pMWin->eEnd==83
| 241-447 | ||||||||||||||||||
1322 | addrIfPos1 = sqlite3VdbeAddOp3(v, 47, regEnd, 0 , 1); | - | ||||||||||||||||||
1323 | ; | - | ||||||||||||||||||
1324 | } executed 241 times by 1 test: end of block Executed by:
| 241 | ||||||||||||||||||
1325 | if( pMWin->eStart==83
| 110-578 | ||||||||||||||||||
1326 | addrIfPos2 = sqlite3VdbeAddOp3(v, 47, regStart, 0 , 1); | - | ||||||||||||||||||
1327 | ; | - | ||||||||||||||||||
1328 | } executed 110 times by 1 test: end of block Executed by:
| 110 | ||||||||||||||||||
1329 | windowAggFinal(pParse, pMWin, 0); | - | ||||||||||||||||||
1330 | windowReturnOneRow(pParse, pMWin, regGosub, addrGosub); | - | ||||||||||||||||||
1331 | sqlite3VdbeAddOp2(v, 5, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)+2); | - | ||||||||||||||||||
1332 | ; | - | ||||||||||||||||||
1333 | sqlite3VdbeAddOp2(v, 11, 0, lblFlushDone); | - | ||||||||||||||||||
1334 | if( pMWin->eStart==83
| 110-578 | ||||||||||||||||||
1335 | sqlite3VdbeJumpHere(v, addrIfPos2); | - | ||||||||||||||||||
1336 | } executed 110 times by 1 test: end of block Executed by:
| 110 | ||||||||||||||||||
1337 | - | |||||||||||||||||||
1338 | if( pMWin->eStart==82
| 142-546 | ||||||||||||||||||
1339 | || pMWin->eStart==85
| 264-282 | ||||||||||||||||||
1340 | || pMWin->eStart==83
| 110-172 | ||||||||||||||||||
1341 | ){ | - | ||||||||||||||||||
1342 | int lblSkipInverse = sqlite3VdbeMakeLabel(v);; | - | ||||||||||||||||||
1343 | if( pMWin->eStart==85
| 252-264 | ||||||||||||||||||
1344 | sqlite3VdbeAddOp3(v, 47, regStart, lblSkipInverse, 1); | - | ||||||||||||||||||
1345 | ; | - | ||||||||||||||||||
1346 | } executed 264 times by 1 test: end of block Executed by:
| 264 | ||||||||||||||||||
1347 | if( pMWin->eStart==83
| 110-406 | ||||||||||||||||||
1348 | sqlite3VdbeAddOp2(v, 5, csrStart, sqlite3VdbeCurrentAddr(v)+2); | - | ||||||||||||||||||
1349 | ; | - | ||||||||||||||||||
1350 | sqlite3VdbeAddOp2(v, 11, 0, lblSkipInverse); | - | ||||||||||||||||||
1351 | } executed 110 times by 1 test: else{end of block Executed by:
| 110 | ||||||||||||||||||
1352 | sqlite3VdbeAddOp2(v, 5, csrStart, sqlite3VdbeCurrentAddr(v)+1); | - | ||||||||||||||||||
1353 | ; | - | ||||||||||||||||||
1354 | } executed 406 times by 1 test: end of block Executed by:
| 406 | ||||||||||||||||||
1355 | windowAggStep(pParse, pMWin, csrStart, 1, regArg, regSize); | - | ||||||||||||||||||
1356 | sqlite3VdbeResolveLabel(v, lblSkipInverse); | - | ||||||||||||||||||
1357 | } executed 516 times by 1 test: end of block Executed by:
| 516 | ||||||||||||||||||
1358 | if( pMWin->eEnd==83
| 241-447 | ||||||||||||||||||
1359 | sqlite3VdbeJumpHere(v, addrIfPos1); | - | ||||||||||||||||||
1360 | } executed 241 times by 1 test: end of block Executed by:
| 241 | ||||||||||||||||||
1361 | sqlite3VdbeAddOp2(v, 11, 0, addrTop); | - | ||||||||||||||||||
1362 | - | |||||||||||||||||||
1363 | - | |||||||||||||||||||
1364 | sqlite3VdbeResolveLabel(v, lblFlushDone); | - | ||||||||||||||||||
1365 | sqlite3VdbeAddOp1(v, 139, pMWin->iEphCsr); | - | ||||||||||||||||||
1366 | sqlite3VdbeAddOp1(v, 66, regFlushPart); | - | ||||||||||||||||||
1367 | ; | - | ||||||||||||||||||
1368 | - | |||||||||||||||||||
1369 | - | |||||||||||||||||||
1370 | sqlite3VdbeJumpHere(v, addrGoto); | - | ||||||||||||||||||
1371 | } executed 688 times by 1 test: end of block Executed by:
| 688 | ||||||||||||||||||
1372 | static void windowCodeCacheStep( | - | ||||||||||||||||||
1373 | Parse *pParse, | - | ||||||||||||||||||
1374 | Select *p, | - | ||||||||||||||||||
1375 | WhereInfo *pWInfo, | - | ||||||||||||||||||
1376 | int regGosub, | - | ||||||||||||||||||
1377 | int addrGosub | - | ||||||||||||||||||
1378 | ){ | - | ||||||||||||||||||
1379 | Window *pMWin = p->pWin; | - | ||||||||||||||||||
1380 | Vdbe *v = sqlite3GetVdbe(pParse); | - | ||||||||||||||||||
1381 | int k; | - | ||||||||||||||||||
1382 | int addr; | - | ||||||||||||||||||
1383 | ExprList *pPart = pMWin->pPartition; | - | ||||||||||||||||||
1384 | ExprList *pOrderBy = pMWin->pOrderBy; | - | ||||||||||||||||||
1385 | int nPeer = pOrderBy
| 3-521 | ||||||||||||||||||
1386 | int regNewPeer; | - | ||||||||||||||||||
1387 | - | |||||||||||||||||||
1388 | int addrGoto; | - | ||||||||||||||||||
1389 | int addrNext; | - | ||||||||||||||||||
1390 | int regFlushPart; | - | ||||||||||||||||||
1391 | int lblFlushPart; | - | ||||||||||||||||||
1392 | int csrLead; | - | ||||||||||||||||||
1393 | int regCtr; | - | ||||||||||||||||||
1394 | int regArg; | - | ||||||||||||||||||
1395 | int regSize; | - | ||||||||||||||||||
1396 | int lblEmpty; | - | ||||||||||||||||||
1397 | int bReverse = pMWin->pOrderBy
| 3-521 | ||||||||||||||||||
1398 | && pMWin->eEnd==87
| 24-61 | ||||||||||||||||||
1399 | - | |||||||||||||||||||
1400 | - | |||||||||||||||||||
1401 | ((void) (0)) | - | ||||||||||||||||||
1402 | - | |||||||||||||||||||
1403 | - | |||||||||||||||||||
1404 | - | |||||||||||||||||||
1405 | - | |||||||||||||||||||
1406 | ; | - | ||||||||||||||||||
1407 | - | |||||||||||||||||||
1408 | lblEmpty = sqlite3VdbeMakeLabel(v); | - | ||||||||||||||||||
1409 | regNewPeer = pParse->nMem+1; | - | ||||||||||||||||||
1410 | pParse->nMem += nPeer; | - | ||||||||||||||||||
1411 | - | |||||||||||||||||||
1412 | - | |||||||||||||||||||
1413 | regFlushPart = ++pParse->nMem; | - | ||||||||||||||||||
1414 | lblFlushPart = sqlite3VdbeMakeLabel(v); | - | ||||||||||||||||||
1415 | - | |||||||||||||||||||
1416 | csrLead = pParse->nTab++; | - | ||||||||||||||||||
1417 | regCtr = ++pParse->nMem; | - | ||||||||||||||||||
1418 | - | |||||||||||||||||||
1419 | windowPartitionCache(pParse, p, pWInfo, regFlushPart, lblFlushPart, ®Size); | - | ||||||||||||||||||
1420 | addrGoto = sqlite3VdbeAddOp0(v, 11); | - | ||||||||||||||||||
1421 | - | |||||||||||||||||||
1422 | - | |||||||||||||||||||
1423 | sqlite3VdbeResolveLabel(v, lblFlushPart); | - | ||||||||||||||||||
1424 | sqlite3VdbeAddOp2(v, 17, 0, sqlite3VdbeCurrentAddr(v)+2); | - | ||||||||||||||||||
1425 | ; | - | ||||||||||||||||||
1426 | sqlite3VdbeAddOp2(v, 111, csrLead, pMWin->iEphCsr); | - | ||||||||||||||||||
1427 | - | |||||||||||||||||||
1428 | - | |||||||||||||||||||
1429 | regArg = windowInitAccum(pParse, pMWin); | - | ||||||||||||||||||
1430 | - | |||||||||||||||||||
1431 | sqlite3VdbeAddOp2(v, 70, 0, regCtr); | - | ||||||||||||||||||
1432 | sqlite3VdbeAddOp2(v, 36, csrLead, lblEmpty); | - | ||||||||||||||||||
1433 | ; | - | ||||||||||||||||||
1434 | sqlite3VdbeAddOp2(v, 36, pMWin->iEphCsr, lblEmpty); | - | ||||||||||||||||||
1435 | ; | - | ||||||||||||||||||
1436 | - | |||||||||||||||||||
1437 | if( bReverse
| 61-463 | ||||||||||||||||||
1438 | int addr2 = sqlite3VdbeCurrentAddr(v); | - | ||||||||||||||||||
1439 | windowAggStep(pParse, pMWin, csrLead, 0, regArg, regSize); | - | ||||||||||||||||||
1440 | sqlite3VdbeAddOp2(v, 5, csrLead, addr2); | - | ||||||||||||||||||
1441 | ; | - | ||||||||||||||||||
1442 | sqlite3VdbeAddOp2(v, 36, csrLead, lblEmpty); | - | ||||||||||||||||||
1443 | ; | - | ||||||||||||||||||
1444 | } executed 61 times by 1 test: end of block Executed by:
| 61 | ||||||||||||||||||
1445 | addrNext = sqlite3VdbeCurrentAddr(v); | - | ||||||||||||||||||
1446 | - | |||||||||||||||||||
1447 | if( pOrderBy
| 3-521 | ||||||||||||||||||
1448 | int bCurrent = (pMWin->eStart==82); | - | ||||||||||||||||||
1449 | int addrJump = 0; | - | ||||||||||||||||||
1450 | if( pMWin->eType==86
| 151-346 | ||||||||||||||||||
1451 | int iOff = pMWin->nBufferCol + (pPart
| 165-181 | ||||||||||||||||||
1452 | int regPeer = pMWin->regPart + (pPart
| 165-181 | ||||||||||||||||||
1453 | KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0); | - | ||||||||||||||||||
1454 | for(k=0; k<nPeer
| 346-388 | ||||||||||||||||||
1455 | sqlite3VdbeAddOp3(v, 90, csrLead, iOff+k, regNewPeer+k); | - | ||||||||||||||||||
1456 | } executed 388 times by 1 test: end of block Executed by:
| 388 | ||||||||||||||||||
1457 | addr = sqlite3VdbeAddOp3(v, 87, regNewPeer, regPeer, nPeer); | - | ||||||||||||||||||
1458 | sqlite3VdbeAppendP4(v, (void*)pKeyInfo, (-9)); | - | ||||||||||||||||||
1459 | addrJump = sqlite3VdbeAddOp3(v, 16, addr+2, 0, addr+2); | - | ||||||||||||||||||
1460 | ; | - | ||||||||||||||||||
1461 | sqlite3VdbeAddOp3(v, 78, regNewPeer, regPeer, nPeer-1); | - | ||||||||||||||||||
1462 | } executed 346 times by 1 test: end of block Executed by:
| 346 | ||||||||||||||||||
1463 | - | |||||||||||||||||||
1464 | windowReturnRows(pParse, pMWin, regCtr, regGosub, addrGosub, | - | ||||||||||||||||||
1465 | (bCurrent ? regArg : 0), (bCurrent ? regSize : 0) | - | ||||||||||||||||||
1466 | ); | - | ||||||||||||||||||
1467 | if( addrJump
executed 346 times by 1 test: sqlite3VdbeJumpHere(v, addrJump); Executed by:
| 151-346 | ||||||||||||||||||
1468 | } executed 497 times by 1 test: end of block Executed by:
| 497 | ||||||||||||||||||
1469 | - | |||||||||||||||||||
1470 | if( bReverse==0
| 61-463 | ||||||||||||||||||
1471 | windowAggStep(pParse, pMWin, csrLead, 0, regArg, regSize); | - | ||||||||||||||||||
1472 | } executed 463 times by 1 test: end of block Executed by:
| 463 | ||||||||||||||||||
1473 | sqlite3VdbeAddOp2(v, 83, regCtr, 1); | - | ||||||||||||||||||
1474 | sqlite3VdbeAddOp2(v, 5, csrLead, addrNext); | - | ||||||||||||||||||
1475 | ; | - | ||||||||||||||||||
1476 | - | |||||||||||||||||||
1477 | windowReturnRows(pParse, pMWin, regCtr, regGosub, addrGosub, 0, 0); | - | ||||||||||||||||||
1478 | - | |||||||||||||||||||
1479 | sqlite3VdbeResolveLabel(v, lblEmpty); | - | ||||||||||||||||||
1480 | sqlite3VdbeAddOp1(v, 139, pMWin->iEphCsr); | - | ||||||||||||||||||
1481 | sqlite3VdbeAddOp1(v, 66, regFlushPart); | - | ||||||||||||||||||
1482 | - | |||||||||||||||||||
1483 | - | |||||||||||||||||||
1484 | sqlite3VdbeJumpHere(v, addrGoto); | - | ||||||||||||||||||
1485 | } executed 524 times by 1 test: end of block Executed by:
| 524 | ||||||||||||||||||
1486 | static void windowCodeDefaultStep( | - | ||||||||||||||||||
1487 | Parse *pParse, | - | ||||||||||||||||||
1488 | Select *p, | - | ||||||||||||||||||
1489 | WhereInfo *pWInfo, | - | ||||||||||||||||||
1490 | int regGosub, | - | ||||||||||||||||||
1491 | int addrGosub | - | ||||||||||||||||||
1492 | ){ | - | ||||||||||||||||||
1493 | Window *pMWin = p->pWin; | - | ||||||||||||||||||
1494 | Vdbe *v = sqlite3GetVdbe(pParse); | - | ||||||||||||||||||
1495 | int k; | - | ||||||||||||||||||
1496 | int iSubCsr = p->pSrc->a[0].iCursor; | - | ||||||||||||||||||
1497 | int nSub = p->pSrc->a[0].pTab->nCol; | - | ||||||||||||||||||
1498 | int reg = pParse->nMem+1; | - | ||||||||||||||||||
1499 | int regRecord = reg+nSub; | - | ||||||||||||||||||
1500 | int regRowid = regRecord+1; | - | ||||||||||||||||||
1501 | int addr; | - | ||||||||||||||||||
1502 | ExprList *pPart = pMWin->pPartition; | - | ||||||||||||||||||
1503 | ExprList *pOrderBy = pMWin->pOrderBy; | - | ||||||||||||||||||
1504 | - | |||||||||||||||||||
1505 | - | |||||||||||||||||||
1506 | ((void) (0)) | - | ||||||||||||||||||
1507 | - | |||||||||||||||||||
1508 | - | |||||||||||||||||||
1509 | ; | - | ||||||||||||||||||
1510 | - | |||||||||||||||||||
1511 | - | |||||||||||||||||||
1512 | ((void) (0)) | - | ||||||||||||||||||
1513 | - | |||||||||||||||||||
1514 | - | |||||||||||||||||||
1515 | - | |||||||||||||||||||
1516 | - | |||||||||||||||||||
1517 | ; | - | ||||||||||||||||||
1518 | - | |||||||||||||||||||
1519 | if( pMWin->eEnd==87
| 36-561 | ||||||||||||||||||
1520 | pOrderBy = 0; | - | ||||||||||||||||||
1521 | } executed 36 times by 1 test: end of block Executed by:
| 36 | ||||||||||||||||||
1522 | - | |||||||||||||||||||
1523 | pParse->nMem += nSub + 2; | - | ||||||||||||||||||
1524 | - | |||||||||||||||||||
1525 | - | |||||||||||||||||||
1526 | - | |||||||||||||||||||
1527 | for(k=0; k<nSub
| 597-2064 | ||||||||||||||||||
1528 | sqlite3VdbeAddOp3(v, 90, iSubCsr, k, reg+k); | - | ||||||||||||||||||
1529 | } executed 2064 times by 1 test: end of block Executed by:
| 2064 | ||||||||||||||||||
1530 | - | |||||||||||||||||||
1531 | - | |||||||||||||||||||
1532 | if( pPart
| 25-351 | ||||||||||||||||||
1533 | int nPart = (pPart
| 221-351 | ||||||||||||||||||
1534 | int addrGoto = 0; | - | ||||||||||||||||||
1535 | int addrJump = 0; | - | ||||||||||||||||||
1536 | int nPeer = (pOrderBy
| 42-530 | ||||||||||||||||||
1537 | - | |||||||||||||||||||
1538 | if( pPart
| 221-351 | ||||||||||||||||||
1539 | int regNewPart = reg + pMWin->nBufferCol; | - | ||||||||||||||||||
1540 | KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pPart, 0, 0); | - | ||||||||||||||||||
1541 | addr = sqlite3VdbeAddOp3(v, 87, regNewPart, pMWin->regPart,nPart); | - | ||||||||||||||||||
1542 | sqlite3VdbeAppendP4(v, (void*)pKeyInfo, (-9)); | - | ||||||||||||||||||
1543 | addrJump = sqlite3VdbeAddOp3(v, 16, addr+2, 0, addr+2); | - | ||||||||||||||||||
1544 | ; | - | ||||||||||||||||||
1545 | windowAggFinal(pParse, pMWin, 1); | - | ||||||||||||||||||
1546 | if( pOrderBy
| 42-309 | ||||||||||||||||||
1547 | addrGoto = sqlite3VdbeAddOp0(v, 11); | - | ||||||||||||||||||
1548 | } executed 309 times by 1 test: end of block Executed by:
| 309 | ||||||||||||||||||
1549 | } executed 351 times by 1 test: end of block Executed by:
| 351 | ||||||||||||||||||
1550 | - | |||||||||||||||||||
1551 | if( pOrderBy
| 42-530 | ||||||||||||||||||
1552 | int regNewPeer = reg + pMWin->nBufferCol + nPart; | - | ||||||||||||||||||
1553 | int regPeer = pMWin->regPart + nPart; | - | ||||||||||||||||||
1554 | - | |||||||||||||||||||
1555 | if( addrJump
executed 309 times by 1 test: sqlite3VdbeJumpHere(v, addrJump); Executed by:
| 221-309 | ||||||||||||||||||
1556 | if( pMWin->eType==86
| 76-454 | ||||||||||||||||||
1557 | KeyInfo *pKeyInfo = sqlite3KeyInfoFromExprList(pParse, pOrderBy, 0, 0); | - | ||||||||||||||||||
1558 | addr = sqlite3VdbeAddOp3(v, 87, regNewPeer, regPeer, nPeer); | - | ||||||||||||||||||
1559 | sqlite3VdbeAppendP4(v, (void*)pKeyInfo, (-9)); | - | ||||||||||||||||||
1560 | addrJump = sqlite3VdbeAddOp3(v, 16, addr+2, 0, addr+2); | - | ||||||||||||||||||
1561 | ; | - | ||||||||||||||||||
1562 | } executed 454 times by 1 test: else{end of block Executed by:
| 454 | ||||||||||||||||||
1563 | addrJump = 0; | - | ||||||||||||||||||
1564 | } executed 76 times by 1 test: end of block Executed by:
| 76 | ||||||||||||||||||
1565 | windowAggFinal(pParse, pMWin, pMWin->eStart==82); | - | ||||||||||||||||||
1566 | if( addrGoto
executed 309 times by 1 test: sqlite3VdbeJumpHere(v, addrGoto); Executed by:
| 221-309 | ||||||||||||||||||
1567 | } executed 530 times by 1 test: end of block Executed by:
| 530 | ||||||||||||||||||
1568 | - | |||||||||||||||||||
1569 | sqlite3VdbeAddOp2(v, 36, pMWin->iEphCsr,sqlite3VdbeCurrentAddr(v)+3); | - | ||||||||||||||||||
1570 | ; | - | ||||||||||||||||||
1571 | sqlite3VdbeAddOp2(v, 12, regGosub, addrGosub); | - | ||||||||||||||||||
1572 | sqlite3VdbeAddOp2(v, 5, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)-1); | - | ||||||||||||||||||
1573 | ; | - | ||||||||||||||||||
1574 | - | |||||||||||||||||||
1575 | sqlite3VdbeAddOp1(v, 139, pMWin->iEphCsr); | - | ||||||||||||||||||
1576 | sqlite3VdbeAddOp3( | - | ||||||||||||||||||
1577 | v, 78, reg+pMWin->nBufferCol, pMWin->regPart, nPart+nPeer-1 | - | ||||||||||||||||||
1578 | ); | - | ||||||||||||||||||
1579 | - | |||||||||||||||||||
1580 | if( addrJump
executed 496 times by 1 test: sqlite3VdbeJumpHere(v, addrJump); Executed by:
| 76-496 | ||||||||||||||||||
1581 | } executed 572 times by 1 test: end of block Executed by:
| 572 | ||||||||||||||||||
1582 | - | |||||||||||||||||||
1583 | - | |||||||||||||||||||
1584 | windowAggStep(pParse, pMWin, -1, 0, reg, 0); | - | ||||||||||||||||||
1585 | - | |||||||||||||||||||
1586 | - | |||||||||||||||||||
1587 | if( pMWin->nBufferCol>0
| 239-358 | ||||||||||||||||||
1588 | sqlite3VdbeAddOp3(v, 102, reg, pMWin->nBufferCol, regRecord); | - | ||||||||||||||||||
1589 | } executed 239 times by 1 test: else{end of block Executed by:
| 239 | ||||||||||||||||||
1590 | sqlite3VdbeAddOp2(v, 75, 0, regRecord); | - | ||||||||||||||||||
1591 | sqlite3VdbeAppendP4(v, (void*)"", 0); | - | ||||||||||||||||||
1592 | } executed 358 times by 1 test: end of block Executed by:
| 358 | ||||||||||||||||||
1593 | sqlite3VdbeAddOp2(v, 121, pMWin->iEphCsr, regRowid); | - | ||||||||||||||||||
1594 | sqlite3VdbeAddOp3(v, 122, pMWin->iEphCsr, regRecord, regRowid); | - | ||||||||||||||||||
1595 | - | |||||||||||||||||||
1596 | - | |||||||||||||||||||
1597 | sqlite3WhereEnd(pWInfo); | - | ||||||||||||||||||
1598 | - | |||||||||||||||||||
1599 | windowAggFinal(pParse, pMWin, 1); | - | ||||||||||||||||||
1600 | sqlite3VdbeAddOp2(v, 36, pMWin->iEphCsr,sqlite3VdbeCurrentAddr(v)+3); | - | ||||||||||||||||||
1601 | ; | - | ||||||||||||||||||
1602 | sqlite3VdbeAddOp2(v, 12, regGosub, addrGosub); | - | ||||||||||||||||||
1603 | sqlite3VdbeAddOp2(v, 5, pMWin->iEphCsr, sqlite3VdbeCurrentAddr(v)-1); | - | ||||||||||||||||||
1604 | ; | - | ||||||||||||||||||
1605 | } executed 597 times by 1 test: end of block Executed by:
| 597 | ||||||||||||||||||
1606 | - | |||||||||||||||||||
1607 | - | |||||||||||||||||||
1608 | - | |||||||||||||||||||
1609 | - | |||||||||||||||||||
1610 | - | |||||||||||||||||||
1611 | - | |||||||||||||||||||
1612 | Window *sqlite3WindowDup(sqlite3 *db, Expr *pOwner, Window *p){ | - | ||||||||||||||||||
1613 | Window *pNew = 0; | - | ||||||||||||||||||
1614 | if( (
| 0-240 | ||||||||||||||||||
1615 | pNew = sqlite3DbMallocZero(db, sizeof(Window)); | - | ||||||||||||||||||
1616 | if( pNew
| 0-240 | ||||||||||||||||||
1617 | pNew->zName = sqlite3DbStrDup(db, p->zName); | - | ||||||||||||||||||
1618 | pNew->pFilter = sqlite3ExprDup(db, p->pFilter, 0); | - | ||||||||||||||||||
1619 | pNew->pPartition = sqlite3ExprListDup(db, p->pPartition, 0); | - | ||||||||||||||||||
1620 | pNew->pOrderBy = sqlite3ExprListDup(db, p->pOrderBy, 0); | - | ||||||||||||||||||
1621 | pNew->eType = p->eType; | - | ||||||||||||||||||
1622 | pNew->eEnd = p->eEnd; | - | ||||||||||||||||||
1623 | pNew->eStart = p->eStart; | - | ||||||||||||||||||
1624 | pNew->pStart = sqlite3ExprDup(db, p->pStart, 0); | - | ||||||||||||||||||
1625 | pNew->pEnd = sqlite3ExprDup(db, p->pEnd, 0); | - | ||||||||||||||||||
1626 | pNew->pOwner = pOwner; | - | ||||||||||||||||||
1627 | } executed 240 times by 1 test: end of block Executed by:
| 240 | ||||||||||||||||||
1628 | } executed 240 times by 1 test: end of block Executed by:
| 240 | ||||||||||||||||||
1629 | return executed 240 times by 1 test: pNew;return pNew; Executed by:
executed 240 times by 1 test: return pNew; Executed by:
| 240 | ||||||||||||||||||
1630 | } | - | ||||||||||||||||||
1631 | - | |||||||||||||||||||
1632 | - | |||||||||||||||||||
1633 | - | |||||||||||||||||||
1634 | - | |||||||||||||||||||
1635 | - | |||||||||||||||||||
1636 | Window *sqlite3WindowListDup(sqlite3 *db, Window *p){ | - | ||||||||||||||||||
1637 | Window *pWin; | - | ||||||||||||||||||
1638 | Window *pRet = 0; | - | ||||||||||||||||||
1639 | Window **pp = &pRet; | - | ||||||||||||||||||
1640 | - | |||||||||||||||||||
1641 | for(pWin=p; pWin
| 12-523667 | ||||||||||||||||||
1642 | *pp = sqlite3WindowDup(db, 0, pWin); | - | ||||||||||||||||||
1643 | if( *
never executed: break; | 0-12 | ||||||||||||||||||
1644 | pp = &((*pp)->pNextWin); | - | ||||||||||||||||||
1645 | } executed 12 times by 1 test: end of block Executed by:
| 12 | ||||||||||||||||||
1646 | - | |||||||||||||||||||
1647 | return executed 523667 times by 7 tests: pRet;return pRet; Executed by:
executed 523667 times by 7 tests: return pRet; Executed by:
| 523667 | ||||||||||||||||||
1648 | } | - | ||||||||||||||||||
1649 | void sqlite3WindowCodeStep( | - | ||||||||||||||||||
1650 | Parse *pParse, | - | ||||||||||||||||||
1651 | Select *p, | - | ||||||||||||||||||
1652 | WhereInfo *pWInfo, | - | ||||||||||||||||||
1653 | int regGosub, | - | ||||||||||||||||||
1654 | int addrGosub | - | ||||||||||||||||||
1655 | ){ | - | ||||||||||||||||||
1656 | Window *pMWin = p->pWin; | - | ||||||||||||||||||
1657 | if( pMWin->eType==76
| 894-915 | ||||||||||||||||||
1658 | && (pMWin->eStart!=87
| 36-516 | ||||||||||||||||||
1659 | ){ | - | ||||||||||||||||||
1660 | ; | - | ||||||||||||||||||
1661 | windowCodeRowExprStep(pParse, p, pWInfo, regGosub, addrGosub); | - | ||||||||||||||||||
1662 | } executed 688 times by 1 test: else{end of block Executed by:
| 688 | ||||||||||||||||||
1663 | Window *pWin; | - | ||||||||||||||||||
1664 | int bCache = 0; | - | ||||||||||||||||||
1665 | - | |||||||||||||||||||
1666 | if( pMWin->eStart==82
| 59-1000 | ||||||||||||||||||
1667 | bCache = 1; | - | ||||||||||||||||||
1668 | } executed 62 times by 1 test: else{end of block Executed by:
| 62 | ||||||||||||||||||
1669 | for(pWin=pMWin; pWin
| 597-1128 | ||||||||||||||||||
1670 | FuncDef *pFunc = pWin->pFunc; | - | ||||||||||||||||||
1671 | if( (
| 333-795 | ||||||||||||||||||
1672 | || (
| 38-757 | ||||||||||||||||||
1673 | || (
| 24-733 | ||||||||||||||||||
1674 | || (
| 38-695 | ||||||||||||||||||
1675 | || (
| 29-666 | ||||||||||||||||||
1676 | ){ | - | ||||||||||||||||||
1677 | bCache = 1; | - | ||||||||||||||||||
1678 | break; executed 462 times by 1 test: break; Executed by:
| 462 | ||||||||||||||||||
1679 | } | - | ||||||||||||||||||
1680 | } executed 666 times by 1 test: end of block Executed by:
| 666 | ||||||||||||||||||
1681 | } executed 1059 times by 1 test: end of block Executed by:
| 1059 | ||||||||||||||||||
1682 | - | |||||||||||||||||||
1683 | - | |||||||||||||||||||
1684 | if( bCache
| 524-597 | ||||||||||||||||||
1685 | ; | - | ||||||||||||||||||
1686 | windowCodeCacheStep(pParse, p, pWInfo, regGosub, addrGosub); | - | ||||||||||||||||||
1687 | } executed 524 times by 1 test: else{end of block Executed by:
| 524 | ||||||||||||||||||
1688 | ; | - | ||||||||||||||||||
1689 | windowCodeDefaultStep(pParse, p, pWInfo, regGosub, addrGosub); | - | ||||||||||||||||||
1690 | } executed 597 times by 1 test: end of block Executed by:
| 597 | ||||||||||||||||||
1691 | } | - | ||||||||||||||||||
1692 | } | - | ||||||||||||||||||
Switch to Source code | Preprocessed file |