SQLite

Check-in [24a2e9ddce]
Login

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

Overview
Comment:Improvements to the ORDER BY suppressor in the NGQP.
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | nextgen-query-plan-exp
Files: files | file ages | folders
SHA1: 24a2e9ddcecd3926817d77abbb75d068ee7140ad
User & Date: drh 2013-05-30 23:21:20.132
Context
2013-05-31
11:57
Fix the constructAutomaticIndex() routine so that it works with NGQP. (check-in: 5e1e613995 user: drh tags: nextgen-query-plan-exp)
2013-05-30
23:21
Improvements to the ORDER BY suppressor in the NGQP. (check-in: 24a2e9ddce user: drh tags: nextgen-query-plan-exp)
22:27
Incremental check-in with various NGQP fixes. Many tests still fail. (check-in: a51d8c9249 user: drh tags: nextgen-query-plan-exp)
Changes
Unified Diff Show Whitespace Changes Patch
Changes to src/where.c.
4584
4585
4586
4587
4588
4589
4590

4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604

4605
4606
4607
4608
4609
4610
4611
4612

4613


4614
4615
4616
4617
4618
4619
4620

4621
4622
4623
4624
4625
4626
4627
    }
    if( !isUnique && requireUnique ) return 0;
    requireUnique = !isUnique;
    iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
    j = 0;
    revSet = rev = 0;
    for(j=0; j<=nColumn && nUsed<nOrderBy; j++, nUsed++){

      pOBExpr = sqlite3ExprSkipCollate(pOrderBy->a[nUsed].pExpr);
      assert( pOBExpr->op==TK_COLUMN );
      if( pOBExpr->iTable!=iCur ) break;
      if( isUnique ) continue;
      if( j<nColumn ){
        /* Normal index columns */
        iColumn = pIndex->aiColumn[j];
        revIdx = pIndex->aSortOrder[j];
        if( iColumn==pIndex->pTable->iPKey ) iColumn = -1;
      }else{
        /* The ROWID column at the end */
        iColumn = -1;
        revIdx = 0;
      }

      if( pOBExpr->iColumn!=iColumn ){
        if( j<pLoop->u.btree.nEq ){ nUsed--; continue; }
        return 0;
      }
      if( iColumn>=0 ){
        pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[nUsed].pExpr);
        if( !pColl ) pColl = db->pDfltColl;
        if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ) return 0;

      }


      if( revSet ){
        if( (rev ^ revIdx)!=pOrderBy->a[nUsed].sortOrder ) return 0;
      }else{
        rev = revIdx ^ pOrderBy->a[nUsed].sortOrder;
        revSet = 1;
      }
    }

    if( rev ) revMask |= ((Bitmask)1)<<i;
  }
  if( nUsed==nOrderBy ){
    *pRevMask = revMask;
    return 1;
  }
  return -1;







>














>

|





|
>

>
>







>







4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
    }
    if( !isUnique && requireUnique ) return 0;
    requireUnique = !isUnique;
    iCur = pWInfo->pTabList->a[pLoop->iTab].iCursor;
    j = 0;
    revSet = rev = 0;
    for(j=0; j<=nColumn && nUsed<nOrderBy; j++, nUsed++){
      int skipable;
      pOBExpr = sqlite3ExprSkipCollate(pOrderBy->a[nUsed].pExpr);
      assert( pOBExpr->op==TK_COLUMN );
      if( pOBExpr->iTable!=iCur ) break;
      if( isUnique ) continue;
      if( j<nColumn ){
        /* Normal index columns */
        iColumn = pIndex->aiColumn[j];
        revIdx = pIndex->aSortOrder[j];
        if( iColumn==pIndex->pTable->iPKey ) iColumn = -1;
      }else{
        /* The ROWID column at the end */
        iColumn = -1;
        revIdx = 0;
      }
      skipable = j<pLoop->u.btree.nEq && pLoop->aTerm[j]->eOperator!=WO_IN;
      if( pOBExpr->iColumn!=iColumn ){
        if( skipable ){ nUsed--; continue; }
        return 0;
      }
      if( iColumn>=0 ){
        pColl = sqlite3ExprCollSeq(pWInfo->pParse, pOrderBy->a[nUsed].pExpr);
        if( !pColl ) pColl = db->pDfltColl;
        if( sqlite3StrICmp(pColl->zName, pIndex->azColl[j])!=0 ){
          return 0;
      }
      }
      if( !skipable ){
      if( revSet ){
        if( (rev ^ revIdx)!=pOrderBy->a[nUsed].sortOrder ) return 0;
      }else{
        rev = revIdx ^ pOrderBy->a[nUsed].sortOrder;
        revSet = 1;
      }
    }
    }
    if( rev ) revMask |= ((Bitmask)1)<<i;
  }
  if( nUsed==nOrderBy ){
    *pRevMask = revMask;
    return 1;
  }
  return -1;