Fossil SCM

Update the built-in SQLite to a version that supports ORDER BY and LIMIT on WITH RECURSIVE queries (but omits support for the non-standard LEVEL pseudo-column). Rewrite the recursive query that computes ancestors to using ORDER BY and LIMIT and omit the use of LEVEL.

drh 2014-01-22 18:19 trunk
Commit af990795fcd3c19773a239157d3e2ac729e02501
--- src/descendants.c
+++ src/descendants.c
@@ -166,17 +166,15 @@
166166
" UNION "
167167
" SELECT plink.pid, event.mtime"
168168
" FROM ancestor, plink, event"
169169
" WHERE plink.cid=ancestor.rid"
170170
" AND event.objid=plink.pid %s"
171
- " AND level<%d"
171
+ " ORDER BY mtime DESC LIMIT %d"
172172
" )"
173173
"INSERT INTO ok"
174
- " SELECT rid FROM ancestor "
175
- " ORDER BY mtime DESC"
176
- " LIMIT %d;",
177
- rid, rid, directOnly ? "AND plink.isPrim" : "", N, N
174
+ " SELECT rid FROM ancestor;",
175
+ rid, rid, directOnly ? "AND plink.isPrim" : "", N
178176
);
179177
}
180178
181179
/*
182180
** Compute up to N direct ancestors (merge ancestors do not count)
183181
--- src/descendants.c
+++ src/descendants.c
@@ -166,17 +166,15 @@
166 " UNION "
167 " SELECT plink.pid, event.mtime"
168 " FROM ancestor, plink, event"
169 " WHERE plink.cid=ancestor.rid"
170 " AND event.objid=plink.pid %s"
171 " AND level<%d"
172 " )"
173 "INSERT INTO ok"
174 " SELECT rid FROM ancestor "
175 " ORDER BY mtime DESC"
176 " LIMIT %d;",
177 rid, rid, directOnly ? "AND plink.isPrim" : "", N, N
178 );
179 }
180
181 /*
182 ** Compute up to N direct ancestors (merge ancestors do not count)
183
--- src/descendants.c
+++ src/descendants.c
@@ -166,17 +166,15 @@
166 " UNION "
167 " SELECT plink.pid, event.mtime"
168 " FROM ancestor, plink, event"
169 " WHERE plink.cid=ancestor.rid"
170 " AND event.objid=plink.pid %s"
171 " ORDER BY mtime DESC LIMIT %d"
172 " )"
173 "INSERT INTO ok"
174 " SELECT rid FROM ancestor;",
175 rid, rid, directOnly ? "AND plink.isPrim" : "", N
 
 
176 );
177 }
178
179 /*
180 ** Compute up to N direct ancestors (merge ancestors do not count)
181
+497 -431
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135135
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136136
** [sqlite_version()] and [sqlite_source_id()].
137137
*/
138138
#define SQLITE_VERSION "3.8.3"
139139
#define SQLITE_VERSION_NUMBER 3008003
140
-#define SQLITE_SOURCE_ID "2014-01-21 00:19:43 cc1cb3217800ff666a00bf4f544a5a477589bc1b"
140
+#define SQLITE_SOURCE_ID "2014-01-22 18:16:27 b6cea42006910d590373e8f9e296d7672edb114b"
141141
142142
/*
143143
** CAPI3REF: Run-Time Library Version Numbers
144144
** KEYWORDS: sqlite3_version, sqlite3_sourceid
145145
**
@@ -8200,11 +8200,10 @@
82008200
#define TK_AGG_FUNCTION 155
82018201
#define TK_AGG_COLUMN 156
82028202
#define TK_UMINUS 157
82038203
#define TK_UPLUS 158
82048204
#define TK_REGISTER 159
8205
-#define TK_LEVEL 160
82068205
82078206
/************** End of parse.h ***********************************************/
82088207
/************** Continuing where we left off in sqliteInt.h ******************/
82098208
#include <stdio.h>
82108209
#include <stdlib.h>
@@ -9129,41 +9128,41 @@
91299128
#define OP_VerifyCookie 49
91309129
#define OP_OpenRead 50 /* synopsis: root=P2 iDb=P3 */
91319130
#define OP_OpenWrite 51 /* synopsis: root=P2 iDb=P3 */
91329131
#define OP_OpenAutoindex 52 /* synopsis: nColumn=P2 */
91339132
#define OP_OpenEphemeral 53 /* synopsis: nColumn=P2 */
9134
-#define OP_SwapCursors 54
9135
-#define OP_SorterOpen 55
9136
-#define OP_OpenPseudo 56 /* synopsis: content in r[P2@P3] */
9137
-#define OP_Close 57
9138
-#define OP_SeekLt 58 /* synopsis: key=r[P3@P4] */
9139
-#define OP_SeekLe 59 /* synopsis: key=r[P3@P4] */
9140
-#define OP_SeekGe 60 /* synopsis: key=r[P3@P4] */
9141
-#define OP_SeekGt 61 /* synopsis: key=r[P3@P4] */
9142
-#define OP_Seek 62 /* synopsis: intkey=r[P2] */
9143
-#define OP_NoConflict 63 /* synopsis: key=r[P3@P4] */
9144
-#define OP_NotFound 64 /* synopsis: key=r[P3@P4] */
9145
-#define OP_Found 65 /* synopsis: key=r[P3@P4] */
9146
-#define OP_NotExists 66 /* synopsis: intkey=r[P3] */
9147
-#define OP_Sequence 67 /* synopsis: r[P2]=rowid */
9148
-#define OP_NewRowid 68 /* synopsis: r[P2]=rowid */
9149
-#define OP_Insert 69 /* synopsis: intkey=r[P3] data=r[P2] */
9150
-#define OP_InsertInt 70 /* synopsis: intkey=P3 data=r[P2] */
9133
+#define OP_SorterOpen 54
9134
+#define OP_OpenPseudo 55 /* synopsis: content in r[P2@P3] */
9135
+#define OP_Close 56
9136
+#define OP_SeekLt 57 /* synopsis: key=r[P3@P4] */
9137
+#define OP_SeekLe 58 /* synopsis: key=r[P3@P4] */
9138
+#define OP_SeekGe 59 /* synopsis: key=r[P3@P4] */
9139
+#define OP_SeekGt 60 /* synopsis: key=r[P3@P4] */
9140
+#define OP_Seek 61 /* synopsis: intkey=r[P2] */
9141
+#define OP_NoConflict 62 /* synopsis: key=r[P3@P4] */
9142
+#define OP_NotFound 63 /* synopsis: key=r[P3@P4] */
9143
+#define OP_Found 64 /* synopsis: key=r[P3@P4] */
9144
+#define OP_NotExists 65 /* synopsis: intkey=r[P3] */
9145
+#define OP_Sequence 66 /* synopsis: r[P2]=rowid */
9146
+#define OP_NewRowid 67 /* synopsis: r[P2]=rowid */
9147
+#define OP_Insert 68 /* synopsis: intkey=r[P3] data=r[P2] */
9148
+#define OP_InsertInt 69 /* synopsis: intkey=P3 data=r[P2] */
9149
+#define OP_Delete 70
91519150
#define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
91529151
#define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9153
-#define OP_Delete 73
9154
-#define OP_ResetCount 74
9155
-#define OP_SorterCompare 75 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9152
+#define OP_ResetCount 73
9153
+#define OP_SorterCompare 74 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9154
+#define OP_SorterData 75 /* synopsis: r[P2]=data */
91569155
#define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
91579156
#define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
91589157
#define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
91599158
#define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
91609159
#define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
91619160
#define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
91629161
#define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
91639162
#define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9164
-#define OP_SorterData 84 /* synopsis: r[P2]=data */
9163
+#define OP_RowKey 84 /* synopsis: r[P2]=key */
91659164
#define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
91669165
#define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
91679166
#define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
91689167
#define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
91699168
#define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9170,69 +9169,68 @@
91709169
#define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
91719170
#define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
91729171
#define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
91739172
#define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
91749173
#define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9175
-#define OP_RowKey 95 /* synopsis: r[P2]=key */
9174
+#define OP_RowData 95 /* synopsis: r[P2]=data */
91769175
#define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
91779176
#define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9178
-#define OP_RowData 98 /* synopsis: r[P2]=data */
9179
-#define OP_Rowid 99 /* synopsis: r[P2]=rowid */
9180
-#define OP_NullRow 100
9181
-#define OP_Last 101
9182
-#define OP_SorterSort 102
9183
-#define OP_Sort 103
9184
-#define OP_Rewind 104
9185
-#define OP_SorterInsert 105
9186
-#define OP_IdxInsert 106 /* synopsis: key=r[P2] */
9187
-#define OP_IdxDelete 107 /* synopsis: key=r[P2@P3] */
9188
-#define OP_IdxRowid 108 /* synopsis: r[P2]=rowid */
9189
-#define OP_IdxLT 109 /* synopsis: key=r[P3@P4] */
9190
-#define OP_IdxGE 110 /* synopsis: key=r[P3@P4] */
9191
-#define OP_Destroy 111
9192
-#define OP_Clear 112
9193
-#define OP_CreateIndex 113 /* synopsis: r[P2]=root iDb=P1 */
9194
-#define OP_CreateTable 114 /* synopsis: r[P2]=root iDb=P1 */
9195
-#define OP_ParseSchema 115
9196
-#define OP_LoadAnalysis 116
9197
-#define OP_DropTable 117
9198
-#define OP_DropIndex 118
9199
-#define OP_DropTrigger 119
9200
-#define OP_IntegrityCk 120
9201
-#define OP_RowSetAdd 121 /* synopsis: rowset(P1)=r[P2] */
9202
-#define OP_RowSetRead 122 /* synopsis: r[P3]=rowset(P1) */
9203
-#define OP_RowSetTest 123 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9204
-#define OP_Program 124
9205
-#define OP_Param 125
9206
-#define OP_FkCounter 126 /* synopsis: fkctr[P1]+=P2 */
9207
-#define OP_FkIfZero 127 /* synopsis: if fkctr[P1]==0 goto P2 */
9208
-#define OP_MemMax 128 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9209
-#define OP_IfPos 129 /* synopsis: if r[P1]>0 goto P2 */
9210
-#define OP_IfNeg 130 /* synopsis: if r[P1]<0 goto P2 */
9211
-#define OP_IfZero 131 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9212
-#define OP_AggFinal 132 /* synopsis: accum=r[P1] N=P2 */
9177
+#define OP_Rowid 98 /* synopsis: r[P2]=rowid */
9178
+#define OP_NullRow 99
9179
+#define OP_Last 100
9180
+#define OP_SorterSort 101
9181
+#define OP_Sort 102
9182
+#define OP_Rewind 103
9183
+#define OP_SorterInsert 104
9184
+#define OP_IdxInsert 105 /* synopsis: key=r[P2] */
9185
+#define OP_IdxDelete 106 /* synopsis: key=r[P2@P3] */
9186
+#define OP_IdxRowid 107 /* synopsis: r[P2]=rowid */
9187
+#define OP_IdxLT 108 /* synopsis: key=r[P3@P4] */
9188
+#define OP_IdxGE 109 /* synopsis: key=r[P3@P4] */
9189
+#define OP_Destroy 110
9190
+#define OP_Clear 111
9191
+#define OP_CreateIndex 112 /* synopsis: r[P2]=root iDb=P1 */
9192
+#define OP_CreateTable 113 /* synopsis: r[P2]=root iDb=P1 */
9193
+#define OP_ParseSchema 114
9194
+#define OP_LoadAnalysis 115
9195
+#define OP_DropTable 116
9196
+#define OP_DropIndex 117
9197
+#define OP_DropTrigger 118
9198
+#define OP_IntegrityCk 119
9199
+#define OP_RowSetAdd 120 /* synopsis: rowset(P1)=r[P2] */
9200
+#define OP_RowSetRead 121 /* synopsis: r[P3]=rowset(P1) */
9201
+#define OP_RowSetTest 122 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9202
+#define OP_Program 123
9203
+#define OP_Param 124
9204
+#define OP_FkCounter 125 /* synopsis: fkctr[P1]+=P2 */
9205
+#define OP_FkIfZero 126 /* synopsis: if fkctr[P1]==0 goto P2 */
9206
+#define OP_MemMax 127 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9207
+#define OP_IfPos 128 /* synopsis: if r[P1]>0 goto P2 */
9208
+#define OP_IfNeg 129 /* synopsis: if r[P1]<0 goto P2 */
9209
+#define OP_IfZero 130 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9210
+#define OP_AggFinal 131 /* synopsis: accum=r[P1] N=P2 */
9211
+#define OP_IncrVacuum 132
92139212
#define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9214
-#define OP_IncrVacuum 134
9215
-#define OP_Expire 135
9216
-#define OP_TableLock 136 /* synopsis: iDb=P1 root=P2 write=P3 */
9217
-#define OP_VBegin 137
9218
-#define OP_VCreate 138
9219
-#define OP_VDestroy 139
9220
-#define OP_VOpen 140
9221
-#define OP_VColumn 141 /* synopsis: r[P3]=vcolumn(P2) */
9222
-#define OP_VNext 142
9213
+#define OP_Expire 134
9214
+#define OP_TableLock 135 /* synopsis: iDb=P1 root=P2 write=P3 */
9215
+#define OP_VBegin 136
9216
+#define OP_VCreate 137
9217
+#define OP_VDestroy 138
9218
+#define OP_VOpen 139
9219
+#define OP_VColumn 140 /* synopsis: r[P3]=vcolumn(P2) */
9220
+#define OP_VNext 141
9221
+#define OP_VRename 142
92239222
#define OP_ToText 143 /* same as TK_TO_TEXT */
92249223
#define OP_ToBlob 144 /* same as TK_TO_BLOB */
92259224
#define OP_ToNumeric 145 /* same as TK_TO_NUMERIC */
92269225
#define OP_ToInt 146 /* same as TK_TO_INT */
92279226
#define OP_ToReal 147 /* same as TK_TO_REAL */
9228
-#define OP_VRename 148
9229
-#define OP_Pagecount 149
9230
-#define OP_MaxPgcnt 150
9231
-#define OP_Trace 151
9232
-#define OP_Noop 152
9233
-#define OP_Explain 153
9227
+#define OP_Pagecount 148
9228
+#define OP_MaxPgcnt 149
9229
+#define OP_Trace 150
9230
+#define OP_Noop 151
9231
+#define OP_Explain 152
92349232
92359233
92369234
/* Properties such as "out2" or "jump" that are specified in
92379235
** comments following the "case" for each opcode in the vdbe.c
92389236
** are encoded into bitvectors as follows:
@@ -9250,23 +9248,23 @@
92509248
/* 16 */ 0x01, 0x01, 0x04, 0x24, 0x04, 0x10, 0x00, 0x02,\
92519249
/* 24 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x20,\
92529250
/* 32 */ 0x00, 0x00, 0x04, 0x05, 0x04, 0x00, 0x00, 0x01,\
92539251
/* 40 */ 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x02,\
92549252
/* 48 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9255
-/* 56 */ 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x08, 0x11,\
9256
-/* 64 */ 0x11, 0x11, 0x11, 0x02, 0x02, 0x00, 0x00, 0x4c,\
9253
+/* 56 */ 0x00, 0x11, 0x11, 0x11, 0x11, 0x08, 0x11, 0x11,\
9254
+/* 64 */ 0x11, 0x11, 0x02, 0x02, 0x00, 0x00, 0x00, 0x4c,\
92579255
/* 72 */ 0x4c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
92589256
/* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
92599257
/* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9260
-/* 96 */ 0x24, 0x02, 0x00, 0x02, 0x00, 0x01, 0x01, 0x01,\
9261
-/* 104 */ 0x01, 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02,\
9262
-/* 112 */ 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,\
9263
-/* 120 */ 0x00, 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01,\
9264
-/* 128 */ 0x08, 0x05, 0x05, 0x05, 0x00, 0x02, 0x01, 0x00,\
9265
-/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04,\
9266
-/* 144 */ 0x04, 0x04, 0x04, 0x04, 0x00, 0x02, 0x02, 0x00,\
9267
-/* 152 */ 0x00, 0x00,}
9258
+/* 96 */ 0x24, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01,\
9259
+/* 104 */ 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00,\
9260
+/* 112 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9261
+/* 120 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
9262
+/* 128 */ 0x05, 0x05, 0x05, 0x00, 0x01, 0x02, 0x00, 0x00,\
9263
+/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,\
9264
+/* 144 */ 0x04, 0x04, 0x04, 0x04, 0x02, 0x02, 0x00, 0x00,\
9265
+/* 152 */ 0x00,}
92689266
92699267
/************** End of opcodes.h *********************************************/
92709268
/************** Continuing where we left off in vdbe.h ***********************/
92719269
92729270
/*
@@ -11430,12 +11428,10 @@
1143011428
#define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */
1143111429
#define NC_HasAgg 0x02 /* One or more aggregate functions seen */
1143211430
#define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */
1143311431
#define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */
1143411432
#define NC_PartIdx 0x10 /* True if resolving a partial index WHERE */
11435
-#define NC_Recursive 0x20 /* Resolvingn a recursive CTE definition */
11436
-#define NC_UsesLevel 0x40 /* The LEVEL pseudo-column has been seen */
1143711433
1143811434
/*
1143911435
** An instance of the following structure contains all information
1144011436
** needed to generate code for a single SELECT statement.
1144111437
**
@@ -11489,16 +11485,73 @@
1148911485
#define SF_Values 0x0080 /* Synthesized from VALUES clause */
1149011486
#define SF_Materialize 0x0100 /* Force materialization of views */
1149111487
#define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
1149211488
#define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
1149311489
#define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
11494
-#define SF_UsesLevel 0x1000 /* Uses the LEVEL pseudo-column */
1149511490
1149611491
1149711492
/*
11498
-** The results of a select can be distributed in several ways. The
11499
-** "SRT" prefix means "SELECT Result Type".
11493
+** The results of a SELECT can be distributed in several ways, as defined
11494
+** by one of the following macros. The "SRT" prefix means "SELECT Result
11495
+** Type".
11496
+**
11497
+** SRT_Union Store results as a key in a temporary index
11498
+** identified by pDest->iSDParm.
11499
+**
11500
+** SRT_Except Remove results from the temporary index pDest->iSDParm.
11501
+**
11502
+** SRT_Exists Store a 1 in memory cell pDest->iSDParm if the result
11503
+** set is not empty.
11504
+**
11505
+** SRT_Discard Throw the results away. This is used by SELECT
11506
+** statements within triggers whose only purpose is
11507
+** the side-effects of functions.
11508
+**
11509
+** All of the above are free to ignore their ORDER BY clause. Those that
11510
+** follow must honor the ORDER BY clause.
11511
+**
11512
+** SRT_Output Generate a row of output (using the OP_ResultRow
11513
+** opcode) for each row in the result set.
11514
+**
11515
+** SRT_Mem Only valid if the result is a single column.
11516
+** Store the first column of the first result row
11517
+** in register pDest->iSDParm then abandon the rest
11518
+** of the query. This destination implies "LIMIT 1".
11519
+**
11520
+** SRT_Set The result must be a single column. Store each
11521
+** row of result as the key in table pDest->iSDParm.
11522
+** Apply the affinity pDest->affSdst before storing
11523
+** results. Used to implement "IN (SELECT ...)".
11524
+**
11525
+** SRT_EphemTab Create an temporary table pDest->iSDParm and store
11526
+** the result there. The cursor is left open after
11527
+** returning. This is like SRT_Table except that
11528
+** this destination uses OP_OpenEphemeral to create
11529
+** the table first.
11530
+**
11531
+** SRT_Coroutine Generate a co-routine that returns a new row of
11532
+** results each time it is invoked. The entry point
11533
+** of the co-routine is stored in register pDest->iSDParm
11534
+** and the result row is stored in pDest->nDest registers
11535
+** starting with pDest->iSdst.
11536
+**
11537
+** SRT_Table Store results in temporary table pDest->iSDParm.
11538
+** This is like SRT_EphemTab except that the table
11539
+** is assumed to already be open.
11540
+**
11541
+** SRT_DistTable Store results in a temporary table pDest->iSDParm.
11542
+** But also use temporary table pDest->iSDParm+1 as
11543
+** a record of all prior results and ignore any duplicate
11544
+** rows. Name means: "Distinct Table".
11545
+**
11546
+** SRT_Queue Store results in priority queue pDest->iSDParm (really
11547
+** an index). Append a sequence number so that all entries
11548
+** are distinct.
11549
+**
11550
+** SRT_DistQueue Store results in priority queue pDest->iSDParm only if
11551
+** the same record has never been stored before. The
11552
+** index at pDest->iSDParm+1 hold all prior stores.
1150011553
*/
1150111554
#define SRT_Union 1 /* Store result as keys in an index */
1150211555
#define SRT_Except 2 /* Remove result from a UNION index */
1150311556
#define SRT_Exists 3 /* Store 1 if the result is not empty */
1150411557
#define SRT_Discard 4 /* Do not save the results anywhere */
@@ -11507,25 +11560,28 @@
1150711560
#define IgnorableOrderby(X) ((X->eDest)<=SRT_Discard)
1150811561
1150911562
#define SRT_Output 5 /* Output each row of result */
1151011563
#define SRT_Mem 6 /* Store result in a memory cell */
1151111564
#define SRT_Set 7 /* Store results as keys in an index */
11512
-#define SRT_Table 8 /* Store result as data with an automatic rowid */
11513
-#define SRT_EphemTab 9 /* Create transient tab and store like SRT_Table */
11514
-#define SRT_Coroutine 10 /* Generate a single row of result */
11515
-#define SRT_DistTable 11 /* Like SRT_TABLE, but unique results only */
11565
+#define SRT_EphemTab 8 /* Create transient tab and store like SRT_Table */
11566
+#define SRT_Coroutine 9 /* Generate a single row of result */
11567
+#define SRT_Table 10 /* Store result as data with an automatic rowid */
11568
+#define SRT_DistTable 11 /* Like SRT_Table, but unique results only */
11569
+#define SRT_Queue 12 /* Store result in an queue */
11570
+#define SRT_DistQueue 13 /* Like SRT_Queue, but unique results only */
1151611571
1151711572
/*
1151811573
** An instance of this object describes where to put of the results of
1151911574
** a SELECT statement.
1152011575
*/
1152111576
struct SelectDest {
11522
- u8 eDest; /* How to dispose of the results. On of SRT_* above. */
11523
- char affSdst; /* Affinity used when eDest==SRT_Set */
11524
- int iSDParm; /* A parameter used by the eDest disposal method */
11525
- int iSdst; /* Base register where results are written */
11526
- int nSdst; /* Number of registers allocated */
11577
+ u8 eDest; /* How to dispose of the results. On of SRT_* above. */
11578
+ char affSdst; /* Affinity used when eDest==SRT_Set */
11579
+ int iSDParm; /* A parameter used by the eDest disposal method */
11580
+ int iSdst; /* Base register where results are written */
11581
+ int nSdst; /* Number of registers allocated */
11582
+ ExprList *pOrderBy; /* Key columns for SRT_Queue and SRT_DistQueue */
1152711583
};
1152811584
1152911585
/*
1153011586
** During code generation of statements that do inserts into AUTOINCREMENT
1153111587
** tables, the following information is attached to the Table.u.autoInc.p
@@ -11696,11 +11752,10 @@
1169611752
Table **apVtabLock; /* Pointer to virtual tables needing locking */
1169711753
#endif
1169811754
Table *pZombieTab; /* List of Table objects to delete after code gen */
1169911755
TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
1170011756
With *pWith; /* Current WITH clause, or NULL */
11701
- int regLevel; /* Register holding the LEVEL variable */
1170211757
u8 bFreeWith; /* True if pWith should be freed with parser */
1170311758
};
1170411759
1170511760
/*
1170611761
** Return true if currently inside an sqlite3_declare_vtab() call.
@@ -23183,41 +23238,41 @@
2318323238
/* 49 */ "VerifyCookie" OpHelp(""),
2318423239
/* 50 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
2318523240
/* 51 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
2318623241
/* 52 */ "OpenAutoindex" OpHelp("nColumn=P2"),
2318723242
/* 53 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23188
- /* 54 */ "SwapCursors" OpHelp(""),
23189
- /* 55 */ "SorterOpen" OpHelp(""),
23190
- /* 56 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
23191
- /* 57 */ "Close" OpHelp(""),
23192
- /* 58 */ "SeekLt" OpHelp("key=r[P3@P4]"),
23193
- /* 59 */ "SeekLe" OpHelp("key=r[P3@P4]"),
23194
- /* 60 */ "SeekGe" OpHelp("key=r[P3@P4]"),
23195
- /* 61 */ "SeekGt" OpHelp("key=r[P3@P4]"),
23196
- /* 62 */ "Seek" OpHelp("intkey=r[P2]"),
23197
- /* 63 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23198
- /* 64 */ "NotFound" OpHelp("key=r[P3@P4]"),
23199
- /* 65 */ "Found" OpHelp("key=r[P3@P4]"),
23200
- /* 66 */ "NotExists" OpHelp("intkey=r[P3]"),
23201
- /* 67 */ "Sequence" OpHelp("r[P2]=rowid"),
23202
- /* 68 */ "NewRowid" OpHelp("r[P2]=rowid"),
23203
- /* 69 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23204
- /* 70 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23243
+ /* 54 */ "SorterOpen" OpHelp(""),
23244
+ /* 55 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
23245
+ /* 56 */ "Close" OpHelp(""),
23246
+ /* 57 */ "SeekLt" OpHelp("key=r[P3@P4]"),
23247
+ /* 58 */ "SeekLe" OpHelp("key=r[P3@P4]"),
23248
+ /* 59 */ "SeekGe" OpHelp("key=r[P3@P4]"),
23249
+ /* 60 */ "SeekGt" OpHelp("key=r[P3@P4]"),
23250
+ /* 61 */ "Seek" OpHelp("intkey=r[P2]"),
23251
+ /* 62 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23252
+ /* 63 */ "NotFound" OpHelp("key=r[P3@P4]"),
23253
+ /* 64 */ "Found" OpHelp("key=r[P3@P4]"),
23254
+ /* 65 */ "NotExists" OpHelp("intkey=r[P3]"),
23255
+ /* 66 */ "Sequence" OpHelp("r[P2]=rowid"),
23256
+ /* 67 */ "NewRowid" OpHelp("r[P2]=rowid"),
23257
+ /* 68 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23258
+ /* 69 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23259
+ /* 70 */ "Delete" OpHelp(""),
2320523260
/* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
2320623261
/* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
23207
- /* 73 */ "Delete" OpHelp(""),
23208
- /* 74 */ "ResetCount" OpHelp(""),
23209
- /* 75 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23262
+ /* 73 */ "ResetCount" OpHelp(""),
23263
+ /* 74 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23264
+ /* 75 */ "SorterData" OpHelp("r[P2]=data"),
2321023265
/* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
2321123266
/* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
2321223267
/* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
2321323268
/* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
2321423269
/* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
2321523270
/* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
2321623271
/* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
2321723272
/* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23218
- /* 84 */ "SorterData" OpHelp("r[P2]=data"),
23273
+ /* 84 */ "RowKey" OpHelp("r[P2]=key"),
2321923274
/* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
2322023275
/* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
2322123276
/* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
2322223277
/* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
2322323278
/* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -23224,69 +23279,68 @@
2322423279
/* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
2322523280
/* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
2322623281
/* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
2322723282
/* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
2322823283
/* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23229
- /* 95 */ "RowKey" OpHelp("r[P2]=key"),
23284
+ /* 95 */ "RowData" OpHelp("r[P2]=data"),
2323023285
/* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
2323123286
/* 97 */ "String8" OpHelp("r[P2]='P4'"),
23232
- /* 98 */ "RowData" OpHelp("r[P2]=data"),
23233
- /* 99 */ "Rowid" OpHelp("r[P2]=rowid"),
23234
- /* 100 */ "NullRow" OpHelp(""),
23235
- /* 101 */ "Last" OpHelp(""),
23236
- /* 102 */ "SorterSort" OpHelp(""),
23237
- /* 103 */ "Sort" OpHelp(""),
23238
- /* 104 */ "Rewind" OpHelp(""),
23239
- /* 105 */ "SorterInsert" OpHelp(""),
23240
- /* 106 */ "IdxInsert" OpHelp("key=r[P2]"),
23241
- /* 107 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23242
- /* 108 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23243
- /* 109 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23244
- /* 110 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23245
- /* 111 */ "Destroy" OpHelp(""),
23246
- /* 112 */ "Clear" OpHelp(""),
23247
- /* 113 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23248
- /* 114 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23249
- /* 115 */ "ParseSchema" OpHelp(""),
23250
- /* 116 */ "LoadAnalysis" OpHelp(""),
23251
- /* 117 */ "DropTable" OpHelp(""),
23252
- /* 118 */ "DropIndex" OpHelp(""),
23253
- /* 119 */ "DropTrigger" OpHelp(""),
23254
- /* 120 */ "IntegrityCk" OpHelp(""),
23255
- /* 121 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23256
- /* 122 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23257
- /* 123 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23258
- /* 124 */ "Program" OpHelp(""),
23259
- /* 125 */ "Param" OpHelp(""),
23260
- /* 126 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23261
- /* 127 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23262
- /* 128 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23263
- /* 129 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23264
- /* 130 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23265
- /* 131 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23266
- /* 132 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23287
+ /* 98 */ "Rowid" OpHelp("r[P2]=rowid"),
23288
+ /* 99 */ "NullRow" OpHelp(""),
23289
+ /* 100 */ "Last" OpHelp(""),
23290
+ /* 101 */ "SorterSort" OpHelp(""),
23291
+ /* 102 */ "Sort" OpHelp(""),
23292
+ /* 103 */ "Rewind" OpHelp(""),
23293
+ /* 104 */ "SorterInsert" OpHelp(""),
23294
+ /* 105 */ "IdxInsert" OpHelp("key=r[P2]"),
23295
+ /* 106 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23296
+ /* 107 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23297
+ /* 108 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23298
+ /* 109 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23299
+ /* 110 */ "Destroy" OpHelp(""),
23300
+ /* 111 */ "Clear" OpHelp(""),
23301
+ /* 112 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23302
+ /* 113 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23303
+ /* 114 */ "ParseSchema" OpHelp(""),
23304
+ /* 115 */ "LoadAnalysis" OpHelp(""),
23305
+ /* 116 */ "DropTable" OpHelp(""),
23306
+ /* 117 */ "DropIndex" OpHelp(""),
23307
+ /* 118 */ "DropTrigger" OpHelp(""),
23308
+ /* 119 */ "IntegrityCk" OpHelp(""),
23309
+ /* 120 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23310
+ /* 121 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23311
+ /* 122 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23312
+ /* 123 */ "Program" OpHelp(""),
23313
+ /* 124 */ "Param" OpHelp(""),
23314
+ /* 125 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23315
+ /* 126 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23316
+ /* 127 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23317
+ /* 128 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23318
+ /* 129 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23319
+ /* 130 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23320
+ /* 131 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23321
+ /* 132 */ "IncrVacuum" OpHelp(""),
2326723322
/* 133 */ "Real" OpHelp("r[P2]=P4"),
23268
- /* 134 */ "IncrVacuum" OpHelp(""),
23269
- /* 135 */ "Expire" OpHelp(""),
23270
- /* 136 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23271
- /* 137 */ "VBegin" OpHelp(""),
23272
- /* 138 */ "VCreate" OpHelp(""),
23273
- /* 139 */ "VDestroy" OpHelp(""),
23274
- /* 140 */ "VOpen" OpHelp(""),
23275
- /* 141 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23276
- /* 142 */ "VNext" OpHelp(""),
23323
+ /* 134 */ "Expire" OpHelp(""),
23324
+ /* 135 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23325
+ /* 136 */ "VBegin" OpHelp(""),
23326
+ /* 137 */ "VCreate" OpHelp(""),
23327
+ /* 138 */ "VDestroy" OpHelp(""),
23328
+ /* 139 */ "VOpen" OpHelp(""),
23329
+ /* 140 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23330
+ /* 141 */ "VNext" OpHelp(""),
23331
+ /* 142 */ "VRename" OpHelp(""),
2327723332
/* 143 */ "ToText" OpHelp(""),
2327823333
/* 144 */ "ToBlob" OpHelp(""),
2327923334
/* 145 */ "ToNumeric" OpHelp(""),
2328023335
/* 146 */ "ToInt" OpHelp(""),
2328123336
/* 147 */ "ToReal" OpHelp(""),
23282
- /* 148 */ "VRename" OpHelp(""),
23283
- /* 149 */ "Pagecount" OpHelp(""),
23284
- /* 150 */ "MaxPgcnt" OpHelp(""),
23285
- /* 151 */ "Trace" OpHelp(""),
23286
- /* 152 */ "Noop" OpHelp(""),
23287
- /* 153 */ "Explain" OpHelp(""),
23337
+ /* 148 */ "Pagecount" OpHelp(""),
23338
+ /* 149 */ "MaxPgcnt" OpHelp(""),
23339
+ /* 150 */ "Trace" OpHelp(""),
23340
+ /* 151 */ "Noop" OpHelp(""),
23341
+ /* 152 */ "Explain" OpHelp(""),
2328823342
};
2328923343
return azName[i];
2329023344
}
2329123345
#endif
2329223346
@@ -69741,37 +69795,10 @@
6974169795
}
6974269796
pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
6974369797
break;
6974469798
}
6974569799
69746
-#ifndef SQLITE_OMIT_CTE
69747
-/* Opcode: SwapCursors P1 P2 * * *
69748
-**
69749
-** Parameters P1 and P2 are both cursors opened by the OpenEphemeral
69750
-** opcode. This opcode deletes the contents of epheremal table P1,
69751
-** then renames P2 to P1 and P1 to P2. In other words, following this
69752
-** opcode cursor P2 is open on an empty table and P1 is open on the
69753
-** table that was initially accessed by P2.
69754
-*/
69755
-case OP_SwapCursors: {
69756
- Mem tmp;
69757
- VdbeCursor *pTmp;
69758
-
69759
- tmp = p->aMem[p->nMem - pOp->p1];
69760
- p->aMem[p->nMem - pOp->p1] = p->aMem[p->nMem - pOp->p2];
69761
- p->aMem[p->nMem - pOp->p2] = tmp;
69762
-
69763
- pTmp = p->apCsr[pOp->p1];
69764
- p->apCsr[pOp->p1] = p->apCsr[pOp->p2];
69765
- p->apCsr[pOp->p2] = pTmp;
69766
-
69767
- assert( pTmp->isTable );
69768
- rc = sqlite3BtreeClearTable(pTmp->pBt, MASTER_ROOT, 0);
69769
- break;
69770
-}
69771
-#endif /* ifndef SQLITE_OMIT_CTE */
69772
-
6977369800
/* Opcode: SorterOpen P1 * * P4 *
6977469801
**
6977569802
** This opcode works like OP_OpenEphemeral except that it opens
6977669803
** a transient index that is specifically designed to sort large
6977769804
** tables using an external merge-sort algorithm.
@@ -70765,11 +70792,10 @@
7076570792
pC = p->apCsr[pOp->p1];
7076670793
assert( pC!=0 );
7076770794
pC->nullRow = 1;
7076870795
pC->rowidIsValid = 0;
7076970796
pC->cacheStatus = CACHE_STALE;
70770
- assert( pC->pCursor || pC->pVtabCursor );
7077170797
if( pC->pCursor ){
7077270798
sqlite3BtreeClearCursor(pC->pCursor);
7077370799
}
7077470800
break;
7077570801
}
@@ -75130,11 +75156,11 @@
7513075156
sqlite3 *db = pParse->db; /* The database connection */
7513175157
struct SrcList_item *pItem; /* Use for looping over pSrcList items */
7513275158
struct SrcList_item *pMatch = 0; /* The matching pSrcList item */
7513375159
NameContext *pTopNC = pNC; /* First namecontext in the list */
7513475160
Schema *pSchema = 0; /* Schema of the expression */
75135
- u8 newOp = TK_COLUMN; /* pExpr->op after resolving name */
75161
+ int isTrigger = 0; /* True if resolved to a trigger column */
7513675162
Table *pTab = 0; /* Table hold the row */
7513775163
Column *pCol; /* A column of pTab */
7513875164
7513975165
assert( pNC ); /* the name context cannot be NULL. */
7514075166
assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
@@ -75171,26 +75197,10 @@
7517175197
/* Start at the inner-most context and move outward until a match is found */
7517275198
while( pNC && cnt==0 ){
7517375199
ExprList *pEList;
7517475200
SrcList *pSrcList = pNC->pSrcList;
7517575201
75176
-#ifndef SQLITE_OMIT_CTE
75177
- /* The identifier "LEVEL", with a table or database qualifier and within a
75178
- ** recursive common table expression, resolves to the special LEVEL pseudo-column.
75179
- ** To access table names called "level", add a table qualifier.
75180
- */
75181
- if( (pNC->ncFlags&NC_Recursive)!=0 && zTab==0 && sqlite3_stricmp(zCol,"level")==0 ){
75182
- assert( cnt==0 );
75183
- cnt = 1;
75184
- newOp = TK_LEVEL;
75185
- pExpr->iColumn = -1;
75186
- pExpr->affinity = SQLITE_AFF_INTEGER;
75187
- pNC->ncFlags |= NC_UsesLevel;
75188
- break;
75189
- }
75190
-#endif
75191
-
7519275202
if( pSrcList ){
7519375203
for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
7519475204
pTab = pItem->pTab;
7519575205
assert( pTab!=0 && pTab->zName!=0 );
7519675206
assert( pTab->nCol>0 );
@@ -75291,11 +75301,11 @@
7529175301
testcase( iCol==32 );
7529275302
pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
7529375303
}
7529475304
pExpr->iColumn = (i16)iCol;
7529575305
pExpr->pTab = pTab;
75296
- newOp = TK_TRIGGER;
75306
+ isTrigger = 1;
7529775307
}
7529875308
}
7529975309
}
7530075310
#endif /* !defined(SQLITE_OMIT_TRIGGER) */
7530175311
@@ -75415,15 +75425,15 @@
7541575425
*/
7541675426
sqlite3ExprDelete(db, pExpr->pLeft);
7541775427
pExpr->pLeft = 0;
7541875428
sqlite3ExprDelete(db, pExpr->pRight);
7541975429
pExpr->pRight = 0;
75420
- pExpr->op = newOp;
75430
+ pExpr->op = (isTrigger ? TK_TRIGGER : TK_COLUMN);
7542175431
lookupname_end:
7542275432
if( cnt==1 ){
7542375433
assert( pNC!=0 );
75424
- if( pExpr->op!=TK_AS && pExpr->op!=TK_LEVEL ){
75434
+ if( pExpr->op!=TK_AS ){
7542575435
sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
7542675436
}
7542775437
/* Increment the nRef value on all name contexts from TopNC up to
7542875438
** the point where the name matched. */
7542975439
for(;;){
@@ -76116,11 +76126,10 @@
7611676126
7611776127
/* Set up the local name-context to pass to sqlite3ResolveExprNames() to
7611876128
** resolve the result-set expression list.
7611976129
*/
7612076130
sNC.ncFlags = NC_AllowAgg;
76121
- if( p->selFlags & SF_Recursive ) sNC.ncFlags |= NC_Recursive;
7612276131
sNC.pSrcList = p->pSrc;
7612376132
sNC.pNext = pOuterNC;
7612476133
7612576134
/* Resolve names in the result set. */
7612676135
pEList = p->pEList;
@@ -76195,14 +76204,10 @@
7619576204
"the GROUP BY clause");
7619676205
return WRC_Abort;
7619776206
}
7619876207
}
7619976208
}
76200
- if( sNC.ncFlags & NC_UsesLevel ){
76201
- p->selFlags |= SF_UsesLevel;
76202
- }
76203
- sNC.ncFlags &= ~(NC_Recursive|NC_UsesLevel);
7620476209
7620576210
/* Advance to the next term of the compound
7620676211
*/
7620776212
p = p->pPrior;
7620876213
nCompound++;
@@ -78835,16 +78840,10 @@
7883578840
inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
7883678841
pExpr->iColumn, iTab, target,
7883778842
pExpr->op2);
7883878843
break;
7883978844
}
78840
-#ifndef SQLITE_OMIT_CTE
78841
- case TK_LEVEL: {
78842
- inReg = pParse->regLevel;
78843
- break;
78844
- }
78845
-#endif
7884678845
case TK_INTEGER: {
7884778846
codeInteger(pParse, pExpr, 0, target);
7884878847
break;
7884978848
}
7885078849
#ifndef SQLITE_OMIT_FLOATING_POINT
@@ -79464,11 +79463,10 @@
7946479463
SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
7946579464
int r2;
7946679465
pExpr = sqlite3ExprSkipCollate(pExpr);
7946779466
if( ConstFactorOk(pParse)
7946879467
&& pExpr->op!=TK_REGISTER
79469
- && pExpr->op!=TK_LEVEL
7947079468
&& sqlite3ExprIsConstantNotJoin(pExpr)
7947179469
){
7947279470
ExprList *p = pParse->pConstExpr;
7947379471
int i;
7947479472
*pReg = 0;
@@ -99909,17 +99907,17 @@
9990999907
/*
9991099908
** Add code to implement the OFFSET
9991199909
*/
9991299910
static void codeOffset(
9991399911
Vdbe *v, /* Generate code into this VM */
99914
- Select *p, /* The SELECT statement being coded */
99912
+ int iOffset, /* Register holding the offset counter */
9991599913
int iContinue /* Jump here to skip the current record */
9991699914
){
99917
- if( p->iOffset && iContinue!=0 ){
99915
+ if( iOffset>0 && iContinue!=0 ){
9991899916
int addr;
99919
- sqlite3VdbeAddOp2(v, OP_AddImm, p->iOffset, -1);
99920
- addr = sqlite3VdbeAddOp1(v, OP_IfNeg, p->iOffset);
99917
+ sqlite3VdbeAddOp2(v, OP_AddImm, iOffset, -1);
99918
+ addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset);
9992199919
sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
9992299920
VdbeComment((v, "skip OFFSET records"));
9992399921
sqlite3VdbeJumpHere(v, addr);
9992499922
}
9992599923
}
@@ -99990,21 +99988,20 @@
9999099988
9999199989
/*
9999299990
** This routine generates the code for the inside of the inner loop
9999399991
** of a SELECT.
9999499992
**
99995
-** If srcTab and nColumn are both zero, then the pEList expressions
99996
-** are evaluated in order to get the data for this row. If nColumn>0
99997
-** then data is pulled from srcTab and pEList is used only to get the
99998
-** datatypes for each column.
99993
+** If srcTab is negative, then the pEList expressions
99994
+** are evaluated in order to get the data for this row. If srcTab is
99995
+** zero or more, then data is pulled from srcTab and pEList is used only
99996
+** to get number columns and the datatype for each column.
9999999997
*/
10000099998
static void selectInnerLoop(
10000199999
Parse *pParse, /* The parser context */
100002100000
Select *p, /* The complete select statement being coded */
100003100001
ExprList *pEList, /* List of values being extracted */
100004100002
int srcTab, /* Pull data from this table */
100005
- int nColumn, /* Number of columns in the source table */
100006100003
ExprList *pOrderBy, /* If not NULL, sort results using this key */
100007100004
DistinctCtx *pDistinct, /* If not NULL, info on how to process DISTINCT */
100008100005
SelectDest *pDest, /* How to dispose of the results */
100009100006
int iContinue, /* Jump here to continue with next row */
100010100007
int iBreak /* Jump here to break out of the inner loop */
@@ -100016,61 +100013,54 @@
100016100013
int eDest = pDest->eDest; /* How to dispose of results */
100017100014
int iParm = pDest->iSDParm; /* First argument to disposal method */
100018100015
int nResultCol; /* Number of result columns */
100019100016
100020100017
assert( v );
100021
- if( NEVER(v==0) ) return;
100022100018
assert( pEList!=0 );
100023100019
hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
100024100020
if( pOrderBy==0 && !hasDistinct ){
100025
- codeOffset(v, p, iContinue);
100021
+ codeOffset(v, p->iOffset, iContinue);
100026100022
}
100027100023
100028100024
/* Pull the requested columns.
100029100025
*/
100030
- if( nColumn>0 ){
100031
- nResultCol = nColumn;
100032
- }else{
100033
- nResultCol = pEList->nExpr;
100034
- }
100026
+ nResultCol = pEList->nExpr;
100035100027
if( pDest->iSdst==0 ){
100036100028
pDest->iSdst = pParse->nMem+1;
100037100029
pDest->nSdst = nResultCol;
100038100030
pParse->nMem += nResultCol;
100039100031
}else{
100040100032
assert( pDest->nSdst==nResultCol );
100041100033
}
100042100034
regResult = pDest->iSdst;
100043
- if( nColumn>0 ){
100044
- for(i=0; i<nColumn; i++){
100035
+ if( srcTab>=0 ){
100036
+ for(i=0; i<nResultCol; i++){
100045100037
sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
100038
+ VdbeComment((v, "%s", pEList->a[i].zName));
100046100039
}
100047100040
}else if( eDest!=SRT_Exists ){
100048100041
/* If the destination is an EXISTS(...) expression, the actual
100049100042
** values returned by the SELECT are not required.
100050100043
*/
100051100044
sqlite3ExprCodeExprList(pParse, pEList, regResult,
100052100045
(eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
100053100046
}
100054
- nColumn = nResultCol;
100055100047
100056100048
/* If the DISTINCT keyword was present on the SELECT statement
100057100049
** and this row has been seen before, then do not make this row
100058100050
** part of the result.
100059100051
*/
100060100052
if( hasDistinct ){
100061
- assert( pEList!=0 );
100062
- assert( pEList->nExpr==nColumn );
100063100053
switch( pDistinct->eTnctType ){
100064100054
case WHERE_DISTINCT_ORDERED: {
100065100055
VdbeOp *pOp; /* No longer required OpenEphemeral instr. */
100066100056
int iJump; /* Jump destination */
100067100057
int regPrev; /* Previous row content */
100068100058
100069100059
/* Allocate space for the previous row */
100070100060
regPrev = pParse->nMem+1;
100071
- pParse->nMem += nColumn;
100061
+ pParse->nMem += nResultCol;
100072100062
100073100063
/* Change the OP_OpenEphemeral coded earlier to an OP_Null
100074100064
** sets the MEM_Cleared bit on the first register of the
100075100065
** previous value. This will cause the OP_Ne below to always
100076100066
** fail on the first iteration of the loop even if the first
@@ -100080,23 +100070,23 @@
100080100070
pOp = sqlite3VdbeGetOp(v, pDistinct->addrTnct);
100081100071
pOp->opcode = OP_Null;
100082100072
pOp->p1 = 1;
100083100073
pOp->p2 = regPrev;
100084100074
100085
- iJump = sqlite3VdbeCurrentAddr(v) + nColumn;
100086
- for(i=0; i<nColumn; i++){
100075
+ iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
100076
+ for(i=0; i<nResultCol; i++){
100087100077
CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
100088
- if( i<nColumn-1 ){
100078
+ if( i<nResultCol-1 ){
100089100079
sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
100090100080
}else{
100091100081
sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
100092100082
}
100093100083
sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
100094100084
sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
100095100085
}
100096100086
assert( sqlite3VdbeCurrentAddr(v)==iJump );
100097
- sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nColumn-1);
100087
+ sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1);
100098100088
break;
100099100089
}
100100100090
100101100091
case WHERE_DISTINCT_UNIQUE: {
100102100092
sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct);
@@ -100103,16 +100093,16 @@
100103100093
break;
100104100094
}
100105100095
100106100096
default: {
100107100097
assert( pDistinct->eTnctType==WHERE_DISTINCT_UNORDERED );
100108
- codeDistinct(pParse, pDistinct->tabTnct, iContinue, nColumn, regResult);
100098
+ codeDistinct(pParse, pDistinct->tabTnct, iContinue, nResultCol, regResult);
100109100099
break;
100110100100
}
100111100101
}
100112100102
if( pOrderBy==0 ){
100113
- codeOffset(v, p, iContinue);
100103
+ codeOffset(v, p->iOffset, iContinue);
100114100104
}
100115100105
}
100116100106
100117100107
switch( eDest ){
100118100108
/* In this mode, write each query result to the key of the temporary
@@ -100120,11 +100110,11 @@
100120100110
*/
100121100111
#ifndef SQLITE_OMIT_COMPOUND_SELECT
100122100112
case SRT_Union: {
100123100113
int r1;
100124100114
r1 = sqlite3GetTempReg(pParse);
100125
- sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1);
100115
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
100126100116
sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
100127100117
sqlite3ReleaseTempReg(pParse, r1);
100128100118
break;
100129100119
}
100130100120
@@ -100131,24 +100121,24 @@
100131100121
/* Construct a record from the query result, but instead of
100132100122
** saving that record, use it as a key to delete elements from
100133100123
** the temporary table iParm.
100134100124
*/
100135100125
case SRT_Except: {
100136
- sqlite3VdbeAddOp3(v, OP_IdxDelete, iParm, regResult, nColumn);
100126
+ sqlite3VdbeAddOp3(v, OP_IdxDelete, iParm, regResult, nResultCol);
100137100127
break;
100138100128
}
100139
-#endif
100129
+#endif /* SQLITE_OMIT_COMPOUND_SELECT */
100140100130
100141100131
/* Store the result as data using a unique key.
100142100132
*/
100143100133
case SRT_DistTable:
100144100134
case SRT_Table:
100145100135
case SRT_EphemTab: {
100146100136
int r1 = sqlite3GetTempReg(pParse);
100147100137
testcase( eDest==SRT_Table );
100148100138
testcase( eDest==SRT_EphemTab );
100149
- sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1);
100139
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
100150100140
#ifndef SQLITE_OMIT_CTE
100151100141
if( eDest==SRT_DistTable ){
100152100142
/* If the destination is DistTable, then cursor (iParm+1) is open
100153100143
** on an ephemeral index. If the current row is already present
100154100144
** in the index, do not write it to the output. If not, add the
@@ -100177,11 +100167,11 @@
100177100167
/* If we are creating a set for an "expr IN (SELECT ...)" construct,
100178100168
** then there should be a single item on the stack. Write this
100179100169
** item into the set table with bogus data.
100180100170
*/
100181100171
case SRT_Set: {
100182
- assert( nColumn==1 );
100172
+ assert( nResultCol==1 );
100183100173
pDest->affSdst =
100184100174
sqlite3CompareAffinity(pEList->a[0].pExpr, pDest->affSdst);
100185100175
if( pOrderBy ){
100186100176
/* At first glance you would think we could optimize out the
100187100177
** ORDER BY in this case since the order of entries in the set
@@ -100209,11 +100199,11 @@
100209100199
/* If this is a scalar select that is part of an expression, then
100210100200
** store the results in the appropriate memory cell and break out
100211100201
** of the scan loop.
100212100202
*/
100213100203
case SRT_Mem: {
100214
- assert( nColumn==1 );
100204
+ assert( nResultCol==1 );
100215100205
if( pOrderBy ){
100216100206
pushOntoSorter(pParse, pOrderBy, p, regResult);
100217100207
}else{
100218100208
sqlite3ExprCodeMove(pParse, regResult, iParm, 1);
100219100209
/* The LIMIT clause will jump out of the loop for us */
@@ -100230,21 +100220,66 @@
100230100220
case SRT_Output: {
100231100221
testcase( eDest==SRT_Coroutine );
100232100222
testcase( eDest==SRT_Output );
100233100223
if( pOrderBy ){
100234100224
int r1 = sqlite3GetTempReg(pParse);
100235
- sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1);
100225
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
100236100226
pushOntoSorter(pParse, pOrderBy, p, r1);
100237100227
sqlite3ReleaseTempReg(pParse, r1);
100238100228
}else if( eDest==SRT_Coroutine ){
100239100229
sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
100240100230
}else{
100241
- sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nColumn);
100242
- sqlite3ExprCacheAffinityChange(pParse, regResult, nColumn);
100231
+ sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nResultCol);
100232
+ sqlite3ExprCacheAffinityChange(pParse, regResult, nResultCol);
100243100233
}
100244100234
break;
100245100235
}
100236
+
100237
+#ifndef SQLITE_OMIT_CTE
100238
+ /* Write the results into a priority queue that is order according to
100239
+ ** pDest->pOrderBy (in pSO). pDest->iSDParm (in iParm) is the cursor for an
100240
+ ** index with pSO->nExpr+2 columns. Build a key using pSO for the first
100241
+ ** pSO->nExpr columns, then make sure all keys are unique by adding a
100242
+ ** final OP_Sequence column. The last column is the record as a blob.
100243
+ */
100244
+ case SRT_DistQueue:
100245
+ case SRT_Queue: {
100246
+ int nKey;
100247
+ int r1, r2, r3;
100248
+ int addrTest = 0;
100249
+ ExprList *pSO;
100250
+ pSO = pDest->pOrderBy;
100251
+ assert( pSO );
100252
+ nKey = pSO->nExpr;
100253
+ r1 = sqlite3GetTempReg(pParse);
100254
+ r2 = sqlite3GetTempRange(pParse, nKey+2);
100255
+ r3 = r2+nKey+1;
100256
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3);
100257
+ if( eDest==SRT_DistQueue ){
100258
+ /* If the destination is DistQueue, then cursor (iParm+1) is open
100259
+ ** on a second ephemeral index that holds all values every previously
100260
+ ** added to the queue. Only add this new value if it has never before
100261
+ ** been added */
100262
+ addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0, r3, 0);
100263
+ sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r3);
100264
+ }
100265
+ for(i=0; i<nKey; i++){
100266
+ sqlite3VdbeAddOp2(v, OP_SCopy,
100267
+ regResult + pSO->a[i].u.x.iOrderByCol - 1,
100268
+ r2+i);
100269
+ }
100270
+ sqlite3VdbeAddOp2(v, OP_Sequence, iParm, r2+nKey);
100271
+ sqlite3VdbeAddOp3(v, OP_MakeRecord, r2, nKey+2, r1);
100272
+ sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
100273
+ if( addrTest ) sqlite3VdbeJumpHere(v, addrTest);
100274
+ sqlite3ReleaseTempReg(pParse, r1);
100275
+ sqlite3ReleaseTempRange(pParse, r2, nKey+2);
100276
+ break;
100277
+ }
100278
+#endif /* SQLITE_OMIT_CTE */
100279
+
100280
+
100246100281
100247100282
#if !defined(SQLITE_OMIT_TRIGGER)
100248100283
/* Discard the results. This is used for SELECT statements inside
100249100284
** the body of a TRIGGER. The purpose of such selects is to call
100250100285
** user-defined functions that have side effects. We do not care
@@ -100330,19 +100365,19 @@
100330100365
**
100331100366
** Space to hold the KeyInfo structure is obtain from malloc. The calling
100332100367
** function is responsible for seeing that this structure is eventually
100333100368
** freed.
100334100369
*/
100335
-static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){
100370
+static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList, int nExtra){
100336100371
int nExpr;
100337100372
KeyInfo *pInfo;
100338100373
struct ExprList_item *pItem;
100339100374
sqlite3 *db = pParse->db;
100340100375
int i;
100341100376
100342100377
nExpr = pList->nExpr;
100343
- pInfo = sqlite3KeyInfoAlloc(db, nExpr, 1);
100378
+ pInfo = sqlite3KeyInfoAlloc(db, nExpr+nExtra, 1);
100344100379
if( pInfo ){
100345100380
assert( sqlite3KeyInfoIsWriteable(pInfo) );
100346100381
for(i=0, pItem=pList->a; i<nExpr; i++, pItem++){
100347100382
CollSeq *pColl;
100348100383
pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
@@ -100479,17 +100514,17 @@
100479100514
if( p->selFlags & SF_UseSorter ){
100480100515
int regSortOut = ++pParse->nMem;
100481100516
int ptab2 = pParse->nTab++;
100482100517
sqlite3VdbeAddOp3(v, OP_OpenPseudo, ptab2, regSortOut, pOrderBy->nExpr+2);
100483100518
addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
100484
- codeOffset(v, p, addrContinue);
100519
+ codeOffset(v, p->iOffset, addrContinue);
100485100520
sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
100486100521
sqlite3VdbeAddOp3(v, OP_Column, ptab2, pOrderBy->nExpr+1, regRow);
100487100522
sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
100488100523
}else{
100489100524
addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak);
100490
- codeOffset(v, p, addrContinue);
100525
+ codeOffset(v, p->iOffset, addrContinue);
100491100526
sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr+1, regRow);
100492100527
}
100493100528
switch( eDest ){
100494100529
case SRT_Table:
100495100530
case SRT_EphemTab: {
@@ -101049,12 +101084,17 @@
101049101084
** the limit and offset. If there is no limit and/or offset, then
101050101085
** iLimit and iOffset are negative.
101051101086
**
101052101087
** This routine changes the values of iLimit and iOffset only if
101053101088
** a limit or offset is defined by pLimit and pOffset. iLimit and
101054
-** iOffset should have been preset to appropriate default values
101055
-** (usually but not always -1) prior to calling this routine.
101089
+** iOffset should have been preset to appropriate default values (zero)
101090
+** prior to calling this routine.
101091
+**
101092
+** The iOffset register (if it exists) is initialized to the value
101093
+** of the OFFSET. The iLimit register is initialized to LIMIT. Register
101094
+** iOffset+1 is initialized to LIMIT+OFFSET.
101095
+**
101056101096
** Only if pLimit!=0 or pOffset!=0 do the limit registers get
101057101097
** redefined. The UNION ALL operator uses this property to force
101058101098
** the reuse of the same limit and offset registers across multiple
101059101099
** SELECT statements.
101060101100
*/
@@ -101074,11 +101114,11 @@
101074101114
sqlite3ExprCacheClear(pParse);
101075101115
assert( p->pOffset==0 || p->pLimit!=0 );
101076101116
if( p->pLimit ){
101077101117
p->iLimit = iLimit = ++pParse->nMem;
101078101118
v = sqlite3GetVdbe(pParse);
101079
- if( NEVER(v==0) ) return; /* VDBE should have already been allocated */
101119
+ assert( v!=0 );
101080101120
if( sqlite3ExprIsInteger(p->pLimit, &n) ){
101081101121
sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit);
101082101122
VdbeComment((v, "LIMIT counter"));
101083101123
if( n==0 ){
101084101124
sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
@@ -101131,11 +101171,169 @@
101131101171
}
101132101172
return pRet;
101133101173
}
101134101174
#endif /* SQLITE_OMIT_COMPOUND_SELECT */
101135101175
101136
-/* Forward reference */
101176
+#ifndef SQLITE_OMIT_CTE
101177
+/*
101178
+** This routine generates VDBE code to compute the content of a WITH RECURSIVE
101179
+** query of the form:
101180
+**
101181
+** <recursive-table> AS (<setup-query> UNION [ALL] <recursive-query>)
101182
+** \___________/ \_______________/
101183
+** p->pPrior p
101184
+**
101185
+**
101186
+** There is exactly one reference to the recursive-table in the FROM clause
101187
+** of recursive-query, marked with the SrcList->a[].isRecursive flag.
101188
+**
101189
+** The setup-query runs once to generate an initial set of rows that go
101190
+** into a Queue table. Rows are extracted from the Queue table one by
101191
+** one. Each row extracted from Queue is output to pDest. Then the single
101192
+** extracted row (now in the iCurrent table) becomes the content of the
101193
+** recursive-table for a recursive-query run. The output of the recursive-query
101194
+** is added back into the Queue table. Then another row is extracted from Queue
101195
+** and the iteration continues until the Queue table is empty.
101196
+**
101197
+** If the compound query operator is UNION then no duplicate rows are ever
101198
+** inserted into the Queue table. The iDistinct table keeps a copy of all rows
101199
+** that have ever been inserted into Queue and causes duplicates to be
101200
+** discarded. If the operator is UNION ALL, then duplicates are allowed.
101201
+**
101202
+** If the query has an ORDER BY, then entries in the Queue table are kept in
101203
+** ORDER BY order and the first entry is extracted for each cycle. Without
101204
+** an ORDER BY, the Queue table is just a FIFO.
101205
+**
101206
+** If a LIMIT clause is provided, then the iteration stops after LIMIT rows
101207
+** have been output to pDest. A LIMIT of zero means to output no rows and a
101208
+** negative LIMIT means to output all rows. If there is also an OFFSET clause
101209
+** with a positive value, then the first OFFSET outputs are discarded rather
101210
+** than being sent to pDest. The LIMIT count does not begin until after OFFSET
101211
+** rows have been skipped.
101212
+*/
101213
+static void generateWithRecursiveQuery(
101214
+ Parse *pParse, /* Parsing context */
101215
+ Select *p, /* The recursive SELECT to be coded */
101216
+ SelectDest *pDest /* What to do with query results */
101217
+){
101218
+ SrcList *pSrc = p->pSrc; /* The FROM clause of the recursive query */
101219
+ int nCol = p->pEList->nExpr; /* Number of columns in the recursive table */
101220
+ Vdbe *v = pParse->pVdbe; /* The prepared statement under construction */
101221
+ Select *pSetup = p->pPrior; /* The setup query */
101222
+ int addrTop; /* Top of the loop */
101223
+ int addrCont, addrBreak; /* CONTINUE and BREAK addresses */
101224
+ int iCurrent; /* The Current table */
101225
+ int regCurrent; /* Register holding Current table */
101226
+ int iQueue; /* The Queue table */
101227
+ int iDistinct = 0; /* To ensure unique results if UNION */
101228
+ int eDest = SRT_Table; /* How to write to Queue */
101229
+ SelectDest destQueue; /* SelectDest targetting the Queue table */
101230
+ int i; /* Loop counter */
101231
+ int rc; /* Result code */
101232
+ ExprList *pOrderBy; /* The ORDER BY clause */
101233
+ Expr *pLimit, *pOffset; /* Saved LIMIT and OFFSET */
101234
+ int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */
101235
+
101236
+ /* Obtain authorization to do a recursive query */
101237
+ if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
101238
+
101239
+ /* Process the LIMIT and OFFSET clauses, if they exist */
101240
+ addrBreak = sqlite3VdbeMakeLabel(v);
101241
+ computeLimitRegisters(pParse, p, addrBreak);
101242
+ pLimit = p->pLimit;
101243
+ pOffset = p->pOffset;
101244
+ regLimit = p->iLimit;
101245
+ regOffset = p->iOffset;
101246
+ p->pLimit = p->pOffset = 0;
101247
+ p->iLimit = p->iOffset = 0;
101248
+
101249
+ /* Locate the cursor number of the Current table */
101250
+ for(i=0; ALWAYS(i<pSrc->nSrc); i++){
101251
+ if( pSrc->a[i].isRecursive ){
101252
+ iCurrent = pSrc->a[i].iCursor;
101253
+ break;
101254
+ }
101255
+ }
101256
+
101257
+ /* Detach the ORDER BY clause from the compound SELECT */
101258
+ pOrderBy = p->pOrderBy;
101259
+ p->pOrderBy = 0;
101260
+
101261
+ /* Allocate cursors numbers for Queue and Distinct. The cursor number for
101262
+ ** the Distinct table must be exactly one greater than Queue in order
101263
+ ** for the SRT_DistTable and SRT_DistQueue destinations to work. */
101264
+ iQueue = pParse->nTab++;
101265
+ if( p->op==TK_UNION ){
101266
+ eDest = pOrderBy ? SRT_DistQueue : SRT_DistTable;
101267
+ iDistinct = pParse->nTab++;
101268
+ }else{
101269
+ eDest = pOrderBy ? SRT_Queue : SRT_Table;
101270
+ }
101271
+ sqlite3SelectDestInit(&destQueue, eDest, iQueue);
101272
+
101273
+ /* Allocate cursors for Current, Queue, and Distinct. */
101274
+ regCurrent = ++pParse->nMem;
101275
+ sqlite3VdbeAddOp3(v, OP_OpenPseudo, iCurrent, regCurrent, nCol);
101276
+ if( pOrderBy ){
101277
+ KeyInfo *pKeyInfo = keyInfoFromExprList(pParse, pOrderBy, 1);
101278
+ sqlite3VdbeAddOp4(v, OP_OpenEphemeral, iQueue, pOrderBy->nExpr+2, 0,
101279
+ (char*)pKeyInfo, P4_KEYINFO);
101280
+ destQueue.pOrderBy = pOrderBy;
101281
+ }else{
101282
+ sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iQueue, nCol);
101283
+ }
101284
+ VdbeComment((v, "Queue table"));
101285
+ if( iDistinct ){
101286
+ p->addrOpenEphm[0] = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iDistinct, 0);
101287
+ p->selFlags |= SF_UsesEphemeral;
101288
+ }
101289
+
101290
+ /* Store the results of the setup-query in Queue. */
101291
+ rc = sqlite3Select(pParse, pSetup, &destQueue);
101292
+ if( rc ) goto end_of_recursive_query;
101293
+
101294
+ /* Find the next row in the Queue and output that row */
101295
+ addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak);
101296
+
101297
+ /* Transfer the next row in Queue over to Current */
101298
+ sqlite3VdbeAddOp1(v, OP_NullRow, iCurrent); /* To reset column cache */
101299
+ if( pOrderBy ){
101300
+ sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent);
101301
+ }else{
101302
+ sqlite3VdbeAddOp2(v, OP_RowData, iQueue, regCurrent);
101303
+ }
101304
+ sqlite3VdbeAddOp1(v, OP_Delete, iQueue);
101305
+
101306
+ /* Output the single row in Current */
101307
+ addrCont = sqlite3VdbeMakeLabel(v);
101308
+ codeOffset(v, regOffset, addrCont);
101309
+ selectInnerLoop(pParse, p, p->pEList, iCurrent,
101310
+ 0, 0, pDest, addrCont, addrBreak);
101311
+ if( regLimit ) sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
101312
+ sqlite3VdbeResolveLabel(v, addrCont);
101313
+
101314
+ /* Execute the recursive SELECT taking the single row in Current as
101315
+ ** the value for the recursive-table. Store the results in the Queue.
101316
+ */
101317
+ p->pPrior = 0;
101318
+ sqlite3Select(pParse, p, &destQueue);
101319
+ assert( p->pPrior==0 );
101320
+ p->pPrior = pSetup;
101321
+
101322
+ /* Keep running the loop until the Queue is empty */
101323
+ sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
101324
+ sqlite3VdbeResolveLabel(v, addrBreak);
101325
+
101326
+end_of_recursive_query:
101327
+ p->pOrderBy = pOrderBy;
101328
+ p->pLimit = pLimit;
101329
+ p->pOffset = pOffset;
101330
+ return;
101331
+}
101332
+#endif
101333
+
101334
+/* Forward references */
101137101335
static int multiSelectOrderBy(
101138101336
Parse *pParse, /* Parsing context */
101139101337
Select *p, /* The right-most of SELECTs to be coded */
101140101338
SelectDest *pDest /* What to do with query results */
101141101339
);
@@ -101239,100 +101437,11 @@
101239101437
goto multi_select_end;
101240101438
}
101241101439
101242101440
#ifndef SQLITE_OMIT_CTE
101243101441
if( p->selFlags & SF_Recursive ){
101244
- SrcList *pSrc = p->pSrc; /* The FROM clause of the right-most SELECT */
101245
- int nCol = p->pEList->nExpr; /* Number of columns in the result set */
101246
- int addrNext;
101247
- int addrSwap;
101248
- int iCont, iBreak;
101249
- int tmp1; /* Intermediate table */
101250
- int tmp2; /* Next intermediate table */
101251
- int tmp3 = 0; /* To ensure unique results if UNION */
101252
- int eDest = SRT_Table;
101253
- SelectDest tmp2dest;
101254
- int i;
101255
- int regLevel = 0; /* Register for LEVEL value */
101256
- int savedRegLevel; /* Saved value of pParse->regLevel */
101257
-
101258
- /* Check that there is no ORDER BY or LIMIT clause. Neither of these
101259
- ** are supported on recursive queries. */
101260
- assert( p->pOffset==0 || p->pLimit );
101261
- if( p->pOrderBy || p->pLimit ){
101262
- sqlite3ErrorMsg(pParse, "%s in a recursive query",
101263
- p->pOrderBy ? "ORDER BY" : "LIMIT"
101264
- );
101265
- goto multi_select_end;
101266
- }
101267
-
101268
- if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ){
101269
- goto multi_select_end;
101270
- }
101271
- iBreak = sqlite3VdbeMakeLabel(v);
101272
- iCont = sqlite3VdbeMakeLabel(v);
101273
-
101274
- for(i=0; ALWAYS(i<pSrc->nSrc); i++){
101275
- if( pSrc->a[i].isRecursive ){
101276
- tmp1 = pSrc->a[i].iCursor;
101277
- break;
101278
- }
101279
- }
101280
-
101281
- tmp2 = pParse->nTab++;
101282
- if( p->op==TK_UNION ){
101283
- eDest = SRT_DistTable;
101284
- tmp3 = pParse->nTab++;
101285
- }
101286
- sqlite3SelectDestInit(&tmp2dest, eDest, tmp2);
101287
-
101288
- sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tmp1, nCol);
101289
- sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tmp2, nCol);
101290
- if( tmp3 ){
101291
- p->addrOpenEphm[0] = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tmp3, 0);
101292
- p->selFlags |= SF_UsesEphemeral;
101293
- }
101294
-
101295
- /* Store the results of the initial SELECT in tmp2. */
101296
- rc = sqlite3Select(pParse, pPrior, &tmp2dest);
101297
- if( rc ) goto multi_select_end;
101298
-
101299
- /* Allocate and initialize a register to hold the LEVEL pseudo-column */
101300
- savedRegLevel = pParse->regLevel;
101301
- if( p->selFlags & SF_UsesLevel ){
101302
- regLevel = pParse->regLevel = ++pParse->nMem;
101303
- sqlite3VdbeAddOp2(v, OP_Integer, 0, regLevel);
101304
- VdbeComment((v, "level=0"));
101305
- }
101306
-
101307
- /* Clear tmp1. Then switch the contents of tmp1 and tmp2. Then return
101308
- ** the contents of tmp1 to the caller. Or, if tmp1 is empty at this
101309
- ** point, the recursive query has finished - jump to address iBreak. */
101310
- addrSwap = sqlite3VdbeAddOp2(v, OP_SwapCursors, tmp1, tmp2);
101311
- sqlite3VdbeAddOp2(v, OP_Rewind, tmp1, iBreak);
101312
- addrNext = sqlite3VdbeCurrentAddr(v);
101313
- selectInnerLoop(pParse, p, p->pEList, tmp1, p->pEList->nExpr,
101314
- 0, 0, &dest, iCont, iBreak);
101315
- sqlite3VdbeResolveLabel(v, iCont);
101316
- sqlite3VdbeAddOp2(v, OP_Next, tmp1, addrNext);
101317
- if( regLevel ){
101318
- sqlite3VdbeAddOp2(v, OP_AddImm, regLevel, 1);
101319
- VdbeComment((v, "level++"));
101320
- }
101321
-
101322
- /* Execute the recursive SELECT. Store the results in tmp2. While this
101323
- ** SELECT is running, the contents of tmp1 are read by recursive
101324
- ** references to the current CTE. */
101325
- p->pPrior = 0;
101326
- rc = sqlite3Select(pParse, p, &tmp2dest);
101327
- assert( p->pPrior==0 );
101328
- p->pPrior = pPrior;
101329
- if( rc ) goto multi_select_end;
101330
-
101331
- sqlite3VdbeAddOp2(v, OP_Goto, 0, addrSwap);
101332
- sqlite3VdbeResolveLabel(v, iBreak);
101333
- pParse->regLevel = savedRegLevel;
101442
+ generateWithRecursiveQuery(pParse, p, &dest);
101334101443
}else
101335101444
#endif
101336101445
101337101446
/* Compound SELECTs that have an ORDER BY clause are handled separately.
101338101447
*/
@@ -101471,11 +101580,11 @@
101471101580
iBreak = sqlite3VdbeMakeLabel(v);
101472101581
iCont = sqlite3VdbeMakeLabel(v);
101473101582
computeLimitRegisters(pParse, p, iBreak);
101474101583
sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak);
101475101584
iStart = sqlite3VdbeCurrentAddr(v);
101476
- selectInnerLoop(pParse, p, p->pEList, unionTab, p->pEList->nExpr,
101585
+ selectInnerLoop(pParse, p, p->pEList, unionTab,
101477101586
0, 0, &dest, iCont, iBreak);
101478101587
sqlite3VdbeResolveLabel(v, iCont);
101479101588
sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart);
101480101589
sqlite3VdbeResolveLabel(v, iBreak);
101481101590
sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
@@ -101549,11 +101658,11 @@
101549101658
sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak);
101550101659
r1 = sqlite3GetTempReg(pParse);
101551101660
iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
101552101661
sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
101553101662
sqlite3ReleaseTempReg(pParse, r1);
101554
- selectInnerLoop(pParse, p, p->pEList, tab1, p->pEList->nExpr,
101663
+ selectInnerLoop(pParse, p, p->pEList, tab1,
101555101664
0, 0, &dest, iCont, iBreak);
101556101665
sqlite3VdbeResolveLabel(v, iCont);
101557101666
sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart);
101558101667
sqlite3VdbeResolveLabel(v, iBreak);
101559101668
sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
@@ -101671,11 +101780,11 @@
101671101780
}
101672101781
if( pParse->db->mallocFailed ) return 0;
101673101782
101674101783
/* Suppress the first OFFSET entries if there is an OFFSET clause
101675101784
*/
101676
- codeOffset(v, p, iContinue);
101785
+ codeOffset(v, p->iOffset, iContinue);
101677101786
101678101787
switch( pDest->eDest ){
101679101788
/* Store the result as data using a unique key.
101680101789
*/
101681101790
case SRT_Table:
@@ -103617,11 +103726,11 @@
103617103726
if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
103618103727
sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
103619103728
"argument");
103620103729
pFunc->iDistinct = -1;
103621103730
}else{
103622
- KeyInfo *pKeyInfo = keyInfoFromExprList(pParse, pE->x.pList);
103731
+ KeyInfo *pKeyInfo = keyInfoFromExprList(pParse, pE->x.pList, 0);
103623103732
sqlite3VdbeAddOp4(v, OP_OpenEphemeral, pFunc->iDistinct, 0, 0,
103624103733
(char*)pKeyInfo, P4_KEYINFO);
103625103734
}
103626103735
}
103627103736
}
@@ -103750,54 +103859,12 @@
103750103859
#endif
103751103860
103752103861
/*
103753103862
** Generate code for the SELECT statement given in the p argument.
103754103863
**
103755
-** The results are distributed in various ways depending on the
103756
-** contents of the SelectDest structure pointed to by argument pDest
103757
-** as follows:
103758
-**
103759
-** pDest->eDest Result
103760
-** ------------ -------------------------------------------
103761
-** SRT_Output Generate a row of output (using the OP_ResultRow
103762
-** opcode) for each row in the result set.
103763
-**
103764
-** SRT_Mem Only valid if the result is a single column.
103765
-** Store the first column of the first result row
103766
-** in register pDest->iSDParm then abandon the rest
103767
-** of the query. This destination implies "LIMIT 1".
103768
-**
103769
-** SRT_Set The result must be a single column. Store each
103770
-** row of result as the key in table pDest->iSDParm.
103771
-** Apply the affinity pDest->affSdst before storing
103772
-** results. Used to implement "IN (SELECT ...)".
103773
-**
103774
-** SRT_Union Store results as a key in a temporary table
103775
-** identified by pDest->iSDParm.
103776
-**
103777
-** SRT_Except Remove results from the temporary table pDest->iSDParm.
103778
-**
103779
-** SRT_Table Store results in temporary table pDest->iSDParm.
103780
-** This is like SRT_EphemTab except that the table
103781
-** is assumed to already be open.
103782
-**
103783
-** SRT_EphemTab Create an temporary table pDest->iSDParm and store
103784
-** the result there. The cursor is left open after
103785
-** returning. This is like SRT_Table except that
103786
-** this destination uses OP_OpenEphemeral to create
103787
-** the table first.
103788
-**
103789
-** SRT_Coroutine Generate a co-routine that returns a new row of
103790
-** results each time it is invoked. The entry point
103791
-** of the co-routine is stored in register pDest->iSDParm.
103792
-**
103793
-** SRT_Exists Store a 1 in memory cell pDest->iSDParm if the result
103794
-** set is not empty.
103795
-**
103796
-** SRT_Discard Throw the results away. This is used by SELECT
103797
-** statements within triggers whose only purpose is
103798
-** the side-effects of functions.
103864
+** The results are returned according to the SelectDest structure.
103865
+** See comments in sqliteInt.h for further information.
103799103866
**
103800103867
** This routine returns the number of errors. If any errors are
103801103868
** encountered, then an appropriate error message is left in
103802103869
** pParse->zErrMsg.
103803103870
**
@@ -104068,11 +104135,11 @@
104068104135
** we figure out that the sorting index is not needed. The addrSortIndex
104069104136
** variable is used to facilitate that change.
104070104137
*/
104071104138
if( pOrderBy ){
104072104139
KeyInfo *pKeyInfo;
104073
- pKeyInfo = keyInfoFromExprList(pParse, pOrderBy);
104140
+ pKeyInfo = keyInfoFromExprList(pParse, pOrderBy, 0);
104074104141
pOrderBy->iECursor = pParse->nTab++;
104075104142
p->addrOpenEphm[2] = addrSortIndex =
104076104143
sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
104077104144
pOrderBy->iECursor, pOrderBy->nExpr+2, 0,
104078104145
(char*)pKeyInfo, P4_KEYINFO);
@@ -104100,11 +104167,11 @@
104100104167
*/
104101104168
if( p->selFlags & SF_Distinct ){
104102104169
sDistinct.tabTnct = pParse->nTab++;
104103104170
sDistinct.addrTnct = sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
104104104171
sDistinct.tabTnct, 0, 0,
104105
- (char*)keyInfoFromExprList(pParse, p->pEList),
104172
+ (char*)keyInfoFromExprList(pParse, p->pEList, 0),
104106104173
P4_KEYINFO);
104107104174
sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
104108104175
sDistinct.eTnctType = WHERE_DISTINCT_UNORDERED;
104109104176
}else{
104110104177
sDistinct.eTnctType = WHERE_DISTINCT_NOOP;
@@ -104134,11 +104201,11 @@
104134104201
sqlite3VdbeChangeToNoop(v, addrSortIndex);
104135104202
p->addrOpenEphm[2] = -1;
104136104203
}
104137104204
104138104205
/* Use the standard inner loop. */
104139
- selectInnerLoop(pParse, p, pEList, 0, 0, pOrderBy, &sDistinct, pDest,
104206
+ selectInnerLoop(pParse, p, pEList, -1, pOrderBy, &sDistinct, pDest,
104140104207
sqlite3WhereContinueLabel(pWInfo),
104141104208
sqlite3WhereBreakLabel(pWInfo));
104142104209
104143104210
/* End the database scan loop.
104144104211
*/
@@ -104224,11 +104291,11 @@
104224104291
** implement it. Allocate that sorting index now. If it turns out
104225104292
** that we do not need it after all, the OP_SorterOpen instruction
104226104293
** will be converted into a Noop.
104227104294
*/
104228104295
sAggInfo.sortingIdx = pParse->nTab++;
104229
- pKeyInfo = keyInfoFromExprList(pParse, pGroupBy);
104296
+ pKeyInfo = keyInfoFromExprList(pParse, pGroupBy, 0);
104230104297
addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen,
104231104298
sAggInfo.sortingIdx, sAggInfo.nSortingColumn,
104232104299
0, (char*)pKeyInfo, P4_KEYINFO);
104233104300
104234104301
/* Initialize memory locations used by GROUP BY aggregate processing
@@ -104406,11 +104473,11 @@
104406104473
sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
104407104474
VdbeComment((v, "Groupby result generator entry point"));
104408104475
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104409104476
finalizeAggFunctions(pParse, &sAggInfo);
104410104477
sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
104411
- selectInnerLoop(pParse, p, p->pEList, 0, 0, pOrderBy,
104478
+ selectInnerLoop(pParse, p, p->pEList, -1, pOrderBy,
104412104479
&sDistinct, pDest,
104413104480
addrOutputRow+1, addrSetAbort);
104414104481
sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104415104482
VdbeComment((v, "end groupby result generator"));
104416104483
@@ -104549,11 +104616,11 @@
104549104616
finalizeAggFunctions(pParse, &sAggInfo);
104550104617
}
104551104618
104552104619
pOrderBy = 0;
104553104620
sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
104554
- selectInnerLoop(pParse, p, p->pEList, 0, 0, 0, 0,
104621
+ selectInnerLoop(pParse, p, p->pEList, -1, 0, 0,
104555104622
pDest, addrEnd, addrEnd);
104556104623
sqlite3ExprListDelete(db, pDel);
104557104624
}
104558104625
sqlite3VdbeResolveLabel(v, addrEnd);
104559104626
@@ -112138,14 +112205,20 @@
112138112205
** scan of the entire table.
112139112206
*/
112140112207
static const u8 aStep[] = { OP_Next, OP_Prev };
112141112208
static const u8 aStart[] = { OP_Rewind, OP_Last };
112142112209
assert( bRev==0 || bRev==1 );
112143
- pLevel->op = aStep[bRev];
112144
- pLevel->p1 = iCur;
112145
- pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
112146
- pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112210
+ if( pTabItem->isRecursive ){
112211
+ /* Tables marked isRecursive have only a single row that is stored in
112212
+ ** a pseudo-cursor. No need to Rewind or Next such cursors. */
112213
+ pLevel->op = OP_Noop;
112214
+ }else{
112215
+ pLevel->op = aStep[bRev];
112216
+ pLevel->p1 = iCur;
112217
+ pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
112218
+ pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112219
+ }
112147112220
}
112148112221
112149112222
/* Insert code to test every subexpression that can be completely
112150112223
** computed using the current set of tables.
112151112224
*/
@@ -119434,17 +119507,10 @@
119434119507
** must be complete. So isInit must not be set until the very end
119435119508
** of this routine.
119436119509
*/
119437119510
if( sqlite3GlobalConfig.isInit ) return SQLITE_OK;
119438119511
119439
-#ifdef SQLITE_ENABLE_SQLLOG
119440
- {
119441
- extern void sqlite3_init_sqllog(void);
119442
- sqlite3_init_sqllog();
119443
- }
119444
-#endif
119445
-
119446119512
/* Make sure the mutex subsystem is initialized. If unable to
119447119513
** initialize the mutex subsystem, return early with the error.
119448119514
** If the system is so sick that we are unable to allocate a mutex,
119449119515
** there is not much SQLite is going to be able to do.
119450119516
**
119451119517
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.3"
139 #define SQLITE_VERSION_NUMBER 3008003
140 #define SQLITE_SOURCE_ID "2014-01-21 00:19:43 cc1cb3217800ff666a00bf4f544a5a477589bc1b"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -8200,11 +8200,10 @@
8200 #define TK_AGG_FUNCTION 155
8201 #define TK_AGG_COLUMN 156
8202 #define TK_UMINUS 157
8203 #define TK_UPLUS 158
8204 #define TK_REGISTER 159
8205 #define TK_LEVEL 160
8206
8207 /************** End of parse.h ***********************************************/
8208 /************** Continuing where we left off in sqliteInt.h ******************/
8209 #include <stdio.h>
8210 #include <stdlib.h>
@@ -9129,41 +9128,41 @@
9129 #define OP_VerifyCookie 49
9130 #define OP_OpenRead 50 /* synopsis: root=P2 iDb=P3 */
9131 #define OP_OpenWrite 51 /* synopsis: root=P2 iDb=P3 */
9132 #define OP_OpenAutoindex 52 /* synopsis: nColumn=P2 */
9133 #define OP_OpenEphemeral 53 /* synopsis: nColumn=P2 */
9134 #define OP_SwapCursors 54
9135 #define OP_SorterOpen 55
9136 #define OP_OpenPseudo 56 /* synopsis: content in r[P2@P3] */
9137 #define OP_Close 57
9138 #define OP_SeekLt 58 /* synopsis: key=r[P3@P4] */
9139 #define OP_SeekLe 59 /* synopsis: key=r[P3@P4] */
9140 #define OP_SeekGe 60 /* synopsis: key=r[P3@P4] */
9141 #define OP_SeekGt 61 /* synopsis: key=r[P3@P4] */
9142 #define OP_Seek 62 /* synopsis: intkey=r[P2] */
9143 #define OP_NoConflict 63 /* synopsis: key=r[P3@P4] */
9144 #define OP_NotFound 64 /* synopsis: key=r[P3@P4] */
9145 #define OP_Found 65 /* synopsis: key=r[P3@P4] */
9146 #define OP_NotExists 66 /* synopsis: intkey=r[P3] */
9147 #define OP_Sequence 67 /* synopsis: r[P2]=rowid */
9148 #define OP_NewRowid 68 /* synopsis: r[P2]=rowid */
9149 #define OP_Insert 69 /* synopsis: intkey=r[P3] data=r[P2] */
9150 #define OP_InsertInt 70 /* synopsis: intkey=P3 data=r[P2] */
9151 #define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9152 #define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9153 #define OP_Delete 73
9154 #define OP_ResetCount 74
9155 #define OP_SorterCompare 75 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9156 #define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9157 #define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9158 #define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9159 #define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9160 #define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9161 #define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9162 #define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
9163 #define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9164 #define OP_SorterData 84 /* synopsis: r[P2]=data */
9165 #define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9166 #define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9167 #define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9168 #define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9169 #define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9170,69 +9169,68 @@
9170 #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9171 #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9172 #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9173 #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9174 #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9175 #define OP_RowKey 95 /* synopsis: r[P2]=key */
9176 #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9177 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9178 #define OP_RowData 98 /* synopsis: r[P2]=data */
9179 #define OP_Rowid 99 /* synopsis: r[P2]=rowid */
9180 #define OP_NullRow 100
9181 #define OP_Last 101
9182 #define OP_SorterSort 102
9183 #define OP_Sort 103
9184 #define OP_Rewind 104
9185 #define OP_SorterInsert 105
9186 #define OP_IdxInsert 106 /* synopsis: key=r[P2] */
9187 #define OP_IdxDelete 107 /* synopsis: key=r[P2@P3] */
9188 #define OP_IdxRowid 108 /* synopsis: r[P2]=rowid */
9189 #define OP_IdxLT 109 /* synopsis: key=r[P3@P4] */
9190 #define OP_IdxGE 110 /* synopsis: key=r[P3@P4] */
9191 #define OP_Destroy 111
9192 #define OP_Clear 112
9193 #define OP_CreateIndex 113 /* synopsis: r[P2]=root iDb=P1 */
9194 #define OP_CreateTable 114 /* synopsis: r[P2]=root iDb=P1 */
9195 #define OP_ParseSchema 115
9196 #define OP_LoadAnalysis 116
9197 #define OP_DropTable 117
9198 #define OP_DropIndex 118
9199 #define OP_DropTrigger 119
9200 #define OP_IntegrityCk 120
9201 #define OP_RowSetAdd 121 /* synopsis: rowset(P1)=r[P2] */
9202 #define OP_RowSetRead 122 /* synopsis: r[P3]=rowset(P1) */
9203 #define OP_RowSetTest 123 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9204 #define OP_Program 124
9205 #define OP_Param 125
9206 #define OP_FkCounter 126 /* synopsis: fkctr[P1]+=P2 */
9207 #define OP_FkIfZero 127 /* synopsis: if fkctr[P1]==0 goto P2 */
9208 #define OP_MemMax 128 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9209 #define OP_IfPos 129 /* synopsis: if r[P1]>0 goto P2 */
9210 #define OP_IfNeg 130 /* synopsis: if r[P1]<0 goto P2 */
9211 #define OP_IfZero 131 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9212 #define OP_AggFinal 132 /* synopsis: accum=r[P1] N=P2 */
9213 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9214 #define OP_IncrVacuum 134
9215 #define OP_Expire 135
9216 #define OP_TableLock 136 /* synopsis: iDb=P1 root=P2 write=P3 */
9217 #define OP_VBegin 137
9218 #define OP_VCreate 138
9219 #define OP_VDestroy 139
9220 #define OP_VOpen 140
9221 #define OP_VColumn 141 /* synopsis: r[P3]=vcolumn(P2) */
9222 #define OP_VNext 142
9223 #define OP_ToText 143 /* same as TK_TO_TEXT */
9224 #define OP_ToBlob 144 /* same as TK_TO_BLOB */
9225 #define OP_ToNumeric 145 /* same as TK_TO_NUMERIC */
9226 #define OP_ToInt 146 /* same as TK_TO_INT */
9227 #define OP_ToReal 147 /* same as TK_TO_REAL */
9228 #define OP_VRename 148
9229 #define OP_Pagecount 149
9230 #define OP_MaxPgcnt 150
9231 #define OP_Trace 151
9232 #define OP_Noop 152
9233 #define OP_Explain 153
9234
9235
9236 /* Properties such as "out2" or "jump" that are specified in
9237 ** comments following the "case" for each opcode in the vdbe.c
9238 ** are encoded into bitvectors as follows:
@@ -9250,23 +9248,23 @@
9250 /* 16 */ 0x01, 0x01, 0x04, 0x24, 0x04, 0x10, 0x00, 0x02,\
9251 /* 24 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x20,\
9252 /* 32 */ 0x00, 0x00, 0x04, 0x05, 0x04, 0x00, 0x00, 0x01,\
9253 /* 40 */ 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x02,\
9254 /* 48 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9255 /* 56 */ 0x00, 0x00, 0x11, 0x11, 0x11, 0x11, 0x08, 0x11,\
9256 /* 64 */ 0x11, 0x11, 0x11, 0x02, 0x02, 0x00, 0x00, 0x4c,\
9257 /* 72 */ 0x4c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
9258 /* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9259 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9260 /* 96 */ 0x24, 0x02, 0x00, 0x02, 0x00, 0x01, 0x01, 0x01,\
9261 /* 104 */ 0x01, 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02,\
9262 /* 112 */ 0x00, 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,\
9263 /* 120 */ 0x00, 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01,\
9264 /* 128 */ 0x08, 0x05, 0x05, 0x05, 0x00, 0x02, 0x01, 0x00,\
9265 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x04,\
9266 /* 144 */ 0x04, 0x04, 0x04, 0x04, 0x00, 0x02, 0x02, 0x00,\
9267 /* 152 */ 0x00, 0x00,}
9268
9269 /************** End of opcodes.h *********************************************/
9270 /************** Continuing where we left off in vdbe.h ***********************/
9271
9272 /*
@@ -11430,12 +11428,10 @@
11430 #define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */
11431 #define NC_HasAgg 0x02 /* One or more aggregate functions seen */
11432 #define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */
11433 #define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */
11434 #define NC_PartIdx 0x10 /* True if resolving a partial index WHERE */
11435 #define NC_Recursive 0x20 /* Resolvingn a recursive CTE definition */
11436 #define NC_UsesLevel 0x40 /* The LEVEL pseudo-column has been seen */
11437
11438 /*
11439 ** An instance of the following structure contains all information
11440 ** needed to generate code for a single SELECT statement.
11441 **
@@ -11489,16 +11485,73 @@
11489 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
11490 #define SF_Materialize 0x0100 /* Force materialization of views */
11491 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
11492 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
11493 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
11494 #define SF_UsesLevel 0x1000 /* Uses the LEVEL pseudo-column */
11495
11496
11497 /*
11498 ** The results of a select can be distributed in several ways. The
11499 ** "SRT" prefix means "SELECT Result Type".
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11500 */
11501 #define SRT_Union 1 /* Store result as keys in an index */
11502 #define SRT_Except 2 /* Remove result from a UNION index */
11503 #define SRT_Exists 3 /* Store 1 if the result is not empty */
11504 #define SRT_Discard 4 /* Do not save the results anywhere */
@@ -11507,25 +11560,28 @@
11507 #define IgnorableOrderby(X) ((X->eDest)<=SRT_Discard)
11508
11509 #define SRT_Output 5 /* Output each row of result */
11510 #define SRT_Mem 6 /* Store result in a memory cell */
11511 #define SRT_Set 7 /* Store results as keys in an index */
11512 #define SRT_Table 8 /* Store result as data with an automatic rowid */
11513 #define SRT_EphemTab 9 /* Create transient tab and store like SRT_Table */
11514 #define SRT_Coroutine 10 /* Generate a single row of result */
11515 #define SRT_DistTable 11 /* Like SRT_TABLE, but unique results only */
 
 
11516
11517 /*
11518 ** An instance of this object describes where to put of the results of
11519 ** a SELECT statement.
11520 */
11521 struct SelectDest {
11522 u8 eDest; /* How to dispose of the results. On of SRT_* above. */
11523 char affSdst; /* Affinity used when eDest==SRT_Set */
11524 int iSDParm; /* A parameter used by the eDest disposal method */
11525 int iSdst; /* Base register where results are written */
11526 int nSdst; /* Number of registers allocated */
 
11527 };
11528
11529 /*
11530 ** During code generation of statements that do inserts into AUTOINCREMENT
11531 ** tables, the following information is attached to the Table.u.autoInc.p
@@ -11696,11 +11752,10 @@
11696 Table **apVtabLock; /* Pointer to virtual tables needing locking */
11697 #endif
11698 Table *pZombieTab; /* List of Table objects to delete after code gen */
11699 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
11700 With *pWith; /* Current WITH clause, or NULL */
11701 int regLevel; /* Register holding the LEVEL variable */
11702 u8 bFreeWith; /* True if pWith should be freed with parser */
11703 };
11704
11705 /*
11706 ** Return true if currently inside an sqlite3_declare_vtab() call.
@@ -23183,41 +23238,41 @@
23183 /* 49 */ "VerifyCookie" OpHelp(""),
23184 /* 50 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23185 /* 51 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23186 /* 52 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23187 /* 53 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23188 /* 54 */ "SwapCursors" OpHelp(""),
23189 /* 55 */ "SorterOpen" OpHelp(""),
23190 /* 56 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
23191 /* 57 */ "Close" OpHelp(""),
23192 /* 58 */ "SeekLt" OpHelp("key=r[P3@P4]"),
23193 /* 59 */ "SeekLe" OpHelp("key=r[P3@P4]"),
23194 /* 60 */ "SeekGe" OpHelp("key=r[P3@P4]"),
23195 /* 61 */ "SeekGt" OpHelp("key=r[P3@P4]"),
23196 /* 62 */ "Seek" OpHelp("intkey=r[P2]"),
23197 /* 63 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23198 /* 64 */ "NotFound" OpHelp("key=r[P3@P4]"),
23199 /* 65 */ "Found" OpHelp("key=r[P3@P4]"),
23200 /* 66 */ "NotExists" OpHelp("intkey=r[P3]"),
23201 /* 67 */ "Sequence" OpHelp("r[P2]=rowid"),
23202 /* 68 */ "NewRowid" OpHelp("r[P2]=rowid"),
23203 /* 69 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23204 /* 70 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23205 /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
23206 /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
23207 /* 73 */ "Delete" OpHelp(""),
23208 /* 74 */ "ResetCount" OpHelp(""),
23209 /* 75 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23210 /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
23211 /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
23212 /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
23213 /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
23214 /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
23215 /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
23216 /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
23217 /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23218 /* 84 */ "SorterData" OpHelp("r[P2]=data"),
23219 /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
23220 /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
23221 /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
23222 /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
23223 /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -23224,69 +23279,68 @@
23224 /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
23225 /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
23226 /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
23227 /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
23228 /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23229 /* 95 */ "RowKey" OpHelp("r[P2]=key"),
23230 /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
23231 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
23232 /* 98 */ "RowData" OpHelp("r[P2]=data"),
23233 /* 99 */ "Rowid" OpHelp("r[P2]=rowid"),
23234 /* 100 */ "NullRow" OpHelp(""),
23235 /* 101 */ "Last" OpHelp(""),
23236 /* 102 */ "SorterSort" OpHelp(""),
23237 /* 103 */ "Sort" OpHelp(""),
23238 /* 104 */ "Rewind" OpHelp(""),
23239 /* 105 */ "SorterInsert" OpHelp(""),
23240 /* 106 */ "IdxInsert" OpHelp("key=r[P2]"),
23241 /* 107 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23242 /* 108 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23243 /* 109 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23244 /* 110 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23245 /* 111 */ "Destroy" OpHelp(""),
23246 /* 112 */ "Clear" OpHelp(""),
23247 /* 113 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23248 /* 114 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23249 /* 115 */ "ParseSchema" OpHelp(""),
23250 /* 116 */ "LoadAnalysis" OpHelp(""),
23251 /* 117 */ "DropTable" OpHelp(""),
23252 /* 118 */ "DropIndex" OpHelp(""),
23253 /* 119 */ "DropTrigger" OpHelp(""),
23254 /* 120 */ "IntegrityCk" OpHelp(""),
23255 /* 121 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23256 /* 122 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23257 /* 123 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23258 /* 124 */ "Program" OpHelp(""),
23259 /* 125 */ "Param" OpHelp(""),
23260 /* 126 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23261 /* 127 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23262 /* 128 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23263 /* 129 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23264 /* 130 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23265 /* 131 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23266 /* 132 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23267 /* 133 */ "Real" OpHelp("r[P2]=P4"),
23268 /* 134 */ "IncrVacuum" OpHelp(""),
23269 /* 135 */ "Expire" OpHelp(""),
23270 /* 136 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23271 /* 137 */ "VBegin" OpHelp(""),
23272 /* 138 */ "VCreate" OpHelp(""),
23273 /* 139 */ "VDestroy" OpHelp(""),
23274 /* 140 */ "VOpen" OpHelp(""),
23275 /* 141 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23276 /* 142 */ "VNext" OpHelp(""),
23277 /* 143 */ "ToText" OpHelp(""),
23278 /* 144 */ "ToBlob" OpHelp(""),
23279 /* 145 */ "ToNumeric" OpHelp(""),
23280 /* 146 */ "ToInt" OpHelp(""),
23281 /* 147 */ "ToReal" OpHelp(""),
23282 /* 148 */ "VRename" OpHelp(""),
23283 /* 149 */ "Pagecount" OpHelp(""),
23284 /* 150 */ "MaxPgcnt" OpHelp(""),
23285 /* 151 */ "Trace" OpHelp(""),
23286 /* 152 */ "Noop" OpHelp(""),
23287 /* 153 */ "Explain" OpHelp(""),
23288 };
23289 return azName[i];
23290 }
23291 #endif
23292
@@ -69741,37 +69795,10 @@
69741 }
69742 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69743 break;
69744 }
69745
69746 #ifndef SQLITE_OMIT_CTE
69747 /* Opcode: SwapCursors P1 P2 * * *
69748 **
69749 ** Parameters P1 and P2 are both cursors opened by the OpenEphemeral
69750 ** opcode. This opcode deletes the contents of epheremal table P1,
69751 ** then renames P2 to P1 and P1 to P2. In other words, following this
69752 ** opcode cursor P2 is open on an empty table and P1 is open on the
69753 ** table that was initially accessed by P2.
69754 */
69755 case OP_SwapCursors: {
69756 Mem tmp;
69757 VdbeCursor *pTmp;
69758
69759 tmp = p->aMem[p->nMem - pOp->p1];
69760 p->aMem[p->nMem - pOp->p1] = p->aMem[p->nMem - pOp->p2];
69761 p->aMem[p->nMem - pOp->p2] = tmp;
69762
69763 pTmp = p->apCsr[pOp->p1];
69764 p->apCsr[pOp->p1] = p->apCsr[pOp->p2];
69765 p->apCsr[pOp->p2] = pTmp;
69766
69767 assert( pTmp->isTable );
69768 rc = sqlite3BtreeClearTable(pTmp->pBt, MASTER_ROOT, 0);
69769 break;
69770 }
69771 #endif /* ifndef SQLITE_OMIT_CTE */
69772
69773 /* Opcode: SorterOpen P1 * * P4 *
69774 **
69775 ** This opcode works like OP_OpenEphemeral except that it opens
69776 ** a transient index that is specifically designed to sort large
69777 ** tables using an external merge-sort algorithm.
@@ -70765,11 +70792,10 @@
70765 pC = p->apCsr[pOp->p1];
70766 assert( pC!=0 );
70767 pC->nullRow = 1;
70768 pC->rowidIsValid = 0;
70769 pC->cacheStatus = CACHE_STALE;
70770 assert( pC->pCursor || pC->pVtabCursor );
70771 if( pC->pCursor ){
70772 sqlite3BtreeClearCursor(pC->pCursor);
70773 }
70774 break;
70775 }
@@ -75130,11 +75156,11 @@
75130 sqlite3 *db = pParse->db; /* The database connection */
75131 struct SrcList_item *pItem; /* Use for looping over pSrcList items */
75132 struct SrcList_item *pMatch = 0; /* The matching pSrcList item */
75133 NameContext *pTopNC = pNC; /* First namecontext in the list */
75134 Schema *pSchema = 0; /* Schema of the expression */
75135 u8 newOp = TK_COLUMN; /* pExpr->op after resolving name */
75136 Table *pTab = 0; /* Table hold the row */
75137 Column *pCol; /* A column of pTab */
75138
75139 assert( pNC ); /* the name context cannot be NULL. */
75140 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
@@ -75171,26 +75197,10 @@
75171 /* Start at the inner-most context and move outward until a match is found */
75172 while( pNC && cnt==0 ){
75173 ExprList *pEList;
75174 SrcList *pSrcList = pNC->pSrcList;
75175
75176 #ifndef SQLITE_OMIT_CTE
75177 /* The identifier "LEVEL", with a table or database qualifier and within a
75178 ** recursive common table expression, resolves to the special LEVEL pseudo-column.
75179 ** To access table names called "level", add a table qualifier.
75180 */
75181 if( (pNC->ncFlags&NC_Recursive)!=0 && zTab==0 && sqlite3_stricmp(zCol,"level")==0 ){
75182 assert( cnt==0 );
75183 cnt = 1;
75184 newOp = TK_LEVEL;
75185 pExpr->iColumn = -1;
75186 pExpr->affinity = SQLITE_AFF_INTEGER;
75187 pNC->ncFlags |= NC_UsesLevel;
75188 break;
75189 }
75190 #endif
75191
75192 if( pSrcList ){
75193 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
75194 pTab = pItem->pTab;
75195 assert( pTab!=0 && pTab->zName!=0 );
75196 assert( pTab->nCol>0 );
@@ -75291,11 +75301,11 @@
75291 testcase( iCol==32 );
75292 pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
75293 }
75294 pExpr->iColumn = (i16)iCol;
75295 pExpr->pTab = pTab;
75296 newOp = TK_TRIGGER;
75297 }
75298 }
75299 }
75300 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
75301
@@ -75415,15 +75425,15 @@
75415 */
75416 sqlite3ExprDelete(db, pExpr->pLeft);
75417 pExpr->pLeft = 0;
75418 sqlite3ExprDelete(db, pExpr->pRight);
75419 pExpr->pRight = 0;
75420 pExpr->op = newOp;
75421 lookupname_end:
75422 if( cnt==1 ){
75423 assert( pNC!=0 );
75424 if( pExpr->op!=TK_AS && pExpr->op!=TK_LEVEL ){
75425 sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
75426 }
75427 /* Increment the nRef value on all name contexts from TopNC up to
75428 ** the point where the name matched. */
75429 for(;;){
@@ -76116,11 +76126,10 @@
76116
76117 /* Set up the local name-context to pass to sqlite3ResolveExprNames() to
76118 ** resolve the result-set expression list.
76119 */
76120 sNC.ncFlags = NC_AllowAgg;
76121 if( p->selFlags & SF_Recursive ) sNC.ncFlags |= NC_Recursive;
76122 sNC.pSrcList = p->pSrc;
76123 sNC.pNext = pOuterNC;
76124
76125 /* Resolve names in the result set. */
76126 pEList = p->pEList;
@@ -76195,14 +76204,10 @@
76195 "the GROUP BY clause");
76196 return WRC_Abort;
76197 }
76198 }
76199 }
76200 if( sNC.ncFlags & NC_UsesLevel ){
76201 p->selFlags |= SF_UsesLevel;
76202 }
76203 sNC.ncFlags &= ~(NC_Recursive|NC_UsesLevel);
76204
76205 /* Advance to the next term of the compound
76206 */
76207 p = p->pPrior;
76208 nCompound++;
@@ -78835,16 +78840,10 @@
78835 inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
78836 pExpr->iColumn, iTab, target,
78837 pExpr->op2);
78838 break;
78839 }
78840 #ifndef SQLITE_OMIT_CTE
78841 case TK_LEVEL: {
78842 inReg = pParse->regLevel;
78843 break;
78844 }
78845 #endif
78846 case TK_INTEGER: {
78847 codeInteger(pParse, pExpr, 0, target);
78848 break;
78849 }
78850 #ifndef SQLITE_OMIT_FLOATING_POINT
@@ -79464,11 +79463,10 @@
79464 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
79465 int r2;
79466 pExpr = sqlite3ExprSkipCollate(pExpr);
79467 if( ConstFactorOk(pParse)
79468 && pExpr->op!=TK_REGISTER
79469 && pExpr->op!=TK_LEVEL
79470 && sqlite3ExprIsConstantNotJoin(pExpr)
79471 ){
79472 ExprList *p = pParse->pConstExpr;
79473 int i;
79474 *pReg = 0;
@@ -99909,17 +99907,17 @@
99909 /*
99910 ** Add code to implement the OFFSET
99911 */
99912 static void codeOffset(
99913 Vdbe *v, /* Generate code into this VM */
99914 Select *p, /* The SELECT statement being coded */
99915 int iContinue /* Jump here to skip the current record */
99916 ){
99917 if( p->iOffset && iContinue!=0 ){
99918 int addr;
99919 sqlite3VdbeAddOp2(v, OP_AddImm, p->iOffset, -1);
99920 addr = sqlite3VdbeAddOp1(v, OP_IfNeg, p->iOffset);
99921 sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
99922 VdbeComment((v, "skip OFFSET records"));
99923 sqlite3VdbeJumpHere(v, addr);
99924 }
99925 }
@@ -99990,21 +99988,20 @@
99990
99991 /*
99992 ** This routine generates the code for the inside of the inner loop
99993 ** of a SELECT.
99994 **
99995 ** If srcTab and nColumn are both zero, then the pEList expressions
99996 ** are evaluated in order to get the data for this row. If nColumn>0
99997 ** then data is pulled from srcTab and pEList is used only to get the
99998 ** datatypes for each column.
99999 */
100000 static void selectInnerLoop(
100001 Parse *pParse, /* The parser context */
100002 Select *p, /* The complete select statement being coded */
100003 ExprList *pEList, /* List of values being extracted */
100004 int srcTab, /* Pull data from this table */
100005 int nColumn, /* Number of columns in the source table */
100006 ExprList *pOrderBy, /* If not NULL, sort results using this key */
100007 DistinctCtx *pDistinct, /* If not NULL, info on how to process DISTINCT */
100008 SelectDest *pDest, /* How to dispose of the results */
100009 int iContinue, /* Jump here to continue with next row */
100010 int iBreak /* Jump here to break out of the inner loop */
@@ -100016,61 +100013,54 @@
100016 int eDest = pDest->eDest; /* How to dispose of results */
100017 int iParm = pDest->iSDParm; /* First argument to disposal method */
100018 int nResultCol; /* Number of result columns */
100019
100020 assert( v );
100021 if( NEVER(v==0) ) return;
100022 assert( pEList!=0 );
100023 hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
100024 if( pOrderBy==0 && !hasDistinct ){
100025 codeOffset(v, p, iContinue);
100026 }
100027
100028 /* Pull the requested columns.
100029 */
100030 if( nColumn>0 ){
100031 nResultCol = nColumn;
100032 }else{
100033 nResultCol = pEList->nExpr;
100034 }
100035 if( pDest->iSdst==0 ){
100036 pDest->iSdst = pParse->nMem+1;
100037 pDest->nSdst = nResultCol;
100038 pParse->nMem += nResultCol;
100039 }else{
100040 assert( pDest->nSdst==nResultCol );
100041 }
100042 regResult = pDest->iSdst;
100043 if( nColumn>0 ){
100044 for(i=0; i<nColumn; i++){
100045 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
 
100046 }
100047 }else if( eDest!=SRT_Exists ){
100048 /* If the destination is an EXISTS(...) expression, the actual
100049 ** values returned by the SELECT are not required.
100050 */
100051 sqlite3ExprCodeExprList(pParse, pEList, regResult,
100052 (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
100053 }
100054 nColumn = nResultCol;
100055
100056 /* If the DISTINCT keyword was present on the SELECT statement
100057 ** and this row has been seen before, then do not make this row
100058 ** part of the result.
100059 */
100060 if( hasDistinct ){
100061 assert( pEList!=0 );
100062 assert( pEList->nExpr==nColumn );
100063 switch( pDistinct->eTnctType ){
100064 case WHERE_DISTINCT_ORDERED: {
100065 VdbeOp *pOp; /* No longer required OpenEphemeral instr. */
100066 int iJump; /* Jump destination */
100067 int regPrev; /* Previous row content */
100068
100069 /* Allocate space for the previous row */
100070 regPrev = pParse->nMem+1;
100071 pParse->nMem += nColumn;
100072
100073 /* Change the OP_OpenEphemeral coded earlier to an OP_Null
100074 ** sets the MEM_Cleared bit on the first register of the
100075 ** previous value. This will cause the OP_Ne below to always
100076 ** fail on the first iteration of the loop even if the first
@@ -100080,23 +100070,23 @@
100080 pOp = sqlite3VdbeGetOp(v, pDistinct->addrTnct);
100081 pOp->opcode = OP_Null;
100082 pOp->p1 = 1;
100083 pOp->p2 = regPrev;
100084
100085 iJump = sqlite3VdbeCurrentAddr(v) + nColumn;
100086 for(i=0; i<nColumn; i++){
100087 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
100088 if( i<nColumn-1 ){
100089 sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
100090 }else{
100091 sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
100092 }
100093 sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
100094 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
100095 }
100096 assert( sqlite3VdbeCurrentAddr(v)==iJump );
100097 sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nColumn-1);
100098 break;
100099 }
100100
100101 case WHERE_DISTINCT_UNIQUE: {
100102 sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct);
@@ -100103,16 +100093,16 @@
100103 break;
100104 }
100105
100106 default: {
100107 assert( pDistinct->eTnctType==WHERE_DISTINCT_UNORDERED );
100108 codeDistinct(pParse, pDistinct->tabTnct, iContinue, nColumn, regResult);
100109 break;
100110 }
100111 }
100112 if( pOrderBy==0 ){
100113 codeOffset(v, p, iContinue);
100114 }
100115 }
100116
100117 switch( eDest ){
100118 /* In this mode, write each query result to the key of the temporary
@@ -100120,11 +100110,11 @@
100120 */
100121 #ifndef SQLITE_OMIT_COMPOUND_SELECT
100122 case SRT_Union: {
100123 int r1;
100124 r1 = sqlite3GetTempReg(pParse);
100125 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1);
100126 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
100127 sqlite3ReleaseTempReg(pParse, r1);
100128 break;
100129 }
100130
@@ -100131,24 +100121,24 @@
100131 /* Construct a record from the query result, but instead of
100132 ** saving that record, use it as a key to delete elements from
100133 ** the temporary table iParm.
100134 */
100135 case SRT_Except: {
100136 sqlite3VdbeAddOp3(v, OP_IdxDelete, iParm, regResult, nColumn);
100137 break;
100138 }
100139 #endif
100140
100141 /* Store the result as data using a unique key.
100142 */
100143 case SRT_DistTable:
100144 case SRT_Table:
100145 case SRT_EphemTab: {
100146 int r1 = sqlite3GetTempReg(pParse);
100147 testcase( eDest==SRT_Table );
100148 testcase( eDest==SRT_EphemTab );
100149 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1);
100150 #ifndef SQLITE_OMIT_CTE
100151 if( eDest==SRT_DistTable ){
100152 /* If the destination is DistTable, then cursor (iParm+1) is open
100153 ** on an ephemeral index. If the current row is already present
100154 ** in the index, do not write it to the output. If not, add the
@@ -100177,11 +100167,11 @@
100177 /* If we are creating a set for an "expr IN (SELECT ...)" construct,
100178 ** then there should be a single item on the stack. Write this
100179 ** item into the set table with bogus data.
100180 */
100181 case SRT_Set: {
100182 assert( nColumn==1 );
100183 pDest->affSdst =
100184 sqlite3CompareAffinity(pEList->a[0].pExpr, pDest->affSdst);
100185 if( pOrderBy ){
100186 /* At first glance you would think we could optimize out the
100187 ** ORDER BY in this case since the order of entries in the set
@@ -100209,11 +100199,11 @@
100209 /* If this is a scalar select that is part of an expression, then
100210 ** store the results in the appropriate memory cell and break out
100211 ** of the scan loop.
100212 */
100213 case SRT_Mem: {
100214 assert( nColumn==1 );
100215 if( pOrderBy ){
100216 pushOntoSorter(pParse, pOrderBy, p, regResult);
100217 }else{
100218 sqlite3ExprCodeMove(pParse, regResult, iParm, 1);
100219 /* The LIMIT clause will jump out of the loop for us */
@@ -100230,21 +100220,66 @@
100230 case SRT_Output: {
100231 testcase( eDest==SRT_Coroutine );
100232 testcase( eDest==SRT_Output );
100233 if( pOrderBy ){
100234 int r1 = sqlite3GetTempReg(pParse);
100235 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nColumn, r1);
100236 pushOntoSorter(pParse, pOrderBy, p, r1);
100237 sqlite3ReleaseTempReg(pParse, r1);
100238 }else if( eDest==SRT_Coroutine ){
100239 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
100240 }else{
100241 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nColumn);
100242 sqlite3ExprCacheAffinityChange(pParse, regResult, nColumn);
100243 }
100244 break;
100245 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100246
100247 #if !defined(SQLITE_OMIT_TRIGGER)
100248 /* Discard the results. This is used for SELECT statements inside
100249 ** the body of a TRIGGER. The purpose of such selects is to call
100250 ** user-defined functions that have side effects. We do not care
@@ -100330,19 +100365,19 @@
100330 **
100331 ** Space to hold the KeyInfo structure is obtain from malloc. The calling
100332 ** function is responsible for seeing that this structure is eventually
100333 ** freed.
100334 */
100335 static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){
100336 int nExpr;
100337 KeyInfo *pInfo;
100338 struct ExprList_item *pItem;
100339 sqlite3 *db = pParse->db;
100340 int i;
100341
100342 nExpr = pList->nExpr;
100343 pInfo = sqlite3KeyInfoAlloc(db, nExpr, 1);
100344 if( pInfo ){
100345 assert( sqlite3KeyInfoIsWriteable(pInfo) );
100346 for(i=0, pItem=pList->a; i<nExpr; i++, pItem++){
100347 CollSeq *pColl;
100348 pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
@@ -100479,17 +100514,17 @@
100479 if( p->selFlags & SF_UseSorter ){
100480 int regSortOut = ++pParse->nMem;
100481 int ptab2 = pParse->nTab++;
100482 sqlite3VdbeAddOp3(v, OP_OpenPseudo, ptab2, regSortOut, pOrderBy->nExpr+2);
100483 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
100484 codeOffset(v, p, addrContinue);
100485 sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
100486 sqlite3VdbeAddOp3(v, OP_Column, ptab2, pOrderBy->nExpr+1, regRow);
100487 sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
100488 }else{
100489 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak);
100490 codeOffset(v, p, addrContinue);
100491 sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr+1, regRow);
100492 }
100493 switch( eDest ){
100494 case SRT_Table:
100495 case SRT_EphemTab: {
@@ -101049,12 +101084,17 @@
101049 ** the limit and offset. If there is no limit and/or offset, then
101050 ** iLimit and iOffset are negative.
101051 **
101052 ** This routine changes the values of iLimit and iOffset only if
101053 ** a limit or offset is defined by pLimit and pOffset. iLimit and
101054 ** iOffset should have been preset to appropriate default values
101055 ** (usually but not always -1) prior to calling this routine.
 
 
 
 
 
101056 ** Only if pLimit!=0 or pOffset!=0 do the limit registers get
101057 ** redefined. The UNION ALL operator uses this property to force
101058 ** the reuse of the same limit and offset registers across multiple
101059 ** SELECT statements.
101060 */
@@ -101074,11 +101114,11 @@
101074 sqlite3ExprCacheClear(pParse);
101075 assert( p->pOffset==0 || p->pLimit!=0 );
101076 if( p->pLimit ){
101077 p->iLimit = iLimit = ++pParse->nMem;
101078 v = sqlite3GetVdbe(pParse);
101079 if( NEVER(v==0) ) return; /* VDBE should have already been allocated */
101080 if( sqlite3ExprIsInteger(p->pLimit, &n) ){
101081 sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit);
101082 VdbeComment((v, "LIMIT counter"));
101083 if( n==0 ){
101084 sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
@@ -101131,11 +101171,169 @@
101131 }
101132 return pRet;
101133 }
101134 #endif /* SQLITE_OMIT_COMPOUND_SELECT */
101135
101136 /* Forward reference */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101137 static int multiSelectOrderBy(
101138 Parse *pParse, /* Parsing context */
101139 Select *p, /* The right-most of SELECTs to be coded */
101140 SelectDest *pDest /* What to do with query results */
101141 );
@@ -101239,100 +101437,11 @@
101239 goto multi_select_end;
101240 }
101241
101242 #ifndef SQLITE_OMIT_CTE
101243 if( p->selFlags & SF_Recursive ){
101244 SrcList *pSrc = p->pSrc; /* The FROM clause of the right-most SELECT */
101245 int nCol = p->pEList->nExpr; /* Number of columns in the result set */
101246 int addrNext;
101247 int addrSwap;
101248 int iCont, iBreak;
101249 int tmp1; /* Intermediate table */
101250 int tmp2; /* Next intermediate table */
101251 int tmp3 = 0; /* To ensure unique results if UNION */
101252 int eDest = SRT_Table;
101253 SelectDest tmp2dest;
101254 int i;
101255 int regLevel = 0; /* Register for LEVEL value */
101256 int savedRegLevel; /* Saved value of pParse->regLevel */
101257
101258 /* Check that there is no ORDER BY or LIMIT clause. Neither of these
101259 ** are supported on recursive queries. */
101260 assert( p->pOffset==0 || p->pLimit );
101261 if( p->pOrderBy || p->pLimit ){
101262 sqlite3ErrorMsg(pParse, "%s in a recursive query",
101263 p->pOrderBy ? "ORDER BY" : "LIMIT"
101264 );
101265 goto multi_select_end;
101266 }
101267
101268 if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ){
101269 goto multi_select_end;
101270 }
101271 iBreak = sqlite3VdbeMakeLabel(v);
101272 iCont = sqlite3VdbeMakeLabel(v);
101273
101274 for(i=0; ALWAYS(i<pSrc->nSrc); i++){
101275 if( pSrc->a[i].isRecursive ){
101276 tmp1 = pSrc->a[i].iCursor;
101277 break;
101278 }
101279 }
101280
101281 tmp2 = pParse->nTab++;
101282 if( p->op==TK_UNION ){
101283 eDest = SRT_DistTable;
101284 tmp3 = pParse->nTab++;
101285 }
101286 sqlite3SelectDestInit(&tmp2dest, eDest, tmp2);
101287
101288 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tmp1, nCol);
101289 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tmp2, nCol);
101290 if( tmp3 ){
101291 p->addrOpenEphm[0] = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, tmp3, 0);
101292 p->selFlags |= SF_UsesEphemeral;
101293 }
101294
101295 /* Store the results of the initial SELECT in tmp2. */
101296 rc = sqlite3Select(pParse, pPrior, &tmp2dest);
101297 if( rc ) goto multi_select_end;
101298
101299 /* Allocate and initialize a register to hold the LEVEL pseudo-column */
101300 savedRegLevel = pParse->regLevel;
101301 if( p->selFlags & SF_UsesLevel ){
101302 regLevel = pParse->regLevel = ++pParse->nMem;
101303 sqlite3VdbeAddOp2(v, OP_Integer, 0, regLevel);
101304 VdbeComment((v, "level=0"));
101305 }
101306
101307 /* Clear tmp1. Then switch the contents of tmp1 and tmp2. Then return
101308 ** the contents of tmp1 to the caller. Or, if tmp1 is empty at this
101309 ** point, the recursive query has finished - jump to address iBreak. */
101310 addrSwap = sqlite3VdbeAddOp2(v, OP_SwapCursors, tmp1, tmp2);
101311 sqlite3VdbeAddOp2(v, OP_Rewind, tmp1, iBreak);
101312 addrNext = sqlite3VdbeCurrentAddr(v);
101313 selectInnerLoop(pParse, p, p->pEList, tmp1, p->pEList->nExpr,
101314 0, 0, &dest, iCont, iBreak);
101315 sqlite3VdbeResolveLabel(v, iCont);
101316 sqlite3VdbeAddOp2(v, OP_Next, tmp1, addrNext);
101317 if( regLevel ){
101318 sqlite3VdbeAddOp2(v, OP_AddImm, regLevel, 1);
101319 VdbeComment((v, "level++"));
101320 }
101321
101322 /* Execute the recursive SELECT. Store the results in tmp2. While this
101323 ** SELECT is running, the contents of tmp1 are read by recursive
101324 ** references to the current CTE. */
101325 p->pPrior = 0;
101326 rc = sqlite3Select(pParse, p, &tmp2dest);
101327 assert( p->pPrior==0 );
101328 p->pPrior = pPrior;
101329 if( rc ) goto multi_select_end;
101330
101331 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrSwap);
101332 sqlite3VdbeResolveLabel(v, iBreak);
101333 pParse->regLevel = savedRegLevel;
101334 }else
101335 #endif
101336
101337 /* Compound SELECTs that have an ORDER BY clause are handled separately.
101338 */
@@ -101471,11 +101580,11 @@
101471 iBreak = sqlite3VdbeMakeLabel(v);
101472 iCont = sqlite3VdbeMakeLabel(v);
101473 computeLimitRegisters(pParse, p, iBreak);
101474 sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak);
101475 iStart = sqlite3VdbeCurrentAddr(v);
101476 selectInnerLoop(pParse, p, p->pEList, unionTab, p->pEList->nExpr,
101477 0, 0, &dest, iCont, iBreak);
101478 sqlite3VdbeResolveLabel(v, iCont);
101479 sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart);
101480 sqlite3VdbeResolveLabel(v, iBreak);
101481 sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
@@ -101549,11 +101658,11 @@
101549 sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak);
101550 r1 = sqlite3GetTempReg(pParse);
101551 iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
101552 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
101553 sqlite3ReleaseTempReg(pParse, r1);
101554 selectInnerLoop(pParse, p, p->pEList, tab1, p->pEList->nExpr,
101555 0, 0, &dest, iCont, iBreak);
101556 sqlite3VdbeResolveLabel(v, iCont);
101557 sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart);
101558 sqlite3VdbeResolveLabel(v, iBreak);
101559 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
@@ -101671,11 +101780,11 @@
101671 }
101672 if( pParse->db->mallocFailed ) return 0;
101673
101674 /* Suppress the first OFFSET entries if there is an OFFSET clause
101675 */
101676 codeOffset(v, p, iContinue);
101677
101678 switch( pDest->eDest ){
101679 /* Store the result as data using a unique key.
101680 */
101681 case SRT_Table:
@@ -103617,11 +103726,11 @@
103617 if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
103618 sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
103619 "argument");
103620 pFunc->iDistinct = -1;
103621 }else{
103622 KeyInfo *pKeyInfo = keyInfoFromExprList(pParse, pE->x.pList);
103623 sqlite3VdbeAddOp4(v, OP_OpenEphemeral, pFunc->iDistinct, 0, 0,
103624 (char*)pKeyInfo, P4_KEYINFO);
103625 }
103626 }
103627 }
@@ -103750,54 +103859,12 @@
103750 #endif
103751
103752 /*
103753 ** Generate code for the SELECT statement given in the p argument.
103754 **
103755 ** The results are distributed in various ways depending on the
103756 ** contents of the SelectDest structure pointed to by argument pDest
103757 ** as follows:
103758 **
103759 ** pDest->eDest Result
103760 ** ------------ -------------------------------------------
103761 ** SRT_Output Generate a row of output (using the OP_ResultRow
103762 ** opcode) for each row in the result set.
103763 **
103764 ** SRT_Mem Only valid if the result is a single column.
103765 ** Store the first column of the first result row
103766 ** in register pDest->iSDParm then abandon the rest
103767 ** of the query. This destination implies "LIMIT 1".
103768 **
103769 ** SRT_Set The result must be a single column. Store each
103770 ** row of result as the key in table pDest->iSDParm.
103771 ** Apply the affinity pDest->affSdst before storing
103772 ** results. Used to implement "IN (SELECT ...)".
103773 **
103774 ** SRT_Union Store results as a key in a temporary table
103775 ** identified by pDest->iSDParm.
103776 **
103777 ** SRT_Except Remove results from the temporary table pDest->iSDParm.
103778 **
103779 ** SRT_Table Store results in temporary table pDest->iSDParm.
103780 ** This is like SRT_EphemTab except that the table
103781 ** is assumed to already be open.
103782 **
103783 ** SRT_EphemTab Create an temporary table pDest->iSDParm and store
103784 ** the result there. The cursor is left open after
103785 ** returning. This is like SRT_Table except that
103786 ** this destination uses OP_OpenEphemeral to create
103787 ** the table first.
103788 **
103789 ** SRT_Coroutine Generate a co-routine that returns a new row of
103790 ** results each time it is invoked. The entry point
103791 ** of the co-routine is stored in register pDest->iSDParm.
103792 **
103793 ** SRT_Exists Store a 1 in memory cell pDest->iSDParm if the result
103794 ** set is not empty.
103795 **
103796 ** SRT_Discard Throw the results away. This is used by SELECT
103797 ** statements within triggers whose only purpose is
103798 ** the side-effects of functions.
103799 **
103800 ** This routine returns the number of errors. If any errors are
103801 ** encountered, then an appropriate error message is left in
103802 ** pParse->zErrMsg.
103803 **
@@ -104068,11 +104135,11 @@
104068 ** we figure out that the sorting index is not needed. The addrSortIndex
104069 ** variable is used to facilitate that change.
104070 */
104071 if( pOrderBy ){
104072 KeyInfo *pKeyInfo;
104073 pKeyInfo = keyInfoFromExprList(pParse, pOrderBy);
104074 pOrderBy->iECursor = pParse->nTab++;
104075 p->addrOpenEphm[2] = addrSortIndex =
104076 sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
104077 pOrderBy->iECursor, pOrderBy->nExpr+2, 0,
104078 (char*)pKeyInfo, P4_KEYINFO);
@@ -104100,11 +104167,11 @@
104100 */
104101 if( p->selFlags & SF_Distinct ){
104102 sDistinct.tabTnct = pParse->nTab++;
104103 sDistinct.addrTnct = sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
104104 sDistinct.tabTnct, 0, 0,
104105 (char*)keyInfoFromExprList(pParse, p->pEList),
104106 P4_KEYINFO);
104107 sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
104108 sDistinct.eTnctType = WHERE_DISTINCT_UNORDERED;
104109 }else{
104110 sDistinct.eTnctType = WHERE_DISTINCT_NOOP;
@@ -104134,11 +104201,11 @@
104134 sqlite3VdbeChangeToNoop(v, addrSortIndex);
104135 p->addrOpenEphm[2] = -1;
104136 }
104137
104138 /* Use the standard inner loop. */
104139 selectInnerLoop(pParse, p, pEList, 0, 0, pOrderBy, &sDistinct, pDest,
104140 sqlite3WhereContinueLabel(pWInfo),
104141 sqlite3WhereBreakLabel(pWInfo));
104142
104143 /* End the database scan loop.
104144 */
@@ -104224,11 +104291,11 @@
104224 ** implement it. Allocate that sorting index now. If it turns out
104225 ** that we do not need it after all, the OP_SorterOpen instruction
104226 ** will be converted into a Noop.
104227 */
104228 sAggInfo.sortingIdx = pParse->nTab++;
104229 pKeyInfo = keyInfoFromExprList(pParse, pGroupBy);
104230 addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen,
104231 sAggInfo.sortingIdx, sAggInfo.nSortingColumn,
104232 0, (char*)pKeyInfo, P4_KEYINFO);
104233
104234 /* Initialize memory locations used by GROUP BY aggregate processing
@@ -104406,11 +104473,11 @@
104406 sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
104407 VdbeComment((v, "Groupby result generator entry point"));
104408 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104409 finalizeAggFunctions(pParse, &sAggInfo);
104410 sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
104411 selectInnerLoop(pParse, p, p->pEList, 0, 0, pOrderBy,
104412 &sDistinct, pDest,
104413 addrOutputRow+1, addrSetAbort);
104414 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104415 VdbeComment((v, "end groupby result generator"));
104416
@@ -104549,11 +104616,11 @@
104549 finalizeAggFunctions(pParse, &sAggInfo);
104550 }
104551
104552 pOrderBy = 0;
104553 sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
104554 selectInnerLoop(pParse, p, p->pEList, 0, 0, 0, 0,
104555 pDest, addrEnd, addrEnd);
104556 sqlite3ExprListDelete(db, pDel);
104557 }
104558 sqlite3VdbeResolveLabel(v, addrEnd);
104559
@@ -112138,14 +112205,20 @@
112138 ** scan of the entire table.
112139 */
112140 static const u8 aStep[] = { OP_Next, OP_Prev };
112141 static const u8 aStart[] = { OP_Rewind, OP_Last };
112142 assert( bRev==0 || bRev==1 );
112143 pLevel->op = aStep[bRev];
112144 pLevel->p1 = iCur;
112145 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
112146 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
 
 
 
 
 
 
112147 }
112148
112149 /* Insert code to test every subexpression that can be completely
112150 ** computed using the current set of tables.
112151 */
@@ -119434,17 +119507,10 @@
119434 ** must be complete. So isInit must not be set until the very end
119435 ** of this routine.
119436 */
119437 if( sqlite3GlobalConfig.isInit ) return SQLITE_OK;
119438
119439 #ifdef SQLITE_ENABLE_SQLLOG
119440 {
119441 extern void sqlite3_init_sqllog(void);
119442 sqlite3_init_sqllog();
119443 }
119444 #endif
119445
119446 /* Make sure the mutex subsystem is initialized. If unable to
119447 ** initialize the mutex subsystem, return early with the error.
119448 ** If the system is so sick that we are unable to allocate a mutex,
119449 ** there is not much SQLite is going to be able to do.
119450 **
119451
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -135,11 +135,11 @@
135 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
136 ** [sqlite_version()] and [sqlite_source_id()].
137 */
138 #define SQLITE_VERSION "3.8.3"
139 #define SQLITE_VERSION_NUMBER 3008003
140 #define SQLITE_SOURCE_ID "2014-01-22 18:16:27 b6cea42006910d590373e8f9e296d7672edb114b"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -8200,11 +8200,10 @@
8200 #define TK_AGG_FUNCTION 155
8201 #define TK_AGG_COLUMN 156
8202 #define TK_UMINUS 157
8203 #define TK_UPLUS 158
8204 #define TK_REGISTER 159
 
8205
8206 /************** End of parse.h ***********************************************/
8207 /************** Continuing where we left off in sqliteInt.h ******************/
8208 #include <stdio.h>
8209 #include <stdlib.h>
@@ -9129,41 +9128,41 @@
9128 #define OP_VerifyCookie 49
9129 #define OP_OpenRead 50 /* synopsis: root=P2 iDb=P3 */
9130 #define OP_OpenWrite 51 /* synopsis: root=P2 iDb=P3 */
9131 #define OP_OpenAutoindex 52 /* synopsis: nColumn=P2 */
9132 #define OP_OpenEphemeral 53 /* synopsis: nColumn=P2 */
9133 #define OP_SorterOpen 54
9134 #define OP_OpenPseudo 55 /* synopsis: content in r[P2@P3] */
9135 #define OP_Close 56
9136 #define OP_SeekLt 57 /* synopsis: key=r[P3@P4] */
9137 #define OP_SeekLe 58 /* synopsis: key=r[P3@P4] */
9138 #define OP_SeekGe 59 /* synopsis: key=r[P3@P4] */
9139 #define OP_SeekGt 60 /* synopsis: key=r[P3@P4] */
9140 #define OP_Seek 61 /* synopsis: intkey=r[P2] */
9141 #define OP_NoConflict 62 /* synopsis: key=r[P3@P4] */
9142 #define OP_NotFound 63 /* synopsis: key=r[P3@P4] */
9143 #define OP_Found 64 /* synopsis: key=r[P3@P4] */
9144 #define OP_NotExists 65 /* synopsis: intkey=r[P3] */
9145 #define OP_Sequence 66 /* synopsis: r[P2]=rowid */
9146 #define OP_NewRowid 67 /* synopsis: r[P2]=rowid */
9147 #define OP_Insert 68 /* synopsis: intkey=r[P3] data=r[P2] */
9148 #define OP_InsertInt 69 /* synopsis: intkey=P3 data=r[P2] */
9149 #define OP_Delete 70
9150 #define OP_Or 71 /* same as TK_OR, synopsis: r[P3]=(r[P1] || r[P2]) */
9151 #define OP_And 72 /* same as TK_AND, synopsis: r[P3]=(r[P1] && r[P2]) */
9152 #define OP_ResetCount 73
9153 #define OP_SorterCompare 74 /* synopsis: if key(P1)!=rtrim(r[P3],P4) goto P2 */
9154 #define OP_SorterData 75 /* synopsis: r[P2]=data */
9155 #define OP_IsNull 76 /* same as TK_ISNULL, synopsis: if r[P1]==NULL goto P2 */
9156 #define OP_NotNull 77 /* same as TK_NOTNULL, synopsis: if r[P1]!=NULL goto P2 */
9157 #define OP_Ne 78 /* same as TK_NE, synopsis: if r[P1]!=r[P3] goto P2 */
9158 #define OP_Eq 79 /* same as TK_EQ, synopsis: if r[P1]==r[P3] goto P2 */
9159 #define OP_Gt 80 /* same as TK_GT, synopsis: if r[P1]>r[P3] goto P2 */
9160 #define OP_Le 81 /* same as TK_LE, synopsis: if r[P1]<=r[P3] goto P2 */
9161 #define OP_Lt 82 /* same as TK_LT, synopsis: if r[P1]<r[P3] goto P2 */
9162 #define OP_Ge 83 /* same as TK_GE, synopsis: if r[P1]>=r[P3] goto P2 */
9163 #define OP_RowKey 84 /* synopsis: r[P2]=key */
9164 #define OP_BitAnd 85 /* same as TK_BITAND, synopsis: r[P3]=r[P1]&r[P2] */
9165 #define OP_BitOr 86 /* same as TK_BITOR, synopsis: r[P3]=r[P1]|r[P2] */
9166 #define OP_ShiftLeft 87 /* same as TK_LSHIFT, synopsis: r[P3]=r[P2]<<r[P1] */
9167 #define OP_ShiftRight 88 /* same as TK_RSHIFT, synopsis: r[P3]=r[P2]>>r[P1] */
9168 #define OP_Add 89 /* same as TK_PLUS, synopsis: r[P3]=r[P1]+r[P2] */
@@ -9170,69 +9169,68 @@
9169 #define OP_Subtract 90 /* same as TK_MINUS, synopsis: r[P3]=r[P2]-r[P1] */
9170 #define OP_Multiply 91 /* same as TK_STAR, synopsis: r[P3]=r[P1]*r[P2] */
9171 #define OP_Divide 92 /* same as TK_SLASH, synopsis: r[P3]=r[P2]/r[P1] */
9172 #define OP_Remainder 93 /* same as TK_REM, synopsis: r[P3]=r[P2]%r[P1] */
9173 #define OP_Concat 94 /* same as TK_CONCAT, synopsis: r[P3]=r[P2]+r[P1] */
9174 #define OP_RowData 95 /* synopsis: r[P2]=data */
9175 #define OP_BitNot 96 /* same as TK_BITNOT, synopsis: r[P1]= ~r[P1] */
9176 #define OP_String8 97 /* same as TK_STRING, synopsis: r[P2]='P4' */
9177 #define OP_Rowid 98 /* synopsis: r[P2]=rowid */
9178 #define OP_NullRow 99
9179 #define OP_Last 100
9180 #define OP_SorterSort 101
9181 #define OP_Sort 102
9182 #define OP_Rewind 103
9183 #define OP_SorterInsert 104
9184 #define OP_IdxInsert 105 /* synopsis: key=r[P2] */
9185 #define OP_IdxDelete 106 /* synopsis: key=r[P2@P3] */
9186 #define OP_IdxRowid 107 /* synopsis: r[P2]=rowid */
9187 #define OP_IdxLT 108 /* synopsis: key=r[P3@P4] */
9188 #define OP_IdxGE 109 /* synopsis: key=r[P3@P4] */
9189 #define OP_Destroy 110
9190 #define OP_Clear 111
9191 #define OP_CreateIndex 112 /* synopsis: r[P2]=root iDb=P1 */
9192 #define OP_CreateTable 113 /* synopsis: r[P2]=root iDb=P1 */
9193 #define OP_ParseSchema 114
9194 #define OP_LoadAnalysis 115
9195 #define OP_DropTable 116
9196 #define OP_DropIndex 117
9197 #define OP_DropTrigger 118
9198 #define OP_IntegrityCk 119
9199 #define OP_RowSetAdd 120 /* synopsis: rowset(P1)=r[P2] */
9200 #define OP_RowSetRead 121 /* synopsis: r[P3]=rowset(P1) */
9201 #define OP_RowSetTest 122 /* synopsis: if r[P3] in rowset(P1) goto P2 */
9202 #define OP_Program 123
9203 #define OP_Param 124
9204 #define OP_FkCounter 125 /* synopsis: fkctr[P1]+=P2 */
9205 #define OP_FkIfZero 126 /* synopsis: if fkctr[P1]==0 goto P2 */
9206 #define OP_MemMax 127 /* synopsis: r[P1]=max(r[P1],r[P2]) */
9207 #define OP_IfPos 128 /* synopsis: if r[P1]>0 goto P2 */
9208 #define OP_IfNeg 129 /* synopsis: if r[P1]<0 goto P2 */
9209 #define OP_IfZero 130 /* synopsis: r[P1]+=P3, if r[P1]==0 goto P2 */
9210 #define OP_AggFinal 131 /* synopsis: accum=r[P1] N=P2 */
9211 #define OP_IncrVacuum 132
9212 #define OP_Real 133 /* same as TK_FLOAT, synopsis: r[P2]=P4 */
9213 #define OP_Expire 134
9214 #define OP_TableLock 135 /* synopsis: iDb=P1 root=P2 write=P3 */
9215 #define OP_VBegin 136
9216 #define OP_VCreate 137
9217 #define OP_VDestroy 138
9218 #define OP_VOpen 139
9219 #define OP_VColumn 140 /* synopsis: r[P3]=vcolumn(P2) */
9220 #define OP_VNext 141
9221 #define OP_VRename 142
9222 #define OP_ToText 143 /* same as TK_TO_TEXT */
9223 #define OP_ToBlob 144 /* same as TK_TO_BLOB */
9224 #define OP_ToNumeric 145 /* same as TK_TO_NUMERIC */
9225 #define OP_ToInt 146 /* same as TK_TO_INT */
9226 #define OP_ToReal 147 /* same as TK_TO_REAL */
9227 #define OP_Pagecount 148
9228 #define OP_MaxPgcnt 149
9229 #define OP_Trace 150
9230 #define OP_Noop 151
9231 #define OP_Explain 152
 
9232
9233
9234 /* Properties such as "out2" or "jump" that are specified in
9235 ** comments following the "case" for each opcode in the vdbe.c
9236 ** are encoded into bitvectors as follows:
@@ -9250,23 +9248,23 @@
9248 /* 16 */ 0x01, 0x01, 0x04, 0x24, 0x04, 0x10, 0x00, 0x02,\
9249 /* 24 */ 0x02, 0x02, 0x02, 0x02, 0x02, 0x00, 0x00, 0x20,\
9250 /* 32 */ 0x00, 0x00, 0x04, 0x05, 0x04, 0x00, 0x00, 0x01,\
9251 /* 40 */ 0x01, 0x05, 0x05, 0x00, 0x00, 0x00, 0x02, 0x02,\
9252 /* 48 */ 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9253 /* 56 */ 0x00, 0x11, 0x11, 0x11, 0x11, 0x08, 0x11, 0x11,\
9254 /* 64 */ 0x11, 0x11, 0x02, 0x02, 0x00, 0x00, 0x00, 0x4c,\
9255 /* 72 */ 0x4c, 0x00, 0x00, 0x00, 0x05, 0x05, 0x15, 0x15,\
9256 /* 80 */ 0x15, 0x15, 0x15, 0x15, 0x00, 0x4c, 0x4c, 0x4c,\
9257 /* 88 */ 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x4c, 0x00,\
9258 /* 96 */ 0x24, 0x02, 0x02, 0x00, 0x01, 0x01, 0x01, 0x01,\
9259 /* 104 */ 0x08, 0x08, 0x00, 0x02, 0x01, 0x01, 0x02, 0x00,\
9260 /* 112 */ 0x02, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
9261 /* 120 */ 0x0c, 0x45, 0x15, 0x01, 0x02, 0x00, 0x01, 0x08,\
9262 /* 128 */ 0x05, 0x05, 0x05, 0x00, 0x01, 0x02, 0x00, 0x00,\
9263 /* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x04,\
9264 /* 144 */ 0x04, 0x04, 0x04, 0x04, 0x02, 0x02, 0x00, 0x00,\
9265 /* 152 */ 0x00,}
9266
9267 /************** End of opcodes.h *********************************************/
9268 /************** Continuing where we left off in vdbe.h ***********************/
9269
9270 /*
@@ -11430,12 +11428,10 @@
11428 #define NC_AllowAgg 0x01 /* Aggregate functions are allowed here */
11429 #define NC_HasAgg 0x02 /* One or more aggregate functions seen */
11430 #define NC_IsCheck 0x04 /* True if resolving names in a CHECK constraint */
11431 #define NC_InAggFunc 0x08 /* True if analyzing arguments to an agg func */
11432 #define NC_PartIdx 0x10 /* True if resolving a partial index WHERE */
 
 
11433
11434 /*
11435 ** An instance of the following structure contains all information
11436 ** needed to generate code for a single SELECT statement.
11437 **
@@ -11489,16 +11485,73 @@
11485 #define SF_Values 0x0080 /* Synthesized from VALUES clause */
11486 #define SF_Materialize 0x0100 /* Force materialization of views */
11487 #define SF_NestedFrom 0x0200 /* Part of a parenthesized FROM clause */
11488 #define SF_MaybeConvert 0x0400 /* Need convertCompoundSelectToSubquery() */
11489 #define SF_Recursive 0x0800 /* The recursive part of a recursive CTE */
 
11490
11491
11492 /*
11493 ** The results of a SELECT can be distributed in several ways, as defined
11494 ** by one of the following macros. The "SRT" prefix means "SELECT Result
11495 ** Type".
11496 **
11497 ** SRT_Union Store results as a key in a temporary index
11498 ** identified by pDest->iSDParm.
11499 **
11500 ** SRT_Except Remove results from the temporary index pDest->iSDParm.
11501 **
11502 ** SRT_Exists Store a 1 in memory cell pDest->iSDParm if the result
11503 ** set is not empty.
11504 **
11505 ** SRT_Discard Throw the results away. This is used by SELECT
11506 ** statements within triggers whose only purpose is
11507 ** the side-effects of functions.
11508 **
11509 ** All of the above are free to ignore their ORDER BY clause. Those that
11510 ** follow must honor the ORDER BY clause.
11511 **
11512 ** SRT_Output Generate a row of output (using the OP_ResultRow
11513 ** opcode) for each row in the result set.
11514 **
11515 ** SRT_Mem Only valid if the result is a single column.
11516 ** Store the first column of the first result row
11517 ** in register pDest->iSDParm then abandon the rest
11518 ** of the query. This destination implies "LIMIT 1".
11519 **
11520 ** SRT_Set The result must be a single column. Store each
11521 ** row of result as the key in table pDest->iSDParm.
11522 ** Apply the affinity pDest->affSdst before storing
11523 ** results. Used to implement "IN (SELECT ...)".
11524 **
11525 ** SRT_EphemTab Create an temporary table pDest->iSDParm and store
11526 ** the result there. The cursor is left open after
11527 ** returning. This is like SRT_Table except that
11528 ** this destination uses OP_OpenEphemeral to create
11529 ** the table first.
11530 **
11531 ** SRT_Coroutine Generate a co-routine that returns a new row of
11532 ** results each time it is invoked. The entry point
11533 ** of the co-routine is stored in register pDest->iSDParm
11534 ** and the result row is stored in pDest->nDest registers
11535 ** starting with pDest->iSdst.
11536 **
11537 ** SRT_Table Store results in temporary table pDest->iSDParm.
11538 ** This is like SRT_EphemTab except that the table
11539 ** is assumed to already be open.
11540 **
11541 ** SRT_DistTable Store results in a temporary table pDest->iSDParm.
11542 ** But also use temporary table pDest->iSDParm+1 as
11543 ** a record of all prior results and ignore any duplicate
11544 ** rows. Name means: "Distinct Table".
11545 **
11546 ** SRT_Queue Store results in priority queue pDest->iSDParm (really
11547 ** an index). Append a sequence number so that all entries
11548 ** are distinct.
11549 **
11550 ** SRT_DistQueue Store results in priority queue pDest->iSDParm only if
11551 ** the same record has never been stored before. The
11552 ** index at pDest->iSDParm+1 hold all prior stores.
11553 */
11554 #define SRT_Union 1 /* Store result as keys in an index */
11555 #define SRT_Except 2 /* Remove result from a UNION index */
11556 #define SRT_Exists 3 /* Store 1 if the result is not empty */
11557 #define SRT_Discard 4 /* Do not save the results anywhere */
@@ -11507,25 +11560,28 @@
11560 #define IgnorableOrderby(X) ((X->eDest)<=SRT_Discard)
11561
11562 #define SRT_Output 5 /* Output each row of result */
11563 #define SRT_Mem 6 /* Store result in a memory cell */
11564 #define SRT_Set 7 /* Store results as keys in an index */
11565 #define SRT_EphemTab 8 /* Create transient tab and store like SRT_Table */
11566 #define SRT_Coroutine 9 /* Generate a single row of result */
11567 #define SRT_Table 10 /* Store result as data with an automatic rowid */
11568 #define SRT_DistTable 11 /* Like SRT_Table, but unique results only */
11569 #define SRT_Queue 12 /* Store result in an queue */
11570 #define SRT_DistQueue 13 /* Like SRT_Queue, but unique results only */
11571
11572 /*
11573 ** An instance of this object describes where to put of the results of
11574 ** a SELECT statement.
11575 */
11576 struct SelectDest {
11577 u8 eDest; /* How to dispose of the results. On of SRT_* above. */
11578 char affSdst; /* Affinity used when eDest==SRT_Set */
11579 int iSDParm; /* A parameter used by the eDest disposal method */
11580 int iSdst; /* Base register where results are written */
11581 int nSdst; /* Number of registers allocated */
11582 ExprList *pOrderBy; /* Key columns for SRT_Queue and SRT_DistQueue */
11583 };
11584
11585 /*
11586 ** During code generation of statements that do inserts into AUTOINCREMENT
11587 ** tables, the following information is attached to the Table.u.autoInc.p
@@ -11696,11 +11752,10 @@
11752 Table **apVtabLock; /* Pointer to virtual tables needing locking */
11753 #endif
11754 Table *pZombieTab; /* List of Table objects to delete after code gen */
11755 TriggerPrg *pTriggerPrg; /* Linked list of coded triggers */
11756 With *pWith; /* Current WITH clause, or NULL */
 
11757 u8 bFreeWith; /* True if pWith should be freed with parser */
11758 };
11759
11760 /*
11761 ** Return true if currently inside an sqlite3_declare_vtab() call.
@@ -23183,41 +23238,41 @@
23238 /* 49 */ "VerifyCookie" OpHelp(""),
23239 /* 50 */ "OpenRead" OpHelp("root=P2 iDb=P3"),
23240 /* 51 */ "OpenWrite" OpHelp("root=P2 iDb=P3"),
23241 /* 52 */ "OpenAutoindex" OpHelp("nColumn=P2"),
23242 /* 53 */ "OpenEphemeral" OpHelp("nColumn=P2"),
23243 /* 54 */ "SorterOpen" OpHelp(""),
23244 /* 55 */ "OpenPseudo" OpHelp("content in r[P2@P3]"),
23245 /* 56 */ "Close" OpHelp(""),
23246 /* 57 */ "SeekLt" OpHelp("key=r[P3@P4]"),
23247 /* 58 */ "SeekLe" OpHelp("key=r[P3@P4]"),
23248 /* 59 */ "SeekGe" OpHelp("key=r[P3@P4]"),
23249 /* 60 */ "SeekGt" OpHelp("key=r[P3@P4]"),
23250 /* 61 */ "Seek" OpHelp("intkey=r[P2]"),
23251 /* 62 */ "NoConflict" OpHelp("key=r[P3@P4]"),
23252 /* 63 */ "NotFound" OpHelp("key=r[P3@P4]"),
23253 /* 64 */ "Found" OpHelp("key=r[P3@P4]"),
23254 /* 65 */ "NotExists" OpHelp("intkey=r[P3]"),
23255 /* 66 */ "Sequence" OpHelp("r[P2]=rowid"),
23256 /* 67 */ "NewRowid" OpHelp("r[P2]=rowid"),
23257 /* 68 */ "Insert" OpHelp("intkey=r[P3] data=r[P2]"),
23258 /* 69 */ "InsertInt" OpHelp("intkey=P3 data=r[P2]"),
23259 /* 70 */ "Delete" OpHelp(""),
23260 /* 71 */ "Or" OpHelp("r[P3]=(r[P1] || r[P2])"),
23261 /* 72 */ "And" OpHelp("r[P3]=(r[P1] && r[P2])"),
23262 /* 73 */ "ResetCount" OpHelp(""),
23263 /* 74 */ "SorterCompare" OpHelp("if key(P1)!=rtrim(r[P3],P4) goto P2"),
23264 /* 75 */ "SorterData" OpHelp("r[P2]=data"),
23265 /* 76 */ "IsNull" OpHelp("if r[P1]==NULL goto P2"),
23266 /* 77 */ "NotNull" OpHelp("if r[P1]!=NULL goto P2"),
23267 /* 78 */ "Ne" OpHelp("if r[P1]!=r[P3] goto P2"),
23268 /* 79 */ "Eq" OpHelp("if r[P1]==r[P3] goto P2"),
23269 /* 80 */ "Gt" OpHelp("if r[P1]>r[P3] goto P2"),
23270 /* 81 */ "Le" OpHelp("if r[P1]<=r[P3] goto P2"),
23271 /* 82 */ "Lt" OpHelp("if r[P1]<r[P3] goto P2"),
23272 /* 83 */ "Ge" OpHelp("if r[P1]>=r[P3] goto P2"),
23273 /* 84 */ "RowKey" OpHelp("r[P2]=key"),
23274 /* 85 */ "BitAnd" OpHelp("r[P3]=r[P1]&r[P2]"),
23275 /* 86 */ "BitOr" OpHelp("r[P3]=r[P1]|r[P2]"),
23276 /* 87 */ "ShiftLeft" OpHelp("r[P3]=r[P2]<<r[P1]"),
23277 /* 88 */ "ShiftRight" OpHelp("r[P3]=r[P2]>>r[P1]"),
23278 /* 89 */ "Add" OpHelp("r[P3]=r[P1]+r[P2]"),
@@ -23224,69 +23279,68 @@
23279 /* 90 */ "Subtract" OpHelp("r[P3]=r[P2]-r[P1]"),
23280 /* 91 */ "Multiply" OpHelp("r[P3]=r[P1]*r[P2]"),
23281 /* 92 */ "Divide" OpHelp("r[P3]=r[P2]/r[P1]"),
23282 /* 93 */ "Remainder" OpHelp("r[P3]=r[P2]%r[P1]"),
23283 /* 94 */ "Concat" OpHelp("r[P3]=r[P2]+r[P1]"),
23284 /* 95 */ "RowData" OpHelp("r[P2]=data"),
23285 /* 96 */ "BitNot" OpHelp("r[P1]= ~r[P1]"),
23286 /* 97 */ "String8" OpHelp("r[P2]='P4'"),
23287 /* 98 */ "Rowid" OpHelp("r[P2]=rowid"),
23288 /* 99 */ "NullRow" OpHelp(""),
23289 /* 100 */ "Last" OpHelp(""),
23290 /* 101 */ "SorterSort" OpHelp(""),
23291 /* 102 */ "Sort" OpHelp(""),
23292 /* 103 */ "Rewind" OpHelp(""),
23293 /* 104 */ "SorterInsert" OpHelp(""),
23294 /* 105 */ "IdxInsert" OpHelp("key=r[P2]"),
23295 /* 106 */ "IdxDelete" OpHelp("key=r[P2@P3]"),
23296 /* 107 */ "IdxRowid" OpHelp("r[P2]=rowid"),
23297 /* 108 */ "IdxLT" OpHelp("key=r[P3@P4]"),
23298 /* 109 */ "IdxGE" OpHelp("key=r[P3@P4]"),
23299 /* 110 */ "Destroy" OpHelp(""),
23300 /* 111 */ "Clear" OpHelp(""),
23301 /* 112 */ "CreateIndex" OpHelp("r[P2]=root iDb=P1"),
23302 /* 113 */ "CreateTable" OpHelp("r[P2]=root iDb=P1"),
23303 /* 114 */ "ParseSchema" OpHelp(""),
23304 /* 115 */ "LoadAnalysis" OpHelp(""),
23305 /* 116 */ "DropTable" OpHelp(""),
23306 /* 117 */ "DropIndex" OpHelp(""),
23307 /* 118 */ "DropTrigger" OpHelp(""),
23308 /* 119 */ "IntegrityCk" OpHelp(""),
23309 /* 120 */ "RowSetAdd" OpHelp("rowset(P1)=r[P2]"),
23310 /* 121 */ "RowSetRead" OpHelp("r[P3]=rowset(P1)"),
23311 /* 122 */ "RowSetTest" OpHelp("if r[P3] in rowset(P1) goto P2"),
23312 /* 123 */ "Program" OpHelp(""),
23313 /* 124 */ "Param" OpHelp(""),
23314 /* 125 */ "FkCounter" OpHelp("fkctr[P1]+=P2"),
23315 /* 126 */ "FkIfZero" OpHelp("if fkctr[P1]==0 goto P2"),
23316 /* 127 */ "MemMax" OpHelp("r[P1]=max(r[P1],r[P2])"),
23317 /* 128 */ "IfPos" OpHelp("if r[P1]>0 goto P2"),
23318 /* 129 */ "IfNeg" OpHelp("if r[P1]<0 goto P2"),
23319 /* 130 */ "IfZero" OpHelp("r[P1]+=P3, if r[P1]==0 goto P2"),
23320 /* 131 */ "AggFinal" OpHelp("accum=r[P1] N=P2"),
23321 /* 132 */ "IncrVacuum" OpHelp(""),
23322 /* 133 */ "Real" OpHelp("r[P2]=P4"),
23323 /* 134 */ "Expire" OpHelp(""),
23324 /* 135 */ "TableLock" OpHelp("iDb=P1 root=P2 write=P3"),
23325 /* 136 */ "VBegin" OpHelp(""),
23326 /* 137 */ "VCreate" OpHelp(""),
23327 /* 138 */ "VDestroy" OpHelp(""),
23328 /* 139 */ "VOpen" OpHelp(""),
23329 /* 140 */ "VColumn" OpHelp("r[P3]=vcolumn(P2)"),
23330 /* 141 */ "VNext" OpHelp(""),
23331 /* 142 */ "VRename" OpHelp(""),
23332 /* 143 */ "ToText" OpHelp(""),
23333 /* 144 */ "ToBlob" OpHelp(""),
23334 /* 145 */ "ToNumeric" OpHelp(""),
23335 /* 146 */ "ToInt" OpHelp(""),
23336 /* 147 */ "ToReal" OpHelp(""),
23337 /* 148 */ "Pagecount" OpHelp(""),
23338 /* 149 */ "MaxPgcnt" OpHelp(""),
23339 /* 150 */ "Trace" OpHelp(""),
23340 /* 151 */ "Noop" OpHelp(""),
23341 /* 152 */ "Explain" OpHelp(""),
 
23342 };
23343 return azName[i];
23344 }
23345 #endif
23346
@@ -69741,37 +69795,10 @@
69795 }
69796 pCx->isOrdered = (pOp->p5!=BTREE_UNORDERED);
69797 break;
69798 }
69799
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69800 /* Opcode: SorterOpen P1 * * P4 *
69801 **
69802 ** This opcode works like OP_OpenEphemeral except that it opens
69803 ** a transient index that is specifically designed to sort large
69804 ** tables using an external merge-sort algorithm.
@@ -70765,11 +70792,10 @@
70792 pC = p->apCsr[pOp->p1];
70793 assert( pC!=0 );
70794 pC->nullRow = 1;
70795 pC->rowidIsValid = 0;
70796 pC->cacheStatus = CACHE_STALE;
 
70797 if( pC->pCursor ){
70798 sqlite3BtreeClearCursor(pC->pCursor);
70799 }
70800 break;
70801 }
@@ -75130,11 +75156,11 @@
75156 sqlite3 *db = pParse->db; /* The database connection */
75157 struct SrcList_item *pItem; /* Use for looping over pSrcList items */
75158 struct SrcList_item *pMatch = 0; /* The matching pSrcList item */
75159 NameContext *pTopNC = pNC; /* First namecontext in the list */
75160 Schema *pSchema = 0; /* Schema of the expression */
75161 int isTrigger = 0; /* True if resolved to a trigger column */
75162 Table *pTab = 0; /* Table hold the row */
75163 Column *pCol; /* A column of pTab */
75164
75165 assert( pNC ); /* the name context cannot be NULL. */
75166 assert( zCol ); /* The Z in X.Y.Z cannot be NULL */
@@ -75171,26 +75197,10 @@
75197 /* Start at the inner-most context and move outward until a match is found */
75198 while( pNC && cnt==0 ){
75199 ExprList *pEList;
75200 SrcList *pSrcList = pNC->pSrcList;
75201
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75202 if( pSrcList ){
75203 for(i=0, pItem=pSrcList->a; i<pSrcList->nSrc; i++, pItem++){
75204 pTab = pItem->pTab;
75205 assert( pTab!=0 && pTab->zName!=0 );
75206 assert( pTab->nCol>0 );
@@ -75291,11 +75301,11 @@
75301 testcase( iCol==32 );
75302 pParse->newmask |= (iCol>=32 ? 0xffffffff : (((u32)1)<<iCol));
75303 }
75304 pExpr->iColumn = (i16)iCol;
75305 pExpr->pTab = pTab;
75306 isTrigger = 1;
75307 }
75308 }
75309 }
75310 #endif /* !defined(SQLITE_OMIT_TRIGGER) */
75311
@@ -75415,15 +75425,15 @@
75425 */
75426 sqlite3ExprDelete(db, pExpr->pLeft);
75427 pExpr->pLeft = 0;
75428 sqlite3ExprDelete(db, pExpr->pRight);
75429 pExpr->pRight = 0;
75430 pExpr->op = (isTrigger ? TK_TRIGGER : TK_COLUMN);
75431 lookupname_end:
75432 if( cnt==1 ){
75433 assert( pNC!=0 );
75434 if( pExpr->op!=TK_AS ){
75435 sqlite3AuthRead(pParse, pExpr, pSchema, pNC->pSrcList);
75436 }
75437 /* Increment the nRef value on all name contexts from TopNC up to
75438 ** the point where the name matched. */
75439 for(;;){
@@ -76116,11 +76126,10 @@
76126
76127 /* Set up the local name-context to pass to sqlite3ResolveExprNames() to
76128 ** resolve the result-set expression list.
76129 */
76130 sNC.ncFlags = NC_AllowAgg;
 
76131 sNC.pSrcList = p->pSrc;
76132 sNC.pNext = pOuterNC;
76133
76134 /* Resolve names in the result set. */
76135 pEList = p->pEList;
@@ -76195,14 +76204,10 @@
76204 "the GROUP BY clause");
76205 return WRC_Abort;
76206 }
76207 }
76208 }
 
 
 
 
76209
76210 /* Advance to the next term of the compound
76211 */
76212 p = p->pPrior;
76213 nCompound++;
@@ -78835,16 +78840,10 @@
78840 inReg = sqlite3ExprCodeGetColumn(pParse, pExpr->pTab,
78841 pExpr->iColumn, iTab, target,
78842 pExpr->op2);
78843 break;
78844 }
 
 
 
 
 
 
78845 case TK_INTEGER: {
78846 codeInteger(pParse, pExpr, 0, target);
78847 break;
78848 }
78849 #ifndef SQLITE_OMIT_FLOATING_POINT
@@ -79464,11 +79463,10 @@
79463 SQLITE_PRIVATE int sqlite3ExprCodeTemp(Parse *pParse, Expr *pExpr, int *pReg){
79464 int r2;
79465 pExpr = sqlite3ExprSkipCollate(pExpr);
79466 if( ConstFactorOk(pParse)
79467 && pExpr->op!=TK_REGISTER
 
79468 && sqlite3ExprIsConstantNotJoin(pExpr)
79469 ){
79470 ExprList *p = pParse->pConstExpr;
79471 int i;
79472 *pReg = 0;
@@ -99909,17 +99907,17 @@
99907 /*
99908 ** Add code to implement the OFFSET
99909 */
99910 static void codeOffset(
99911 Vdbe *v, /* Generate code into this VM */
99912 int iOffset, /* Register holding the offset counter */
99913 int iContinue /* Jump here to skip the current record */
99914 ){
99915 if( iOffset>0 && iContinue!=0 ){
99916 int addr;
99917 sqlite3VdbeAddOp2(v, OP_AddImm, iOffset, -1);
99918 addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset);
99919 sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
99920 VdbeComment((v, "skip OFFSET records"));
99921 sqlite3VdbeJumpHere(v, addr);
99922 }
99923 }
@@ -99990,21 +99988,20 @@
99988
99989 /*
99990 ** This routine generates the code for the inside of the inner loop
99991 ** of a SELECT.
99992 **
99993 ** If srcTab is negative, then the pEList expressions
99994 ** are evaluated in order to get the data for this row. If srcTab is
99995 ** zero or more, then data is pulled from srcTab and pEList is used only
99996 ** to get number columns and the datatype for each column.
99997 */
99998 static void selectInnerLoop(
99999 Parse *pParse, /* The parser context */
100000 Select *p, /* The complete select statement being coded */
100001 ExprList *pEList, /* List of values being extracted */
100002 int srcTab, /* Pull data from this table */
 
100003 ExprList *pOrderBy, /* If not NULL, sort results using this key */
100004 DistinctCtx *pDistinct, /* If not NULL, info on how to process DISTINCT */
100005 SelectDest *pDest, /* How to dispose of the results */
100006 int iContinue, /* Jump here to continue with next row */
100007 int iBreak /* Jump here to break out of the inner loop */
@@ -100016,61 +100013,54 @@
100013 int eDest = pDest->eDest; /* How to dispose of results */
100014 int iParm = pDest->iSDParm; /* First argument to disposal method */
100015 int nResultCol; /* Number of result columns */
100016
100017 assert( v );
 
100018 assert( pEList!=0 );
100019 hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
100020 if( pOrderBy==0 && !hasDistinct ){
100021 codeOffset(v, p->iOffset, iContinue);
100022 }
100023
100024 /* Pull the requested columns.
100025 */
100026 nResultCol = pEList->nExpr;
 
 
 
 
100027 if( pDest->iSdst==0 ){
100028 pDest->iSdst = pParse->nMem+1;
100029 pDest->nSdst = nResultCol;
100030 pParse->nMem += nResultCol;
100031 }else{
100032 assert( pDest->nSdst==nResultCol );
100033 }
100034 regResult = pDest->iSdst;
100035 if( srcTab>=0 ){
100036 for(i=0; i<nResultCol; i++){
100037 sqlite3VdbeAddOp3(v, OP_Column, srcTab, i, regResult+i);
100038 VdbeComment((v, "%s", pEList->a[i].zName));
100039 }
100040 }else if( eDest!=SRT_Exists ){
100041 /* If the destination is an EXISTS(...) expression, the actual
100042 ** values returned by the SELECT are not required.
100043 */
100044 sqlite3ExprCodeExprList(pParse, pEList, regResult,
100045 (eDest==SRT_Output)?SQLITE_ECEL_DUP:0);
100046 }
 
100047
100048 /* If the DISTINCT keyword was present on the SELECT statement
100049 ** and this row has been seen before, then do not make this row
100050 ** part of the result.
100051 */
100052 if( hasDistinct ){
 
 
100053 switch( pDistinct->eTnctType ){
100054 case WHERE_DISTINCT_ORDERED: {
100055 VdbeOp *pOp; /* No longer required OpenEphemeral instr. */
100056 int iJump; /* Jump destination */
100057 int regPrev; /* Previous row content */
100058
100059 /* Allocate space for the previous row */
100060 regPrev = pParse->nMem+1;
100061 pParse->nMem += nResultCol;
100062
100063 /* Change the OP_OpenEphemeral coded earlier to an OP_Null
100064 ** sets the MEM_Cleared bit on the first register of the
100065 ** previous value. This will cause the OP_Ne below to always
100066 ** fail on the first iteration of the loop even if the first
@@ -100080,23 +100070,23 @@
100070 pOp = sqlite3VdbeGetOp(v, pDistinct->addrTnct);
100071 pOp->opcode = OP_Null;
100072 pOp->p1 = 1;
100073 pOp->p2 = regPrev;
100074
100075 iJump = sqlite3VdbeCurrentAddr(v) + nResultCol;
100076 for(i=0; i<nResultCol; i++){
100077 CollSeq *pColl = sqlite3ExprCollSeq(pParse, pEList->a[i].pExpr);
100078 if( i<nResultCol-1 ){
100079 sqlite3VdbeAddOp3(v, OP_Ne, regResult+i, iJump, regPrev+i);
100080 }else{
100081 sqlite3VdbeAddOp3(v, OP_Eq, regResult+i, iContinue, regPrev+i);
100082 }
100083 sqlite3VdbeChangeP4(v, -1, (const char *)pColl, P4_COLLSEQ);
100084 sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
100085 }
100086 assert( sqlite3VdbeCurrentAddr(v)==iJump );
100087 sqlite3VdbeAddOp3(v, OP_Copy, regResult, regPrev, nResultCol-1);
100088 break;
100089 }
100090
100091 case WHERE_DISTINCT_UNIQUE: {
100092 sqlite3VdbeChangeToNoop(v, pDistinct->addrTnct);
@@ -100103,16 +100093,16 @@
100093 break;
100094 }
100095
100096 default: {
100097 assert( pDistinct->eTnctType==WHERE_DISTINCT_UNORDERED );
100098 codeDistinct(pParse, pDistinct->tabTnct, iContinue, nResultCol, regResult);
100099 break;
100100 }
100101 }
100102 if( pOrderBy==0 ){
100103 codeOffset(v, p->iOffset, iContinue);
100104 }
100105 }
100106
100107 switch( eDest ){
100108 /* In this mode, write each query result to the key of the temporary
@@ -100120,11 +100110,11 @@
100110 */
100111 #ifndef SQLITE_OMIT_COMPOUND_SELECT
100112 case SRT_Union: {
100113 int r1;
100114 r1 = sqlite3GetTempReg(pParse);
100115 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
100116 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
100117 sqlite3ReleaseTempReg(pParse, r1);
100118 break;
100119 }
100120
@@ -100131,24 +100121,24 @@
100121 /* Construct a record from the query result, but instead of
100122 ** saving that record, use it as a key to delete elements from
100123 ** the temporary table iParm.
100124 */
100125 case SRT_Except: {
100126 sqlite3VdbeAddOp3(v, OP_IdxDelete, iParm, regResult, nResultCol);
100127 break;
100128 }
100129 #endif /* SQLITE_OMIT_COMPOUND_SELECT */
100130
100131 /* Store the result as data using a unique key.
100132 */
100133 case SRT_DistTable:
100134 case SRT_Table:
100135 case SRT_EphemTab: {
100136 int r1 = sqlite3GetTempReg(pParse);
100137 testcase( eDest==SRT_Table );
100138 testcase( eDest==SRT_EphemTab );
100139 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
100140 #ifndef SQLITE_OMIT_CTE
100141 if( eDest==SRT_DistTable ){
100142 /* If the destination is DistTable, then cursor (iParm+1) is open
100143 ** on an ephemeral index. If the current row is already present
100144 ** in the index, do not write it to the output. If not, add the
@@ -100177,11 +100167,11 @@
100167 /* If we are creating a set for an "expr IN (SELECT ...)" construct,
100168 ** then there should be a single item on the stack. Write this
100169 ** item into the set table with bogus data.
100170 */
100171 case SRT_Set: {
100172 assert( nResultCol==1 );
100173 pDest->affSdst =
100174 sqlite3CompareAffinity(pEList->a[0].pExpr, pDest->affSdst);
100175 if( pOrderBy ){
100176 /* At first glance you would think we could optimize out the
100177 ** ORDER BY in this case since the order of entries in the set
@@ -100209,11 +100199,11 @@
100199 /* If this is a scalar select that is part of an expression, then
100200 ** store the results in the appropriate memory cell and break out
100201 ** of the scan loop.
100202 */
100203 case SRT_Mem: {
100204 assert( nResultCol==1 );
100205 if( pOrderBy ){
100206 pushOntoSorter(pParse, pOrderBy, p, regResult);
100207 }else{
100208 sqlite3ExprCodeMove(pParse, regResult, iParm, 1);
100209 /* The LIMIT clause will jump out of the loop for us */
@@ -100230,21 +100220,66 @@
100220 case SRT_Output: {
100221 testcase( eDest==SRT_Coroutine );
100222 testcase( eDest==SRT_Output );
100223 if( pOrderBy ){
100224 int r1 = sqlite3GetTempReg(pParse);
100225 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1);
100226 pushOntoSorter(pParse, pOrderBy, p, r1);
100227 sqlite3ReleaseTempReg(pParse, r1);
100228 }else if( eDest==SRT_Coroutine ){
100229 sqlite3VdbeAddOp1(v, OP_Yield, pDest->iSDParm);
100230 }else{
100231 sqlite3VdbeAddOp2(v, OP_ResultRow, regResult, nResultCol);
100232 sqlite3ExprCacheAffinityChange(pParse, regResult, nResultCol);
100233 }
100234 break;
100235 }
100236
100237 #ifndef SQLITE_OMIT_CTE
100238 /* Write the results into a priority queue that is order according to
100239 ** pDest->pOrderBy (in pSO). pDest->iSDParm (in iParm) is the cursor for an
100240 ** index with pSO->nExpr+2 columns. Build a key using pSO for the first
100241 ** pSO->nExpr columns, then make sure all keys are unique by adding a
100242 ** final OP_Sequence column. The last column is the record as a blob.
100243 */
100244 case SRT_DistQueue:
100245 case SRT_Queue: {
100246 int nKey;
100247 int r1, r2, r3;
100248 int addrTest = 0;
100249 ExprList *pSO;
100250 pSO = pDest->pOrderBy;
100251 assert( pSO );
100252 nKey = pSO->nExpr;
100253 r1 = sqlite3GetTempReg(pParse);
100254 r2 = sqlite3GetTempRange(pParse, nKey+2);
100255 r3 = r2+nKey+1;
100256 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r3);
100257 if( eDest==SRT_DistQueue ){
100258 /* If the destination is DistQueue, then cursor (iParm+1) is open
100259 ** on a second ephemeral index that holds all values every previously
100260 ** added to the queue. Only add this new value if it has never before
100261 ** been added */
100262 addrTest = sqlite3VdbeAddOp4Int(v, OP_Found, iParm+1, 0, r3, 0);
100263 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm+1, r3);
100264 }
100265 for(i=0; i<nKey; i++){
100266 sqlite3VdbeAddOp2(v, OP_SCopy,
100267 regResult + pSO->a[i].u.x.iOrderByCol - 1,
100268 r2+i);
100269 }
100270 sqlite3VdbeAddOp2(v, OP_Sequence, iParm, r2+nKey);
100271 sqlite3VdbeAddOp3(v, OP_MakeRecord, r2, nKey+2, r1);
100272 sqlite3VdbeAddOp2(v, OP_IdxInsert, iParm, r1);
100273 if( addrTest ) sqlite3VdbeJumpHere(v, addrTest);
100274 sqlite3ReleaseTempReg(pParse, r1);
100275 sqlite3ReleaseTempRange(pParse, r2, nKey+2);
100276 break;
100277 }
100278 #endif /* SQLITE_OMIT_CTE */
100279
100280
100281
100282 #if !defined(SQLITE_OMIT_TRIGGER)
100283 /* Discard the results. This is used for SELECT statements inside
100284 ** the body of a TRIGGER. The purpose of such selects is to call
100285 ** user-defined functions that have side effects. We do not care
@@ -100330,19 +100365,19 @@
100365 **
100366 ** Space to hold the KeyInfo structure is obtain from malloc. The calling
100367 ** function is responsible for seeing that this structure is eventually
100368 ** freed.
100369 */
100370 static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList, int nExtra){
100371 int nExpr;
100372 KeyInfo *pInfo;
100373 struct ExprList_item *pItem;
100374 sqlite3 *db = pParse->db;
100375 int i;
100376
100377 nExpr = pList->nExpr;
100378 pInfo = sqlite3KeyInfoAlloc(db, nExpr+nExtra, 1);
100379 if( pInfo ){
100380 assert( sqlite3KeyInfoIsWriteable(pInfo) );
100381 for(i=0, pItem=pList->a; i<nExpr; i++, pItem++){
100382 CollSeq *pColl;
100383 pColl = sqlite3ExprCollSeq(pParse, pItem->pExpr);
@@ -100479,17 +100514,17 @@
100514 if( p->selFlags & SF_UseSorter ){
100515 int regSortOut = ++pParse->nMem;
100516 int ptab2 = pParse->nTab++;
100517 sqlite3VdbeAddOp3(v, OP_OpenPseudo, ptab2, regSortOut, pOrderBy->nExpr+2);
100518 addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
100519 codeOffset(v, p->iOffset, addrContinue);
100520 sqlite3VdbeAddOp2(v, OP_SorterData, iTab, regSortOut);
100521 sqlite3VdbeAddOp3(v, OP_Column, ptab2, pOrderBy->nExpr+1, regRow);
100522 sqlite3VdbeChangeP5(v, OPFLAG_CLEARCACHE);
100523 }else{
100524 addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak);
100525 codeOffset(v, p->iOffset, addrContinue);
100526 sqlite3VdbeAddOp3(v, OP_Column, iTab, pOrderBy->nExpr+1, regRow);
100527 }
100528 switch( eDest ){
100529 case SRT_Table:
100530 case SRT_EphemTab: {
@@ -101049,12 +101084,17 @@
101084 ** the limit and offset. If there is no limit and/or offset, then
101085 ** iLimit and iOffset are negative.
101086 **
101087 ** This routine changes the values of iLimit and iOffset only if
101088 ** a limit or offset is defined by pLimit and pOffset. iLimit and
101089 ** iOffset should have been preset to appropriate default values (zero)
101090 ** prior to calling this routine.
101091 **
101092 ** The iOffset register (if it exists) is initialized to the value
101093 ** of the OFFSET. The iLimit register is initialized to LIMIT. Register
101094 ** iOffset+1 is initialized to LIMIT+OFFSET.
101095 **
101096 ** Only if pLimit!=0 or pOffset!=0 do the limit registers get
101097 ** redefined. The UNION ALL operator uses this property to force
101098 ** the reuse of the same limit and offset registers across multiple
101099 ** SELECT statements.
101100 */
@@ -101074,11 +101114,11 @@
101114 sqlite3ExprCacheClear(pParse);
101115 assert( p->pOffset==0 || p->pLimit!=0 );
101116 if( p->pLimit ){
101117 p->iLimit = iLimit = ++pParse->nMem;
101118 v = sqlite3GetVdbe(pParse);
101119 assert( v!=0 );
101120 if( sqlite3ExprIsInteger(p->pLimit, &n) ){
101121 sqlite3VdbeAddOp2(v, OP_Integer, n, iLimit);
101122 VdbeComment((v, "LIMIT counter"));
101123 if( n==0 ){
101124 sqlite3VdbeAddOp2(v, OP_Goto, 0, iBreak);
@@ -101131,11 +101171,169 @@
101171 }
101172 return pRet;
101173 }
101174 #endif /* SQLITE_OMIT_COMPOUND_SELECT */
101175
101176 #ifndef SQLITE_OMIT_CTE
101177 /*
101178 ** This routine generates VDBE code to compute the content of a WITH RECURSIVE
101179 ** query of the form:
101180 **
101181 ** <recursive-table> AS (<setup-query> UNION [ALL] <recursive-query>)
101182 ** \___________/ \_______________/
101183 ** p->pPrior p
101184 **
101185 **
101186 ** There is exactly one reference to the recursive-table in the FROM clause
101187 ** of recursive-query, marked with the SrcList->a[].isRecursive flag.
101188 **
101189 ** The setup-query runs once to generate an initial set of rows that go
101190 ** into a Queue table. Rows are extracted from the Queue table one by
101191 ** one. Each row extracted from Queue is output to pDest. Then the single
101192 ** extracted row (now in the iCurrent table) becomes the content of the
101193 ** recursive-table for a recursive-query run. The output of the recursive-query
101194 ** is added back into the Queue table. Then another row is extracted from Queue
101195 ** and the iteration continues until the Queue table is empty.
101196 **
101197 ** If the compound query operator is UNION then no duplicate rows are ever
101198 ** inserted into the Queue table. The iDistinct table keeps a copy of all rows
101199 ** that have ever been inserted into Queue and causes duplicates to be
101200 ** discarded. If the operator is UNION ALL, then duplicates are allowed.
101201 **
101202 ** If the query has an ORDER BY, then entries in the Queue table are kept in
101203 ** ORDER BY order and the first entry is extracted for each cycle. Without
101204 ** an ORDER BY, the Queue table is just a FIFO.
101205 **
101206 ** If a LIMIT clause is provided, then the iteration stops after LIMIT rows
101207 ** have been output to pDest. A LIMIT of zero means to output no rows and a
101208 ** negative LIMIT means to output all rows. If there is also an OFFSET clause
101209 ** with a positive value, then the first OFFSET outputs are discarded rather
101210 ** than being sent to pDest. The LIMIT count does not begin until after OFFSET
101211 ** rows have been skipped.
101212 */
101213 static void generateWithRecursiveQuery(
101214 Parse *pParse, /* Parsing context */
101215 Select *p, /* The recursive SELECT to be coded */
101216 SelectDest *pDest /* What to do with query results */
101217 ){
101218 SrcList *pSrc = p->pSrc; /* The FROM clause of the recursive query */
101219 int nCol = p->pEList->nExpr; /* Number of columns in the recursive table */
101220 Vdbe *v = pParse->pVdbe; /* The prepared statement under construction */
101221 Select *pSetup = p->pPrior; /* The setup query */
101222 int addrTop; /* Top of the loop */
101223 int addrCont, addrBreak; /* CONTINUE and BREAK addresses */
101224 int iCurrent; /* The Current table */
101225 int regCurrent; /* Register holding Current table */
101226 int iQueue; /* The Queue table */
101227 int iDistinct = 0; /* To ensure unique results if UNION */
101228 int eDest = SRT_Table; /* How to write to Queue */
101229 SelectDest destQueue; /* SelectDest targetting the Queue table */
101230 int i; /* Loop counter */
101231 int rc; /* Result code */
101232 ExprList *pOrderBy; /* The ORDER BY clause */
101233 Expr *pLimit, *pOffset; /* Saved LIMIT and OFFSET */
101234 int regLimit, regOffset; /* Registers used by LIMIT and OFFSET */
101235
101236 /* Obtain authorization to do a recursive query */
101237 if( sqlite3AuthCheck(pParse, SQLITE_RECURSIVE, 0, 0, 0) ) return;
101238
101239 /* Process the LIMIT and OFFSET clauses, if they exist */
101240 addrBreak = sqlite3VdbeMakeLabel(v);
101241 computeLimitRegisters(pParse, p, addrBreak);
101242 pLimit = p->pLimit;
101243 pOffset = p->pOffset;
101244 regLimit = p->iLimit;
101245 regOffset = p->iOffset;
101246 p->pLimit = p->pOffset = 0;
101247 p->iLimit = p->iOffset = 0;
101248
101249 /* Locate the cursor number of the Current table */
101250 for(i=0; ALWAYS(i<pSrc->nSrc); i++){
101251 if( pSrc->a[i].isRecursive ){
101252 iCurrent = pSrc->a[i].iCursor;
101253 break;
101254 }
101255 }
101256
101257 /* Detach the ORDER BY clause from the compound SELECT */
101258 pOrderBy = p->pOrderBy;
101259 p->pOrderBy = 0;
101260
101261 /* Allocate cursors numbers for Queue and Distinct. The cursor number for
101262 ** the Distinct table must be exactly one greater than Queue in order
101263 ** for the SRT_DistTable and SRT_DistQueue destinations to work. */
101264 iQueue = pParse->nTab++;
101265 if( p->op==TK_UNION ){
101266 eDest = pOrderBy ? SRT_DistQueue : SRT_DistTable;
101267 iDistinct = pParse->nTab++;
101268 }else{
101269 eDest = pOrderBy ? SRT_Queue : SRT_Table;
101270 }
101271 sqlite3SelectDestInit(&destQueue, eDest, iQueue);
101272
101273 /* Allocate cursors for Current, Queue, and Distinct. */
101274 regCurrent = ++pParse->nMem;
101275 sqlite3VdbeAddOp3(v, OP_OpenPseudo, iCurrent, regCurrent, nCol);
101276 if( pOrderBy ){
101277 KeyInfo *pKeyInfo = keyInfoFromExprList(pParse, pOrderBy, 1);
101278 sqlite3VdbeAddOp4(v, OP_OpenEphemeral, iQueue, pOrderBy->nExpr+2, 0,
101279 (char*)pKeyInfo, P4_KEYINFO);
101280 destQueue.pOrderBy = pOrderBy;
101281 }else{
101282 sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iQueue, nCol);
101283 }
101284 VdbeComment((v, "Queue table"));
101285 if( iDistinct ){
101286 p->addrOpenEphm[0] = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, iDistinct, 0);
101287 p->selFlags |= SF_UsesEphemeral;
101288 }
101289
101290 /* Store the results of the setup-query in Queue. */
101291 rc = sqlite3Select(pParse, pSetup, &destQueue);
101292 if( rc ) goto end_of_recursive_query;
101293
101294 /* Find the next row in the Queue and output that row */
101295 addrTop = sqlite3VdbeAddOp2(v, OP_Rewind, iQueue, addrBreak);
101296
101297 /* Transfer the next row in Queue over to Current */
101298 sqlite3VdbeAddOp1(v, OP_NullRow, iCurrent); /* To reset column cache */
101299 if( pOrderBy ){
101300 sqlite3VdbeAddOp3(v, OP_Column, iQueue, pOrderBy->nExpr+1, regCurrent);
101301 }else{
101302 sqlite3VdbeAddOp2(v, OP_RowData, iQueue, regCurrent);
101303 }
101304 sqlite3VdbeAddOp1(v, OP_Delete, iQueue);
101305
101306 /* Output the single row in Current */
101307 addrCont = sqlite3VdbeMakeLabel(v);
101308 codeOffset(v, regOffset, addrCont);
101309 selectInnerLoop(pParse, p, p->pEList, iCurrent,
101310 0, 0, pDest, addrCont, addrBreak);
101311 if( regLimit ) sqlite3VdbeAddOp3(v, OP_IfZero, regLimit, addrBreak, -1);
101312 sqlite3VdbeResolveLabel(v, addrCont);
101313
101314 /* Execute the recursive SELECT taking the single row in Current as
101315 ** the value for the recursive-table. Store the results in the Queue.
101316 */
101317 p->pPrior = 0;
101318 sqlite3Select(pParse, p, &destQueue);
101319 assert( p->pPrior==0 );
101320 p->pPrior = pSetup;
101321
101322 /* Keep running the loop until the Queue is empty */
101323 sqlite3VdbeAddOp2(v, OP_Goto, 0, addrTop);
101324 sqlite3VdbeResolveLabel(v, addrBreak);
101325
101326 end_of_recursive_query:
101327 p->pOrderBy = pOrderBy;
101328 p->pLimit = pLimit;
101329 p->pOffset = pOffset;
101330 return;
101331 }
101332 #endif
101333
101334 /* Forward references */
101335 static int multiSelectOrderBy(
101336 Parse *pParse, /* Parsing context */
101337 Select *p, /* The right-most of SELECTs to be coded */
101338 SelectDest *pDest /* What to do with query results */
101339 );
@@ -101239,100 +101437,11 @@
101437 goto multi_select_end;
101438 }
101439
101440 #ifndef SQLITE_OMIT_CTE
101441 if( p->selFlags & SF_Recursive ){
101442 generateWithRecursiveQuery(pParse, p, &dest);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101443 }else
101444 #endif
101445
101446 /* Compound SELECTs that have an ORDER BY clause are handled separately.
101447 */
@@ -101471,11 +101580,11 @@
101580 iBreak = sqlite3VdbeMakeLabel(v);
101581 iCont = sqlite3VdbeMakeLabel(v);
101582 computeLimitRegisters(pParse, p, iBreak);
101583 sqlite3VdbeAddOp2(v, OP_Rewind, unionTab, iBreak);
101584 iStart = sqlite3VdbeCurrentAddr(v);
101585 selectInnerLoop(pParse, p, p->pEList, unionTab,
101586 0, 0, &dest, iCont, iBreak);
101587 sqlite3VdbeResolveLabel(v, iCont);
101588 sqlite3VdbeAddOp2(v, OP_Next, unionTab, iStart);
101589 sqlite3VdbeResolveLabel(v, iBreak);
101590 sqlite3VdbeAddOp2(v, OP_Close, unionTab, 0);
@@ -101549,11 +101658,11 @@
101658 sqlite3VdbeAddOp2(v, OP_Rewind, tab1, iBreak);
101659 r1 = sqlite3GetTempReg(pParse);
101660 iStart = sqlite3VdbeAddOp2(v, OP_RowKey, tab1, r1);
101661 sqlite3VdbeAddOp4Int(v, OP_NotFound, tab2, iCont, r1, 0);
101662 sqlite3ReleaseTempReg(pParse, r1);
101663 selectInnerLoop(pParse, p, p->pEList, tab1,
101664 0, 0, &dest, iCont, iBreak);
101665 sqlite3VdbeResolveLabel(v, iCont);
101666 sqlite3VdbeAddOp2(v, OP_Next, tab1, iStart);
101667 sqlite3VdbeResolveLabel(v, iBreak);
101668 sqlite3VdbeAddOp2(v, OP_Close, tab2, 0);
@@ -101671,11 +101780,11 @@
101780 }
101781 if( pParse->db->mallocFailed ) return 0;
101782
101783 /* Suppress the first OFFSET entries if there is an OFFSET clause
101784 */
101785 codeOffset(v, p->iOffset, iContinue);
101786
101787 switch( pDest->eDest ){
101788 /* Store the result as data using a unique key.
101789 */
101790 case SRT_Table:
@@ -103617,11 +103726,11 @@
103726 if( pE->x.pList==0 || pE->x.pList->nExpr!=1 ){
103727 sqlite3ErrorMsg(pParse, "DISTINCT aggregates must have exactly one "
103728 "argument");
103729 pFunc->iDistinct = -1;
103730 }else{
103731 KeyInfo *pKeyInfo = keyInfoFromExprList(pParse, pE->x.pList, 0);
103732 sqlite3VdbeAddOp4(v, OP_OpenEphemeral, pFunc->iDistinct, 0, 0,
103733 (char*)pKeyInfo, P4_KEYINFO);
103734 }
103735 }
103736 }
@@ -103750,54 +103859,12 @@
103859 #endif
103860
103861 /*
103862 ** Generate code for the SELECT statement given in the p argument.
103863 **
103864 ** The results are returned according to the SelectDest structure.
103865 ** See comments in sqliteInt.h for further information.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103866 **
103867 ** This routine returns the number of errors. If any errors are
103868 ** encountered, then an appropriate error message is left in
103869 ** pParse->zErrMsg.
103870 **
@@ -104068,11 +104135,11 @@
104135 ** we figure out that the sorting index is not needed. The addrSortIndex
104136 ** variable is used to facilitate that change.
104137 */
104138 if( pOrderBy ){
104139 KeyInfo *pKeyInfo;
104140 pKeyInfo = keyInfoFromExprList(pParse, pOrderBy, 0);
104141 pOrderBy->iECursor = pParse->nTab++;
104142 p->addrOpenEphm[2] = addrSortIndex =
104143 sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
104144 pOrderBy->iECursor, pOrderBy->nExpr+2, 0,
104145 (char*)pKeyInfo, P4_KEYINFO);
@@ -104100,11 +104167,11 @@
104167 */
104168 if( p->selFlags & SF_Distinct ){
104169 sDistinct.tabTnct = pParse->nTab++;
104170 sDistinct.addrTnct = sqlite3VdbeAddOp4(v, OP_OpenEphemeral,
104171 sDistinct.tabTnct, 0, 0,
104172 (char*)keyInfoFromExprList(pParse, p->pEList, 0),
104173 P4_KEYINFO);
104174 sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
104175 sDistinct.eTnctType = WHERE_DISTINCT_UNORDERED;
104176 }else{
104177 sDistinct.eTnctType = WHERE_DISTINCT_NOOP;
@@ -104134,11 +104201,11 @@
104201 sqlite3VdbeChangeToNoop(v, addrSortIndex);
104202 p->addrOpenEphm[2] = -1;
104203 }
104204
104205 /* Use the standard inner loop. */
104206 selectInnerLoop(pParse, p, pEList, -1, pOrderBy, &sDistinct, pDest,
104207 sqlite3WhereContinueLabel(pWInfo),
104208 sqlite3WhereBreakLabel(pWInfo));
104209
104210 /* End the database scan loop.
104211 */
@@ -104224,11 +104291,11 @@
104291 ** implement it. Allocate that sorting index now. If it turns out
104292 ** that we do not need it after all, the OP_SorterOpen instruction
104293 ** will be converted into a Noop.
104294 */
104295 sAggInfo.sortingIdx = pParse->nTab++;
104296 pKeyInfo = keyInfoFromExprList(pParse, pGroupBy, 0);
104297 addrSortingIdx = sqlite3VdbeAddOp4(v, OP_SorterOpen,
104298 sAggInfo.sortingIdx, sAggInfo.nSortingColumn,
104299 0, (char*)pKeyInfo, P4_KEYINFO);
104300
104301 /* Initialize memory locations used by GROUP BY aggregate processing
@@ -104406,11 +104473,11 @@
104473 sqlite3VdbeAddOp2(v, OP_IfPos, iUseFlag, addrOutputRow+2);
104474 VdbeComment((v, "Groupby result generator entry point"));
104475 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104476 finalizeAggFunctions(pParse, &sAggInfo);
104477 sqlite3ExprIfFalse(pParse, pHaving, addrOutputRow+1, SQLITE_JUMPIFNULL);
104478 selectInnerLoop(pParse, p, p->pEList, -1, pOrderBy,
104479 &sDistinct, pDest,
104480 addrOutputRow+1, addrSetAbort);
104481 sqlite3VdbeAddOp1(v, OP_Return, regOutputRow);
104482 VdbeComment((v, "end groupby result generator"));
104483
@@ -104549,11 +104616,11 @@
104616 finalizeAggFunctions(pParse, &sAggInfo);
104617 }
104618
104619 pOrderBy = 0;
104620 sqlite3ExprIfFalse(pParse, pHaving, addrEnd, SQLITE_JUMPIFNULL);
104621 selectInnerLoop(pParse, p, p->pEList, -1, 0, 0,
104622 pDest, addrEnd, addrEnd);
104623 sqlite3ExprListDelete(db, pDel);
104624 }
104625 sqlite3VdbeResolveLabel(v, addrEnd);
104626
@@ -112138,14 +112205,20 @@
112205 ** scan of the entire table.
112206 */
112207 static const u8 aStep[] = { OP_Next, OP_Prev };
112208 static const u8 aStart[] = { OP_Rewind, OP_Last };
112209 assert( bRev==0 || bRev==1 );
112210 if( pTabItem->isRecursive ){
112211 /* Tables marked isRecursive have only a single row that is stored in
112212 ** a pseudo-cursor. No need to Rewind or Next such cursors. */
112213 pLevel->op = OP_Noop;
112214 }else{
112215 pLevel->op = aStep[bRev];
112216 pLevel->p1 = iCur;
112217 pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
112218 pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
112219 }
112220 }
112221
112222 /* Insert code to test every subexpression that can be completely
112223 ** computed using the current set of tables.
112224 */
@@ -119434,17 +119507,10 @@
119507 ** must be complete. So isInit must not be set until the very end
119508 ** of this routine.
119509 */
119510 if( sqlite3GlobalConfig.isInit ) return SQLITE_OK;
119511
 
 
 
 
 
 
 
119512 /* Make sure the mutex subsystem is initialized. If unable to
119513 ** initialize the mutex subsystem, return early with the error.
119514 ** If the system is so sick that we are unable to allocate a mutex,
119515 ** there is not much SQLite is going to be able to do.
119516 **
119517
+1 -1
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107107
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108108
** [sqlite_version()] and [sqlite_source_id()].
109109
*/
110110
#define SQLITE_VERSION "3.8.3"
111111
#define SQLITE_VERSION_NUMBER 3008003
112
-#define SQLITE_SOURCE_ID "2014-01-21 00:19:43 cc1cb3217800ff666a00bf4f544a5a477589bc1b"
112
+#define SQLITE_SOURCE_ID "2014-01-22 18:16:27 b6cea42006910d590373e8f9e296d7672edb114b"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
118118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.3"
111 #define SQLITE_VERSION_NUMBER 3008003
112 #define SQLITE_SOURCE_ID "2014-01-21 00:19:43 cc1cb3217800ff666a00bf4f544a5a477589bc1b"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -107,11 +107,11 @@
107 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
108 ** [sqlite_version()] and [sqlite_source_id()].
109 */
110 #define SQLITE_VERSION "3.8.3"
111 #define SQLITE_VERSION_NUMBER 3008003
112 #define SQLITE_SOURCE_ID "2014-01-22 18:16:27 b6cea42006910d590373e8f9e296d7672edb114b"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
118

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button