diff options
author | danielk1977 <danielk1977@noemail.net> | 2008-01-03 07:09:48 +0000 |
---|---|---|
committer | danielk1977 <danielk1977@noemail.net> | 2008-01-03 07:09:48 +0000 |
commit | 0d78bae377957221773e982ab023ecff924dfd4a (patch) | |
tree | 13129128b4b0a0d6cd9a86792edbffec5897d273 /src | |
parent | 2400345a32488bda0d49f2587aed862b592f186f (diff) | |
download | sqlite-0d78bae377957221773e982ab023ecff924dfd4a.tar.gz sqlite-0d78bae377957221773e982ab023ecff924dfd4a.zip |
Fix EXPLAIN and EXPLAIN query plan to work with new opcode format. (CVS 4662)
FossilOrigin-Name: b166c33a7b9a58d571619d2248019eda09651dd2
Diffstat (limited to 'src')
-rw-r--r-- | src/prepare.c | 7 | ||||
-rw-r--r-- | src/shell.c | 26 | ||||
-rw-r--r-- | src/vdbe.c | 5 | ||||
-rw-r--r-- | src/vdbeaux.c | 60 |
4 files changed, 65 insertions, 33 deletions
diff --git a/src/prepare.c b/src/prepare.c index ca1e2277c..33e3fda89 100644 --- a/src/prepare.c +++ b/src/prepare.c @@ -13,7 +13,7 @@ ** interface, and routines that contribute to loading the database schema ** from disk. ** -** $Id: prepare.c,v 1.69 2008/01/03 00:01:24 drh Exp $ +** $Id: prepare.c,v 1.70 2008/01/03 07:09:48 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -572,12 +572,15 @@ int sqlite3Prepare( sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "from", P4_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "detail", P4_STATIC); }else{ - sqlite3VdbeSetNumCols(sParse.pVdbe, 5); + sqlite3VdbeSetNumCols(sParse.pVdbe, 8); sqlite3VdbeSetColName(sParse.pVdbe, 0, COLNAME_NAME, "addr", P4_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 1, COLNAME_NAME, "opcode", P4_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 2, COLNAME_NAME, "p1", P4_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 3, COLNAME_NAME, "p2", P4_STATIC); sqlite3VdbeSetColName(sParse.pVdbe, 4, COLNAME_NAME, "p3", P4_STATIC); + sqlite3VdbeSetColName(sParse.pVdbe, 5, COLNAME_NAME, "p4", P4_STATIC); + sqlite3VdbeSetColName(sParse.pVdbe, 6, COLNAME_NAME, "p5", P4_STATIC); + sqlite3VdbeSetColName(sParse.pVdbe, 7, COLNAME_NAME, "comment",P4_STATIC); } } #endif diff --git a/src/shell.c b/src/shell.c index 9c1babcdb..2f00a2c28 100644 --- a/src/shell.c +++ b/src/shell.c @@ -12,7 +12,7 @@ ** This file contains code to implement the "sqlite" command line ** utility for accessing SQLite databases. ** -** $Id: shell.c,v 1.171 2007/12/18 15:41:44 drh Exp $ +** $Id: shell.c,v 1.172 2008/01/03 07:09:48 danielk1977 Exp $ */ #include <stdlib.h> #include <string.h> @@ -337,6 +337,7 @@ struct callback_data { #define MODE_Tcl 6 /* Generate ANSI-C or TCL quoted elements */ #define MODE_Csv 7 /* Quote strings, numbers are plain */ #define MODE_NUM_OF 8 /* The number of modes (not a mode itself) */ +#define MODE_Explain 9 /* Like MODE_Column, but do not truncate data */ static const char *modeDescr[MODE_NUM_OF] = { "line", @@ -526,14 +527,15 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){ } break; } + case MODE_Explain: case MODE_Column: { if( p->cnt++==0 ){ for(i=0; i<nArg; i++){ int w, n; if( i<ArraySize(p->colWidth) ){ - w = p->colWidth[i]; + w = p->colWidth[i]; }else{ - w = 0; + w = 0; } if( w<=0 ){ w = strlen(azCol[i] ? azCol[i] : ""); @@ -570,6 +572,9 @@ static int callback(void *pArg, int nArg, char **azArg, char **azCol){ }else{ w = 10; } + if( p->mode==MODE_Explain && azArg[i] && strlen(azArg[i])>w ){ + w = strlen(azArg[i]); + } fprintf(p->out,"%-*.*s%s",w,w, azArg[i] ? azArg[i] : p->nullvalue, i==nArg-1 ? "\n": " "); } @@ -1145,14 +1150,17 @@ static int do_meta_command(char *zLine, struct callback_data *p){ ** did an .explain followed by a .width, .mode or .header ** command. */ - p->mode = MODE_Column; + p->mode = MODE_Explain; p->showHeader = 1; memset(p->colWidth,0,ArraySize(p->colWidth)); - p->colWidth[0] = 4; - p->colWidth[1] = 14; - p->colWidth[2] = 10; - p->colWidth[3] = 10; - p->colWidth[4] = 33; + p->colWidth[0] = 4; /* addr */ + p->colWidth[1] = 14; /* opcode */ + p->colWidth[2] = 10; /* P1 */ + p->colWidth[3] = 10; /* P2 */ + p->colWidth[4] = 10; /* P3 */ + p->colWidth[5] = 20; /* P4 */ + p->colWidth[6] = 2; /* P5 */ + p->colWidth[7] = 7; /* Comment */ }else if (p->explainPrev.valid) { p->explainPrev.valid = 0; p->mode = p->explainPrev.mode; diff --git a/src/vdbe.c b/src/vdbe.c index 6f1330b67..f7b149a65 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -43,7 +43,7 @@ ** in this file for details. If in doubt, do not deviate from existing ** commenting and indentation practices when changing or adding code. ** -** $Id: vdbe.c,v 1.664 2008/01/03 00:01:25 drh Exp $ +** $Id: vdbe.c,v 1.665 2008/01/03 07:09:48 danielk1977 Exp $ */ #include "sqliteInt.h" #include <ctype.h> @@ -2037,7 +2037,8 @@ case OP_SetNumColumns: { /* no-push */ ** values in the record, extract a NULL. ** ** The value extracted is pushed onto the stack. Or if P3 is a positive -** integer register number, then the value is written into that register. +** non-zero integer register number, then the value is written into that +** register. ** ** If the KeyAsData opcode has previously executed on this cursor, then the ** field might be extracted from the key rather than the data. diff --git a/src/vdbeaux.c b/src/vdbeaux.c index 5221ec6cf..dd631571f 100644 --- a/src/vdbeaux.c +++ b/src/vdbeaux.c @@ -615,7 +615,6 @@ VdbeOp *sqlite3VdbeGetOp(Vdbe *p, int addr){ */ static char *displayP4(Op *pOp, char *zTemp, int nTemp){ char *zP4 = zTemp; - int nP4; assert( nTemp>=20 ); switch( pOp->p4type ){ case P4_KEYINFO: { @@ -698,12 +697,6 @@ static char *displayP4(Op *pOp, char *zTemp, int nTemp){ } } assert( zP4!=0 ); -#ifdef SQLITE_DEBUG - if( pOp->zComment && zP4==zTemp && (nP4 = strlen(zP4))<nTemp ){ - sqlite3_snprintf(nTemp-nP4, &zP4[nP4], "%s# %s", - nP4>0 ? " " : "", pOp->zComment); - } -#endif return zP4; } #endif @@ -794,18 +787,20 @@ int sqlite3VdbeList( }else{ Op *pOp = &p->aOp[i]; Mem *pMem = p->pResultSet = p->aStack; - pMem->flags = MEM_Int; - pMem->type = SQLITE_INTEGER; - pMem->u.i = i; /* Program counter */ - pMem++; - - pMem->flags = MEM_Static|MEM_Str|MEM_Term; - pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */ - assert( pMem->z!=0 ); - pMem->n = strlen(pMem->z); - pMem->type = SQLITE_TEXT; - pMem->enc = SQLITE_UTF8; - pMem++; + if( p->explain==1 ){ + pMem->flags = MEM_Int; + pMem->type = SQLITE_INTEGER; + pMem->u.i = i; /* Program counter */ + pMem++; + + pMem->flags = MEM_Static|MEM_Str|MEM_Term; + pMem->z = (char*)sqlite3OpcodeName(pOp->opcode); /* Opcode */ + assert( pMem->z!=0 ); + pMem->n = strlen(pMem->z); + pMem->type = SQLITE_TEXT; + pMem->enc = SQLITE_UTF8; + pMem++; + } pMem->flags = MEM_Int; pMem->u.i = pOp->p1; /* P1 */ @@ -817,14 +812,39 @@ int sqlite3VdbeList( pMem->type = SQLITE_INTEGER; pMem++; + if( p->explain==1 ){ + pMem->flags = MEM_Int; + pMem->u.i = pOp->p3; /* P3 */ + pMem->type = SQLITE_INTEGER; + pMem++; + } + pMem->flags = MEM_Ephem|MEM_Str|MEM_Term; /* P4 */ pMem->z = displayP4(pOp, pMem->zShort, sizeof(pMem->zShort)); assert( pMem->z!=0 ); pMem->n = strlen(pMem->z); pMem->type = SQLITE_TEXT; pMem->enc = SQLITE_UTF8; + pMem++; + + if( p->explain==1 ){ + pMem->flags = MEM_Str|MEM_Term|MEM_Short; + pMem->n = sprintf(pMem->zShort, "%.2x", pOp->p5); /* P5 */ + pMem->z = pMem->zShort; + pMem->type = SQLITE_TEXT; + pMem->enc = SQLITE_UTF8; + pMem++; + + pMem->flags = MEM_Null; /* Comment */ + if( pOp->zComment ){ + pMem->flags = MEM_Str|MEM_Term; + pMem->z = pOp->zComment; + pMem->n = strlen(pMem->z); + pMem->enc = SQLITE_UTF8; + } + } - p->nResColumn = 5 - 2*(p->explain-1); + p->nResColumn = 8 - 5*(p->explain-1); p->pTos = pMem; p->rc = SQLITE_OK; rc = SQLITE_ROW; |