/ Check-in [39f708d1]
Login

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

Overview
Comment:Small performance optimization in sqlite3WhereBegin().
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 39f708d1e286931365a8992dbe7f900108ff1dad146032a284ad1dec09b11e06
User & Date: drh 2017-08-25 13:34:18
Context
2017-08-25
15:43
Size and performance optimization for sqlite3Init(). check-in: 776d9128 user: drh tags: trunk
13:34
Small performance optimization in sqlite3WhereBegin(). check-in: 39f708d1 user: drh tags: trunk
13:02
Convert a branch made unreachable by [59560d07] into an assert(). check-in: 2738b8db user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  4533   4533     /* Special case: No FROM clause
  4534   4534     */
  4535   4535     if( nTabList==0 ){
  4536   4536       if( pOrderBy ) pWInfo->nOBSat = pOrderBy->nExpr;
  4537   4537       if( wctrlFlags & WHERE_WANT_DISTINCT ){
  4538   4538         pWInfo->eDistinct = WHERE_DISTINCT_UNIQUE;
  4539   4539       }
  4540         -  }
  4541         -
  4542         -  /* Assign a bit from the bitmask to every term in the FROM clause.
  4543         -  **
  4544         -  ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
  4545         -  **
  4546         -  ** The rule of the previous sentence ensures thta if X is the bitmask for
  4547         -  ** a table T, then X-1 is the bitmask for all other tables to the left of T.
  4548         -  ** Knowing the bitmask for all tables to the left of a left join is
  4549         -  ** important.  Ticket #3015.
  4550         -  **
  4551         -  ** Note that bitmasks are created for all pTabList->nSrc tables in
  4552         -  ** pTabList, not just the first nTabList tables.  nTabList is normally
  4553         -  ** equal to pTabList->nSrc but might be shortened to 1 if the
  4554         -  ** WHERE_OR_SUBCLAUSE flag is set.
  4555         -  */
  4556         -  for(ii=0; ii<pTabList->nSrc; ii++){
  4557         -    createMask(pMaskSet, pTabList->a[ii].iCursor);
  4558         -    sqlite3WhereTabFuncArgs(pParse, &pTabList->a[ii], &pWInfo->sWC);
  4559         -  }
  4560         -#ifdef SQLITE_DEBUG
  4561         -  {
  4562         -    Bitmask mx = 0;
  4563         -    for(ii=0; ii<pTabList->nSrc; ii++){
  4564         -      Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
  4565         -      assert( m>=mx );
  4566         -      mx = m;
  4567         -    }
  4568         -  }
  4569         -#endif
  4570         -
         4540  +  }else{
         4541  +    /* Assign a bit from the bitmask to every term in the FROM clause.
         4542  +    **
         4543  +    ** The N-th term of the FROM clause is assigned a bitmask of 1<<N.
         4544  +    **
         4545  +    ** The rule of the previous sentence ensures thta if X is the bitmask for
         4546  +    ** a table T, then X-1 is the bitmask for all other tables to the left of T.
         4547  +    ** Knowing the bitmask for all tables to the left of a left join is
         4548  +    ** important.  Ticket #3015.
         4549  +    **
         4550  +    ** Note that bitmasks are created for all pTabList->nSrc tables in
         4551  +    ** pTabList, not just the first nTabList tables.  nTabList is normally
         4552  +    ** equal to pTabList->nSrc but might be shortened to 1 if the
         4553  +    ** WHERE_OR_SUBCLAUSE flag is set.
         4554  +    */
         4555  +    ii = 0;
         4556  +    do{
         4557  +      createMask(pMaskSet, pTabList->a[ii].iCursor);
         4558  +      sqlite3WhereTabFuncArgs(pParse, &pTabList->a[ii], &pWInfo->sWC);
         4559  +    }while( (++ii)<pTabList->nSrc );
         4560  +  #ifdef SQLITE_DEBUG
         4561  +    {
         4562  +      Bitmask mx = 0;
         4563  +      for(ii=0; ii<pTabList->nSrc; ii++){
         4564  +        Bitmask m = sqlite3WhereGetMask(pMaskSet, pTabList->a[ii].iCursor);
         4565  +        assert( m>=mx );
         4566  +        mx = m;
         4567  +      }
         4568  +    }
         4569  +  #endif
         4570  +  }
         4571  +  
  4571   4572     /* Analyze all of the subexpressions. */
  4572   4573     sqlite3WhereExprAnalyze(pTabList, &pWInfo->sWC);
  4573   4574     if( db->mallocFailed ) goto whereBeginError;
  4574   4575   
  4575   4576     /* Special case: WHERE terms that do not refer to any tables in the join
  4576   4577     ** (constant expressions). Evaluate each such term, and jump over all the
  4577   4578     ** generated code if the result is not true.