/ Check-in [9fd0faf5]
Login

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

Overview
Comment:The previous fix for ticket [d85fffd6ffe856092ed8da] in check-in [0a514e62ad1ebe5c12da8dae] did not completely address the probably in that it only worked for cases where the OP_SCopy that loaded the register was the last instruction in the sequence for the expression, which is not necessarily the case for expressions like CASE...END. This revision prevents the registered that will be recomputed from being cached in the first place.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9fd0faf517993587d2f54212638545fc85fbbc84a031bcfae8c1e5894825d83b
User & Date: drh 2018-04-26 18:34:26
Context
2018-04-27
15:17
Enhance the comments in the templatevtab.c implementation. check-in: 05f6278a user: drh tags: trunk
2018-04-26
18:34
The previous fix for ticket [d85fffd6ffe856092ed8da] in check-in [0a514e62ad1ebe5c12da8dae] did not completely address the probably in that it only worked for cases where the OP_SCopy that loaded the register was the last instruction in the sequence for the expression, which is not necessarily the case for expressions like CASE...END. This revision prevents the registered that will be recomputed from being cached in the first place. check-in: 9fd0faf5 user: drh tags: trunk
17:43
When processing an "ORDER BY ... LIMIT" that does not use an index, check whether or not a record may appear in the final result set before adding it to the temp b-tree used for sorting. check-in: 0fcfc36c user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/update.c.

   598    598     for(i=0; i<pTab->nCol; i++){
   599    599       if( i==pTab->iPKey ){
   600    600         sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i);
   601    601       }else{
   602    602         j = aXRef[i];
   603    603         if( j>=0 ){
   604    604           sqlite3ExprCode(pParse, pChanges->a[j].pExpr, regNew+i);
   605         -        if( tmask&TRIGGER_BEFORE ){
   606         -          /* Must preserve copied values even in case the original is
   607         -          ** reloaded in the After-BEFORE-trigger-reload-loop below.
   608         -          ** Ticket d85fffd6ffe856092ed8daefa811b1e399706b28 */
   609         -          sqlite3VdbeSwapOpcode(v, -1, OP_SCopy, OP_Copy);
   610         -        }
   611    605         }else if( 0==(tmask&TRIGGER_BEFORE) || i>31 || (newmask & MASKBIT32(i)) ){
   612    606           /* This branch loads the value of a column that will not be changed 
   613    607           ** into a register. This is done if there are no BEFORE triggers, or
   614    608           ** if there are one or more BEFORE triggers that use this value via
   615    609           ** a new.* reference in a trigger program.
   616    610           */
   617    611           testcase( i==31 );
   618    612           testcase( i==32 );
   619    613           sqlite3ExprCodeGetColumnToReg(pParse, pTab, i, iDataCur, regNew+i);
          614  +        if( tmask & TRIGGER_BEFORE ){
          615  +          /* This value will be recomputed in After-BEFORE-trigger-reload-loop
          616  +          ** below, so make sure that it is not cached and reused.
          617  +          ** Ticket d85fffd6ffe856092ed8daefa811b1e399706b28. */
          618  +          sqlite3ExprCacheRemove(pParse, regNew+i, 1);
          619  +        }
   620    620         }else{
   621    621           sqlite3VdbeAddOp2(v, OP_Null, 0, regNew+i);
   622    622         }
   623    623       }
   624    624     }
   625    625   
   626    626     /* Fire any BEFORE UPDATE triggers. This happens before constraints are

Changes to src/vdbe.h.

   196    196   #else
   197    197   # define sqlite3VdbeVerifyNoMallocRequired(A,B)
   198    198   # define sqlite3VdbeVerifyNoResultRow(A)
   199    199   #endif
   200    200   VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp, int iLineno);
   201    201   void sqlite3VdbeAddParseSchemaOp(Vdbe*,int,char*);
   202    202   void sqlite3VdbeChangeOpcode(Vdbe*, u32 addr, u8);
   203         -void sqlite3VdbeSwapOpcode(Vdbe*, u32 addr, u8, u8);
   204    203   void sqlite3VdbeChangeP1(Vdbe*, u32 addr, int P1);
   205    204   void sqlite3VdbeChangeP2(Vdbe*, u32 addr, int P2);
   206    205   void sqlite3VdbeChangeP3(Vdbe*, u32 addr, int P3);
   207    206   void sqlite3VdbeChangeP5(Vdbe*, u16 P5);
   208    207   void sqlite3VdbeJumpHere(Vdbe*, int addr);
   209    208   int sqlite3VdbeChangeToNoop(Vdbe*, int addr);
   210    209   int sqlite3VdbeDeletePriorOpcode(Vdbe*, u8 op);

Changes to src/vdbeaux.c.

   839    839     sqlite3VdbeGetOp(p,addr)->p3 = val;
   840    840   }
   841    841   void sqlite3VdbeChangeP5(Vdbe *p, u16 p5){
   842    842     assert( p->nOp>0 || p->db->mallocFailed );
   843    843     if( p->nOp>0 ) p->aOp[p->nOp-1].p5 = p5;
   844    844   }
   845    845   
   846         -/* Change the opcode to iNew if it was previously iOld */
   847         -void sqlite3VdbeSwapOpcode(Vdbe *p, u32 addr, u8 iOld, u8 iNew){
   848         -  VdbeOp *pOp = sqlite3VdbeGetOp(p,addr);
   849         -  if( pOp->opcode==iOld ) pOp->opcode = iNew;
   850         -}
   851         -
   852    846   /*
   853    847   ** Change the P2 operand of instruction addr so that it points to
   854    848   ** the address of the next instruction to be coded.
   855    849   */
   856    850   void sqlite3VdbeJumpHere(Vdbe *p, int addr){
   857    851     sqlite3VdbeChangeP2(p, addr, p->nOp);
   858    852   }

Changes to test/trigger1.test.

   756    756   #
   757    757   do_execsql_test trigger1-19.0 {
   758    758     CREATE TABLE t19(a INT PRIMARY KEY, b, c)WITHOUT ROWID;
   759    759     INSERT INTO t19(a,b,c) VALUES(1,2,3);
   760    760     CREATE TRIGGER t19r3 BEFORE UPDATE ON t19 BEGIN SELECT new.b; END;
   761    761     UPDATE t19 SET c=b WHERE a=1;
   762    762     SELECT * FROM t19;
          763  +} {1 2 2}
          764  +do_execsql_test trigger1-19.1 {
          765  +  DELETE FROM t19;
          766  +  INSERT INTO t19(a,b,c) VALUES(1,2,3);
          767  +  UPDATE t19 SET c=CASE WHEN b=2 THEN b ELSE b+99 END WHERE a=1;
          768  +  SELECT * FROM t19;
   763    769   } {1 2 2}
   764    770   
   765    771   finish_test