mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-10 01:02:56 +03:00
Change the ANALYZE command so that it will accept an index name as its
argument and only reanalyze that one index. A quick smoke-test works. Need to study the implications to the query planner and test corner cases. FossilOrigin-Name: c8f9edd962442cbdd848c48f1a134557ab8c6ef5
This commit is contained in:
18
manifest
18
manifest
@@ -1,5 +1,5 @@
|
|||||||
C Further\stests\sfor\sos_unix.c.
|
C Change\sthe\sANALYZE\scommand\sso\sthat\sit\swill\saccept\san\sindex\sname\sas\sits\nargument\sand\sonly\sreanalyze\sthat\sone\sindex.\s\sA\squick\ssmoke-test\sworks.\nNeed\sto\sstudy\sthe\simplications\sto\sthe\squery\splanner\sand\stest\scorner\scases.
|
||||||
D 2011-03-30T19:08:03.321
|
D 2011-03-31T02:03:28.435
|
||||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||||
F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f
|
F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f
|
||||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||||
@@ -115,7 +115,7 @@ F sqlite.pc.in 42b7bf0d02e08b9e77734a47798d1a55a9e0716b
|
|||||||
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
F sqlite3.1 6be1ad09113570e1fc8dcaff84c9b0b337db5ffc
|
||||||
F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
|
F sqlite3.pc.in ae6f59a76e862f5c561eb32a380228a02afc3cad
|
||||||
F src/alter.c 6a0c176e64a34929a4436048066a84ef4f1445b3
|
F src/alter.c 6a0c176e64a34929a4436048066a84ef4f1445b3
|
||||||
F src/analyze.c cafa5a22eb602ebdc5ba90995a41c1e84dda47a1
|
F src/analyze.c ecc36fc13e5a982ce8136b8d598fc402b3787139
|
||||||
F src/attach.c 438ea6f6b5d5961c1f49b737f2ce0f14ce7c6877
|
F src/attach.c 438ea6f6b5d5961c1f49b737f2ce0f14ce7c6877
|
||||||
F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
|
F src/auth.c 523da7fb4979469955d822ff9298352d6b31de34
|
||||||
F src/backup.c 537f89c7ef5021cb580f31f782e556ffffcb2ed1
|
F src/backup.c 537f89c7ef5021cb580f31f782e556ffffcb2ed1
|
||||||
@@ -920,7 +920,11 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
|||||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||||
P 3a27af5b3c688c651ba1fae261026ef77b7ff5e3
|
P a84f7711949ea3885b0e36e48118d2c76a8a5b82
|
||||||
R 8aec69201b7794049bf0ef28fa4da45f
|
R 2733d2c2848c13b668e60a30cb1bc35d
|
||||||
U dan
|
T *bgcolor * #ab8eb2
|
||||||
Z 9b217166a2b3bec7df70dcbc250ff848
|
T *branch * analyze-idx
|
||||||
|
T *sym-analyze-idx *
|
||||||
|
T -sym-trunk *
|
||||||
|
U drh
|
||||||
|
Z 6f592daac956cab070466c419bbb51de
|
||||||
|
@@ -1 +1 @@
|
|||||||
a84f7711949ea3885b0e36e48118d2c76a8a5b82
|
c8f9edd962442cbdd848c48f1a134557ab8c6ef5
|
@@ -34,7 +34,8 @@ static void openStatTable(
|
|||||||
Parse *pParse, /* Parsing context */
|
Parse *pParse, /* Parsing context */
|
||||||
int iDb, /* The database we are looking in */
|
int iDb, /* The database we are looking in */
|
||||||
int iStatCur, /* Open the sqlite_stat1 table on this cursor */
|
int iStatCur, /* Open the sqlite_stat1 table on this cursor */
|
||||||
const char *zWhere /* Delete entries associated with this table */
|
const char *zWhere, /* Delete entries for this table or index */
|
||||||
|
const char *zWhereType /* Either "tbl" or "idx" */
|
||||||
){
|
){
|
||||||
static const struct {
|
static const struct {
|
||||||
const char *zName;
|
const char *zName;
|
||||||
@@ -79,7 +80,7 @@ static void openStatTable(
|
|||||||
sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
|
sqlite3TableLock(pParse, iDb, aRoot[i], 1, zTab);
|
||||||
if( zWhere ){
|
if( zWhere ){
|
||||||
sqlite3NestedParse(pParse,
|
sqlite3NestedParse(pParse,
|
||||||
"DELETE FROM %Q.%s WHERE tbl=%Q", pDb->zName, zTab, zWhere
|
"DELETE FROM %Q.%s WHERE %s=%Q", pDb->zName, zTab, zWhereType, zWhere
|
||||||
);
|
);
|
||||||
}else{
|
}else{
|
||||||
/* The sqlite_stat[12] table already exists. Delete all rows. */
|
/* The sqlite_stat[12] table already exists. Delete all rows. */
|
||||||
@@ -103,6 +104,7 @@ static void openStatTable(
|
|||||||
static void analyzeOneTable(
|
static void analyzeOneTable(
|
||||||
Parse *pParse, /* Parser context */
|
Parse *pParse, /* Parser context */
|
||||||
Table *pTab, /* Table whose indices are to be analyzed */
|
Table *pTab, /* Table whose indices are to be analyzed */
|
||||||
|
Index *pOnlyIdx, /* If not NULL, only analyze this one index */
|
||||||
int iStatCur, /* Index of VdbeCursor that writes the sqlite_stat1 table */
|
int iStatCur, /* Index of VdbeCursor that writes the sqlite_stat1 table */
|
||||||
int iMem /* Available memory locations begin here */
|
int iMem /* Available memory locations begin here */
|
||||||
){
|
){
|
||||||
@@ -160,9 +162,12 @@ static void analyzeOneTable(
|
|||||||
iIdxCur = pParse->nTab++;
|
iIdxCur = pParse->nTab++;
|
||||||
sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
|
sqlite3VdbeAddOp4(v, OP_String8, 0, regTabname, 0, pTab->zName, 0);
|
||||||
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
|
||||||
int nCol = pIdx->nColumn;
|
int nCol;
|
||||||
KeyInfo *pKey = sqlite3IndexKeyinfo(pParse, pIdx);
|
KeyInfo *pKey;
|
||||||
|
|
||||||
|
if( pOnlyIdx && pOnlyIdx!=pIdx ) continue;
|
||||||
|
nCol = pIdx->nColumn;
|
||||||
|
pKey = sqlite3IndexKeyinfo(pParse, pIdx);
|
||||||
if( iMem+1+(nCol*2)>pParse->nMem ){
|
if( iMem+1+(nCol*2)>pParse->nMem ){
|
||||||
pParse->nMem = iMem+1+(nCol*2);
|
pParse->nMem = iMem+1+(nCol*2);
|
||||||
}
|
}
|
||||||
@@ -383,20 +388,21 @@ static void analyzeDatabase(Parse *pParse, int iDb){
|
|||||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||||
iStatCur = pParse->nTab;
|
iStatCur = pParse->nTab;
|
||||||
pParse->nTab += 2;
|
pParse->nTab += 2;
|
||||||
openStatTable(pParse, iDb, iStatCur, 0);
|
openStatTable(pParse, iDb, iStatCur, 0, 0);
|
||||||
iMem = pParse->nMem+1;
|
iMem = pParse->nMem+1;
|
||||||
for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
|
for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
|
||||||
Table *pTab = (Table*)sqliteHashData(k);
|
Table *pTab = (Table*)sqliteHashData(k);
|
||||||
analyzeOneTable(pParse, pTab, iStatCur, iMem);
|
analyzeOneTable(pParse, pTab, 0, iStatCur, iMem);
|
||||||
}
|
}
|
||||||
loadAnalysis(pParse, iDb);
|
loadAnalysis(pParse, iDb);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** Generate code that will do an analysis of a single table in
|
** Generate code that will do an analysis of a single table in
|
||||||
** a database.
|
** a database. If pOnlyIdx is not NULL then it is a single index
|
||||||
|
** in pTab that should be analyzed.
|
||||||
*/
|
*/
|
||||||
static void analyzeTable(Parse *pParse, Table *pTab){
|
static void analyzeTable(Parse *pParse, Table *pTab, Index *pOnlyIdx){
|
||||||
int iDb;
|
int iDb;
|
||||||
int iStatCur;
|
int iStatCur;
|
||||||
|
|
||||||
@@ -406,8 +412,12 @@ static void analyzeTable(Parse *pParse, Table *pTab){
|
|||||||
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
sqlite3BeginWriteOperation(pParse, 0, iDb);
|
||||||
iStatCur = pParse->nTab;
|
iStatCur = pParse->nTab;
|
||||||
pParse->nTab += 2;
|
pParse->nTab += 2;
|
||||||
openStatTable(pParse, iDb, iStatCur, pTab->zName);
|
if( pOnlyIdx ){
|
||||||
analyzeOneTable(pParse, pTab, iStatCur, pParse->nMem+1);
|
openStatTable(pParse, iDb, iStatCur, pOnlyIdx->zName, "idx");
|
||||||
|
}else{
|
||||||
|
openStatTable(pParse, iDb, iStatCur, pTab->zName, "tbl");
|
||||||
|
}
|
||||||
|
analyzeOneTable(pParse, pTab, pOnlyIdx, iStatCur, pParse->nMem+1);
|
||||||
loadAnalysis(pParse, iDb);
|
loadAnalysis(pParse, iDb);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -429,6 +439,7 @@ void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){
|
|||||||
int i;
|
int i;
|
||||||
char *z, *zDb;
|
char *z, *zDb;
|
||||||
Table *pTab;
|
Table *pTab;
|
||||||
|
Index *pIdx;
|
||||||
Token *pTableName;
|
Token *pTableName;
|
||||||
|
|
||||||
/* Read the database schema. If an error occurs, leave an error message
|
/* Read the database schema. If an error occurs, leave an error message
|
||||||
@@ -453,11 +464,12 @@ void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){
|
|||||||
}else{
|
}else{
|
||||||
z = sqlite3NameFromToken(db, pName1);
|
z = sqlite3NameFromToken(db, pName1);
|
||||||
if( z ){
|
if( z ){
|
||||||
pTab = sqlite3LocateTable(pParse, 0, z, 0);
|
if( (pIdx = sqlite3FindIndex(db, z, 0))!=0 ){
|
||||||
sqlite3DbFree(db, z);
|
analyzeTable(pParse, pIdx->pTable, pIdx);
|
||||||
if( pTab ){
|
}else if( (pTab = sqlite3LocateTable(pParse, 0, z, 0))!=0 ){
|
||||||
analyzeTable(pParse, pTab);
|
analyzeTable(pParse, pTab, 0);
|
||||||
}
|
}
|
||||||
|
sqlite3DbFree(db, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
@@ -467,11 +479,12 @@ void sqlite3Analyze(Parse *pParse, Token *pName1, Token *pName2){
|
|||||||
zDb = db->aDb[iDb].zName;
|
zDb = db->aDb[iDb].zName;
|
||||||
z = sqlite3NameFromToken(db, pTableName);
|
z = sqlite3NameFromToken(db, pTableName);
|
||||||
if( z ){
|
if( z ){
|
||||||
pTab = sqlite3LocateTable(pParse, 0, z, zDb);
|
if( (pIdx = sqlite3FindIndex(db, z, zDb))!=0 ){
|
||||||
sqlite3DbFree(db, z);
|
analyzeTable(pParse, pIdx->pTable, pIdx);
|
||||||
if( pTab ){
|
}else if( (pTab = sqlite3LocateTable(pParse, 0, z, zDb))!=0 ){
|
||||||
analyzeTable(pParse, pTab);
|
analyzeTable(pParse, pTab, 0);
|
||||||
}
|
}
|
||||||
|
sqlite3DbFree(db, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user