1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-06 15:49:35 +03:00

Fix EXPLAIN and EXPLAIN query plan to work with new opcode format. (CVS 4662)

FossilOrigin-Name: b166c33a7b9a58d571619d2248019eda09651dd2
This commit is contained in:
danielk1977
2008-01-03 07:09:48 +00:00
parent 2400345a32
commit 0d78bae377
6 changed files with 76 additions and 44 deletions

View File

@@ -1,5 +1,5 @@
C Revamp\ssqlite3VdbeAddOpList()\sso\sthat\sthe\sstructure\sholds\sinteger\svalues\nfor\sP1,\sP2,\sand\sP3.\s(CVS\s4661)
D 2008-01-03T01:28:59
C Fix\sEXPLAIN\sand\sEXPLAIN\squery\splan\sto\swork\swith\snew\sopcode\sformat.\s(CVS\s4662)
D 2008-01-03T07:09:48
F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
F Makefile.in 30789bf70614bad659351660d76b8e533f3340e9
F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -128,12 +128,12 @@ F src/pager.c 0cb6ccea4b9615627d61d7c4417cedc45776d429
F src/pager.h f504f7ae84060fee0416a853e368d3d113c3d6fa
F src/parse.y 2ae06e8d3190faace49c5b82e7cea1fc60d084a1
F src/pragma.c 61b9d171a6d53d36a77c66cb921d47a5c09a8441
F src/prepare.c 31ce0903040ec6f71da10c74869e10137890d981
F src/prepare.c f1bb8eb642082e618a359c08e3e107490eafe0e3
F src/printf.c eb27822ba2eec669161409ca31279a24c26ac910
F src/random.c 4a22746501bf36b0a088c66e38dde5daba6a35da
F src/select.c fb57c9f49f5a117a1680dd4dd517e1e8631baf68
F src/server.c 087b92a39d883e3fa113cae259d64e4c7438bc96
F src/shell.c 77895a54c2082157e169c857a2e244525ec25af7
F src/shell.c 5391e889384d2062249f668110d64ed16f601c4b
F src/sqlite.h.in 2a7e3776534bbe6ff2cdc058f3abebe91e7e429f
F src/sqlite3ext.h a93f59cdee3638dc0c9c086f80df743a4e68c3cb
F src/sqliteInt.h 2e30ff7e6ee65743d38447f00ef873ce058be7be
@@ -168,11 +168,11 @@ F src/update.c 39ac597c81b1d7d0396d5571d620bfa694f21151
F src/utf.c ef4b7d83bae533b76c3e1bf635b113fdad86a736
F src/util.c 05f31144bbd3f1a24f4139ae029c42545cb72624
F src/vacuum.c 3f34f278809bf3eb0b62ec46ff779e9c385b28f0
F src/vdbe.c fd5f6fc98eda1c1664cb1bfd09479ec3fb642139
F src/vdbe.c 83dfa6980067dca0750b87d374a898ea199c4fa5
F src/vdbe.h 0d29000e30e60714f8de9fd4373ec8569c728e07
F src/vdbeInt.h 2985f1369273e635898cf5952237efcb3fdb21f3
F src/vdbeapi.c bf615ff2cf2b121f1609cbadd4f52720289733b5
F src/vdbeaux.c cd0a3f702bb90a76adba3581005a9dc7853565f9
F src/vdbeaux.c 5d04881cd87f0efa51bc0dd3a9b2db261ab0e9c2
F src/vdbeblob.c 82f51cdf9b0c0af729732fde48c824e498c0a1ca
F src/vdbefifo.c 334c838c8f42d61a94813d136019ee566b5dc2f6
F src/vdbemem.c 123994fcd344993d2fb050a83b91b341bbbd08b4
@@ -603,7 +603,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
P 027875e4d4c4bd7686dc880c6917a968049b2fec
R bafbb97261d5cb777f4a74b378e386c4
U drh
Z 286f034de62a5f2d303f92883ddc5640
P 4dc507d87b242619fe32606452227900e16a6de7
R 125024a4bb4ac98d08154804cd32abf6
U danielk1977
Z 42b14c9552be08386812f3638911e78b

View File

@@ -1 +1 @@
4dc507d87b242619fe32606452227900e16a6de7
b166c33a7b9a58d571619d2248019eda09651dd2

View File

@@ -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

View File

@@ -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;

View File

@@ -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.

View File

@@ -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++;
p->nResColumn = 5 - 2*(p->explain-1);
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 = 8 - 5*(p->explain-1);
p->pTos = pMem;
p->rc = SQLITE_OK;
rc = SQLITE_ROW;