/ Check-in [1c0bf030]
Login

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

Overview
Comment:Merge recent trunk changes into the fullscan-covering-index branch.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | fullscan-covering-index
Files: files | file ages | folders
SHA1: 1c0bf0305ce9528a0d07c86a390c5872e16bdb57
User & Date: drh 2012-09-17 19:26:02
Context
2012-09-17
20:44
Add the ability to disable the covering-index-scan optimization at compile-time, start-time, or at run-time. Add test cases to check this configurability. check-in: ccb8ecc3 user: drh tags: fullscan-covering-index
19:26
Merge recent trunk changes into the fullscan-covering-index branch. check-in: 1c0bf030 user: drh tags: fullscan-covering-index
19:12
Remove obsolete bits from the bitvector that defines disabled optimizations in the SQLITE_TESTCTRL_OPTIMIZATIONS verb of sqlite3_test_control(). check-in: 4c21ee2d user: drh tags: trunk
2012-09-15
18:45
Attempt to use a covering index even on a full table scan, under the theory that the index will be smaller and require less disk I/O and thus be faster. check-in: cfaa7bc1 user: drh tags: fullscan-covering-index
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/expr.c.

  1658   1658     }
  1659   1659   #endif
  1660   1660   
  1661   1661     switch( pExpr->op ){
  1662   1662       case TK_IN: {
  1663   1663         char affinity;              /* Affinity of the LHS of the IN */
  1664   1664         KeyInfo keyInfo;            /* Keyinfo for the generated table */
         1665  +      static u8 sortOrder = 0;    /* Fake aSortOrder for keyInfo */
  1665   1666         int addr;                   /* Address of OP_OpenEphemeral instruction */
  1666   1667         Expr *pLeft = pExpr->pLeft; /* the LHS of the IN operator */
  1667   1668   
  1668   1669         if( rMayHaveNull ){
  1669   1670           sqlite3VdbeAddOp2(v, OP_Null, 0, rMayHaveNull);
  1670   1671         }
  1671   1672   
................................................................................
  1685   1686         ** is used.
  1686   1687         */
  1687   1688         pExpr->iTable = pParse->nTab++;
  1688   1689         addr = sqlite3VdbeAddOp2(v, OP_OpenEphemeral, pExpr->iTable, !isRowid);
  1689   1690         if( rMayHaveNull==0 ) sqlite3VdbeChangeP5(v, BTREE_UNORDERED);
  1690   1691         memset(&keyInfo, 0, sizeof(keyInfo));
  1691   1692         keyInfo.nField = 1;
         1693  +      keyInfo.aSortOrder = &sortOrder;
  1692   1694   
  1693   1695         if( ExprHasProperty(pExpr, EP_xIsSelect) ){
  1694   1696           /* Case 1:     expr IN (SELECT ...)
  1695   1697           **
  1696   1698           ** Generate code to write the results of the select into the temporary
  1697   1699           ** table allocated and opened above.
  1698   1700           */
................................................................................
  1725   1727           struct ExprList_item *pItem;
  1726   1728           int r1, r2, r3;
  1727   1729   
  1728   1730           if( !affinity ){
  1729   1731             affinity = SQLITE_AFF_NONE;
  1730   1732           }
  1731   1733           keyInfo.aColl[0] = sqlite3ExprCollSeq(pParse, pExpr->pLeft);
         1734  +        keyInfo.aSortOrder = &sortOrder;
  1732   1735   
  1733   1736           /* Loop through each expression in <exprlist>. */
  1734   1737           r1 = sqlite3GetTempReg(pParse);
  1735   1738           r2 = sqlite3GetTempReg(pParse);
  1736   1739           sqlite3VdbeAddOp2(v, OP_Null, 0, r2);
  1737   1740           for(i=pList->nExpr, pItem=pList->a; i>0; i--, pItem++){
  1738   1741             Expr *pE2 = pItem->pExpr;

Changes to src/func.c.

   489    489   /*
   490    490   ** For LIKE and GLOB matching on EBCDIC machines, assume that every
   491    491   ** character is exactly one byte in size.  Also, all characters are
   492    492   ** able to participate in upper-case-to-lower-case mappings in EBCDIC
   493    493   ** whereas only characters less than 0x80 do in ASCII.
   494    494   */
   495    495   #if defined(SQLITE_EBCDIC)
   496         -# define sqlite3Utf8Read(A,C)  (*(A++))
          496  +# define sqlite3Utf8Read(A)    (*((*A)++))
   497    497   # define GlogUpperToLower(A)   A = sqlite3UpperToLower[A]
   498    498   #else
   499    499   # define GlogUpperToLower(A)   if( !((A)&~0x7f) ){ A = sqlite3UpperToLower[A]; }
   500    500   #endif
   501    501   
   502    502   static const struct compareInfo globInfo = { '*', '?', '[', 0 };
   503    503   /* The correct SQL-92 behavior is for the LIKE operator to ignore
................................................................................
   546    546     int seen;
   547    547     u8 matchOne = pInfo->matchOne;
   548    548     u8 matchAll = pInfo->matchAll;
   549    549     u8 matchSet = pInfo->matchSet;
   550    550     u8 noCase = pInfo->noCase; 
   551    551     int prevEscape = 0;     /* True if the previous character was 'escape' */
   552    552   
   553         -  while( (c = sqlite3Utf8Read(zPattern,&zPattern))!=0 ){
   554         -    if( !prevEscape && c==matchAll ){
   555         -      while( (c=sqlite3Utf8Read(zPattern,&zPattern)) == matchAll
          553  +  while( (c = sqlite3Utf8Read(&zPattern))!=0 ){
          554  +    if( c==matchAll && !prevEscape ){
          555  +      while( (c=sqlite3Utf8Read(&zPattern)) == matchAll
   556    556                  || c == matchOne ){
   557         -        if( c==matchOne && sqlite3Utf8Read(zString, &zString)==0 ){
          557  +        if( c==matchOne && sqlite3Utf8Read(&zString)==0 ){
   558    558             return 0;
   559    559           }
   560    560         }
   561    561         if( c==0 ){
   562    562           return 1;
   563    563         }else if( c==esc ){
   564         -        c = sqlite3Utf8Read(zPattern, &zPattern);
          564  +        c = sqlite3Utf8Read(&zPattern);
   565    565           if( c==0 ){
   566    566             return 0;
   567    567           }
   568    568         }else if( c==matchSet ){
   569    569           assert( esc==0 );         /* This is GLOB, not LIKE */
   570    570           assert( matchSet<0x80 );  /* '[' is a single-byte character */
   571    571           while( *zString && patternCompare(&zPattern[-1],zString,pInfo,esc)==0 ){
   572    572             SQLITE_SKIP_UTF8(zString);
   573    573           }
   574    574           return *zString!=0;
   575    575         }
   576         -      while( (c2 = sqlite3Utf8Read(zString,&zString))!=0 ){
          576  +      while( (c2 = sqlite3Utf8Read(&zString))!=0 ){
   577    577           if( noCase ){
   578    578             GlogUpperToLower(c2);
   579    579             GlogUpperToLower(c);
   580    580             while( c2 != 0 && c2 != c ){
   581         -            c2 = sqlite3Utf8Read(zString, &zString);
          581  +            c2 = sqlite3Utf8Read(&zString);
   582    582               GlogUpperToLower(c2);
   583    583             }
   584    584           }else{
   585    585             while( c2 != 0 && c2 != c ){
   586         -            c2 = sqlite3Utf8Read(zString, &zString);
          586  +            c2 = sqlite3Utf8Read(&zString);
   587    587             }
   588    588           }
   589    589           if( c2==0 ) return 0;
   590    590           if( patternCompare(zPattern,zString,pInfo,esc) ) return 1;
   591    591         }
   592    592         return 0;
   593         -    }else if( !prevEscape && c==matchOne ){
   594         -      if( sqlite3Utf8Read(zString, &zString)==0 ){
          593  +    }else if( c==matchOne && !prevEscape ){
          594  +      if( sqlite3Utf8Read(&zString)==0 ){
   595    595           return 0;
   596    596         }
   597    597       }else if( c==matchSet ){
   598    598         u32 prior_c = 0;
   599    599         assert( esc==0 );    /* This only occurs for GLOB, not LIKE */
   600    600         seen = 0;
   601    601         invert = 0;
   602         -      c = sqlite3Utf8Read(zString, &zString);
          602  +      c = sqlite3Utf8Read(&zString);
   603    603         if( c==0 ) return 0;
   604         -      c2 = sqlite3Utf8Read(zPattern, &zPattern);
          604  +      c2 = sqlite3Utf8Read(&zPattern);
   605    605         if( c2=='^' ){
   606    606           invert = 1;
   607         -        c2 = sqlite3Utf8Read(zPattern, &zPattern);
          607  +        c2 = sqlite3Utf8Read(&zPattern);
   608    608         }
   609    609         if( c2==']' ){
   610    610           if( c==']' ) seen = 1;
   611         -        c2 = sqlite3Utf8Read(zPattern, &zPattern);
          611  +        c2 = sqlite3Utf8Read(&zPattern);
   612    612         }
   613    613         while( c2 && c2!=']' ){
   614    614           if( c2=='-' && zPattern[0]!=']' && zPattern[0]!=0 && prior_c>0 ){
   615         -          c2 = sqlite3Utf8Read(zPattern, &zPattern);
          615  +          c2 = sqlite3Utf8Read(&zPattern);
   616    616             if( c>=prior_c && c<=c2 ) seen = 1;
   617    617             prior_c = 0;
   618    618           }else{
   619    619             if( c==c2 ){
   620    620               seen = 1;
   621    621             }
   622    622             prior_c = c2;
   623    623           }
   624         -        c2 = sqlite3Utf8Read(zPattern, &zPattern);
          624  +        c2 = sqlite3Utf8Read(&zPattern);
   625    625         }
   626    626         if( c2==0 || (seen ^ invert)==0 ){
   627    627           return 0;
   628    628         }
   629    629       }else if( esc==c && !prevEscape ){
   630    630         prevEscape = 1;
   631    631       }else{
   632         -      c2 = sqlite3Utf8Read(zString, &zString);
          632  +      c2 = sqlite3Utf8Read(&zString);
   633    633         if( noCase ){
   634    634           GlogUpperToLower(c);
   635    635           GlogUpperToLower(c2);
   636    636         }
   637    637         if( c!=c2 ){
   638    638           return 0;
   639    639         }
................................................................................
   697    697       const unsigned char *zEsc = sqlite3_value_text(argv[2]);
   698    698       if( zEsc==0 ) return;
   699    699       if( sqlite3Utf8CharLen((char*)zEsc, -1)!=1 ){
   700    700         sqlite3_result_error(context, 
   701    701             "ESCAPE expression must be a single character", -1);
   702    702         return;
   703    703       }
   704         -    escape = sqlite3Utf8Read(zEsc, &zEsc);
          704  +    escape = sqlite3Utf8Read(&zEsc);
   705    705     }
   706    706     if( zA && zB ){
   707    707       struct compareInfo *pInfo = sqlite3_user_data(context);
   708    708   #ifdef SQLITE_TEST
   709    709       sqlite3_like_count++;
   710    710   #endif
   711    711       

Changes to src/select.c.

  1888   1888   
  1889   1889       for(i=0, apColl=pKeyInfo->aColl; i<nCol; i++, apColl++){
  1890   1890         *apColl = multiSelectCollSeq(pParse, p, i);
  1891   1891         if( 0==*apColl ){
  1892   1892           *apColl = db->pDfltColl;
  1893   1893         }
  1894   1894       }
         1895  +    pKeyInfo->aSortOrder = (u8*)apColl;
  1895   1896   
  1896   1897       for(pLoop=p; pLoop; pLoop=pLoop->pPrior){
  1897   1898         for(i=0; i<2; i++){
  1898   1899           int addr = pLoop->addrOpenEphm[i];
  1899   1900           if( addr<0 ){
  1900   1901             /* If [0] is unused then [1] is also unused.  So we can
  1901   1902             ** always safely abort as soon as the first unused slot is found */

Changes to src/sqliteInt.h.

   958    958   #define SQLITE_EnableTrigger  0x40000000  /* True to enable triggers */
   959    959   
   960    960   /*
   961    961   ** Bits of the sqlite3.flags field that are used by the
   962    962   ** sqlite3_test_control(SQLITE_TESTCTRL_OPTIMIZATIONS,...) interface.
   963    963   ** These must be the low-order bits of the flags field.
   964    964   */
   965         -#define SQLITE_QueryFlattener 0x01        /* Disable query flattening */
   966         -#define SQLITE_ColumnCache    0x02        /* Disable the column cache */
   967         -#define SQLITE_IndexSort      0x04        /* Disable indexes for sorting */
   968         -#define SQLITE_IndexSearch    0x08        /* Disable indexes for searching */
   969         -#define SQLITE_IndexCover     0x10        /* Disable index covering table */
   970         -#define SQLITE_GroupByOrder   0x20        /* Disable GROUPBY cover of ORDERBY */
   971         -#define SQLITE_FactorOutConst 0x40        /* Disable factoring out constants */
   972         -#define SQLITE_IdxRealAsInt   0x80        /* Store REAL as INT in indices */
   973         -#define SQLITE_DistinctOpt    0x80        /* DISTINCT using indexes */
   974         -#define SQLITE_OptMask        0xff        /* Mask of all disablable opts */
          965  +#define SQLITE_QueryFlattener 0x01   /* Disable query flattening */
          966  +#define SQLITE_ColumnCache    0x02   /* Disable the column cache */
          967  +#define SQLITE_GroupByOrder   0x04   /* Disable GROUPBY cover of ORDERBY */
          968  +#define SQLITE_FactorOutConst 0x08   /* Disable factoring out constants */
          969  +#define SQLITE_IdxRealAsInt   0x10   /* Store REAL as INT in indices */
          970  +#define SQLITE_DistinctOpt    0x20   /* DISTINCT using indexes */
          971  +#define SQLITE_OptMask        0xff   /* Mask of all disablable opts */
   975    972   
   976    973   /*
   977    974   ** Possible values for the sqlite.magic field.
   978    975   ** The numbers are obtained at random and have no special meaning, other
   979    976   ** than being distinct from one another.
   980    977   */
   981    978   #define SQLITE_MAGIC_OPEN     0xa029a697  /* Database is open */
................................................................................
  2952   2949   int sqlite3FixExprList(DbFixer*, ExprList*);
  2953   2950   int sqlite3FixTriggerStep(DbFixer*, TriggerStep*);
  2954   2951   int sqlite3AtoF(const char *z, double*, int, u8);
  2955   2952   int sqlite3GetInt32(const char *, int*);
  2956   2953   int sqlite3Atoi(const char*);
  2957   2954   int sqlite3Utf16ByteLen(const void *pData, int nChar);
  2958   2955   int sqlite3Utf8CharLen(const char *pData, int nByte);
  2959         -u32 sqlite3Utf8Read(const u8*, const u8**);
         2956  +u32 sqlite3Utf8Read(const u8**);
  2960   2957   
  2961   2958   /*
  2962   2959   ** Routines to read and write variable-length integers.  These used to
  2963   2960   ** be defined locally, but now we use the varint routines in the util.c
  2964   2961   ** file.  Code should use the MACRO forms below, as the Varint32 versions
  2965   2962   ** are coded to assume the single byte case is already handled (which 
  2966   2963   ** the MACRO form does).

Changes to src/test1.c.

  5932   5932     static const struct {
  5933   5933       const char *zOptName;
  5934   5934       int mask;
  5935   5935     } aOpt[] = {
  5936   5936       { "all",              SQLITE_OptMask        },
  5937   5937       { "query-flattener",  SQLITE_QueryFlattener },
  5938   5938       { "column-cache",     SQLITE_ColumnCache    },
  5939         -    { "index-sort",       SQLITE_IndexSort      },
  5940         -    { "index-search",     SQLITE_IndexSearch    },
  5941         -    { "index-cover",      SQLITE_IndexCover     },
  5942   5939       { "groupby-order",    SQLITE_GroupByOrder   },
  5943   5940       { "factor-constants", SQLITE_FactorOutConst },
  5944   5941       { "real-as-int",      SQLITE_IdxRealAsInt   },
         5942  +    { "distinct-opt",     SQLITE_DistinctOpt    },
  5945   5943     };
  5946   5944   
  5947   5945     if( objc!=4 ){
  5948   5946       Tcl_WrongNumArgs(interp, 1, objv, "DB OPT BOOLEAN");
  5949   5947       return TCL_ERROR;
  5950   5948     }
  5951   5949     if( getDbPointer(interp, Tcl_GetString(objv[1]), &db) ) return TCL_ERROR;

Changes to src/utf.c.

   160    160         c = (c<<6) + (0x3f & *(zIn++));                      \
   161    161       }                                                      \
   162    162       if( c<0x80                                             \
   163    163           || (c&0xFFFFF800)==0xD800                          \
   164    164           || (c&0xFFFFFFFE)==0xFFFE ){  c = 0xFFFD; }        \
   165    165     }
   166    166   u32 sqlite3Utf8Read(
   167         -  const unsigned char *zIn,       /* First byte of UTF-8 character */
   168         -  const unsigned char **pzNext    /* Write first byte past UTF-8 char here */
          167  +  const unsigned char **pz    /* Pointer to string from which to read char */
   169    168   ){
   170    169     unsigned int c;
   171    170   
   172    171     /* Same as READ_UTF8() above but without the zTerm parameter.
   173    172     ** For this routine, we assume the UTF8 string is always zero-terminated.
   174    173     */
   175         -  c = *(zIn++);
          174  +  c = *((*pz)++);
   176    175     if( c>=0xc0 ){
   177    176       c = sqlite3Utf8Trans1[c-0xc0];
   178         -    while( (*zIn & 0xc0)==0x80 ){
   179         -      c = (c<<6) + (0x3f & *(zIn++));
          177  +    while( (*(*pz) & 0xc0)==0x80 ){
          178  +      c = (c<<6) + (0x3f & *((*pz)++));
   180    179       }
   181    180       if( c<0x80
   182    181           || (c&0xFFFFF800)==0xD800
   183    182           || (c&0xFFFFFFFE)==0xFFFE ){  c = 0xFFFD; }
   184    183     }
   185         -  *pzNext = zIn;
   186    184     return c;
   187    185   }
   188    186   
   189    187   
   190    188   
   191    189   
   192    190   /*
................................................................................
   279    277     }
   280    278     z = zOut;
   281    279   
   282    280     if( pMem->enc==SQLITE_UTF8 ){
   283    281       if( desiredEnc==SQLITE_UTF16LE ){
   284    282         /* UTF-8 -> UTF-16 Little-endian */
   285    283         while( zIn<zTerm ){
   286         -        /* c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn); */
   287    284           READ_UTF8(zIn, zTerm, c);
   288    285           WRITE_UTF16LE(z, c);
   289    286         }
   290    287       }else{
   291    288         assert( desiredEnc==SQLITE_UTF16BE );
   292    289         /* UTF-8 -> UTF-16 Big-endian */
   293    290         while( zIn<zTerm ){
   294         -        /* c = sqlite3Utf8Read(zIn, zTerm, (const u8**)&zIn); */
   295    291           READ_UTF8(zIn, zTerm, c);
   296    292           WRITE_UTF16BE(z, c);
   297    293         }
   298    294       }
   299    295       pMem->n = (int)(z - zOut);
   300    296       *z++ = 0;
   301    297     }else{
................................................................................
   415    411   */
   416    412   int sqlite3Utf8To8(unsigned char *zIn){
   417    413     unsigned char *zOut = zIn;
   418    414     unsigned char *zStart = zIn;
   419    415     u32 c;
   420    416   
   421    417     while( zIn[0] && zOut<=zIn ){
   422         -    c = sqlite3Utf8Read(zIn, (const u8**)&zIn);
          418  +    c = sqlite3Utf8Read((const u8**)&zIn);
   423    419       if( c!=0xfffd ){
   424    420         WRITE_UTF8(zOut, c);
   425    421       }
   426    422     }
   427    423     *zOut = 0;
   428    424     return (int)(zOut - zStart);
   429    425   }
................................................................................
   520    516     for(i=0; i<0x00110000; i++){
   521    517       z = zBuf;
   522    518       WRITE_UTF8(z, i);
   523    519       n = (int)(z-zBuf);
   524    520       assert( n>0 && n<=4 );
   525    521       z[0] = 0;
   526    522       z = zBuf;
   527         -    c = sqlite3Utf8Read(z, (const u8**)&z);
          523  +    c = sqlite3Utf8Read((const u8**)&z);
   528    524       t = i;
   529    525       if( i>=0xD800 && i<=0xDFFF ) t = 0xFFFD;
   530    526       if( (i&0xFFFFFFFE)==0xFFFE ) t = 0xFFFD;
   531    527       assert( c==t );
   532    528       assert( (z-zBuf)==n );
   533    529     }
   534    530     for(i=0; i<0x00110000; i++){

Changes to src/vdbeaux.c.

   741    741       nByte = sizeof(*pKeyInfo) + (nField-1)*sizeof(pKeyInfo->aColl[0]) + nField;
   742    742       pKeyInfo = sqlite3DbMallocRaw(0, nByte);
   743    743       pOp->p4.pKeyInfo = pKeyInfo;
   744    744       if( pKeyInfo ){
   745    745         u8 *aSortOrder;
   746    746         memcpy((char*)pKeyInfo, zP4, nByte - nField);
   747    747         aSortOrder = pKeyInfo->aSortOrder;
   748         -      if( aSortOrder ){
   749         -        pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
   750         -        memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
   751         -      }
          748  +      assert( aSortOrder!=0 );
          749  +      pKeyInfo->aSortOrder = (unsigned char*)&pKeyInfo->aColl[nField];
          750  +      memcpy(pKeyInfo->aSortOrder, aSortOrder, nField);
   752    751         pOp->p4type = P4_KEYINFO;
   753    752       }else{
   754    753         p->db->mallocFailed = 1;
   755    754         pOp->p4type = P4_NOTUSED;
   756    755       }
   757    756     }else if( n==P4_KEYINFO_HANDOFF ){
   758    757       pOp->p4.p = (void*)zP4;
................................................................................
   857    856     char *zP4 = zTemp;
   858    857     assert( nTemp>=20 );
   859    858     switch( pOp->p4type ){
   860    859       case P4_KEYINFO_STATIC:
   861    860       case P4_KEYINFO: {
   862    861         int i, j;
   863    862         KeyInfo *pKeyInfo = pOp->p4.pKeyInfo;
          863  +      assert( pKeyInfo->aSortOrder!=0 );
   864    864         sqlite3_snprintf(nTemp, zTemp, "keyinfo(%d", pKeyInfo->nField);
   865    865         i = sqlite3Strlen30(zTemp);
   866    866         for(j=0; j<pKeyInfo->nField; j++){
   867    867           CollSeq *pColl = pKeyInfo->aColl[j];
   868    868           if( pColl ){
   869    869             int n = sqlite3Strlen30(pColl->zName);
   870    870             if( i+n>nTemp-6 ){
   871    871               memcpy(&zTemp[i],",...",4);
   872    872               break;
   873    873             }
   874    874             zTemp[i++] = ',';
   875         -          if( pKeyInfo->aSortOrder && pKeyInfo->aSortOrder[j] ){
          875  +          if( pKeyInfo->aSortOrder[j] ){
   876    876               zTemp[i++] = '-';
   877    877             }
   878    878             memcpy(&zTemp[i], pColl->zName,n+1);
   879    879             i += n;
   880    880           }else if( i+4<nTemp-6 ){
   881    881             memcpy(&zTemp[i],",nil",4);
   882    882             i += 4;
................................................................................
  2579   2579       return 0;
  2580   2580     }
  2581   2581     if( flags&MEM_Int ){
  2582   2582       /* Figure out whether to use 1, 2, 4, 6 or 8 bytes. */
  2583   2583   #   define MAX_6BYTE ((((i64)0x00008000)<<32)-1)
  2584   2584       i64 i = pMem->u.i;
  2585   2585       u64 u;
  2586         -    if( file_format>=4 && (i&1)==i ){
  2587         -      return 8+(u32)i;
  2588         -    }
  2589   2586       if( i<0 ){
  2590   2587         if( i<(-MAX_6BYTE) ) return 6;
  2591   2588         /* Previous test prevents:  u = -(-9223372036854775808) */
  2592   2589         u = -i;
  2593   2590       }else{
  2594   2591         u = i;
  2595   2592       }
  2596         -    if( u<=127 ) return 1;
         2593  +    if( u<=127 ){
         2594  +      return ((i&1)==i && file_format>=4) ? 8+(u32)u : 1;
         2595  +    }
  2597   2596       if( u<=32767 ) return 2;
  2598   2597       if( u<=8388607 ) return 3;
  2599   2598       if( u<=2147483647 ) return 4;
  2600   2599       if( u<=MAX_6BYTE ) return 5;
  2601   2600       return 6;
  2602   2601     }
  2603   2602     if( flags&MEM_Real ){
................................................................................
  2874   2873       if( !p ) return 0;
  2875   2874     }else{
  2876   2875       p = (UnpackedRecord*)&pSpace[nOff];
  2877   2876       *ppFree = 0;
  2878   2877     }
  2879   2878   
  2880   2879     p->aMem = (Mem*)&((char*)p)[ROUND8(sizeof(UnpackedRecord))];
         2880  +  assert( pKeyInfo->aSortOrder!=0 );
  2881   2881     p->pKeyInfo = pKeyInfo;
  2882   2882     p->nField = pKeyInfo->nField + 1;
  2883   2883     return p;
  2884   2884   }
  2885   2885   
  2886   2886   /*
  2887   2887   ** Given the nKey-byte encoding of a record in pKey[], populate the 
................................................................................
  2967   2967     ** to ignore the compiler warnings and leave this variable uninitialized.
  2968   2968     */
  2969   2969     /*  mem1.u.i = 0;  // not needed, here to silence compiler warning */
  2970   2970     
  2971   2971     idx1 = getVarint32(aKey1, szHdr1);
  2972   2972     d1 = szHdr1;
  2973   2973     nField = pKeyInfo->nField;
         2974  +  assert( pKeyInfo->aSortOrder!=0 );
  2974   2975     while( idx1<szHdr1 && i<pPKey2->nField ){
  2975   2976       u32 serial_type1;
  2976   2977   
  2977   2978       /* Read the serial types for the next element in each key. */
  2978   2979       idx1 += getVarint32( aKey1+idx1, serial_type1 );
  2979   2980       if( d1>=nKey1 && sqlite3VdbeSerialTypeLen(serial_type1)>0 ) break;
  2980   2981   
................................................................................
  2986   2987       */
  2987   2988       rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i],
  2988   2989                              i<nField ? pKeyInfo->aColl[i] : 0);
  2989   2990       if( rc!=0 ){
  2990   2991         assert( mem1.zMalloc==0 );  /* See comment below */
  2991   2992   
  2992   2993         /* Invert the result if we are using DESC sort order. */
  2993         -      if( pKeyInfo->aSortOrder && i<nField && pKeyInfo->aSortOrder[i] ){
         2994  +      if( i<nField && pKeyInfo->aSortOrder[i] ){
  2994   2995           rc = -rc;
  2995   2996         }
  2996   2997       
  2997   2998         /* If the PREFIX_SEARCH flag is set and all fields except the final
  2998   2999         ** rowid field were equal, then clear the PREFIX_SEARCH flag and set 
  2999   3000         ** pPKey2->rowid to the value of the rowid field in (pKey1, nKey1).
  3000   3001         ** This is used by the OP_IsUnique opcode.