/ Check-in [545bb336]
Login

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

Overview
Comment:Factor an invariant out the loop termination condition for the ORDER BY satisfied-by-index analyzer routine.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 545bb33688663066cf3f09e4cdc4d5cfe59fb8db
User & Date: drh 2012-10-02 01:46:48
Context
2012-10-02
14:11
Only continue an ORDER BY optimization into inner loops if the equality constraints on the inner loop match terms of an outer ordered index that are actually used by the ORDER BY clause. check-in: b0e7b4df user: drh tags: trunk
01:46
Factor an invariant out the loop termination condition for the ORDER BY satisfied-by-index analyzer routine. check-in: 545bb336 user: drh tags: trunk
01:25
Make sure the outer loop cursor numbers are recorded in time for them to be used by the ORDER BY optimizer. check-in: 351dc8d9 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  2855   2855     ** the index.
  2856   2856     **
  2857   2857     ** Note that indices have pIdx->nColumn regular columns plus
  2858   2858     ** one additional column containing the rowid.  The rowid column
  2859   2859     ** of the index is also allowed to match against the ORDER BY
  2860   2860     ** clause.
  2861   2861     */
  2862         -  for(i=0,j=nPriorSat,pTerm=&pOrderBy->a[j]; j<nTerm && i<=pIdx->nColumn; i++){
         2862  +  for(i=0,j=nPriorSat,pTerm=&pOrderBy->a[j]; j<nTerm; i++){
  2863   2863       Expr *pExpr;       /* The expression of the ORDER BY pTerm */
  2864   2864       CollSeq *pColl;    /* The collating sequence of pExpr */
  2865   2865       int termSortOrder; /* Sort order for this term */
  2866   2866       int iColumn;       /* The i-th column of the index.  -1 for rowid */
  2867   2867       int iSortOrder;    /* 1 for DESC, 0 for ASC on the i-th index term */
  2868   2868       const char *zColl; /* Name of the collating sequence for i-th index term */
  2869   2869   
         2870  +    assert( i<=pIdx->nColumn );
  2870   2871       pExpr = pTerm->pExpr;
  2871   2872       if( pExpr->op!=TK_COLUMN || pExpr->iTable!=base ){
  2872   2873         /* Can not use an index sort on anything that is not a column in the
  2873   2874         ** left-most table of the FROM clause */
  2874   2875         break;
  2875   2876       }
  2876   2877       pColl = sqlite3ExprCollSeq(pParse, pExpr);