/ Check-in [e7188fad]
Login

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

Overview
Comment:Further enhancements to generated VDBE code for ORDER BY.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | orderby-planning
Files: files | file ages | folders
SHA1: e7188fad87ec82d36a39b80ccaf8006bf45a9bcd
User & Date: drh 2014-03-24 01:43:50
Original Comment: Further enhancements to geneverated VDBE code for ORDER BY.
Context
2014-03-24
02:20
Remove a pointless OP_Once operation in ORDER BY clauses with LIMIT. check-in: e6c59d23 user: drh tags: orderby-planning
01:43
Further enhancements to generated VDBE code for ORDER BY. check-in: e7188fad user: drh tags: orderby-planning
2014-03-23
18:47
merge fixes from trunk check-in: faf7f9ca user: drh tags: orderby-planning
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.c.

   469    469     int nExpr = pSort->pOrderBy->nExpr;              /* No. of ORDER BY terms */
   470    470     int nBase = nExpr + 1 + nData;                   /* Fields in sorter record */
   471    471     int regBase = sqlite3GetTempRange(pParse, nBase); /* Regs for sorter record */
   472    472     int regRecord = sqlite3GetTempReg(pParse);       /* Assemblied sorter record */
   473    473     int nOBSat = pSort->nOBSat;                      /* No. ORDER BY terms to skip */
   474    474     int op;                               /* Opcode to add sorter record to sorter */
   475    475   
   476         -  sqlite3ExprCacheClear(pParse);
   477         -  sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, 0);
          476  +  sqlite3ExprCodeExprList(pParse, pSort->pOrderBy, regBase, SQLITE_ECEL_DUP);
   478    477     sqlite3VdbeAddOp2(v, OP_Sequence, pSort->iECursor, regBase+nExpr);
   479    478     sqlite3VdbeAddOp3(v, OP_Move, regData, regBase+nExpr+1, nData);
   480    479     sqlite3VdbeAddOp3(v, OP_MakeRecord, regBase+nOBSat, nBase-nOBSat, regRecord);
   481    480     if( nOBSat>0 ){
   482    481       int regPrevKey;   /* The first nOBSat columns of the previous row */
   483    482       int addrFirst;    /* Address of the OP_IfNot opcode */
   484    483       int addrJmp;      /* Address of the OP_Jump opcode */
................................................................................
  1123   1122   ){
  1124   1123     Vdbe *v = pParse->pVdbe;                     /* The prepared statement */
  1125   1124     int addrBreak = sqlite3VdbeMakeLabel(v);     /* Jump here to exit loop */
  1126   1125     int addrContinue = sqlite3VdbeMakeLabel(v);  /* Jump here for next cycle */
  1127   1126     int addr;
  1128   1127     int addrOnce = 0;
  1129   1128     int iTab;
  1130         -  int pseudoTab = 0;
  1131   1129     ExprList *pOrderBy = pSort->pOrderBy;
  1132   1130     int eDest = pDest->eDest;
  1133   1131     int iParm = pDest->iSDParm;
  1134   1132     int regRow;
  1135   1133     int regRowid;
  1136   1134     int nKey;
  1137   1135     int iSortTab;                   /* Sorter cursor to read from */
  1138   1136     int nSortData;                  /* Trailing values to read from sorter */
  1139   1137     u8 p5;                          /* p5 parameter for 1st OP_Column */
  1140   1138     int i;
         1139  +#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
         1140  +  struct ExprList_item *aOutEx = p->pEList->a;
         1141  +#endif
  1141   1142   
  1142   1143     if( pSort->labelBkOut ){
  1143   1144       sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
  1144   1145       sqlite3VdbeAddOp2(v, OP_Goto, 0, addrBreak);
  1145   1146       sqlite3VdbeResolveLabel(v, pSort->labelBkOut);
  1146   1147       addrOnce = sqlite3CodeOnce(pParse); VdbeCoverage(v);
  1147   1148     }
  1148   1149     iTab = pSort->iECursor;
  1149   1150     regRow = sqlite3GetTempReg(pParse);
  1150   1151     if( eDest==SRT_Output || eDest==SRT_Coroutine ){
  1151         -    pseudoTab = pParse->nTab++;
  1152         -    sqlite3VdbeAddOp3(v, OP_OpenPseudo, pseudoTab, regRow, nColumn);
  1153   1152       regRowid = 0;
  1154   1153       regRow = pDest->iSdst;
  1155   1154       nSortData = nColumn;
  1156   1155     }else{
  1157   1156       regRowid = sqlite3GetTempReg(pParse);
  1158   1157       regRow = sqlite3GetTempReg(pParse);
  1159   1158       nSortData = 1;
................................................................................
  1176   1175       sqlite3VdbeAddOp3(v, OP_Column, iTab, nKey+1, regRow);
  1177   1176       iSortTab = iTab;
  1178   1177       p5 = 0;
  1179   1178     }
  1180   1179     for(i=0; i<nSortData; i++){
  1181   1180       sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+1+i, regRow+i);
  1182   1181       if( i==0 ) sqlite3VdbeChangeP5(v, p5);
         1182  +    VdbeComment((v, "%s", aOutEx[i].zName ? aOutEx[i].zName : aOutEx[i].zSpan));
  1183   1183     }
  1184   1184     switch( eDest ){
  1185   1185       case SRT_Table:
  1186   1186       case SRT_EphemTab: {
  1187   1187         testcase( eDest==SRT_Table );
  1188   1188         testcase( eDest==SRT_EphemTab );
  1189   1189         sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);