/ Check-in [a33f88ac]
Login

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

Overview
Comment:An experimental optimization to DISTINCT that causes an immediate exit of the inner loop of a join following each output row if the inner loop does not contribute any columns to the result set.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | distinct-early-out
Files: files | file ages | folders
SHA3-256: a33f88acd7e02361fac1874c71dae1dbfc78bc578b0181bd488a6a735ea5a453
User & Date: drh 2017-11-21 23:47:42
Context
2017-11-21
23:47
An experimental optimization to DISTINCT that causes an immediate exit of the inner loop of a join following each output row if the inner loop does not contribute any columns to the result set. Leaf check-in: a33f88ac user: drh tags: distinct-early-out
23:38
Fix the skip-ahead-distinct optimization on joins for cases there the table in the inner loop of the join does not contribute any columns to the result set. Proposed fix for ticket [ef9318757b152e3a2] check-in: 2dcef5a9 user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/where.c.

4943
4944
4945
4946
4947
4948
4949


















4950
4951
4952
4953
4954
4955
4956
  Parse *pParse = pWInfo->pParse;
  Vdbe *v = pParse->pVdbe;
  int i;
  WhereLevel *pLevel;
  WhereLoop *pLoop;
  SrcList *pTabList = pWInfo->pTabList;
  sqlite3 *db = pParse->db;



















  /* Generate loop termination code.
  */
  VdbeModuleComment((v, "End WHERE-core"));
  sqlite3ExprCacheClear(pParse);
  for(i=pWInfo->nLevel-1; i>=0; i--){
    int addr;







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
  Parse *pParse = pWInfo->pParse;
  Vdbe *v = pParse->pVdbe;
  int i;
  WhereLevel *pLevel;
  WhereLoop *pLoop;
  SrcList *pTabList = pWInfo->pTabList;
  sqlite3 *db = pParse->db;

  /* For a DISTINCT join in which no columns of inner loops appear in
  ** the result set, put a jump right after the inner loop body that
  ** causes the unused inner loops to exit.
  */
  if( pWInfo->eDistinct==WHERE_DISTINCT_ORDERED
   && pWInfo->nLevel>1
  ){
    Bitmask tabUsed;
    tabUsed = sqlite3WhereExprListUsage(&pWInfo->sMaskSet, pWInfo->pResultSet);
    for(i=pWInfo->nLevel-1; i>=0; i--){
      pLoop = pWInfo->a[i].pWLoop;
      if( (tabUsed & pLoop->maskSelf)!=0 ) break;
    }
    if( i<pWInfo->nLevel-1 ){
      sqlite3VdbeGoto(v, pWInfo->a[i].addrCont);
    }
  }

  /* Generate loop termination code.
  */
  VdbeModuleComment((v, "End WHERE-core"));
  sqlite3ExprCacheClear(pParse);
  for(i=pWInfo->nLevel-1; i>=0; i--){
    int addr;