/ Check-in [c4db0ad1]
Login

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

Overview
Comment:Fix a performance regression caused by the previous commit.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | index-on-cast
Files: files | file ages | folders
SHA3-256:c4db0ad12d4f3d2800d36404f391b325cdc4aa7f8dcea93b2d63a489d9095ad4
User & Date: drh 2019-01-28 18:58:54
Context
2019-01-28
19:06
Fix the query planner so that it is able to use an index on a CAST expression. check-in: 2c886f3d user: drh tags: trunk
18:58
Fix a performance regression caused by the previous commit. Closed-Leaf check-in: c4db0ad1 user: drh tags: index-on-cast
18:08
Make indexes on CAST(...) expressions work. check-in: 3ef711d9 user: dan tags: index-on-cast
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

   305    305       if( pScan->iEquiv>=pScan->nEquiv ) break;
   306    306       pWC = pScan->pOrigWC;
   307    307       k = 0;
   308    308       pScan->iEquiv++;
   309    309     }
   310    310     return 0;
   311    311   }
          312  +
          313  +/*
          314  +** This is whereScanInit() for the case of an index on an expression.
          315  +** It is factored out into a separate tail-recursion subroutine so that
          316  +** the normal whereScanInit() routine, which is a high-runner, does not
          317  +** need to push registers onto the stack as part of its prologue.
          318  +*/
          319  +static SQLITE_NOINLINE WhereTerm *whereScanInitIndexExpr(WhereScan *pScan){
          320  +  pScan->idxaff = sqlite3ExprAffinity(pScan->pIdxExpr);
          321  +  return whereScanNext(pScan);
          322  +}
   312    323   
   313    324   /*
   314    325   ** Initialize a WHERE clause scanner object.  Return a pointer to the
   315    326   ** first match.  Return NULL if there are no matches.
   316    327   **
   317    328   ** The scanner will be searching the WHERE clause pWC.  It will look
   318    329   ** for terms of the form "X <op> <expr>" where X is column iColumn of table
................................................................................
   338    349     Index *pIdx             /* Must be compatible with this index */
   339    350   ){
   340    351     pScan->pOrigWC = pWC;
   341    352     pScan->pWC = pWC;
   342    353     pScan->pIdxExpr = 0;
   343    354     pScan->idxaff = 0;
   344    355     pScan->zCollName = 0;
          356  +  pScan->opMask = opMask;
          357  +  pScan->k = 0;
          358  +  pScan->aiCur[0] = iCur;
          359  +  pScan->nEquiv = 1;
          360  +  pScan->iEquiv = 1;
   345    361     if( pIdx ){
   346    362       int j = iColumn;
   347    363       iColumn = pIdx->aiColumn[j];
   348    364       if( iColumn==XN_EXPR ){
   349    365         pScan->pIdxExpr = pIdx->aColExpr->a[j].pExpr;
   350    366         pScan->zCollName = pIdx->azColl[j];
   351         -      pScan->idxaff = sqlite3ExprAffinity(pScan->pIdxExpr);
          367  +      pScan->aiColumn[0] = XN_EXPR;
          368  +      return whereScanInitIndexExpr(pScan);
   352    369       }else if( iColumn==pIdx->pTable->iPKey ){
   353    370         iColumn = XN_ROWID;
   354    371       }else if( iColumn>=0 ){
   355    372         pScan->idxaff = pIdx->pTable->aCol[iColumn].affinity;
   356    373         pScan->zCollName = pIdx->azColl[j];
   357    374       }
   358    375     }else if( iColumn==XN_EXPR ){
   359    376       return 0;
   360    377     }
   361         -  pScan->opMask = opMask;
   362         -  pScan->k = 0;
   363         -  pScan->aiCur[0] = iCur;
   364    378     pScan->aiColumn[0] = iColumn;
   365         -  pScan->nEquiv = 1;
   366         -  pScan->iEquiv = 1;
   367    379     return whereScanNext(pScan);
   368    380   }
   369    381   
   370    382   /*
   371    383   ** Search for a term in the WHERE clause that is of the form "X <op> <expr>"
   372    384   ** where X is a reference to the iColumn of table iCur or of index pIdx
   373    385   ** if pIdx!=0 and <op> is one of the WO_xx operator codes specified by