SQLite

Changes On Branch unpack-opcode
Login

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

Changes In Branch unpack-opcode Excluding Merge-Ins

This is equivalent to a diff from 871e091d to 39ae92f5

2015-10-15
21:30
Performance optimization for the OP_Column opcode. (check-in: 076be547 user: drh tags: trunk)
21:13
Merge updates from trunk. (Leaf check-in: 40493680 user: mistachkin tags: mutexInitIsInitReCheck)
21:12
Merge updates from trunk. (Leaf check-in: a447cf90 user: mistachkin tags: mutexInitSimpleCmpSwap)
20:17
Experiments with an OP_Unpack opcode that extracts multiple columns from a record without caching. (Leaf check-in: 39ae92f5 user: drh tags: unpack-opcode)
19:21
Enhance the use of the column cache for UPDATE statements, making them more efficient for the case where a column is modified to be an expression of other unmodified columns. (check-in: 871e091d user: drh tags: trunk)
18:04
Add the OP_IntCopy opcode - an optimized version of OP_SCopy that only works for integer values. (check-in: 3a2f73a4 user: drh tags: trunk)

Changes to src/select.c.

1226
1227
1228
1229
1230
1231
1232

1233
1234
1235
1236
1237
1238
1239
1240
1241




1242
1243
1244
1245
1246
1247
1248
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238




1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249







+





-
-
-
-
+
+
+
+







    sqlite3VdbeAddOp3(v, OP_OpenPseudo, iSortTab, regSortOut, nKey+1+nSortData);
    if( addrOnce ) sqlite3VdbeJumpHere(v, addrOnce);
    addr = 1 + sqlite3VdbeAddOp2(v, OP_SorterSort, iTab, addrBreak);
    VdbeCoverage(v);
    codeOffset(v, p->iOffset, addrContinue);
    sqlite3VdbeAddOp3(v, OP_SorterData, iTab, regSortOut, iSortTab);
    bSeq = 0;
    sqlite3VdbeAddOp4Int(v, OP_Unpack, regSortOut, regRow, nSortData, nKey);
  }else{
    addr = 1 + sqlite3VdbeAddOp2(v, OP_Sort, iTab, addrBreak); VdbeCoverage(v);
    codeOffset(v, p->iOffset, addrContinue);
    iSortTab = iTab;
    bSeq = 1;
  }
  for(i=0; i<nSortData; i++){
    sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq+i, regRow+i);
    VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
    for(i=0; i<nSortData; i++){
      sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq+i, regRow+i);
      VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
    }
  }
  switch( eDest ){
    case SRT_EphemTab: {
      sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
      sqlite3VdbeAddOp3(v, OP_Insert, iParm, regRow, regRowid);
      sqlite3VdbeChangeP5(v, OPFLAG_APPEND);
      break;
5336
5337
5338
5339
5340
5341
5342

5343
5344


5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5337
5338
5339
5340
5341
5342
5343
5344


5345
5346



5347
5348
5349
5350
5351
5352
5353







+
-
-
+
+
-
-
-







      ** from the previous row currently stored in a0, a1, a2...
      */
      addrTopOfLoop = sqlite3VdbeCurrentAddr(v);
      sqlite3ExprCacheClear(pParse);
      if( groupBySort ){
        sqlite3VdbeAddOp3(v, OP_SorterData, sAggInfo.sortingIdx,
                          sortOut, sortPTab);
        sqlite3VdbeAddOp4Int(v, OP_Unpack, sortOut, iBMem, pGroupBy->nExpr, 0);
      }
      for(j=0; j<pGroupBy->nExpr; j++){
      }else{
        for(j=0; j<pGroupBy->nExpr; j++){
        if( groupBySort ){
          sqlite3VdbeAddOp3(v, OP_Column, sortPTab, j, iBMem+j);
        }else{
          sAggInfo.directMode = 1;
          sqlite3ExprCode(pParse, pGroupBy->a[j].pExpr, iBMem+j);
        }
      }
      sqlite3VdbeAddOp4(v, OP_Compare, iAMem, iBMem, pGroupBy->nExpr,
                          (char*)sqlite3KeyInfoRef(pKeyInfo), P4_KEYINFO);
      addr1 = sqlite3VdbeCurrentAddr(v);

Changes to src/vdbe.c.

2609
2610
2611
2612
2613
2614
2615













































2616
2617
2618
2619
2620
2621
2622
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667







+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







    pDest->flags = fx|MEM_Term;
  }
op_column_error:
  UPDATE_MAX_BLOBSIZE(pDest);
  REGISTER_TRACE(pOp->p3, pDest);
  break;
}

/* Opcode: Unpack P1 P2 P3 P4 *
** Synopsis: r[P2@P3] = unpack(P1)
**
** Decode the P3 fields of the record object held in register P1
** start with the P4-th field and store the values in registers P2
** and following.
*/
case OP_Unpack: {
  const unsigned char *aKey;
  int d; 
  u32 idx;                        /* Offset in aKey[] to read from */
  u16 u;                          /* Unsigned loop counter */
  u32 szHdr;
  int nField;     
  u32 serial_type;
  int iOfst;                      /* Skip this many fields */

  pIn1 = &aMem[pOp->p1];
  assert( pIn1->flags & MEM_Blob );
  aKey = (const unsigned char*)pIn1->z;
  pOut = &aMem[pOp->p2];
  nField = pOp->p3;
  assert( pOp->p4type==P4_INT32 );
  iOfst = pOp->p4.i;
  idx = getVarint32(aKey, szHdr);
  d = szHdr;
  u = 0;
  while( idx<szHdr && d<=pIn1->n ){
    idx += getVarint32(&aKey[idx], serial_type);
    if( iOfst ){
      iOfst--;
      d += sqlite3VdbeSerialTypeLen(serial_type);
    }else{
      memAboutToChange(p, pOut);
      sqlite3VdbeMemSetNull(pOut);
      pOut->enc = encoding;
      d += sqlite3VdbeSerialGet(&aKey[d], serial_type, pOut);
      REGISTER_TRACE((int)(pOut - aMem), pOut);
      pOut++;
      if( (++u)>=nField ) break;
    }
  }
  break;
}

/* Opcode: Affinity P1 P2 * P4 *
** Synopsis: affinity(r[P1@P2])
**
** Apply affinities to a range of P2 registers starting with P1.
**
** P4 is a string that is P2 characters long. The nth character of the