/ Check-in [8225924e]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:The ANALYZE command picks for 15 samples for sqlite_stat3 with the largest nEq fields, plus 5 other evenly spaced samples.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | stat3-enhancement
Files: files | file ages | folders
SHA1: 8225924ea015a0c331b69134139922ec83f989f8
User & Date: drh 2011-08-13 00:58:05
Context
2011-08-13
15:25
Add the sqlite_stat3.nDLT field. Use an linear congruence PRNG to choose which samples to select from among those with the same nEq field. check-in: 1dcd2428 user: drh tags: stat3-enhancement
00:58
The ANALYZE command picks for 15 samples for sqlite_stat3 with the largest nEq fields, plus 5 other evenly spaced samples. check-in: 8225924e user: drh tags: stat3-enhancement
2011-08-12
01:51
Begin a branch that experimentally replaces sqlite_stat2 with a new table called sqlite_stat3 that will hopefully facilitate better query planning decisions. check-in: 52e1d7e8 user: drh tags: stat3-enhancement
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

   203    203     }
   204    204   }
   205    205   
   206    206   /*
   207    207   ** Recommended number of samples for sqlite_stat3
   208    208   */
   209    209   #ifndef SQLITE_STAT3_SAMPLES
   210         -# define SQLITE_STAT3_SAMPLES 16
          210  +# define SQLITE_STAT3_SAMPLES 20
   211    211   #endif
          212  +
          213  +/*
          214  +** Three SQL functions - stat3_init(), stat3_push(), and stat3_pop() -
          215  +** share an instance of the following structure to hold their state
          216  +** information.
          217  +*/
          218  +typedef struct Stat3Accum Stat3Accum;
          219  +struct Stat3Accum {
          220  +  tRowcnt nRow;             /* Number of rows in the entire table */
          221  +  tRowcnt nPSample;         /* How often to do a periodic sample */
          222  +  int iMin;                 /* Index of entry with minimum nEq and hash */
          223  +  int mxSample;             /* Maximum number of samples to accumulate */
          224  +  int nSample;              /* Current number of samples */
          225  +  struct Stat3Sample {
          226  +    i64 iRowid;                /* Rowid in main table of the key */
          227  +    tRowcnt nEq;               /* sqlite_stat3.nEq */
          228  +    tRowcnt nLt;               /* sqlite_stat3.nLt */
          229  +    u8 isPSample;              /* True if a periodic sample */
          230  +    u32 iHash;                 /* Tiebreaker hash */
          231  +  } *a;                     /* An array of samples */
          232  +};
          233  +
          234  +#ifdef SQLITE_ENABLE_STAT3
          235  +/*
          236  +** Implementation of the stat3_init(C,S) SQL function.  The two parameters
          237  +** are the number of rows in the table or index (C) and the number of samples
          238  +** to accumulate (S).
          239  +**
          240  +** This routine allocates the Stat3Accum object.
          241  +**
          242  +** The return value is the Stat3Accum object (P).
          243  +*/
          244  +static void stat3Init(
          245  +  sqlite3_context *context,
          246  +  int argc,
          247  +  sqlite3_value **argv
          248  +){
          249  +  Stat3Accum *p;
          250  +  tRowcnt nRow;
          251  +  int mxSample;
          252  +  int n;
          253  +
          254  +  nRow = (tRowcnt)sqlite3_value_int64(argv[0]);
          255  +  mxSample = sqlite3_value_int(argv[1]);
          256  +  n = sizeof(*p) + sizeof(p->a[0])*mxSample;
          257  +  p = sqlite3_malloc( n );
          258  +  if( p==0 ){
          259  +    sqlite3_result_error_nomem(context);
          260  +    return;
          261  +  }
          262  +  memset(p, 0, n);
          263  +  p->a = (struct Stat3Sample*)&p[1];
          264  +  p->nRow = nRow;
          265  +  p->mxSample = mxSample;
          266  +  p->nPSample = p->nRow/6 + 1;
          267  +  sqlite3_result_blob(context, p, sizeof(p), sqlite3_free);
          268  +}
          269  +static const FuncDef stat3InitFuncdef = {
          270  +  2,                /* nArg */
          271  +  SQLITE_UTF8,      /* iPrefEnc */
          272  +  0,                /* flags */
          273  +  0,                /* pUserData */
          274  +  0,                /* pNext */
          275  +  stat3Init,        /* xFunc */
          276  +  0,                /* xStep */
          277  +  0,                /* xFinalize */
          278  +  "stat3_init",     /* zName */
          279  +  0,                /* pHash */
          280  +  0                 /* pDestructor */
          281  +};
          282  +
          283  +
          284  +/*
          285  +** Implementation of the stat3_push(nEq,nLt,rowid,P) SQL function.  The
          286  +** arguments describe a single key instance.  This routine makes the 
          287  +** decision about whether or not to retain this key for the sqlite_stat3
          288  +** table.
          289  +**
          290  +** The return value is NULL.
          291  +*/
          292  +static void stat3Push(
          293  +  sqlite3_context *context,
          294  +  int argc,
          295  +  sqlite3_value **argv
          296  +){
          297  +  Stat3Accum *p = (Stat3Accum*)sqlite3_value_blob(argv[3]);
          298  +  tRowcnt nEq = sqlite3_value_int64(argv[0]);
          299  +  tRowcnt nLt = sqlite3_value_int64(argv[1]);
          300  +  i64 rowid = sqlite3_value_int64(argv[2]);
          301  +  u8 isPSample = 0;
          302  +  u8 doInsert = 0;
          303  +  int iMin = p->iMin;
          304  +  struct Stat3Sample *pSample;
          305  +  int i;
          306  +  u32 h, h1, h2, h3;
          307  +  if( nEq==0 ) return;
          308  +
          309  +  h1 = (unsigned)(rowid&0xffff);
          310  +  h2 = (unsigned)nEq;
          311  +  h3 = (unsigned)(nLt+1);
          312  +  h = h1*h2*h3*0x10010001;
          313  +
          314  +  if( (nLt/p->nPSample)!=((nEq+nLt)/p->nPSample) ){
          315  +    doInsert = isPSample = 1;
          316  +  }else if( p->nSample<p->mxSample ){
          317  +    doInsert = 1;
          318  +  }else{
          319  +    if( nEq>p->a[iMin].nEq || (nEq==p->a[iMin].nEq && h>p->a[iMin].iHash) ){
          320  +      doInsert = 1;
          321  +    }
          322  +  }
          323  +  if( !doInsert ) return;
          324  +  if( p->nSample==p->mxSample ){
          325  +    pSample = &p->a[iMin];
          326  +  }else{
          327  +    pSample = &p->a[p->nSample++];
          328  +  }
          329  +  pSample->iRowid = rowid;
          330  +  pSample->nEq = nEq;
          331  +  pSample->nLt = nLt;
          332  +  pSample->iHash = h;
          333  +  pSample->isPSample = isPSample;
          334  +
          335  +  /* Find the new minimum */
          336  +  if( p->nSample==p->mxSample ){
          337  +    pSample = p->a;
          338  +    i = 0;
          339  +    while( pSample->isPSample ){
          340  +      i++;
          341  +      pSample++;
          342  +      assert( i<p->nSample );
          343  +    }
          344  +    nEq = pSample->nEq;
          345  +    h = pSample->iHash;
          346  +    iMin = i;
          347  +    for(i++, pSample++; i<p->nSample; i++, pSample++){
          348  +      if( pSample->isPSample ) continue;
          349  +      if( pSample->nEq<nEq
          350  +       || (pSample->nEq==nEq && pSample->iHash<h)
          351  +      ){
          352  +        iMin = i;
          353  +        nEq = pSample->nEq;
          354  +        h = pSample->iHash;
          355  +      }
          356  +    }
          357  +    p->iMin = iMin;
          358  +  }
          359  +}
          360  +static const FuncDef stat3PushFuncdef = {
          361  +  3,                /* nArg */
          362  +  SQLITE_UTF8,      /* iPrefEnc */
          363  +  0,                /* flags */
          364  +  0,                /* pUserData */
          365  +  0,                /* pNext */
          366  +  stat3Push,        /* xFunc */
          367  +  0,                /* xStep */
          368  +  0,                /* xFinalize */
          369  +  "stat3_push",     /* zName */
          370  +  0,                /* pHash */
          371  +  0                 /* pDestructor */
          372  +};
          373  +
          374  +/*
          375  +** Implementation of the stat3_get(P,N,...) SQL function.  This routine is
          376  +** used to query the results.  Content is returned for the Nth sqlite_stat3
          377  +** row where N is between 0 and S-1 and S is the number of samples.  The
          378  +** value returned depends on the number of arguments.
          379  +**
          380  +**   argc==2    result:  rowid
          381  +**   argc==3    result:  nEq
          382  +**   argc==4    result:  nLt
          383  +*/
          384  +static void stat3Get(
          385  +  sqlite3_context *context,
          386  +  int argc,
          387  +  sqlite3_value **argv
          388  +){
          389  +  int n = sqlite3_value_int(argv[1]);
          390  +  Stat3Accum *p = (Stat3Accum*)sqlite3_value_blob(argv[0]);
          391  +
          392  +  assert( p!=0 );
          393  +  if( p->nSample<=n ) return;
          394  +  switch( argc ){
          395  +    case 2: sqlite3_result_int64(context, p->a[n].iRowid); break;
          396  +    case 3: sqlite3_result_int64(context, p->a[n].nEq);    break;
          397  +    case 4: sqlite3_result_int64(context, p->a[n].nLt);    break;
          398  +  }
          399  +}
          400  +static const FuncDef stat3GetFuncdef = {
          401  +  -1,               /* nArg */
          402  +  SQLITE_UTF8,      /* iPrefEnc */
          403  +  0,                /* flags */
          404  +  0,                /* pUserData */
          405  +  0,                /* pNext */
          406  +  stat3Get,         /* xFunc */
          407  +  0,                /* xStep */
          408  +  0,                /* xFinalize */
          409  +  "stat3_get",     /* zName */
          410  +  0,                /* pHash */
          411  +  0                 /* pDestructor */
          412  +};
          413  +#endif /* SQLITE_ENABLE_STAT3 */
          414  +
          415  +
          416  +
   212    417   
   213    418   /*
   214    419   ** Generate code to do an analysis of all indices associated with
   215    420   ** a single table.
   216    421   */
   217    422   static void analyzeOneTable(
   218    423     Parse *pParse,   /* Parser context */
................................................................................
   230    435     int endOfLoop;               /* The end of the loop */
   231    436     int jZeroRows = -1;          /* Jump from here if number of rows is zero */
   232    437     int iDb;                     /* Index of database containing pTab */
   233    438     int regTabname = iMem++;     /* Register containing table name */
   234    439     int regIdxname = iMem++;     /* Register containing index name */
   235    440     int regStat1 = iMem++;       /* The stat column of sqlite_stat1 */
   236    441   #ifdef SQLITE_ENABLE_STAT3
   237         -  int regNumEq = iMem-1;       /* Number of instances.  Same as regStat1 */
          442  +  int regNumEq = regStat1;     /* Number of instances.  Same as regStat1 */
   238    443     int regNumLt = iMem++;       /* Number of keys less than regSample */
   239    444     int regSample = iMem++;      /* The next sample value */
   240         -  int regNext = iMem++;        /* Index of next sample to record */
   241         -  int regSpacing = iMem++;     /* Spacing between samples */
   242         -  int regBigSize = iMem++;     /* Always save entries with nEq >= this */
          445  +  int regRowid = regSample;    /* Rowid of a sample */
          446  +  int regAccum = iMem++;       /* Register to hold Stat3Accum object */
          447  +  int regLoop = iMem++;        /* Loop counter */
          448  +  int regCount = iMem++;       /* Number of rows in the table or index */
   243    449     int regTemp1 = iMem++;       /* Intermediate register */
   244         -  int regCount = iMem++;       /* Number of rows in the table or index */
   245         -  int regGosub = iMem++;       /* Register holding subroutine return addr */
          450  +  int regTemp2 = iMem++;       /* Intermediate register */
   246    451     int once = 1;                /* One-time initialization */
   247    452     int shortJump = 0;           /* Instruction address */
   248         -  int addrStoreStat3 = 0;      /* Address of subroutine to wrote to stat3 */
          453  +  int iTabCur = pParse->nTab++; /* Table cursor */
   249    454   #endif
   250    455     int regCol = iMem++;         /* Content of a column in analyzed table */
   251    456     int regRec = iMem++;         /* Register holding completed record */
   252    457     int regTemp = iMem++;        /* Temporary use register */
   253         -  int regRowid = iMem++;       /* Rowid for the inserted record */
          458  +  int regNewRowid = iMem++;    /* Rowid for the inserted record */
   254    459   
   255    460   
   256    461     v = sqlite3GetVdbe(pParse);
   257    462     if( v==0 || NEVER(pTab==0) ){
   258    463       return;
   259    464     }
   260    465     if( pTab->tnum==0 ){
................................................................................
   303    508           (char *)pKey, P4_KEYINFO_HANDOFF);
   304    509       VdbeComment((v, "%s", pIdx->zName));
   305    510   
   306    511       /* Populate the register containing the index name. */
   307    512       sqlite3VdbeAddOp4(v, OP_String8, 0, regIdxname, 0, pIdx->zName, 0);
   308    513   
   309    514   #ifdef SQLITE_ENABLE_STAT3
   310         -
   311         -    /* If this iteration of the loop is generating code to analyze the
   312         -    ** first index in the pTab->pIndex list, then register regLast has
   313         -    ** not been populated. In this case populate it now.  */
   314    515       if( once ){
   315    516         once = 0;
   316         -      sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regCount);
   317         -      sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_STAT3_SAMPLES, regTemp1);
   318         -      sqlite3VdbeAddOp3(v, OP_Divide, regTemp1, regCount, regSpacing);
   319         -      sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_STAT3_SAMPLES/2, regTemp1);
   320         -      sqlite3VdbeAddOp3(v, OP_Divide, regTemp1, regCount, regBigSize);
   321         -
   322         -      /* Generate code for a subroutine that store the most recent sample
   323         -      ** in the sqlite_stat3 table
   324         -      */
   325         -      shortJump = sqlite3VdbeAddOp0(v, OP_Goto);
   326         -        sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 5, regRec, "bbbbb", 0);
   327         -        VdbeComment((v, "begin stat3 write subroutine"));
   328         -      sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regRowid);
   329         -      sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regRec, regRowid);
   330         -      sqlite3VdbeAddOp3(v, OP_Add, regNext, regSpacing, regNext);
   331         -      sqlite3VdbeAddOp1(v, OP_Return, regGosub);
   332         -      addrStoreStat3 = 
   333         -      sqlite3VdbeAddOp3(v, OP_Ge, regBigSize, shortJump+1, regNumEq);
   334         -      sqlite3VdbeAddOp3(v, OP_Add, regNumEq, regNumLt, regTemp1);
   335         -      sqlite3VdbeAddOp3(v, OP_Ge, regNext, shortJump+1, regTemp1);
   336         -      sqlite3VdbeAddOp1(v, OP_Return, regGosub);
   337         -      VdbeComment((v, "end stat3 write subroutine"));
   338         -      sqlite3VdbeJumpHere(v, shortJump);
          517  +      sqlite3OpenTable(pParse, iTabCur, iDb, pTab, OP_OpenRead);
   339    518       }
   340         -    /* Reset state registers */
   341         -    sqlite3VdbeAddOp2(v, OP_Copy, regSpacing, regNext);
          519  +    sqlite3VdbeAddOp2(v, OP_Count, iIdxCur, regCount);
          520  +    sqlite3VdbeAddOp2(v, OP_Integer, SQLITE_STAT3_SAMPLES, regTemp1);
   342    521       sqlite3VdbeAddOp2(v, OP_Integer, 0, regNumEq);
   343    522       sqlite3VdbeAddOp2(v, OP_Integer, 0, regNumLt);
   344         -
          523  +    sqlite3VdbeAddOp4(v, OP_Function, 1, regCount, regAccum,
          524  +                      (char*)&stat3InitFuncdef, P4_FUNCDEF);
          525  +    sqlite3VdbeChangeP5(v, 2);
   345    526   #endif /* SQLITE_ENABLE_STAT3 */
   346    527   
   347    528       /* The block of memory cells initialized here is used as follows.
   348    529       **
   349    530       **    iMem:                
   350    531       **        The total number of rows in the table.
   351    532       **
................................................................................
   385    566         assert( pIdx->azColl[i]!=0 );
   386    567         pColl = sqlite3LocateCollSeq(pParse, pIdx->azColl[i]);
   387    568         aChngAddr[i] = sqlite3VdbeAddOp4(v, OP_Ne, regCol, 0, iMem+nCol+i+1,
   388    569                                         (char*)pColl, P4_COLLSEQ);
   389    570         sqlite3VdbeChangeP5(v, SQLITE_NULLEQ);
   390    571         VdbeComment((v, "jump if column %d changed", i));
   391    572   #ifdef SQLITE_ENABLE_STAT3
   392         -      if( i==0 && addrStoreStat3 ){
          573  +      if( i==0 ){
   393    574           sqlite3VdbeAddOp2(v, OP_AddImm, regNumEq, 1);
   394    575           VdbeComment((v, "incr repeat count"));
   395    576         }
   396    577   #endif
   397    578       }
   398    579       sqlite3VdbeAddOp2(v, OP_Goto, 0, endOfLoop);
   399    580       for(i=0; i<nCol; i++){
   400    581         sqlite3VdbeJumpHere(v, aChngAddr[i]);  /* Set jump dest for the OP_Ne */
   401    582         if( i==0 ){
   402    583           sqlite3VdbeJumpHere(v, addrIfNot);   /* Jump dest for OP_IfNot */
   403    584   #ifdef SQLITE_ENABLE_STAT3
   404         -        sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrStoreStat3);
   405         -        sqlite3VdbeAddOp2(v, OP_Copy, regCol, regSample);
          585  +        sqlite3VdbeAddOp4(v, OP_Function, 1, regNumEq, regTemp2,
          586  +                          (char*)&stat3PushFuncdef, P4_FUNCDEF);
          587  +        sqlite3VdbeChangeP5(v, 4);
          588  +        sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, pIdx->nColumn, regRowid);
   406    589           sqlite3VdbeAddOp3(v, OP_Add, regNumEq, regNumLt, regNumLt);
   407    590           sqlite3VdbeAddOp2(v, OP_Integer, 1, regNumEq);
   408    591   #endif        
   409    592         }
   410    593         sqlite3VdbeAddOp2(v, OP_AddImm, iMem+i+1, 1);
   411    594         sqlite3VdbeAddOp3(v, OP_Column, iIdxCur, i, iMem+nCol+i+1);
   412    595       }
................................................................................
   414    597   
   415    598       /* Always jump here after updating the iMem+1...iMem+1+nCol counters */
   416    599       sqlite3VdbeResolveLabel(v, endOfLoop);
   417    600   
   418    601       sqlite3VdbeAddOp2(v, OP_Next, iIdxCur, topOfLoop);
   419    602       sqlite3VdbeAddOp1(v, OP_Close, iIdxCur);
   420    603   #ifdef SQLITE_ENABLE_STAT3
   421         -    sqlite3VdbeAddOp2(v, OP_Gosub, regGosub, addrStoreStat3);
          604  +    sqlite3VdbeAddOp4(v, OP_Function, 1, regNumEq, regTemp2,
          605  +                      (char*)&stat3PushFuncdef, P4_FUNCDEF);
          606  +    sqlite3VdbeChangeP5(v, 4);
          607  +    sqlite3VdbeAddOp2(v, OP_Integer, -1, regLoop);
          608  +    shortJump = 
          609  +    sqlite3VdbeAddOp2(v, OP_AddImm, regLoop, 1);
          610  +    sqlite3VdbeAddOp4(v, OP_Function, 1, regAccum, regTemp1,
          611  +                      (char*)&stat3GetFuncdef, P4_FUNCDEF);
          612  +    sqlite3VdbeChangeP5(v, 2);
          613  +    sqlite3VdbeAddOp1(v, OP_IsNull, regTemp1);
          614  +    sqlite3VdbeAddOp3(v, OP_NotExists, iTabCur, shortJump, regTemp1);
          615  +    sqlite3VdbeAddOp3(v, OP_Column, iTabCur, pIdx->aiColumn[0], regSample);
          616  +    sqlite3ColumnDefault(v, pTab, pIdx->aiColumn[0], regSample);
          617  +    sqlite3VdbeAddOp4(v, OP_Function, 1, regAccum, regNumEq,
          618  +                      (char*)&stat3GetFuncdef, P4_FUNCDEF);
          619  +    sqlite3VdbeChangeP5(v, 3);
          620  +    sqlite3VdbeAddOp4(v, OP_Function, 1, regAccum, regNumLt,
          621  +                      (char*)&stat3GetFuncdef, P4_FUNCDEF);
          622  +    sqlite3VdbeChangeP5(v, 4);
          623  +    sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 5, regRec, "bbbbb", 0);
          624  +    sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur+1, regNewRowid);
          625  +    sqlite3VdbeAddOp3(v, OP_Insert, iStatCur+1, regRec, regNewRowid);
          626  +    sqlite3VdbeAddOp2(v, OP_Goto, 0, shortJump);
          627  +    sqlite3VdbeJumpHere(v, shortJump+2);
   422    628   #endif        
   423    629   
   424    630       /* Store the results in sqlite_stat1.
   425    631       **
   426    632       ** The result is a single row of the sqlite_stat1 table.  The first
   427    633       ** two columns are the names of the table and index.  The third column
   428    634       ** is a string composed of a list of integer statistics about the
................................................................................
   449    655         sqlite3VdbeAddOp3(v, OP_Add, iMem, iMem+i+1, regTemp);
   450    656         sqlite3VdbeAddOp2(v, OP_AddImm, regTemp, -1);
   451    657         sqlite3VdbeAddOp3(v, OP_Divide, iMem+i+1, regTemp, regTemp);
   452    658         sqlite3VdbeAddOp1(v, OP_ToInt, regTemp);
   453    659         sqlite3VdbeAddOp3(v, OP_Concat, regTemp, regStat1, regStat1);
   454    660       }
   455    661       sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
   456         -    sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid);
   457         -    sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid);
          662  +    sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
          663  +    sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regNewRowid);
   458    664       sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
   459    665     }
   460    666   
   461    667     /* If the table has no indices, create a single sqlite_stat1 entry
   462    668     ** containing NULL as the index name and the row count as the content.
   463    669     */
   464    670     if( pTab->pIndex==0 ){
................................................................................
   469    675       jZeroRows = sqlite3VdbeAddOp1(v, OP_IfNot, regStat1);
   470    676     }else{
   471    677       sqlite3VdbeJumpHere(v, jZeroRows);
   472    678       jZeroRows = sqlite3VdbeAddOp0(v, OP_Goto);
   473    679     }
   474    680     sqlite3VdbeAddOp2(v, OP_Null, 0, regIdxname);
   475    681     sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regRec, "aaa", 0);
   476         -  sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regRowid);
   477         -  sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regRowid);
          682  +  sqlite3VdbeAddOp2(v, OP_NewRowid, iStatCur, regNewRowid);
          683  +  sqlite3VdbeAddOp3(v, OP_Insert, iStatCur, regRec, regNewRowid);
   478    684     sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
   479    685     if( pParse->nMem<regRec ) pParse->nMem = regRec;
   480    686     sqlite3VdbeJumpHere(v, jZeroRows);
   481    687   }
   482    688   
   483    689   
   484    690   /*
................................................................................
   500    706     Schema *pSchema = db->aDb[iDb].pSchema;    /* Schema of database iDb */
   501    707     HashElem *k;
   502    708     int iStatCur;
   503    709     int iMem;
   504    710   
   505    711     sqlite3BeginWriteOperation(pParse, 0, iDb);
   506    712     iStatCur = pParse->nTab;
   507         -  pParse->nTab += 2;
          713  +  pParse->nTab += 3;
   508    714     openStatTable(pParse, iDb, iStatCur, 0, 0);
   509    715     iMem = pParse->nMem+1;
   510    716     assert( sqlite3SchemaMutexHeld(db, iDb, 0) );
   511    717     for(k=sqliteHashFirst(&pSchema->tblHash); k; k=sqliteHashNext(k)){
   512    718       Table *pTab = (Table*)sqliteHashData(k);
   513    719       analyzeOneTable(pParse, pTab, 0, iStatCur, iMem);
   514    720     }
................................................................................
   525    731     int iStatCur;
   526    732   
   527    733     assert( pTab!=0 );
   528    734     assert( sqlite3BtreeHoldsAllMutexes(pParse->db) );
   529    735     iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);
   530    736     sqlite3BeginWriteOperation(pParse, 0, iDb);
   531    737     iStatCur = pParse->nTab;
   532         -  pParse->nTab += 2;
          738  +  pParse->nTab += 3;
   533    739     if( pOnlyIdx ){
   534    740       openStatTable(pParse, iDb, iStatCur, pOnlyIdx->zName, "idx");
   535    741     }else{
   536    742       openStatTable(pParse, iDb, iStatCur, pTab->zName, "tbl");
   537    743     }
   538    744     analyzeOneTable(pParse, pTab, pOnlyIdx, iStatCur, pParse->nMem+1);
   539    745     loadAnalysis(pParse, iDb);