Fossil SCM

Update the built-in SQLite to include the latest bug fixes, especially the fix to count(*) on WITHOUT ROWID tables. Fix the "fossil all" command so that it works on a WITHOUT ROWID global_config table.

drh 2013-11-12 15:57 trunk
Commit c0700615ffbbb5345bf7b3a253870758fe3612d0
3 files changed +16 -27 +100 -16 +20 -6
+16 -27
--- src/allrepo.c
+++ src/allrepo.c
@@ -141,11 +141,11 @@
141141
int useCheckouts = 0;
142142
int quiet = 0;
143143
int dryRunFlag = 0;
144144
int stopOnError = find_option("dontstop",0,0)==0;
145145
int rc;
146
- Bag outOfDate;
146
+ int nToDel = 0;
147147
148148
dryRunFlag = find_option("dry-run","n",0)!=0;
149149
if( !dryRunFlag ){
150150
dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
151151
}
@@ -243,33 +243,32 @@
243243
}
244244
verify_all_options();
245245
zFossil = quoteFilename(g.nameOfExe);
246246
if( useCheckouts ){
247247
db_prepare(&q,
248
- "SELECT substr(name, 7) COLLATE nocase, max(rowid)"
248
+ "SELECT DISTINCT substr(name, 7), name COLLATE nocase"
249249
" FROM global_config"
250250
" WHERE substr(name, 1, 6)=='ckout:'"
251
- " GROUP BY 1 ORDER BY 1"
251
+ " ORDER BY 1"
252252
);
253253
}else{
254254
db_prepare(&q,
255
- "SELECT substr(name, 6) COLLATE nocase, max(rowid)"
255
+ "SELECT DISTINCT substr(name, 6), name COLLATE nocase"
256256
" FROM global_config"
257257
" WHERE substr(name, 1, 5)=='repo:'"
258
- " GROUP BY 1 ORDER BY 1"
258
+ " ORDER BY 1"
259259
);
260260
}
261
- bag_init(&outOfDate);
261
+ db_multi_exec("CREATE TEMP TABLE todel(x TEXT)");
262262
while( db_step(&q)==SQLITE_ROW ){
263263
const char *zFilename = db_column_text(&q, 0);
264
- int rowid = db_column_int(&q, 1);
265
- if( file_access(zFilename, 0) || !file_is_canonical(zFilename) ){
266
- bag_insert(&outOfDate, rowid);
267
- continue;
268
- }
269
- if( useCheckouts && file_isdir(zFilename)!=1 ){
270
- bag_insert(&outOfDate, rowid);
264
+ if( file_access(zFilename, 0)
265
+ || !file_is_canonical(zFilename)
266
+ || (useCheckouts && file_isdir(zFilename)!=1)
267
+ ){
268
+ db_multi_exec("INSERT INTO todel VALUES(%Q)", db_column_text(&q, 1));
269
+ nToDel++;
271270
continue;
272271
}
273272
if( zCmd[0]=='l' ){
274273
fossil_print("%s\n", zFilename);
275274
continue;
@@ -291,24 +290,14 @@
291290
db_finalize(&q);
292291
293292
/* If any repositories whose names appear in the ~/.fossil file could not
294293
** be found, remove those names from the ~/.fossil file.
295294
*/
296
- if( bag_count(&outOfDate)>0 ){
297
- Blob sql;
298
- char *zSep = "(";
299
- int rowid;
300
- blob_zero(&sql);
301
- blob_appendf(&sql, "DELETE FROM global_config WHERE rowid IN ");
302
- for(rowid=bag_first(&outOfDate); rowid>0; rowid=bag_next(&outOfDate,rowid)){
303
- blob_appendf(&sql, "%s%d", zSep, rowid);
304
- zSep = ",";
305
- }
306
- blob_appendf(&sql, ")");
295
+ if( nToDel>0 ){
296
+ const char *zSql = "DELETE FROM global_config WHERE name IN toDel";
307297
if( dryRunFlag ){
308
- fossil_print("%s\n", blob_str(&sql));
298
+ fossil_print("%s\n", zSql);
309299
}else{
310
- db_multi_exec(blob_str(&sql));
300
+ db_multi_exec(zSql);
311301
}
312
- blob_reset(&sql);
313302
}
314303
}
315304
--- src/allrepo.c
+++ src/allrepo.c
@@ -141,11 +141,11 @@
141 int useCheckouts = 0;
142 int quiet = 0;
143 int dryRunFlag = 0;
144 int stopOnError = find_option("dontstop",0,0)==0;
145 int rc;
146 Bag outOfDate;
147
148 dryRunFlag = find_option("dry-run","n",0)!=0;
149 if( !dryRunFlag ){
150 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
151 }
@@ -243,33 +243,32 @@
243 }
244 verify_all_options();
245 zFossil = quoteFilename(g.nameOfExe);
246 if( useCheckouts ){
247 db_prepare(&q,
248 "SELECT substr(name, 7) COLLATE nocase, max(rowid)"
249 " FROM global_config"
250 " WHERE substr(name, 1, 6)=='ckout:'"
251 " GROUP BY 1 ORDER BY 1"
252 );
253 }else{
254 db_prepare(&q,
255 "SELECT substr(name, 6) COLLATE nocase, max(rowid)"
256 " FROM global_config"
257 " WHERE substr(name, 1, 5)=='repo:'"
258 " GROUP BY 1 ORDER BY 1"
259 );
260 }
261 bag_init(&outOfDate);
262 while( db_step(&q)==SQLITE_ROW ){
263 const char *zFilename = db_column_text(&q, 0);
264 int rowid = db_column_int(&q, 1);
265 if( file_access(zFilename, 0) || !file_is_canonical(zFilename) ){
266 bag_insert(&outOfDate, rowid);
267 continue;
268 }
269 if( useCheckouts && file_isdir(zFilename)!=1 ){
270 bag_insert(&outOfDate, rowid);
271 continue;
272 }
273 if( zCmd[0]=='l' ){
274 fossil_print("%s\n", zFilename);
275 continue;
@@ -291,24 +290,14 @@
291 db_finalize(&q);
292
293 /* If any repositories whose names appear in the ~/.fossil file could not
294 ** be found, remove those names from the ~/.fossil file.
295 */
296 if( bag_count(&outOfDate)>0 ){
297 Blob sql;
298 char *zSep = "(";
299 int rowid;
300 blob_zero(&sql);
301 blob_appendf(&sql, "DELETE FROM global_config WHERE rowid IN ");
302 for(rowid=bag_first(&outOfDate); rowid>0; rowid=bag_next(&outOfDate,rowid)){
303 blob_appendf(&sql, "%s%d", zSep, rowid);
304 zSep = ",";
305 }
306 blob_appendf(&sql, ")");
307 if( dryRunFlag ){
308 fossil_print("%s\n", blob_str(&sql));
309 }else{
310 db_multi_exec(blob_str(&sql));
311 }
312 blob_reset(&sql);
313 }
314 }
315
--- src/allrepo.c
+++ src/allrepo.c
@@ -141,11 +141,11 @@
141 int useCheckouts = 0;
142 int quiet = 0;
143 int dryRunFlag = 0;
144 int stopOnError = find_option("dontstop",0,0)==0;
145 int rc;
146 int nToDel = 0;
147
148 dryRunFlag = find_option("dry-run","n",0)!=0;
149 if( !dryRunFlag ){
150 dryRunFlag = find_option("test",0,0)!=0; /* deprecated */
151 }
@@ -243,33 +243,32 @@
243 }
244 verify_all_options();
245 zFossil = quoteFilename(g.nameOfExe);
246 if( useCheckouts ){
247 db_prepare(&q,
248 "SELECT DISTINCT substr(name, 7), name COLLATE nocase"
249 " FROM global_config"
250 " WHERE substr(name, 1, 6)=='ckout:'"
251 " ORDER BY 1"
252 );
253 }else{
254 db_prepare(&q,
255 "SELECT DISTINCT substr(name, 6), name COLLATE nocase"
256 " FROM global_config"
257 " WHERE substr(name, 1, 5)=='repo:'"
258 " ORDER BY 1"
259 );
260 }
261 db_multi_exec("CREATE TEMP TABLE todel(x TEXT)");
262 while( db_step(&q)==SQLITE_ROW ){
263 const char *zFilename = db_column_text(&q, 0);
264 if( file_access(zFilename, 0)
265 || !file_is_canonical(zFilename)
266 || (useCheckouts && file_isdir(zFilename)!=1)
267 ){
268 db_multi_exec("INSERT INTO todel VALUES(%Q)", db_column_text(&q, 1));
269 nToDel++;
 
270 continue;
271 }
272 if( zCmd[0]=='l' ){
273 fossil_print("%s\n", zFilename);
274 continue;
@@ -291,24 +290,14 @@
290 db_finalize(&q);
291
292 /* If any repositories whose names appear in the ~/.fossil file could not
293 ** be found, remove those names from the ~/.fossil file.
294 */
295 if( nToDel>0 ){
296 const char *zSql = "DELETE FROM global_config WHERE name IN toDel";
 
 
 
 
 
 
 
 
 
297 if( dryRunFlag ){
298 fossil_print("%s\n", zSql);
299 }else{
300 db_multi_exec(zSql);
301 }
 
302 }
303 }
304
+100 -16
--- 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.2"
139139
#define SQLITE_VERSION_NUMBER 3008002
140
-#define SQLITE_SOURCE_ID "2013-11-11 16:55:52 924d63b283a3d059838114c95d42c6feaf913529"
140
+#define SQLITE_SOURCE_ID "2013-11-12 15:33:40 0f924c6ef6cf2ac5a61aafa8dd8e3309b3970499"
141141
142142
/*
143143
** CAPI3REF: Run-Time Library Version Numbers
144144
** KEYWORDS: sqlite3_version, sqlite3_sourceid
145145
**
@@ -5321,14 +5321,26 @@
53215321
**
53225322
** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
53235323
** the correct order to satisfy the ORDER BY clause so that no separate
53245324
** sorting step is required.
53255325
**
5326
-** ^The estimatedCost value is an estimate of the cost of doing the
5327
-** particular lookup. A full scan of a table with N entries should have
5328
-** a cost of N. A binary search of a table of N entries should have a
5329
-** cost of approximately log(N).
5326
+** ^The estimatedCost value is an estimate of the cost of a particular
5327
+** strategy. A cost of N indicates that the cost of the strategy is similar
5328
+** to a linear scan of an SQLite table with N rows. A cost of log(N)
5329
+** indicates that the expense of the operation is similar to that of a
5330
+** binary search on a unique indexed field of an SQLite table with N rows.
5331
+**
5332
+** ^The estimatedRows value is an estimate of the number of rows that
5333
+** will be returned by the strategy.
5334
+**
5335
+** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
5336
+** structure for SQLite version 3.8.2. If a virtual table extension is
5337
+** used with an SQLite version earlier than 3.8.2, the results of attempting
5338
+** to read or write the estimatedRows field are undefined (but are likely
5339
+** to included crashing the application). The estimatedRows field should
5340
+** therefore only be used if [sqlite3_libversion_number()] returns a
5341
+** value greater than or equal to 3008002.
53305342
*/
53315343
struct sqlite3_index_info {
53325344
/* Inputs */
53335345
int nConstraint; /* Number of entries in aConstraint */
53345346
struct sqlite3_index_constraint {
@@ -5349,11 +5361,13 @@
53495361
} *aConstraintUsage;
53505362
int idxNum; /* Number used to identify the index */
53515363
char *idxStr; /* String, possibly obtained from sqlite3_malloc */
53525364
int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
53535365
int orderByConsumed; /* True if output is already ordered */
5354
- double estimatedCost; /* Estimated cost of using this index */
5366
+ double estimatedCost; /* Estimated cost of using this index */
5367
+ /* Fields below are only available in SQLite 3.8.2 and later */
5368
+ sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
53555369
};
53565370
53575371
/*
53585372
** CAPI3REF: Virtual Table Constraint Operator Codes
53595373
**
@@ -104060,15 +104074,16 @@
104060104074
104061104075
/* Search for the index that has the lowest scan cost.
104062104076
**
104063104077
** (2011-04-15) Do not do a full scan of an unordered index.
104064104078
**
104065
- ** (2013-10-03) Do not count the entires in a partial index.
104079
+ ** (2013-10-03) Do not count the entries in a partial index.
104066104080
**
104067104081
** In practice the KeyInfo structure will not be used. It is only
104068104082
** passed to keep OP_OpenRead happy.
104069104083
*/
104084
+ if( !HasRowid(pTab) ) pBest = sqlite3PrimaryKeyIndex(pTab);
104070104085
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
104071104086
if( pIdx->bUnordered==0
104072104087
&& pIdx->szIdxRow<pTab->szTabRow
104073104088
&& pIdx->pPartIdxWhere==0
104074104089
&& (!pBest || pIdx->szIdxRow<pBest->szIdxRow)
@@ -107998,11 +108013,12 @@
107998108013
LogEst rSetup; /* One-time setup cost (ex: create transient index) */
107999108014
LogEst rRun; /* Cost of running each loop */
108000108015
LogEst nOut; /* Estimated number of output rows */
108001108016
union {
108002108017
struct { /* Information for internal btree tables */
108003
- int nEq; /* Number of equality constraints */
108018
+ u16 nEq; /* Number of equality constraints */
108019
+ u16 nSkip; /* Number of initial index columns skipped */
108004108020
Index *pIndex; /* Index used, or NULL */
108005108021
} btree;
108006108022
struct { /* Information for virtual tables */
108007108023
int idxNum; /* Index number */
108008108024
u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -109859,10 +109875,11 @@
109859109875
}
109860109876
sqlite3DebugPrintf(" idxNum=%d\n", p->idxNum);
109861109877
sqlite3DebugPrintf(" idxStr=%s\n", p->idxStr);
109862109878
sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed);
109863109879
sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost);
109880
+ sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows);
109864109881
}
109865109882
#else
109866109883
#define TRACE_IDX_INPUTS(A)
109867109884
#define TRACE_IDX_OUTPUTS(A)
109868109885
#endif
@@ -111825,11 +111842,16 @@
111825111842
if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
111826111843
int i = sqlite3Strlen30(zName) - 1;
111827111844
while( zName[i]!='_' ) i--;
111828111845
zName += i;
111829111846
}
111830
- sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
111847
+ if( p->u.btree.nSkip ){
111848
+ sqlite3DebugPrintf(".%-15s %d+%d", zName,
111849
+ p->u.btree.nSkip, p->u.btree.nEq);
111850
+ }else{
111851
+ sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
111852
+ }
111831111853
}else{
111832111854
sqlite3DebugPrintf("%20s","");
111833111855
}
111834111856
}else{
111835111857
char *z;
@@ -112668,10 +112690,11 @@
112668112690
pIdxInfo->idxStr = 0;
112669112691
pIdxInfo->idxNum = 0;
112670112692
pIdxInfo->needToFreeIdxStr = 0;
112671112693
pIdxInfo->orderByConsumed = 0;
112672112694
pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
112695
+ pIdxInfo->estimatedRows = 25;
112673112696
rc = vtabBestIndex(pParse, pTab, pIdxInfo);
112674112697
if( rc ) goto whereLoopAddVtab_exit;
112675112698
pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
112676112699
pNew->prereq = 0;
112677112700
mxTerm = -1;
@@ -112727,12 +112750,11 @@
112727112750
pNew->u.vtab.idxStr = pIdxInfo->idxStr;
112728112751
pNew->u.vtab.isOrdered = (u8)((pIdxInfo->nOrderBy!=0)
112729112752
&& pIdxInfo->orderByConsumed);
112730112753
pNew->rSetup = 0;
112731112754
pNew->rRun = sqlite3LogEstFromDouble(pIdxInfo->estimatedCost);
112732
- /* TUNING: Every virtual table query returns 25 rows */
112733
- pNew->nOut = 46; assert( 46==sqlite3LogEst(25) );
112755
+ pNew->nOut = sqlite3LogEst(pIdxInfo->estimatedRows);
112734112756
whereLoopInsert(pBuilder, pNew);
112735112757
if( pNew->u.vtab.needFree ){
112736112758
sqlite3_free(pNew->u.vtab.idxStr);
112737112759
pNew->u.vtab.needFree = 0;
112738112760
}
@@ -141028,10 +141050,20 @@
141028141050
** ever contain very many entries, so a fixed number of buckets is
141029141051
** used.
141030141052
*/
141031141053
#define HASHSIZE 128
141032141054
141055
+/* The xBestIndex method of this virtual table requires an estimate of
141056
+** the number of rows in the virtual table to calculate the costs of
141057
+** various strategies. If possible, this estimate is loaded from the
141058
+** sqlite_stat1 table (with RTREE_MIN_ROWEST as a hard-coded minimum).
141059
+** Otherwise, if no sqlite_stat1 entry is available, use
141060
+** RTREE_DEFAULT_ROWEST.
141061
+*/
141062
+#define RTREE_DEFAULT_ROWEST 1048576
141063
+#define RTREE_MIN_ROWEST 100
141064
+
141033141065
/*
141034141066
** An rtree virtual-table object.
141035141067
*/
141036141068
struct Rtree {
141037141069
sqlite3_vtab base;
@@ -141042,10 +141074,11 @@
141042141074
int iDepth; /* Current depth of the r-tree structure */
141043141075
char *zDb; /* Name of database containing r-tree table */
141044141076
char *zName; /* Name of r-tree table */
141045141077
RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
141046141078
int nBusy; /* Current number of users of this structure */
141079
+ i64 nRowEst; /* Estimated number of rows in this table */
141047141080
141048141081
/* List of nodes removed during a CondenseTree operation. List is
141049141082
** linked together via the pointer normally used for hash chains -
141050141083
** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree
141051141084
** headed by the node (leaf nodes have RtreeNode.iNode==0).
@@ -142233,10 +142266,23 @@
142233142266
}
142234142267
142235142268
rtreeRelease(pRtree);
142236142269
return rc;
142237142270
}
142271
+
142272
+/*
142273
+** Set the pIdxInfo->estimatedRows variable to nRow. Unless this
142274
+** extension is currently being used by a version of SQLite too old to
142275
+** support estimatedRows. In that case this function is a no-op.
142276
+*/
142277
+static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
142278
+#if SQLITE_VERSION_NUMBER>=3008002
142279
+ if( sqlite3_libversion_number()>=3008002 ){
142280
+ pIdxInfo->estimatedRows = nRow;
142281
+ }
142282
+#endif
142283
+}
142238142284
142239142285
/*
142240142286
** Rtree virtual table module xBestIndex method. There are three
142241142287
** table scan strategies to choose from (in order from most to
142242142288
** least desirable):
@@ -142269,17 +142315,18 @@
142269142315
** The second of each pair of bytes identifies the coordinate column
142270142316
** to which the constraint applies. The leftmost coordinate column
142271142317
** is 'a', the second from the left 'b' etc.
142272142318
*/
142273142319
static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
142320
+ Rtree *pRtree = (Rtree*)tab;
142274142321
int rc = SQLITE_OK;
142275142322
int ii;
142323
+ i64 nRow; /* Estimated rows returned by this scan */
142276142324
142277142325
int iIdx = 0;
142278142326
char zIdxStr[RTREE_MAX_DIMENSIONS*8+1];
142279142327
memset(zIdxStr, 0, sizeof(zIdxStr));
142280
- UNUSED_PARAMETER(tab);
142281142328
142282142329
assert( pIdxInfo->idxStr==0 );
142283142330
for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
142284142331
struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
142285142332
@@ -142295,13 +142342,15 @@
142295142342
pIdxInfo->aConstraintUsage[jj].omit = 1;
142296142343
142297142344
/* This strategy involves a two rowid lookups on an B-Tree structures
142298142345
** and then a linear search of an R-Tree node. This should be
142299142346
** considered almost as quick as a direct rowid lookup (for which
142300
- ** sqlite uses an internal cost of 0.0).
142347
+ ** sqlite uses an internal cost of 0.0). It is expected to return
142348
+ ** a single row.
142301142349
*/
142302
- pIdxInfo->estimatedCost = 10.0;
142350
+ pIdxInfo->estimatedCost = 30.0;
142351
+ setEstimatedRows(pIdxInfo, 1);
142303142352
return SQLITE_OK;
142304142353
}
142305142354
142306142355
if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
142307142356
u8 op;
@@ -142326,12 +142375,15 @@
142326142375
pIdxInfo->idxNum = 2;
142327142376
pIdxInfo->needToFreeIdxStr = 1;
142328142377
if( iIdx>0 && 0==(pIdxInfo->idxStr = sqlite3_mprintf("%s", zIdxStr)) ){
142329142378
return SQLITE_NOMEM;
142330142379
}
142331
- assert( iIdx>=0 );
142332
- pIdxInfo->estimatedCost = (2000000.0 / (double)(iIdx + 1));
142380
+
142381
+ nRow = pRtree->nRowEst / (iIdx + 1);
142382
+ pIdxInfo->estimatedCost = (double)6.0 * (double)nRow;
142383
+ setEstimatedRows(pIdxInfo, nRow);
142384
+
142333142385
return rc;
142334142386
}
142335142387
142336142388
/*
142337142389
** Return the N-dimensional volumn of the cell stored in *p.
@@ -143801,10 +143853,41 @@
143801143853
rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
143802143854
sqlite3_free(zSql);
143803143855
}
143804143856
return rc;
143805143857
}
143858
+
143859
+/*
143860
+** This function populates the pRtree->nRowEst variable with an estimate
143861
+** of the number of rows in the virtual table. If possible, this is based
143862
+** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
143863
+*/
143864
+static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
143865
+ const char *zSql = "SELECT stat FROM sqlite_stat1 WHERE tbl= ? || '_rowid'";
143866
+ sqlite3_stmt *p;
143867
+ int rc;
143868
+ i64 nRow = 0;
143869
+
143870
+ rc = sqlite3_prepare_v2(db, zSql, -1, &p, 0);
143871
+ if( rc==SQLITE_OK ){
143872
+ sqlite3_bind_text(p, 1, pRtree->zName, -1, SQLITE_STATIC);
143873
+ if( sqlite3_step(p)==SQLITE_ROW ) nRow = sqlite3_column_int64(p, 0);
143874
+ rc = sqlite3_finalize(p);
143875
+ }else if( rc!=SQLITE_NOMEM ){
143876
+ rc = SQLITE_OK;
143877
+ }
143878
+
143879
+ if( rc==SQLITE_OK ){
143880
+ if( nRow==0 ){
143881
+ pRtree->nRowEst = RTREE_DEFAULT_ROWEST;
143882
+ }else{
143883
+ pRtree->nRowEst = MAX(nRow, RTREE_MIN_ROWEST);
143884
+ }
143885
+ }
143886
+
143887
+ return rc;
143888
+}
143806143889
143807143890
static sqlite3_module rtreeModule = {
143808143891
0, /* iVersion */
143809143892
rtreeCreate, /* xCreate - create a table */
143810143893
rtreeConnect, /* xConnect - connect to an existing table */
@@ -143887,10 +143970,11 @@
143887143970
appStmt[5] = &pRtree->pDeleteRowid;
143888143971
appStmt[6] = &pRtree->pReadParent;
143889143972
appStmt[7] = &pRtree->pWriteParent;
143890143973
appStmt[8] = &pRtree->pDeleteParent;
143891143974
143975
+ rc = rtreeQueryStat1(db, pRtree);
143892143976
for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){
143893143977
char *zSql = sqlite3_mprintf(azSql[i], zDb, zPrefix);
143894143978
if( zSql ){
143895143979
rc = sqlite3_prepare_v2(db, zSql, -1, appStmt[i], 0);
143896143980
}else{
143897143981
--- 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.2"
139 #define SQLITE_VERSION_NUMBER 3008002
140 #define SQLITE_SOURCE_ID "2013-11-11 16:55:52 924d63b283a3d059838114c95d42c6feaf913529"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -5321,14 +5321,26 @@
5321 **
5322 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
5323 ** the correct order to satisfy the ORDER BY clause so that no separate
5324 ** sorting step is required.
5325 **
5326 ** ^The estimatedCost value is an estimate of the cost of doing the
5327 ** particular lookup. A full scan of a table with N entries should have
5328 ** a cost of N. A binary search of a table of N entries should have a
5329 ** cost of approximately log(N).
 
 
 
 
 
 
 
 
 
 
 
 
5330 */
5331 struct sqlite3_index_info {
5332 /* Inputs */
5333 int nConstraint; /* Number of entries in aConstraint */
5334 struct sqlite3_index_constraint {
@@ -5349,11 +5361,13 @@
5349 } *aConstraintUsage;
5350 int idxNum; /* Number used to identify the index */
5351 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
5352 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
5353 int orderByConsumed; /* True if output is already ordered */
5354 double estimatedCost; /* Estimated cost of using this index */
 
 
5355 };
5356
5357 /*
5358 ** CAPI3REF: Virtual Table Constraint Operator Codes
5359 **
@@ -104060,15 +104074,16 @@
104060
104061 /* Search for the index that has the lowest scan cost.
104062 **
104063 ** (2011-04-15) Do not do a full scan of an unordered index.
104064 **
104065 ** (2013-10-03) Do not count the entires in a partial index.
104066 **
104067 ** In practice the KeyInfo structure will not be used. It is only
104068 ** passed to keep OP_OpenRead happy.
104069 */
 
104070 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
104071 if( pIdx->bUnordered==0
104072 && pIdx->szIdxRow<pTab->szTabRow
104073 && pIdx->pPartIdxWhere==0
104074 && (!pBest || pIdx->szIdxRow<pBest->szIdxRow)
@@ -107998,11 +108013,12 @@
107998 LogEst rSetup; /* One-time setup cost (ex: create transient index) */
107999 LogEst rRun; /* Cost of running each loop */
108000 LogEst nOut; /* Estimated number of output rows */
108001 union {
108002 struct { /* Information for internal btree tables */
108003 int nEq; /* Number of equality constraints */
 
108004 Index *pIndex; /* Index used, or NULL */
108005 } btree;
108006 struct { /* Information for virtual tables */
108007 int idxNum; /* Index number */
108008 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -109859,10 +109875,11 @@
109859 }
109860 sqlite3DebugPrintf(" idxNum=%d\n", p->idxNum);
109861 sqlite3DebugPrintf(" idxStr=%s\n", p->idxStr);
109862 sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed);
109863 sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost);
 
109864 }
109865 #else
109866 #define TRACE_IDX_INPUTS(A)
109867 #define TRACE_IDX_OUTPUTS(A)
109868 #endif
@@ -111825,11 +111842,16 @@
111825 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
111826 int i = sqlite3Strlen30(zName) - 1;
111827 while( zName[i]!='_' ) i--;
111828 zName += i;
111829 }
111830 sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
 
 
 
 
 
111831 }else{
111832 sqlite3DebugPrintf("%20s","");
111833 }
111834 }else{
111835 char *z;
@@ -112668,10 +112690,11 @@
112668 pIdxInfo->idxStr = 0;
112669 pIdxInfo->idxNum = 0;
112670 pIdxInfo->needToFreeIdxStr = 0;
112671 pIdxInfo->orderByConsumed = 0;
112672 pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
 
112673 rc = vtabBestIndex(pParse, pTab, pIdxInfo);
112674 if( rc ) goto whereLoopAddVtab_exit;
112675 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
112676 pNew->prereq = 0;
112677 mxTerm = -1;
@@ -112727,12 +112750,11 @@
112727 pNew->u.vtab.idxStr = pIdxInfo->idxStr;
112728 pNew->u.vtab.isOrdered = (u8)((pIdxInfo->nOrderBy!=0)
112729 && pIdxInfo->orderByConsumed);
112730 pNew->rSetup = 0;
112731 pNew->rRun = sqlite3LogEstFromDouble(pIdxInfo->estimatedCost);
112732 /* TUNING: Every virtual table query returns 25 rows */
112733 pNew->nOut = 46; assert( 46==sqlite3LogEst(25) );
112734 whereLoopInsert(pBuilder, pNew);
112735 if( pNew->u.vtab.needFree ){
112736 sqlite3_free(pNew->u.vtab.idxStr);
112737 pNew->u.vtab.needFree = 0;
112738 }
@@ -141028,10 +141050,20 @@
141028 ** ever contain very many entries, so a fixed number of buckets is
141029 ** used.
141030 */
141031 #define HASHSIZE 128
141032
 
 
 
 
 
 
 
 
 
 
141033 /*
141034 ** An rtree virtual-table object.
141035 */
141036 struct Rtree {
141037 sqlite3_vtab base;
@@ -141042,10 +141074,11 @@
141042 int iDepth; /* Current depth of the r-tree structure */
141043 char *zDb; /* Name of database containing r-tree table */
141044 char *zName; /* Name of r-tree table */
141045 RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
141046 int nBusy; /* Current number of users of this structure */
 
141047
141048 /* List of nodes removed during a CondenseTree operation. List is
141049 ** linked together via the pointer normally used for hash chains -
141050 ** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree
141051 ** headed by the node (leaf nodes have RtreeNode.iNode==0).
@@ -142233,10 +142266,23 @@
142233 }
142234
142235 rtreeRelease(pRtree);
142236 return rc;
142237 }
 
 
 
 
 
 
 
 
 
 
 
 
 
142238
142239 /*
142240 ** Rtree virtual table module xBestIndex method. There are three
142241 ** table scan strategies to choose from (in order from most to
142242 ** least desirable):
@@ -142269,17 +142315,18 @@
142269 ** The second of each pair of bytes identifies the coordinate column
142270 ** to which the constraint applies. The leftmost coordinate column
142271 ** is 'a', the second from the left 'b' etc.
142272 */
142273 static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
 
142274 int rc = SQLITE_OK;
142275 int ii;
 
142276
142277 int iIdx = 0;
142278 char zIdxStr[RTREE_MAX_DIMENSIONS*8+1];
142279 memset(zIdxStr, 0, sizeof(zIdxStr));
142280 UNUSED_PARAMETER(tab);
142281
142282 assert( pIdxInfo->idxStr==0 );
142283 for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
142284 struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
142285
@@ -142295,13 +142342,15 @@
142295 pIdxInfo->aConstraintUsage[jj].omit = 1;
142296
142297 /* This strategy involves a two rowid lookups on an B-Tree structures
142298 ** and then a linear search of an R-Tree node. This should be
142299 ** considered almost as quick as a direct rowid lookup (for which
142300 ** sqlite uses an internal cost of 0.0).
 
142301 */
142302 pIdxInfo->estimatedCost = 10.0;
 
142303 return SQLITE_OK;
142304 }
142305
142306 if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
142307 u8 op;
@@ -142326,12 +142375,15 @@
142326 pIdxInfo->idxNum = 2;
142327 pIdxInfo->needToFreeIdxStr = 1;
142328 if( iIdx>0 && 0==(pIdxInfo->idxStr = sqlite3_mprintf("%s", zIdxStr)) ){
142329 return SQLITE_NOMEM;
142330 }
142331 assert( iIdx>=0 );
142332 pIdxInfo->estimatedCost = (2000000.0 / (double)(iIdx + 1));
 
 
 
142333 return rc;
142334 }
142335
142336 /*
142337 ** Return the N-dimensional volumn of the cell stored in *p.
@@ -143801,10 +143853,41 @@
143801 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
143802 sqlite3_free(zSql);
143803 }
143804 return rc;
143805 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
143806
143807 static sqlite3_module rtreeModule = {
143808 0, /* iVersion */
143809 rtreeCreate, /* xCreate - create a table */
143810 rtreeConnect, /* xConnect - connect to an existing table */
@@ -143887,10 +143970,11 @@
143887 appStmt[5] = &pRtree->pDeleteRowid;
143888 appStmt[6] = &pRtree->pReadParent;
143889 appStmt[7] = &pRtree->pWriteParent;
143890 appStmt[8] = &pRtree->pDeleteParent;
143891
 
143892 for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){
143893 char *zSql = sqlite3_mprintf(azSql[i], zDb, zPrefix);
143894 if( zSql ){
143895 rc = sqlite3_prepare_v2(db, zSql, -1, appStmt[i], 0);
143896 }else{
143897
--- 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.2"
139 #define SQLITE_VERSION_NUMBER 3008002
140 #define SQLITE_SOURCE_ID "2013-11-12 15:33:40 0f924c6ef6cf2ac5a61aafa8dd8e3309b3970499"
141
142 /*
143 ** CAPI3REF: Run-Time Library Version Numbers
144 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
145 **
@@ -5321,14 +5321,26 @@
5321 **
5322 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
5323 ** the correct order to satisfy the ORDER BY clause so that no separate
5324 ** sorting step is required.
5325 **
5326 ** ^The estimatedCost value is an estimate of the cost of a particular
5327 ** strategy. A cost of N indicates that the cost of the strategy is similar
5328 ** to a linear scan of an SQLite table with N rows. A cost of log(N)
5329 ** indicates that the expense of the operation is similar to that of a
5330 ** binary search on a unique indexed field of an SQLite table with N rows.
5331 **
5332 ** ^The estimatedRows value is an estimate of the number of rows that
5333 ** will be returned by the strategy.
5334 **
5335 ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
5336 ** structure for SQLite version 3.8.2. If a virtual table extension is
5337 ** used with an SQLite version earlier than 3.8.2, the results of attempting
5338 ** to read or write the estimatedRows field are undefined (but are likely
5339 ** to included crashing the application). The estimatedRows field should
5340 ** therefore only be used if [sqlite3_libversion_number()] returns a
5341 ** value greater than or equal to 3008002.
5342 */
5343 struct sqlite3_index_info {
5344 /* Inputs */
5345 int nConstraint; /* Number of entries in aConstraint */
5346 struct sqlite3_index_constraint {
@@ -5349,11 +5361,13 @@
5361 } *aConstraintUsage;
5362 int idxNum; /* Number used to identify the index */
5363 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
5364 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
5365 int orderByConsumed; /* True if output is already ordered */
5366 double estimatedCost; /* Estimated cost of using this index */
5367 /* Fields below are only available in SQLite 3.8.2 and later */
5368 sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
5369 };
5370
5371 /*
5372 ** CAPI3REF: Virtual Table Constraint Operator Codes
5373 **
@@ -104060,15 +104074,16 @@
104074
104075 /* Search for the index that has the lowest scan cost.
104076 **
104077 ** (2011-04-15) Do not do a full scan of an unordered index.
104078 **
104079 ** (2013-10-03) Do not count the entries in a partial index.
104080 **
104081 ** In practice the KeyInfo structure will not be used. It is only
104082 ** passed to keep OP_OpenRead happy.
104083 */
104084 if( !HasRowid(pTab) ) pBest = sqlite3PrimaryKeyIndex(pTab);
104085 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
104086 if( pIdx->bUnordered==0
104087 && pIdx->szIdxRow<pTab->szTabRow
104088 && pIdx->pPartIdxWhere==0
104089 && (!pBest || pIdx->szIdxRow<pBest->szIdxRow)
@@ -107998,11 +108013,12 @@
108013 LogEst rSetup; /* One-time setup cost (ex: create transient index) */
108014 LogEst rRun; /* Cost of running each loop */
108015 LogEst nOut; /* Estimated number of output rows */
108016 union {
108017 struct { /* Information for internal btree tables */
108018 u16 nEq; /* Number of equality constraints */
108019 u16 nSkip; /* Number of initial index columns skipped */
108020 Index *pIndex; /* Index used, or NULL */
108021 } btree;
108022 struct { /* Information for virtual tables */
108023 int idxNum; /* Index number */
108024 u8 needFree; /* True if sqlite3_free(idxStr) is needed */
@@ -109859,10 +109875,11 @@
109875 }
109876 sqlite3DebugPrintf(" idxNum=%d\n", p->idxNum);
109877 sqlite3DebugPrintf(" idxStr=%s\n", p->idxStr);
109878 sqlite3DebugPrintf(" orderByConsumed=%d\n", p->orderByConsumed);
109879 sqlite3DebugPrintf(" estimatedCost=%g\n", p->estimatedCost);
109880 sqlite3DebugPrintf(" estimatedRows=%lld\n", p->estimatedRows);
109881 }
109882 #else
109883 #define TRACE_IDX_INPUTS(A)
109884 #define TRACE_IDX_OUTPUTS(A)
109885 #endif
@@ -111825,11 +111842,16 @@
111842 if( strncmp(zName, "sqlite_autoindex_", 17)==0 ){
111843 int i = sqlite3Strlen30(zName) - 1;
111844 while( zName[i]!='_' ) i--;
111845 zName += i;
111846 }
111847 if( p->u.btree.nSkip ){
111848 sqlite3DebugPrintf(".%-15s %d+%d", zName,
111849 p->u.btree.nSkip, p->u.btree.nEq);
111850 }else{
111851 sqlite3DebugPrintf(".%-16s %2d", zName, p->u.btree.nEq);
111852 }
111853 }else{
111854 sqlite3DebugPrintf("%20s","");
111855 }
111856 }else{
111857 char *z;
@@ -112668,10 +112690,11 @@
112690 pIdxInfo->idxStr = 0;
112691 pIdxInfo->idxNum = 0;
112692 pIdxInfo->needToFreeIdxStr = 0;
112693 pIdxInfo->orderByConsumed = 0;
112694 pIdxInfo->estimatedCost = SQLITE_BIG_DBL / (double)2;
112695 pIdxInfo->estimatedRows = 25;
112696 rc = vtabBestIndex(pParse, pTab, pIdxInfo);
112697 if( rc ) goto whereLoopAddVtab_exit;
112698 pIdxCons = *(struct sqlite3_index_constraint**)&pIdxInfo->aConstraint;
112699 pNew->prereq = 0;
112700 mxTerm = -1;
@@ -112727,12 +112750,11 @@
112750 pNew->u.vtab.idxStr = pIdxInfo->idxStr;
112751 pNew->u.vtab.isOrdered = (u8)((pIdxInfo->nOrderBy!=0)
112752 && pIdxInfo->orderByConsumed);
112753 pNew->rSetup = 0;
112754 pNew->rRun = sqlite3LogEstFromDouble(pIdxInfo->estimatedCost);
112755 pNew->nOut = sqlite3LogEst(pIdxInfo->estimatedRows);
 
112756 whereLoopInsert(pBuilder, pNew);
112757 if( pNew->u.vtab.needFree ){
112758 sqlite3_free(pNew->u.vtab.idxStr);
112759 pNew->u.vtab.needFree = 0;
112760 }
@@ -141028,10 +141050,20 @@
141050 ** ever contain very many entries, so a fixed number of buckets is
141051 ** used.
141052 */
141053 #define HASHSIZE 128
141054
141055 /* The xBestIndex method of this virtual table requires an estimate of
141056 ** the number of rows in the virtual table to calculate the costs of
141057 ** various strategies. If possible, this estimate is loaded from the
141058 ** sqlite_stat1 table (with RTREE_MIN_ROWEST as a hard-coded minimum).
141059 ** Otherwise, if no sqlite_stat1 entry is available, use
141060 ** RTREE_DEFAULT_ROWEST.
141061 */
141062 #define RTREE_DEFAULT_ROWEST 1048576
141063 #define RTREE_MIN_ROWEST 100
141064
141065 /*
141066 ** An rtree virtual-table object.
141067 */
141068 struct Rtree {
141069 sqlite3_vtab base;
@@ -141042,10 +141074,11 @@
141074 int iDepth; /* Current depth of the r-tree structure */
141075 char *zDb; /* Name of database containing r-tree table */
141076 char *zName; /* Name of r-tree table */
141077 RtreeNode *aHash[HASHSIZE]; /* Hash table of in-memory nodes. */
141078 int nBusy; /* Current number of users of this structure */
141079 i64 nRowEst; /* Estimated number of rows in this table */
141080
141081 /* List of nodes removed during a CondenseTree operation. List is
141082 ** linked together via the pointer normally used for hash chains -
141083 ** RtreeNode.pNext. RtreeNode.iNode stores the depth of the sub-tree
141084 ** headed by the node (leaf nodes have RtreeNode.iNode==0).
@@ -142233,10 +142266,23 @@
142266 }
142267
142268 rtreeRelease(pRtree);
142269 return rc;
142270 }
142271
142272 /*
142273 ** Set the pIdxInfo->estimatedRows variable to nRow. Unless this
142274 ** extension is currently being used by a version of SQLite too old to
142275 ** support estimatedRows. In that case this function is a no-op.
142276 */
142277 static void setEstimatedRows(sqlite3_index_info *pIdxInfo, i64 nRow){
142278 #if SQLITE_VERSION_NUMBER>=3008002
142279 if( sqlite3_libversion_number()>=3008002 ){
142280 pIdxInfo->estimatedRows = nRow;
142281 }
142282 #endif
142283 }
142284
142285 /*
142286 ** Rtree virtual table module xBestIndex method. There are three
142287 ** table scan strategies to choose from (in order from most to
142288 ** least desirable):
@@ -142269,17 +142315,18 @@
142315 ** The second of each pair of bytes identifies the coordinate column
142316 ** to which the constraint applies. The leftmost coordinate column
142317 ** is 'a', the second from the left 'b' etc.
142318 */
142319 static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
142320 Rtree *pRtree = (Rtree*)tab;
142321 int rc = SQLITE_OK;
142322 int ii;
142323 i64 nRow; /* Estimated rows returned by this scan */
142324
142325 int iIdx = 0;
142326 char zIdxStr[RTREE_MAX_DIMENSIONS*8+1];
142327 memset(zIdxStr, 0, sizeof(zIdxStr));
 
142328
142329 assert( pIdxInfo->idxStr==0 );
142330 for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(int)(sizeof(zIdxStr)-1); ii++){
142331 struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
142332
@@ -142295,13 +142342,15 @@
142342 pIdxInfo->aConstraintUsage[jj].omit = 1;
142343
142344 /* This strategy involves a two rowid lookups on an B-Tree structures
142345 ** and then a linear search of an R-Tree node. This should be
142346 ** considered almost as quick as a direct rowid lookup (for which
142347 ** sqlite uses an internal cost of 0.0). It is expected to return
142348 ** a single row.
142349 */
142350 pIdxInfo->estimatedCost = 30.0;
142351 setEstimatedRows(pIdxInfo, 1);
142352 return SQLITE_OK;
142353 }
142354
142355 if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
142356 u8 op;
@@ -142326,12 +142375,15 @@
142375 pIdxInfo->idxNum = 2;
142376 pIdxInfo->needToFreeIdxStr = 1;
142377 if( iIdx>0 && 0==(pIdxInfo->idxStr = sqlite3_mprintf("%s", zIdxStr)) ){
142378 return SQLITE_NOMEM;
142379 }
142380
142381 nRow = pRtree->nRowEst / (iIdx + 1);
142382 pIdxInfo->estimatedCost = (double)6.0 * (double)nRow;
142383 setEstimatedRows(pIdxInfo, nRow);
142384
142385 return rc;
142386 }
142387
142388 /*
142389 ** Return the N-dimensional volumn of the cell stored in *p.
@@ -143801,10 +143853,41 @@
143853 rc = sqlite3_exec(pRtree->db, zSql, 0, 0, 0);
143854 sqlite3_free(zSql);
143855 }
143856 return rc;
143857 }
143858
143859 /*
143860 ** This function populates the pRtree->nRowEst variable with an estimate
143861 ** of the number of rows in the virtual table. If possible, this is based
143862 ** on sqlite_stat1 data. Otherwise, use RTREE_DEFAULT_ROWEST.
143863 */
143864 static int rtreeQueryStat1(sqlite3 *db, Rtree *pRtree){
143865 const char *zSql = "SELECT stat FROM sqlite_stat1 WHERE tbl= ? || '_rowid'";
143866 sqlite3_stmt *p;
143867 int rc;
143868 i64 nRow = 0;
143869
143870 rc = sqlite3_prepare_v2(db, zSql, -1, &p, 0);
143871 if( rc==SQLITE_OK ){
143872 sqlite3_bind_text(p, 1, pRtree->zName, -1, SQLITE_STATIC);
143873 if( sqlite3_step(p)==SQLITE_ROW ) nRow = sqlite3_column_int64(p, 0);
143874 rc = sqlite3_finalize(p);
143875 }else if( rc!=SQLITE_NOMEM ){
143876 rc = SQLITE_OK;
143877 }
143878
143879 if( rc==SQLITE_OK ){
143880 if( nRow==0 ){
143881 pRtree->nRowEst = RTREE_DEFAULT_ROWEST;
143882 }else{
143883 pRtree->nRowEst = MAX(nRow, RTREE_MIN_ROWEST);
143884 }
143885 }
143886
143887 return rc;
143888 }
143889
143890 static sqlite3_module rtreeModule = {
143891 0, /* iVersion */
143892 rtreeCreate, /* xCreate - create a table */
143893 rtreeConnect, /* xConnect - connect to an existing table */
@@ -143887,10 +143970,11 @@
143970 appStmt[5] = &pRtree->pDeleteRowid;
143971 appStmt[6] = &pRtree->pReadParent;
143972 appStmt[7] = &pRtree->pWriteParent;
143973 appStmt[8] = &pRtree->pDeleteParent;
143974
143975 rc = rtreeQueryStat1(db, pRtree);
143976 for(i=0; i<N_STATEMENT && rc==SQLITE_OK; i++){
143977 char *zSql = sqlite3_mprintf(azSql[i], zDb, zPrefix);
143978 if( zSql ){
143979 rc = sqlite3_prepare_v2(db, zSql, -1, appStmt[i], 0);
143980 }else{
143981
+20 -6
--- 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.2"
111111
#define SQLITE_VERSION_NUMBER 3008002
112
-#define SQLITE_SOURCE_ID "2013-11-11 16:55:52 924d63b283a3d059838114c95d42c6feaf913529"
112
+#define SQLITE_SOURCE_ID "2013-11-12 15:33:40 0f924c6ef6cf2ac5a61aafa8dd8e3309b3970499"
113113
114114
/*
115115
** CAPI3REF: Run-Time Library Version Numbers
116116
** KEYWORDS: sqlite3_version, sqlite3_sourceid
117117
**
@@ -5293,14 +5293,26 @@
52935293
**
52945294
** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
52955295
** the correct order to satisfy the ORDER BY clause so that no separate
52965296
** sorting step is required.
52975297
**
5298
-** ^The estimatedCost value is an estimate of the cost of doing the
5299
-** particular lookup. A full scan of a table with N entries should have
5300
-** a cost of N. A binary search of a table of N entries should have a
5301
-** cost of approximately log(N).
5298
+** ^The estimatedCost value is an estimate of the cost of a particular
5299
+** strategy. A cost of N indicates that the cost of the strategy is similar
5300
+** to a linear scan of an SQLite table with N rows. A cost of log(N)
5301
+** indicates that the expense of the operation is similar to that of a
5302
+** binary search on a unique indexed field of an SQLite table with N rows.
5303
+**
5304
+** ^The estimatedRows value is an estimate of the number of rows that
5305
+** will be returned by the strategy.
5306
+**
5307
+** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
5308
+** structure for SQLite version 3.8.2. If a virtual table extension is
5309
+** used with an SQLite version earlier than 3.8.2, the results of attempting
5310
+** to read or write the estimatedRows field are undefined (but are likely
5311
+** to included crashing the application). The estimatedRows field should
5312
+** therefore only be used if [sqlite3_libversion_number()] returns a
5313
+** value greater than or equal to 3008002.
53025314
*/
53035315
struct sqlite3_index_info {
53045316
/* Inputs */
53055317
int nConstraint; /* Number of entries in aConstraint */
53065318
struct sqlite3_index_constraint {
@@ -5321,11 +5333,13 @@
53215333
} *aConstraintUsage;
53225334
int idxNum; /* Number used to identify the index */
53235335
char *idxStr; /* String, possibly obtained from sqlite3_malloc */
53245336
int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
53255337
int orderByConsumed; /* True if output is already ordered */
5326
- double estimatedCost; /* Estimated cost of using this index */
5338
+ double estimatedCost; /* Estimated cost of using this index */
5339
+ /* Fields below are only available in SQLite 3.8.2 and later */
5340
+ sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
53275341
};
53285342
53295343
/*
53305344
** CAPI3REF: Virtual Table Constraint Operator Codes
53315345
**
53325346
--- 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.2"
111 #define SQLITE_VERSION_NUMBER 3008002
112 #define SQLITE_SOURCE_ID "2013-11-11 16:55:52 924d63b283a3d059838114c95d42c6feaf913529"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -5293,14 +5293,26 @@
5293 **
5294 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
5295 ** the correct order to satisfy the ORDER BY clause so that no separate
5296 ** sorting step is required.
5297 **
5298 ** ^The estimatedCost value is an estimate of the cost of doing the
5299 ** particular lookup. A full scan of a table with N entries should have
5300 ** a cost of N. A binary search of a table of N entries should have a
5301 ** cost of approximately log(N).
 
 
 
 
 
 
 
 
 
 
 
 
5302 */
5303 struct sqlite3_index_info {
5304 /* Inputs */
5305 int nConstraint; /* Number of entries in aConstraint */
5306 struct sqlite3_index_constraint {
@@ -5321,11 +5333,13 @@
5321 } *aConstraintUsage;
5322 int idxNum; /* Number used to identify the index */
5323 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
5324 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
5325 int orderByConsumed; /* True if output is already ordered */
5326 double estimatedCost; /* Estimated cost of using this index */
 
 
5327 };
5328
5329 /*
5330 ** CAPI3REF: Virtual Table Constraint Operator Codes
5331 **
5332
--- 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.2"
111 #define SQLITE_VERSION_NUMBER 3008002
112 #define SQLITE_SOURCE_ID "2013-11-12 15:33:40 0f924c6ef6cf2ac5a61aafa8dd8e3309b3970499"
113
114 /*
115 ** CAPI3REF: Run-Time Library Version Numbers
116 ** KEYWORDS: sqlite3_version, sqlite3_sourceid
117 **
@@ -5293,14 +5293,26 @@
5293 **
5294 ** ^The orderByConsumed means that output from [xFilter]/[xNext] will occur in
5295 ** the correct order to satisfy the ORDER BY clause so that no separate
5296 ** sorting step is required.
5297 **
5298 ** ^The estimatedCost value is an estimate of the cost of a particular
5299 ** strategy. A cost of N indicates that the cost of the strategy is similar
5300 ** to a linear scan of an SQLite table with N rows. A cost of log(N)
5301 ** indicates that the expense of the operation is similar to that of a
5302 ** binary search on a unique indexed field of an SQLite table with N rows.
5303 **
5304 ** ^The estimatedRows value is an estimate of the number of rows that
5305 ** will be returned by the strategy.
5306 **
5307 ** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
5308 ** structure for SQLite version 3.8.2. If a virtual table extension is
5309 ** used with an SQLite version earlier than 3.8.2, the results of attempting
5310 ** to read or write the estimatedRows field are undefined (but are likely
5311 ** to included crashing the application). The estimatedRows field should
5312 ** therefore only be used if [sqlite3_libversion_number()] returns a
5313 ** value greater than or equal to 3008002.
5314 */
5315 struct sqlite3_index_info {
5316 /* Inputs */
5317 int nConstraint; /* Number of entries in aConstraint */
5318 struct sqlite3_index_constraint {
@@ -5321,11 +5333,13 @@
5333 } *aConstraintUsage;
5334 int idxNum; /* Number used to identify the index */
5335 char *idxStr; /* String, possibly obtained from sqlite3_malloc */
5336 int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
5337 int orderByConsumed; /* True if output is already ordered */
5338 double estimatedCost; /* Estimated cost of using this index */
5339 /* Fields below are only available in SQLite 3.8.2 and later */
5340 sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
5341 };
5342
5343 /*
5344 ** CAPI3REF: Virtual Table Constraint Operator Codes
5345 **
5346

Keyboard Shortcuts

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