blob: 54d985510dd4401c75930d68ee8926a264dd33cc [file] [log] [blame]
drh9f18e8a2005-07-08 12:13:04 +00001/*
2** 2005 July 8
3**
4** The author disclaims copyright to this source code. In place of
5** a legal notice, here is a blessing:
6**
7** May you do good and not evil.
8** May you find forgiveness for yourself and forgive others.
9** May you share freely, never taking more than you give.
10**
11*************************************************************************
12** This file contains code associated with the ANALYZE command.
13**
drh8558cde2008-01-05 05:20:10 +000014** @(#) $Id: analyze.c,v 1.33 2008/01/05 05:20:10 drh Exp $
drh9f18e8a2005-07-08 12:13:04 +000015*/
16#ifndef SQLITE_OMIT_ANALYZE
17#include "sqliteInt.h"
18
19/*
drhff2d5ea2005-07-23 00:41:48 +000020** This routine generates code that opens the sqlite_stat1 table on cursor
21** iStatCur.
22**
23** If the sqlite_stat1 tables does not previously exist, it is created.
24** If it does previously exist, all entires associated with table zWhere
25** are removed. If zWhere==0 then all entries are removed.
26*/
27static void openStatTable(
28 Parse *pParse, /* Parsing context */
29 int iDb, /* The database we are looking in */
30 int iStatCur, /* Open the sqlite_stat1 table on this cursor */
31 const char *zWhere /* Delete entries associated with this table */
32){
33 sqlite3 *db = pParse->db;
34 Db *pDb;
35 int iRootPage;
36 Table *pStat;
37 Vdbe *v = sqlite3GetVdbe(pParse);
38
drhcf1be452007-05-12 12:08:51 +000039 if( v==0 ) return;
drh1fee73e2007-08-29 04:00:57 +000040 assert( sqlite3BtreeHoldsAllMutexes(db) );
41 assert( sqlite3VdbeDb(v)==db );
drhff2d5ea2005-07-23 00:41:48 +000042 pDb = &db->aDb[iDb];
43 if( (pStat = sqlite3FindTable(db, "sqlite_stat1", pDb->zName))==0 ){
44 /* The sqlite_stat1 tables does not exist. Create it.
45 ** Note that a side-effect of the CREATE TABLE statement is to leave
46 ** the rootpage of the new table on the top of the stack. This is
47 ** important because the OpenWrite opcode below will be needing it. */
48 sqlite3NestedParse(pParse,
49 "CREATE TABLE %Q.sqlite_stat1(tbl,idx,stat)",
50 pDb->zName
51 );
52 iRootPage = 0; /* Cause rootpage to be taken from top of stack */
53 }else if( zWhere ){
54 /* The sqlite_stat1 table exists. Delete all entries associated with
55 ** the table zWhere. */
56 sqlite3NestedParse(pParse,
57 "DELETE FROM %Q.sqlite_stat1 WHERE tbl=%Q",
58 pDb->zName, zWhere
59 );
60 iRootPage = pStat->tnum;
61 }else{
62 /* The sqlite_stat1 table already exists. Delete all rows. */
63 iRootPage = pStat->tnum;
drh66a51672008-01-03 00:01:23 +000064 sqlite3VdbeAddOp2(v, OP_Clear, pStat->tnum, iDb);
drhff2d5ea2005-07-23 00:41:48 +000065 }
66
danielk1977c00da102006-01-07 13:21:04 +000067 /* Open the sqlite_stat1 table for writing. Unless it was created
68 ** by this vdbe program, lock it for writing at the shared-cache level.
69 ** If this vdbe did create the sqlite_stat1 table, then it must have
70 ** already obtained a schema-lock, making the write-lock redundant.
drhff2d5ea2005-07-23 00:41:48 +000071 */
danielk1977c00da102006-01-07 13:21:04 +000072 if( iRootPage>0 ){
73 sqlite3TableLock(pParse, iDb, iRootPage, 1, "sqlite_stat1");
74 }
danielk1977207872a2008-01-03 07:54:23 +000075 sqlite3VdbeAddOp3(v, OP_OpenWrite, iStatCur, iRootPage, iDb);
drh66a51672008-01-03 00:01:23 +000076 sqlite3VdbeAddOp2(v, OP_SetNumColumns, iStatCur, 3);
drhff2d5ea2005-07-23 00:41:48 +000077}
78
79/*
80** Generate code to do an analysis of all indices associated with
81** a single table.
82*/
83static void analyzeOneTable(
84 Parse *pParse, /* Parser context */
85 Table *pTab, /* Table whose indices are to be analyzed */
86 int iStatCur, /* Cursor that writes to the sqlite_stat1 table */
87 int iMem /* Available memory locations begin here */
88){
89 Index *pIdx; /* An index to being analyzed */
90 int iIdxCur; /* Cursor number for index being analyzed */
91 int nCol; /* Number of columns in the index */
92 Vdbe *v; /* The virtual machine being built up */
93 int i; /* Loop counter */
94 int topOfLoop; /* The top of the loop */
95 int endOfLoop; /* The end of the loop */
96 int addr; /* The address of an instruction */
danielk1977da184232006-01-05 11:34:32 +000097 int iDb; /* Index of database containing pTab */
drhff2d5ea2005-07-23 00:41:48 +000098
99 v = sqlite3GetVdbe(pParse);
drhcf1be452007-05-12 12:08:51 +0000100 if( v==0 || pTab==0 || pTab->pIndex==0 ){
drh0c356672005-09-10 22:40:53 +0000101 /* Do no analysis for tables that have no indices */
drhff2d5ea2005-07-23 00:41:48 +0000102 return;
103 }
drh1fee73e2007-08-29 04:00:57 +0000104 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
danielk1977da184232006-01-05 11:34:32 +0000105 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
106 assert( iDb>=0 );
drhe6e04962005-07-23 02:17:03 +0000107#ifndef SQLITE_OMIT_AUTHORIZATION
108 if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
danielk1977da184232006-01-05 11:34:32 +0000109 pParse->db->aDb[iDb].zName ) ){
drhe6e04962005-07-23 02:17:03 +0000110 return;
111 }
112#endif
113
danielk1977c00da102006-01-07 13:21:04 +0000114 /* Establish a read-lock on the table at the shared-cache level. */
115 sqlite3TableLock(pParse, iDb, pTab->tnum, 0, pTab->zName);
116
drhff2d5ea2005-07-23 00:41:48 +0000117 iIdxCur = pParse->nTab;
118 for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
danielk1977b3bf5562006-01-10 17:58:23 +0000119 KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
120
drhff2d5ea2005-07-23 00:41:48 +0000121 /* Open a cursor to the index to be analyzed
122 */
danielk1977da184232006-01-05 11:34:32 +0000123 assert( iDb==sqlite3SchemaToIndex(pParse->db, pIdx->pSchema) );
danielk1977207872a2008-01-03 07:54:23 +0000124 sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIdx->tnum, iDb,
drh66a51672008-01-03 00:01:23 +0000125 (char *)pKey, P4_KEYINFO_HANDOFF);
danielk1977207872a2008-01-03 07:54:23 +0000126 VdbeComment((v, "%s", pIdx->zName));
drhff2d5ea2005-07-23 00:41:48 +0000127 nCol = pIdx->nColumn;
128 if( iMem+nCol*2>=pParse->nMem ){
129 pParse->nMem = iMem+nCol*2+1;
130 }
drh66a51672008-01-03 00:01:23 +0000131 sqlite3VdbeAddOp2(v, OP_SetNumColumns, iIdxCur, nCol+1);
drhff2d5ea2005-07-23 00:41:48 +0000132
133 /* Memory cells are used as follows:
134 **
135 ** mem[iMem]: The total number of rows in the table.
136 ** mem[iMem+1]: Number of distinct values in column 1
137 ** ...
138 ** mem[iMem+nCol]: Number of distinct values in column N
139 ** mem[iMem+nCol+1] Last observed value of column 1
140 ** ...
141 ** mem[iMem+nCol+nCol]: Last observed value of column N
142 **
143 ** Cells iMem through iMem+nCol are initialized to 0. The others
144 ** are initialized to NULL.
145 */
drhff2d5ea2005-07-23 00:41:48 +0000146 for(i=0; i<=nCol; i++){
drh4c583122008-01-04 22:01:03 +0000147 sqlite3VdbeAddOp2(v, OP_Integer, 0, iMem+i);
drhff2d5ea2005-07-23 00:41:48 +0000148 }
drhff2d5ea2005-07-23 00:41:48 +0000149 for(i=0; i<nCol; i++){
drh4c583122008-01-04 22:01:03 +0000150 sqlite3VdbeAddOp2(v, OP_Null, 0, iMem+nCol+i+1);
drhff2d5ea2005-07-23 00:41:48 +0000151 }
152
153 /* Do the analysis.
154 */
drhff2d5ea2005-07-23 00:41:48 +0000155 endOfLoop = sqlite3VdbeMakeLabel(v);
drh66a51672008-01-03 00:01:23 +0000156 sqlite3VdbeAddOp2(v, OP_Rewind, iIdxCur, endOfLoop);
drhe6e04962005-07-23 02:17:03 +0000157 topOfLoop = sqlite3VdbeCurrentAddr(v);
drh8558cde2008-01-05 05:20:10 +0000158 sqlite3VdbeAddOp2(v, OP_AddImm, iMem, 1);
drhff2d5ea2005-07-23 00:41:48 +0000159 for(i=0; i<nCol; i++){
drh66a51672008-01-03 00:01:23 +0000160 sqlite3VdbeAddOp2(v, OP_Column, iIdxCur, i);
drhb1fdb2a2008-01-05 04:06:03 +0000161 sqlite3VdbeAddOp1(v, OP_SCopy, iMem+nCol+i+1);
drh66a51672008-01-03 00:01:23 +0000162 sqlite3VdbeAddOp1(v, OP_Ne, 0x100);
drhff2d5ea2005-07-23 00:41:48 +0000163 }
drh66a51672008-01-03 00:01:23 +0000164 sqlite3VdbeAddOp2(v, OP_Goto, 0, endOfLoop);
drhff2d5ea2005-07-23 00:41:48 +0000165 for(i=0; i<nCol; i++){
drh8558cde2008-01-05 05:20:10 +0000166 addr = sqlite3VdbeAddOp2(v, OP_AddImm, iMem+i+1, 1);
drhff2d5ea2005-07-23 00:41:48 +0000167 sqlite3VdbeChangeP2(v, topOfLoop + 3*i + 3, addr);
drhb1fdb2a2008-01-05 04:06:03 +0000168 sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, iMem+nCol+i+1);
drhff2d5ea2005-07-23 00:41:48 +0000169 }
170 sqlite3VdbeResolveLabel(v, endOfLoop);
drh66a51672008-01-03 00:01:23 +0000171 sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, topOfLoop);
172 sqlite3VdbeAddOp1(v, OP_Close, iIdxCur);
drhff2d5ea2005-07-23 00:41:48 +0000173
174 /* Store the results.
175 **
drh4c103832007-06-20 13:37:31 +0000176 ** The result is a single row of the sqlite_stat1 table. The first
drhff2d5ea2005-07-23 00:41:48 +0000177 ** two columns are the names of the table and index. The third column
178 ** is a string composed of a list of integer statistics about the
drh17a18f22005-07-23 14:52:12 +0000179 ** index. The first integer in the list is the total number of entires
180 ** in the index. There is one additional integer in the list for each
181 ** column of the table. This additional integer is a guess of how many
182 ** rows of the table the index will select. If D is the count of distinct
183 ** values and K is the total number of rows, then the integer is computed
184 ** as:
drhff2d5ea2005-07-23 00:41:48 +0000185 **
186 ** I = (K+D-1)/D
187 **
188 ** If K==0 then no entry is made into the sqlite_stat1 table.
189 ** If K>0 then it is always the case the D>0 so division by zero
190 ** is never possible.
191 */
drhb1fdb2a2008-01-05 04:06:03 +0000192 sqlite3VdbeAddOp1(v, OP_SCopy, iMem);
drh66a51672008-01-03 00:01:23 +0000193 addr = sqlite3VdbeAddOp0(v, OP_IfNot);
194 sqlite3VdbeAddOp1(v, OP_NewRowid, iStatCur);
195 sqlite3VdbeAddOp4(v, OP_String8, 0, 0, 0, pTab->zName, 0);
196 sqlite3VdbeAddOp4(v, OP_String8, 0, 0, 0, pIdx->zName, 0);
drhb1fdb2a2008-01-05 04:06:03 +0000197 sqlite3VdbeAddOp1(v, OP_SCopy, iMem);
drh66a51672008-01-03 00:01:23 +0000198 sqlite3VdbeAddOp4(v, OP_String8, 0, 0, 0, " ", 0);
drhff2d5ea2005-07-23 00:41:48 +0000199 for(i=0; i<nCol; i++){
drhb1fdb2a2008-01-05 04:06:03 +0000200 sqlite3VdbeAddOp1(v, OP_SCopy, iMem);
201 sqlite3VdbeAddOp1(v, OP_SCopy, iMem+i+1);
drh66a51672008-01-03 00:01:23 +0000202 sqlite3VdbeAddOp0(v, OP_Add);
drh8558cde2008-01-05 05:20:10 +0000203 sqlite3VdbeAddOp2(v, OP_AddImm, 0, -1);
drhb1fdb2a2008-01-05 04:06:03 +0000204 sqlite3VdbeAddOp1(v, OP_SCopy, iMem+i+1);
drh66a51672008-01-03 00:01:23 +0000205 sqlite3VdbeAddOp0(v, OP_Divide);
206 sqlite3VdbeAddOp0(v, OP_ToInt);
drhff2d5ea2005-07-23 00:41:48 +0000207 if( i==nCol-1 ){
drh66a51672008-01-03 00:01:23 +0000208 sqlite3VdbeAddOp1(v, OP_Concat, nCol*2-1);
drhff2d5ea2005-07-23 00:41:48 +0000209 }else{
drhb1fdb2a2008-01-05 04:06:03 +0000210 sqlite3VdbeAddOp1(v, OP_Copy, -1);
drhff2d5ea2005-07-23 00:41:48 +0000211 }
212 }
drh66a51672008-01-03 00:01:23 +0000213 sqlite3VdbeAddOp4(v, OP_MakeRecord, 3, 0, 0, "aaa", 0);
danielk19771f4aa332008-01-03 09:51:55 +0000214 sqlite3CodeInsert(pParse, iStatCur, OPFLAG_APPEND);
drhd654be82005-09-20 17:42:23 +0000215 sqlite3VdbeJumpHere(v, addr);
drhff2d5ea2005-07-23 00:41:48 +0000216 }
217}
218
219/*
drh497e4462005-07-23 03:18:40 +0000220** Generate code that will cause the most recent index analysis to
221** be laoded into internal hash tables where is can be used.
222*/
223static void loadAnalysis(Parse *pParse, int iDb){
224 Vdbe *v = sqlite3GetVdbe(pParse);
drhcf1be452007-05-12 12:08:51 +0000225 if( v ){
drh66a51672008-01-03 00:01:23 +0000226 sqlite3VdbeAddOp1(v, OP_LoadAnalysis, iDb);
drhcf1be452007-05-12 12:08:51 +0000227 }
drh497e4462005-07-23 03:18:40 +0000228}
229
230/*
drhff2d5ea2005-07-23 00:41:48 +0000231** Generate code that will do an analysis of an entire database
232*/
233static void analyzeDatabase(Parse *pParse, int iDb){
234 sqlite3 *db = pParse->db;
danielk1977e501b892006-01-09 06:29:47 +0000235 Schema *pSchema = db->aDb[iDb].pSchema; /* Schema of database iDb */
drhff2d5ea2005-07-23 00:41:48 +0000236 HashElem *k;
237 int iStatCur;
238 int iMem;
239
240 sqlite3BeginWriteOperation(pParse, 0, iDb);
241 iStatCur = pParse->nTab++;
242 openStatTable(pParse, iDb, iStatCur, 0);
drh0a07c102008-01-03 18:03:08 +0000243 iMem = pParse->nMem+1;
danielk1977da184232006-01-05 11:34:32 +0000244 for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
drhff2d5ea2005-07-23 00:41:48 +0000245 Table *pTab = (Table*)sqliteHashData(k);
246 analyzeOneTable(pParse, pTab, iStatCur, iMem);
247 }
drh497e4462005-07-23 03:18:40 +0000248 loadAnalysis(pParse, iDb);
drhff2d5ea2005-07-23 00:41:48 +0000249}
250
251/*
252** Generate code that will do an analysis of a single table in
253** a database.
254*/
255static void analyzeTable(Parse *pParse, Table *pTab){
256 int iDb;
257 int iStatCur;
258
259 assert( pTab!=0 );
drh1fee73e2007-08-29 04:00:57 +0000260 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
danielk1977da184232006-01-05 11:34:32 +0000261 iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
drhff2d5ea2005-07-23 00:41:48 +0000262 sqlite3BeginWriteOperation(pParse, 0, iDb);
263 iStatCur = pParse->nTab++;
264 openStatTable(pParse, iDb, iStatCur, pTab->zName);
drh0a07c102008-01-03 18:03:08 +0000265 analyzeOneTable(pParse, pTab, iStatCur, pParse->nMem+1);
drh497e4462005-07-23 03:18:40 +0000266 loadAnalysis(pParse, iDb);
drhff2d5ea2005-07-23 00:41:48 +0000267}
268
269/*
270** Generate code for the ANALYZE command. The parser calls this routine
271** when it recognizes an ANALYZE command.
drh9f18e8a2005-07-08 12:13:04 +0000272**
273** ANALYZE -- 1
drhff2d5ea2005-07-23 00:41:48 +0000274** ANALYZE <database> -- 2
drh9f18e8a2005-07-08 12:13:04 +0000275** ANALYZE ?<database>.?<tablename> -- 3
276**
277** Form 1 causes all indices in all attached databases to be analyzed.
278** Form 2 analyzes all indices the single database named.
279** Form 3 analyzes all indices associated with the named table.
280*/
281void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){
drhff2d5ea2005-07-23 00:41:48 +0000282 sqlite3 *db = pParse->db;
283 int iDb;
284 int i;
285 char *z, *zDb;
286 Table *pTab;
287 Token *pTableName;
288
289 /* Read the database schema. If an error occurs, leave an error message
290 ** and code in pParse and return NULL. */
drh1fee73e2007-08-29 04:00:57 +0000291 assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
drhff2d5ea2005-07-23 00:41:48 +0000292 if( SQLITE_OK!=sqlite3ReadSchema(pParse) ){
293 return;
294 }
295
296 if( pName1==0 ){
297 /* Form 1: Analyze everything */
298 for(i=0; i<db->nDb; i++){
299 if( i==1 ) continue; /* Do not analyze the TEMP database */
300 analyzeDatabase(pParse, i);
301 }
drhe6e04962005-07-23 02:17:03 +0000302 }else if( pName2==0 || pName2->n==0 ){
drhff2d5ea2005-07-23 00:41:48 +0000303 /* Form 2: Analyze the database or table named */
304 iDb = sqlite3FindDb(db, pName1);
305 if( iDb>=0 ){
306 analyzeDatabase(pParse, iDb);
drhe6e04962005-07-23 02:17:03 +0000307 }else{
drh17435752007-08-16 04:30:38 +0000308 z = sqlite3NameFromToken(db, pName1);
danielk1977b8b4bfa2007-11-15 13:10:22 +0000309 if( z ){
310 pTab = sqlite3LocateTable(pParse, z, 0);
311 sqlite3_free(z);
312 if( pTab ){
313 analyzeTable(pParse, pTab);
314 }
drhe6e04962005-07-23 02:17:03 +0000315 }
drhff2d5ea2005-07-23 00:41:48 +0000316 }
drhff2d5ea2005-07-23 00:41:48 +0000317 }else{
318 /* Form 3: Analyze the fully qualified table name */
319 iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
320 if( iDb>=0 ){
321 zDb = db->aDb[iDb].zName;
drh17435752007-08-16 04:30:38 +0000322 z = sqlite3NameFromToken(db, pTableName);
drhcf1be452007-05-12 12:08:51 +0000323 if( z ){
324 pTab = sqlite3LocateTable(pParse, z, zDb);
drh17435752007-08-16 04:30:38 +0000325 sqlite3_free(z);
drhcf1be452007-05-12 12:08:51 +0000326 if( pTab ){
327 analyzeTable(pParse, pTab);
328 }
drhff2d5ea2005-07-23 00:41:48 +0000329 }
330 }
331 }
drh9f18e8a2005-07-08 12:13:04 +0000332}
333
drh497e4462005-07-23 03:18:40 +0000334/*
335** Used to pass information from the analyzer reader through to the
336** callback routine.
337*/
338typedef struct analysisInfo analysisInfo;
339struct analysisInfo {
340 sqlite3 *db;
341 const char *zDatabase;
342};
343
344/*
345** This callback is invoked once for each index when reading the
346** sqlite_stat1 table.
347**
348** argv[0] = name of the index
349** argv[1] = results of analysis - on integer for each column
350*/
351static int analysisLoader(void *pData, int argc, char **argv, char **azNotUsed){
352 analysisInfo *pInfo = (analysisInfo*)pData;
353 Index *pIndex;
354 int i, c;
355 unsigned int v;
356 const char *z;
357
358 assert( argc==2 );
drh1ec43c92005-09-06 10:26:47 +0000359 if( argv==0 || argv[0]==0 || argv[1]==0 ){
drh497e4462005-07-23 03:18:40 +0000360 return 0;
361 }
362 pIndex = sqlite3FindIndex(pInfo->db, argv[0], pInfo->zDatabase);
363 if( pIndex==0 ){
364 return 0;
365 }
366 z = argv[1];
drh17a18f22005-07-23 14:52:12 +0000367 for(i=0; *z && i<=pIndex->nColumn; i++){
drh497e4462005-07-23 03:18:40 +0000368 v = 0;
369 while( (c=z[0])>='0' && c<='9' ){
370 v = v*10 + c - '0';
371 z++;
372 }
373 pIndex->aiRowEst[i] = v;
374 if( *z==' ' ) z++;
375 }
376 return 0;
377}
378
379/*
380** Load the content of the sqlite_stat1 table into the index hash tables.
381*/
drhcf1be452007-05-12 12:08:51 +0000382int sqlite3AnalysisLoad(sqlite3 *db, int iDb){
drh497e4462005-07-23 03:18:40 +0000383 analysisInfo sInfo;
384 HashElem *i;
385 char *zSql;
drhcf1be452007-05-12 12:08:51 +0000386 int rc;
drh497e4462005-07-23 03:18:40 +0000387
drhff0587c2007-08-29 17:43:19 +0000388 assert( iDb>=0 && iDb<db->nDb );
389 assert( db->aDb[iDb].pBt!=0 );
390 assert( sqlite3BtreeHoldsMutex(db->aDb[iDb].pBt) );
drh1fee73e2007-08-29 04:00:57 +0000391
drh497e4462005-07-23 03:18:40 +0000392 /* Clear any prior statistics */
danielk1977da184232006-01-05 11:34:32 +0000393 for(i=sqliteHashFirst(&db->aDb[iDb].pSchema->idxHash);i;i=sqliteHashNext(i)){
drh497e4462005-07-23 03:18:40 +0000394 Index *pIdx = sqliteHashData(i);
drh51147ba2005-07-23 22:59:55 +0000395 sqlite3DefaultRowEst(pIdx);
drh497e4462005-07-23 03:18:40 +0000396 }
397
398 /* Check to make sure the sqlite_stat1 table existss */
399 sInfo.db = db;
400 sInfo.zDatabase = db->aDb[iDb].zName;
401 if( sqlite3FindTable(db, "sqlite_stat1", sInfo.zDatabase)==0 ){
drhcf1be452007-05-12 12:08:51 +0000402 return SQLITE_ERROR;
drh497e4462005-07-23 03:18:40 +0000403 }
404
405
406 /* Load new statistics out of the sqlite_stat1 table */
danielk19771e536952007-08-16 10:09:01 +0000407 zSql = sqlite3MPrintf(db, "SELECT idx, stat FROM %Q.sqlite_stat1",
drh497e4462005-07-23 03:18:40 +0000408 sInfo.zDatabase);
409 sqlite3SafetyOff(db);
drhcf1be452007-05-12 12:08:51 +0000410 rc = sqlite3_exec(db, zSql, analysisLoader, &sInfo, 0);
drh497e4462005-07-23 03:18:40 +0000411 sqlite3SafetyOn(db);
drh17435752007-08-16 04:30:38 +0000412 sqlite3_free(zSql);
drhcf1be452007-05-12 12:08:51 +0000413 return rc;
drh497e4462005-07-23 03:18:40 +0000414}
drh9f18e8a2005-07-08 12:13:04 +0000415
drhff2d5ea2005-07-23 00:41:48 +0000416
drh9f18e8a2005-07-08 12:13:04 +0000417#endif /* SQLITE_OMIT_ANALYZE */