/ Check-in [253ed40a]
Login

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

Overview
Comment:Modify VFilter and VRename to use registers instead of the vdbe stack for inputs. (CVS 4670)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 253ed40aa36247fc846cc41c8612cd29899d9f8f
User & Date: danielk1977 2008-01-03 18:39:42
Context
2008-01-03
18:44
Update OP_Rowid, OP_Column and related opcodes to use registers. (CVS 4671) check-in: 4f396707 user: drh tags: trunk
18:39
Modify VFilter and VRename to use registers instead of the vdbe stack for inputs. (CVS 4670) check-in: 253ed40a user: danielk1977 tags: trunk
18:03
Registers (aka memory cells) in the VM are now numbered starting with 1 instead of 0. A register number of 0 means "no such register". (CVS 4669) check-in: 0b849805 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/alter.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that used to generate VDBE code
    13     13   ** that implements the ALTER TABLE command.
    14     14   **
    15         -** $Id: alter.c,v 1.36 2008/01/03 00:01:24 drh Exp $
           15  +** $Id: alter.c,v 1.37 2008/01/03 18:39:42 danielk1977 Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   #include <ctype.h>
    19     19   
    20     20   /*
    21     21   ** The code in this file only exists if we are not omitting the
    22     22   ** ALTER TABLE logic from the build.
................................................................................
   358    358     /* If this is a virtual table, invoke the xRename() function if
   359    359     ** one is defined. The xRename() callback will modify the names
   360    360     ** of any resources used by the v-table implementation (including other
   361    361     ** SQLite tables) that are identified by the name of the virtual table.
   362    362     */
   363    363   #ifndef SQLITE_OMIT_VIRTUALTABLE
   364    364     if( isVirtualRename ){
          365  +    int i;
   365    366       sqlite3VdbeAddOp4(v, OP_String8, 0, 0, 0, zName, 0);
   366         -    sqlite3VdbeAddOp4(v, OP_VRename, 0, 0, 0,(const char*)pTab->pVtab, P4_VTAB);
          367  +    i = sqlite3StackToReg(pParse, 1);
          368  +    sqlite3VdbeAddOp4(v, OP_VRename, i, 0, 0,(const char*)pTab->pVtab, P4_VTAB);
   367    369     }
   368    370   #endif
   369    371   
   370    372     /* figure out how many UTF-8 characters are in zName */
   371    373     zTabName = pTab->zName;
   372    374     nTabName = sqlite3Utf8CharLen(zTabName, -1);
   373    375   

Changes to src/vdbe.c.

    39     39   **
    40     40   ** Various scripts scan this source file in order to generate HTML
    41     41   ** documentation, headers files, or other derived files.  The formatting
    42     42   ** of the code in this file is, therefore, important.  See other comments
    43     43   ** in this file for details.  If in doubt, do not deviate from existing
    44     44   ** commenting and indentation practices when changing or adding code.
    45     45   **
    46         -** $Id: vdbe.c,v 1.671 2008/01/03 18:03:09 drh Exp $
           46  +** $Id: vdbe.c,v 1.672 2008/01/03 18:39:42 danielk1977 Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include <ctype.h>
    50     50   #include "vdbeInt.h"
    51     51   
    52     52   /*
    53     53   ** The following global variable is incremented every time a cursor
................................................................................
  4984   4984       }
  4985   4985     }
  4986   4986     break;
  4987   4987   }
  4988   4988   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  4989   4989   
  4990   4990   #ifndef SQLITE_OMIT_VIRTUALTABLE
  4991         -/* Opcode: VFilter P1 P2 P4
         4991  +/* Opcode: VFilter P1 P2 P3 P4 *
  4992   4992   **
  4993   4993   ** P1 is a cursor opened using VOpen.  P2 is an address to jump to if
  4994   4994   ** the filtered result set is empty.
  4995   4995   **
  4996   4996   ** P4 is either NULL or a string that was generated by the xBestIndex
  4997   4997   ** method of the module.  The interpretation of the P4 string is left
  4998   4998   ** to the module implementation.
  4999   4999   **
  5000   5000   ** This opcode invokes the xFilter method on the virtual table specified
  5001         -** by P1.  The integer query plan parameter to xFilter is the top of the
  5002         -** stack.  Next down on the stack is the argc parameter.  Beneath the
  5003         -** next of stack are argc additional parameters which are passed to
  5004         -** xFilter as argv. The topmost parameter (i.e. 3rd element popped from
  5005         -** the stack) becomes argv[argc-1] when passed to xFilter.
         5001  +** by P1.  The integer query plan parameter to xFilter is stored in register
         5002  +** P3. Register P3+1 stores the argc parameter to be passed to the
         5003  +** xFilter method. Registers P3+2..P3+1+argc are the argc additional
         5004  +** parametersneath additional parameters which are passed to
         5005  +** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
  5006   5006   **
  5007         -** The integer query plan parameter, argc, and all argv stack values 
  5008         -** are popped from the stack before this instruction completes.
  5009         -**
  5010         -** A jump is made to P2 if the result set after filtering would be 
  5011         -** empty.
         5007  +** A jump is made to P2 if the result set after filtering would be empty.
  5012   5008   */
  5013   5009   case OP_VFilter: {   /* no-push */
  5014   5010     int nArg;
  5015         -
         5011  +  int iQuery;
  5016   5012     const sqlite3_module *pModule;
         5013  +  Mem *pQuery = &p->aMem[pOp->p3];
         5014  +  Mem *pArgc = &pQuery[1];
  5017   5015   
  5018   5016     Cursor *pCur = p->apCsr[pOp->p1];
  5019   5017     assert( pCur->pVtabCursor );
  5020   5018     pModule = pCur->pVtabCursor->pVtab->pModule;
  5021   5019   
  5022   5020     /* Grab the index number and argc parameters off the top of the stack. */
  5023         -  assert( (&pTos[-1])>=p->aStack );
  5024         -  assert( (pTos[0].flags&MEM_Int)!=0 && pTos[-1].flags==MEM_Int );
  5025         -  nArg = pTos[-1].u.i;
         5021  +  assert( (pQuery->flags&MEM_Int)!=0 && pArgc->flags==MEM_Int );
         5022  +  nArg = pArgc->u.i;
         5023  +  iQuery = pQuery->u.i;
  5026   5024   
  5027   5025     /* Invoke the xFilter method */
  5028   5026     {
  5029   5027       int res = 0;
  5030   5028       int i;
  5031   5029       Mem **apArg = p->apArg;
  5032   5030       for(i = 0; i<nArg; i++){
  5033         -      apArg[i] = &pTos[i+1-2-nArg];
         5031  +      apArg[i] = &pArgc[i+1];
  5034   5032         storeTypeInfo(apArg[i], 0);
  5035   5033       }
  5036   5034   
  5037   5035       if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
  5038   5036       p->inVtabMethod = 1;
  5039         -    rc = pModule->xFilter(pCur->pVtabCursor, pTos->u.i, pOp->p4.z, nArg, apArg);
         5037  +    rc = pModule->xFilter(pCur->pVtabCursor, iQuery, pOp->p4.z, nArg, apArg);
  5040   5038       p->inVtabMethod = 0;
  5041   5039       if( rc==SQLITE_OK ){
  5042   5040         res = pModule->xEof(pCur->pVtabCursor);
  5043   5041       }
  5044   5042       if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
  5045   5043   
  5046   5044       if( res ){
  5047   5045         pc = pOp->p2 - 1;
  5048   5046       }
  5049   5047     }
  5050   5048   
  5051         -  /* Pop the index number, argc value and parameters off the stack */
  5052         -  popStack(&pTos, 2+nArg);
  5053   5049     break;
  5054   5050   }
  5055   5051   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  5056   5052   
  5057   5053   #ifndef SQLITE_OMIT_VIRTUALTABLE
  5058   5054   /* Opcode: VRowid P1 * *
  5059   5055   **
................................................................................
  5169   5165     }
  5170   5166   
  5171   5167     break;
  5172   5168   }
  5173   5169   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  5174   5170   
  5175   5171   #ifndef SQLITE_OMIT_VIRTUALTABLE
  5176         -/* Opcode: VRename * * P4
         5172  +/* Opcode: VRename P1 * P4
  5177   5173   **
  5178   5174   ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
  5179   5175   ** This opcode invokes the corresponding xRename method. The value
  5180         -** on the top of the stack is popped and passed as the zName argument
  5181         -** to the xRename method.
         5176  +** in register P1 is passed as the zName argument to the xRename method.
  5182   5177   */
  5183   5178   case OP_VRename: {   /* no-push */
  5184   5179     sqlite3_vtab *pVtab = pOp->p4.pVtab;
         5180  +  Mem *pName = &p->aMem[pOp->p1];
  5185   5181     assert( pVtab->pModule->xRename );
  5186   5182   
  5187         -  Stringify(pTos, encoding);
         5183  +  Stringify(pName, encoding);
  5188   5184   
  5189   5185     if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
  5190   5186     sqlite3VtabLock(pVtab);
  5191         -  rc = pVtab->pModule->xRename(pVtab, pTos->z);
         5187  +  rc = pVtab->pModule->xRename(pVtab, pName->z);
  5192   5188     sqlite3VtabUnlock(db, pVtab);
  5193   5189     if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
  5194   5190   
  5195         -  popStack(&pTos, 1);
  5196   5191     break;
  5197   5192   }
  5198   5193   #endif
  5199   5194   
  5200   5195   #ifndef SQLITE_OMIT_VIRTUALTABLE
  5201   5196   /* Opcode: VUpdate P1 P2 P3 P4
  5202   5197   **

Changes to src/vdbeaux.c.

   329    329         doesStatementRollback = 1;
   330    330   #ifndef SQLITE_OMIT_VIRTUALTABLE
   331    331       }else if( opcode==OP_VUpdate || opcode==OP_VRename ){
   332    332         doesStatementRollback = 1;
   333    333       }else if( opcode==OP_VFilter ){
   334    334         int n;
   335    335         assert( p->nOp - i >= 3 );
   336         -      assert( pOp[-2].opcode==OP_Integer );
   337         -      n = pOp[-2].p1;
          336  +      assert( pOp[-1].opcode==OP_MemInt );
          337  +      n = pOp[-1].p1;
   338    338         if( n>nMaxArgs ) nMaxArgs = n;
   339    339   #endif
   340    340       }
   341    341       if( opcodeNoPush(opcode) ){
   342    342         nMaxStack--;
   343    343       }
   344    344   

Changes to src/where.c.

    12     12   ** This module contains C code that generates VDBE code used to process
    13     13   ** the WHERE clause of SQL statements.  This module is reponsible for
    14     14   ** generating the code that loops through a table looking for applicable
    15     15   ** rows.  Indices are selected and used to speed the search when doing
    16     16   ** so is applicable.  Because this module is responsible for selecting
    17     17   ** indices, you might also think of this module as the "query optimizer".
    18     18   **
    19         -** $Id: where.c,v 1.270 2008/01/03 18:03:09 drh Exp $
           19  +** $Id: where.c,v 1.271 2008/01/03 18:39:42 danielk1977 Exp $
    20     20   */
    21     21   #include "sqliteInt.h"
    22     22   
    23     23   /*
    24     24   ** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
    25     25   */
    26     26   #define BMS  (sizeof(Bitmask)*8)
................................................................................
  2267   2267   
  2268   2268   #ifndef SQLITE_OMIT_VIRTUALTABLE
  2269   2269       if( pLevel->pBestIdx ){
  2270   2270         /* Case 0:  The table is a virtual-table.  Use the VFilter and VNext
  2271   2271         **          to access the data.
  2272   2272         */
  2273   2273         int j;
         2274  +      int iReg;   /* P3 Value for OP_VFilter */
  2274   2275         sqlite3_index_info *pBestIdx = pLevel->pBestIdx;
  2275   2276         int nConstraint = pBestIdx->nConstraint;
  2276   2277         struct sqlite3_index_constraint_usage *aUsage =
  2277   2278                                                     pBestIdx->aConstraintUsage;
  2278   2279         const struct sqlite3_index_constraint *aConstraint =
  2279   2280                                                     pBestIdx->aConstraint;
  2280   2281   
................................................................................
  2285   2286               int iTerm = aConstraint[k].iTermOffset;
  2286   2287               sqlite3ExprCode(pParse, wc.a[iTerm].pExpr->pRight);
  2287   2288               break;
  2288   2289             }
  2289   2290           }
  2290   2291           if( k==nConstraint ) break;
  2291   2292         }
  2292         -      sqlite3VdbeAddOp2(v, OP_Integer, j-1, 0);
  2293         -      sqlite3VdbeAddOp2(v, OP_Integer, pBestIdx->idxNum, 0);
  2294         -      sqlite3VdbeAddOp4(v, OP_VFilter, iCur, brk, 0, pBestIdx->idxStr,
         2293  +      iReg = ++pParse->nMem;
         2294  +      pParse->nMem++;
         2295  +      sqlite3StackToReg(pParse, j-1);
         2296  +      sqlite3VdbeAddOp2(v, OP_MemInt, pBestIdx->idxNum, iReg);
         2297  +      sqlite3VdbeAddOp2(v, OP_MemInt, j-1, iReg+1);
         2298  +      sqlite3VdbeAddOp4(v, OP_VFilter, iCur, brk, iReg, pBestIdx->idxStr,
  2295   2299                           pBestIdx->needToFreeIdxStr ? P4_MPRINTF : P4_STATIC);
  2296   2300         pBestIdx->needToFreeIdxStr = 0;
  2297   2301         for(j=0; j<pBestIdx->nConstraint; j++){
  2298   2302           if( aUsage[j].omit ){
  2299   2303             int iTerm = aConstraint[j].iTermOffset;
  2300   2304             disableTerm(pLevel, &wc.a[iTerm]);
  2301   2305           }