aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2005-07-23 02:17:03 +0000
committerdrh <drh@noemail.net>2005-07-23 02:17:03 +0000
commite6e049694d27fe483b13fb476498d8e3aa82e36c (patch)
tree67f6857a9cfe250bd9fe24b2be00207292fd19e9 /src
parentff2d5ea4081b769e40d021527e9836b224f357ad (diff)
downloadsqlite-e6e049694d27fe483b13fb476498d8e3aa82e36c.tar.gz
sqlite-e6e049694d27fe483b13fb476498d8e3aa82e36c.zip
Full-coverage testing and documentation for the ANALYZE command. The
results of analysis are still not loaded or used, however. (CVS 2561) FossilOrigin-Name: bd7583a5d63412785a9c5de54d25b509da241605
Diffstat (limited to 'src')
-rw-r--r--src/analyze.c33
-rw-r--r--src/sqlite.h.in3
-rw-r--r--src/tclsqlite.c3
3 files changed, 24 insertions, 15 deletions
diff --git a/src/analyze.c b/src/analyze.c
index 76c134899..a3f8e84c8 100644
--- a/src/analyze.c
+++ b/src/analyze.c
@@ -11,7 +11,7 @@
*************************************************************************
** This file contains code associated with the ANALYZE command.
**
-** @(#) $Id: analyze.c,v 1.2 2005/07/23 00:41:49 drh Exp $
+** @(#) $Id: analyze.c,v 1.3 2005/07/23 02:17:03 drh Exp $
*/
#ifndef SQLITE_OMIT_ANALYZE
#include "sqliteInt.h"
@@ -64,7 +64,7 @@ static void openStatTable(
/* Open the sqlite_stat1 table for writing.
*/
sqlite3VdbeAddOp(v, OP_Integer, iDb, 0);
- sqlite3VdbeAddOp(v, OP_OpenWrite, iStatCur, 0);
+ sqlite3VdbeAddOp(v, OP_OpenWrite, iStatCur, iRootPage);
sqlite3VdbeAddOp(v, OP_SetNumColumns, iStatCur, 3);
}
@@ -92,6 +92,14 @@ static void analyzeOneTable(
/* Do no analysis for tables with fewer than 2 indices */
return;
}
+
+#ifndef SQLITE_OMIT_AUTHORIZATION
+ if( sqlite3AuthCheck(pParse, SQLITE_ANALYZE, pTab->zName, 0,
+ pParse->db->aDb[pTab->iDb].zName ) ){
+ return;
+ }
+#endif
+
iIdxCur = pParse->nTab;
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
/* Open a cursor to the index to be analyzed
@@ -130,9 +138,9 @@ static void analyzeOneTable(
/* Do the analysis.
*/
- sqlite3VdbeAddOp(v, OP_Rewind, iIdxCur, 0);
- topOfLoop = sqlite3VdbeCurrentAddr(v);
endOfLoop = sqlite3VdbeMakeLabel(v);
+ sqlite3VdbeAddOp(v, OP_Rewind, iIdxCur, endOfLoop);
+ topOfLoop = sqlite3VdbeCurrentAddr(v);
sqlite3VdbeAddOp(v, OP_MemIncr, iMem, 0);
for(i=0; i<nCol; i++){
sqlite3VdbeAddOp(v, OP_Column, iIdxCur, i);
@@ -263,20 +271,19 @@ void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){
if( i==1 ) continue; /* Do not analyze the TEMP database */
analyzeDatabase(pParse, i);
}
- }else if( pName2==0 ){
+ }else if( pName2==0 || pName2->n==0 ){
/* Form 2: Analyze the database or table named */
iDb = sqlite3FindDb(db, pName1);
if( iDb>=0 ){
analyzeDatabase(pParse, iDb);
- return;
- }
- z = sqlite3NameFromToken(pName1);
- pTab = sqlite3LocateTable(pParse, z, 0);
- sqliteFree(z);
- if( pTab ){
- analyzeTable(pParse, pTab);
+ }else{
+ z = sqlite3NameFromToken(pName1);
+ pTab = sqlite3LocateTable(pParse, z, 0);
+ sqliteFree(z);
+ if( pTab ){
+ analyzeTable(pParse, pTab);
+ }
}
- return;
}else{
/* Form 3: Analyze the fully qualified table name */
iDb = sqlite3TwoPartName(pParse, pName1, pName2, &pTableName);
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 7457268c3..9590fd8bf 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -12,7 +12,7 @@
** This header file defines the interface that the SQLite library
** presents to client programs.
**
-** @(#) $Id: sqlite.h.in,v 1.137 2005/07/09 02:39:40 drh Exp $
+** @(#) $Id: sqlite.h.in,v 1.138 2005/07/23 02:17:03 drh Exp $
*/
#ifndef _SQLITE3_H_
#define _SQLITE3_H_
@@ -452,6 +452,7 @@ int sqlite3_set_authorizer(
#define SQLITE_DETACH 25 /* Database Name NULL */
#define SQLITE_ALTER_TABLE 26 /* Database Name Table Name */
#define SQLITE_REINDEX 27 /* Index Name NULL */
+#define SQLITE_ANALYZE 28 /* Table Name NULL */
/*
diff --git a/src/tclsqlite.c b/src/tclsqlite.c
index 64a2a3b8e..bc98e348d 100644
--- a/src/tclsqlite.c
+++ b/src/tclsqlite.c
@@ -11,7 +11,7 @@
*************************************************************************
** A TCL Interface to SQLite
**
-** $Id: tclsqlite.c,v 1.127 2005/06/26 17:55:34 drh Exp $
+** $Id: tclsqlite.c,v 1.128 2005/07/23 02:17:03 drh Exp $
*/
#ifndef NO_TCL /* Omit this whole file if TCL is unavailable */
@@ -472,6 +472,7 @@ static int auth_callback(
case SQLITE_DETACH : zCode="SQLITE_DETACH"; break;
case SQLITE_ALTER_TABLE : zCode="SQLITE_ALTER_TABLE"; break;
case SQLITE_REINDEX : zCode="SQLITE_REINDEX"; break;
+ case SQLITE_ANALYZE : zCode="SQLITE_ANALYZE"; break;
default : zCode="????"; break;
}
Tcl_DStringInit(&str);