/ Check-in [ecbef450]
Login

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

Overview
Comment:Eliminate the OP_VRowid opcode. The regular OP_Rowid now work for both regular and virtual tables. (CVS 6537)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: ecbef45011f1f98d940b2d3492941213d9f04172
User & Date: drh 2009-04-22 17:15:03
Context
2009-04-23
13:22
Rework the column-cache mechanism to be more robust (and more correct). The column-alias cache is currently disabled, (CVS 6538) check-in: dd4d67a6 user: drh tags: trunk
2009-04-22
17:15
Eliminate the OP_VRowid opcode. The regular OP_Rowid now work for both regular and virtual tables. (CVS 6537) check-in: ecbef450 user: drh tags: trunk
15:32
Change the OP_Rowid opcode so that a deferred OP_Seek is pending, it simply pulls the rowid from the deferred seek target and does not actually move the cursor or do a seek. Other where.c cleanups. (CVS 6536) check-in: 1c508a99 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Show Whitespace Changes Patch

Changes to src/expr.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 routines used for analyzing expressions and
    13     13   ** for generating VDBE code that evaluates expressions in SQLite.
    14     14   **
    15         -** $Id: expr.c,v 1.426 2009/04/08 13:51:51 drh Exp $
           15  +** $Id: expr.c,v 1.427 2009/04/22 17:15:03 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   /*
    20     20   ** Return the 'affinity' of the expression pExpr if any.
    21     21   **
    22     22   ** If pExpr is a column, a reference to a column via an 'AS' alias,
................................................................................
  1741   1741         VdbeComment((v, "OPT: tab%d.col%d -> r%d", iTable, iColumn, p->iReg));
  1742   1742   #endif
  1743   1743         return p->iReg;
  1744   1744       }
  1745   1745     }  
  1746   1746     assert( v!=0 );
  1747   1747     if( iColumn<0 ){
  1748         -    int op = (pTab && IsVirtual(pTab)) ? OP_VRowid : OP_Rowid;
  1749         -    sqlite3VdbeAddOp2(v, op, iTable, iReg);
         1748  +    sqlite3VdbeAddOp2(v, OP_Rowid, iTable, iReg);
  1750   1749     }else if( pTab==0 ){
  1751   1750       sqlite3VdbeAddOp3(v, OP_Column, iTable, iColumn, iReg);
  1752   1751     }else{
  1753   1752       int op = IsVirtual(pTab) ? OP_VColumn : OP_Column;
  1754   1753       sqlite3VdbeAddOp3(v, op, iTable, iColumn, iReg);
  1755   1754       sqlite3ColumnDefault(v, pTab, iColumn);
  1756   1755   #ifndef SQLITE_OMIT_FLOATING_POINT

Changes to src/update.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 are called by the parser
    13     13   ** to handle UPDATE statements.
    14     14   **
    15         -** $Id: update.c,v 1.196 2009/02/28 10:47:42 danielk1977 Exp $
           15  +** $Id: update.c,v 1.197 2009/04/22 17:15:03 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   #ifndef SQLITE_OMIT_VIRTUALTABLE
    20     20   /* Forward declaration */
    21     21   static void updateVirtualTable(
    22     22     Parse *pParse,       /* The parsing context */
................................................................................
   348    348     pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, 0,
   349    349                                WHERE_ONEPASS_DESIRED, 0);
   350    350     if( pWInfo==0 ) goto update_cleanup;
   351    351     okOnePass = pWInfo->okOnePass;
   352    352   
   353    353     /* Remember the rowid of every item to be updated.
   354    354     */
   355         -  sqlite3VdbeAddOp2(v, IsVirtual(pTab)?OP_VRowid:OP_Rowid, iCur, regOldRowid);
          355  +  sqlite3VdbeAddOp2(v, OP_Rowid, iCur, regOldRowid);
   356    356     if( !okOnePass ){
   357    357       regRowSet = ++pParse->nMem;
   358    358       sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, regOldRowid);
   359    359     }
   360    360   
   361    361     /* End the database scan loop.
   362    362     */

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.838 2009/04/22 15:32:59 drh Exp $
           46  +** $Id: vdbe.c,v 1.839 2009/04/22 17:15:03 drh Exp $
    47     47   */
    48     48   #include "sqliteInt.h"
    49     49   #include "vdbeInt.h"
    50     50   
    51     51   /*
    52     52   ** The following global variable is incremented every time a cursor
    53     53   ** moves, either by the OP_SeekXX, OP_Next, or OP_Prev opcodes.  The test
................................................................................
  3892   3892     break;
  3893   3893   }
  3894   3894   
  3895   3895   /* Opcode: Rowid P1 P2 * * *
  3896   3896   **
  3897   3897   ** Store in register P2 an integer which is the key of the table entry that
  3898   3898   ** P1 is currently point to.
         3899  +**
         3900  +** P1 can be either an ordinary table or a virtual table.  There used to
         3901  +** be a separate OP_VRowid opcode for use with virtual tables, but this
         3902  +** one opcode now works for both table types.
  3899   3903   */
  3900   3904   case OP_Rowid: {                 /* out2-prerelease */
  3901   3905     int i = pOp->p1;
  3902   3906     VdbeCursor *pC;
  3903   3907     i64 v;
  3904   3908   
  3905   3909     assert( i>=0 && i<p->nCursor );
  3906   3910     pC = p->apCsr[i];
  3907   3911     assert( pC!=0 );
  3908         -  if( pC->deferredMoveto ){
         3912  +  if( pC->nullRow ){
         3913  +    /* Do nothing so that reg[P2] remains NULL */
         3914  +    break;
         3915  +  }else if( pC->deferredMoveto ){
  3909   3916       v = pC->movetoTarget;
         3917  +  }else if( pC->pseudoTable ){
         3918  +    v = keyToInt(pC->iKey);
         3919  +#ifndef SQLITE_OMIT_VIRTUALTABLE
         3920  +  }else if( pC->pVtabCursor ){
         3921  +    sqlite3_vtab *pVtab;
         3922  +    const sqlite3_module *pModule;
         3923  +    pVtab = pC->pVtabCursor->pVtab;
         3924  +    pModule = pVtab->pModule;
         3925  +    assert( pModule->xRowid );
         3926  +    if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
         3927  +    rc = pModule->xRowid(pC->pVtabCursor, &v);
         3928  +    sqlite3DbFree(db, p->zErrMsg);
         3929  +    p->zErrMsg = pVtab->zErrMsg;
         3930  +    pVtab->zErrMsg = 0;
         3931  +    if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
         3932  +#endif /* SQLITE_OMIT_VIRTUALTABLE */
  3910   3933     }else{
  3911   3934       rc = sqlite3VdbeCursorMoveto(pC);
  3912   3935       if( rc ) goto abort_due_to_error;
  3913   3936       if( pC->rowidIsValid ){
  3914   3937         v = pC->lastRowid;
  3915         -    }else if( pC->pseudoTable ){
  3916         -      v = keyToInt(pC->iKey);
  3917         -    }else if( pC->nullRow ){
  3918         -      /* Leave the rowid set to a NULL */
  3919         -      break;
  3920   3938       }else{
  3921   3939         assert( pC->pCursor!=0 );
  3922   3940         sqlite3BtreeKeySize(pC->pCursor, &v);
  3923   3941         v = keyToInt(v);
  3924   3942       }
  3925   3943     }
  3926   3944     pOut->u.i = v;
................................................................................
  5087   5105         pc = pOp->p2 - 1;
  5088   5106       }
  5089   5107     }
  5090   5108     pCur->nullRow = 0;
  5091   5109   
  5092   5110     break;
  5093   5111   }
  5094         -#endif /* SQLITE_OMIT_VIRTUALTABLE */
  5095         -
  5096         -#ifndef SQLITE_OMIT_VIRTUALTABLE
  5097         -/* Opcode: VRowid P1 P2 * * *
  5098         -**
  5099         -** Store into register P2  the rowid of
  5100         -** the virtual-table that the P1 cursor is pointing to.
  5101         -*/
  5102         -case OP_VRowid: {             /* out2-prerelease */
  5103         -  sqlite3_vtab *pVtab;
  5104         -  const sqlite3_module *pModule;
  5105         -  sqlite_int64 iRow;
  5106         -  VdbeCursor *pCur = p->apCsr[pOp->p1];
  5107         -
  5108         -  assert( pCur->pVtabCursor );
  5109         -  if( pCur->nullRow ){
  5110         -    break;
  5111         -  }
  5112         -  pVtab = pCur->pVtabCursor->pVtab;
  5113         -  pModule = pVtab->pModule;
  5114         -  assert( pModule->xRowid );
  5115         -  if( sqlite3SafetyOff(db) ) goto abort_due_to_misuse;
  5116         -  rc = pModule->xRowid(pCur->pVtabCursor, &iRow);
  5117         -  sqlite3DbFree(db, p->zErrMsg);
  5118         -  p->zErrMsg = pVtab->zErrMsg;
  5119         -  pVtab->zErrMsg = 0;
  5120         -  if( sqlite3SafetyOn(db) ) goto abort_due_to_misuse;
  5121         -  MemSetTypeFlag(pOut, MEM_Int);
  5122         -  pOut->u.i = iRow;
  5123         -  break;
  5124         -}
  5125   5112   #endif /* SQLITE_OMIT_VIRTUALTABLE */
  5126   5113   
  5127   5114   #ifndef SQLITE_OMIT_VIRTUALTABLE
  5128   5115   /* Opcode: VColumn P1 P2 P3 * *
  5129   5116   **
  5130   5117   ** Store the value of the P2-th column of
  5131   5118   ** the row of the virtual-table that the 

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 responsible 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.386 2009/04/22 15:32:59 drh Exp $
           19  +** $Id: where.c,v 1.387 2009/04/22 17:15:03 drh Exp $
    20     20   */
    21     21   #include "sqliteInt.h"
    22     22   
    23     23   /*
    24     24   ** Trace output macros
    25     25   */
    26     26   #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
................................................................................
  2971   2971       assert( regRowSet>0 );
  2972   2972       if( iRowidReg==0 ){
  2973   2973         /* The rowid was not available as a side-effect of the code 
  2974   2974         ** genenerated above. So extract it from the cursor now.
  2975   2975         */
  2976   2976         assert( iReleaseReg==0 );
  2977   2977         iReleaseReg = iRowidReg = sqlite3GetTempReg(pParse);
  2978         -#ifndef SQLITE_OMIT_VIRTUALTABLE
  2979         -      if( (pLevel->plan.wsFlags & WHERE_VIRTUALTABLE)!=0 ){
  2980         -        sqlite3VdbeAddOp2(v, OP_VRowid, iCur, iRowidReg);
  2981         -      }else
  2982         -#endif
  2983         -      {
  2984   2978           sqlite3VdbeAddOp2(v, OP_Rowid, iCur, iRowidReg);
  2985   2979         }
  2986         -    }
  2987   2980       
  2988   2981       if( pWInfo->wctrlFlags&WHERE_FILL_ROWSET ){
  2989   2982         sqlite3VdbeAddOp2(v, OP_RowSetAdd, regRowSet, iRowidReg);
  2990   2983         VVA_ONLY( pWInfo->iRowidHandler = 0; )
  2991   2984       }else{
  2992   2985         assert( pWInfo->wctrlFlags&WHERE_FILL_ROWTEST );
  2993   2986         pWInfo->iRowidHandler =