/ Check-in [71e9ae72]
Login

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

Overview
Comment:Merge the OFFSET-on-query-without-FROM fix from trunk.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | orderby-planning
Files: files | file ages | folders
SHA1: 71e9ae72c272dc86720b2bfe719f57de437c400b
User & Date: drh 2014-03-21 18:45:19
Context
2014-03-23
17:45
Use only a single OP_MakeRecord instead of two when constructing entries to go onto a sorter. check-in: d696cded user: drh tags: orderby-planning
2014-03-21
20:58
Add the ability to use indices for the first few terms of an ORDER BY clause, then sort in batches to handle the later terms. check-in: fa06a6fe user: drh tags: trunk
18:45
Merge the OFFSET-on-query-without-FROM fix from trunk. check-in: 71e9ae72 user: drh tags: orderby-planning
18:16
Fix the OFFSET clause so that it works correctly on queries that lack a FROM clause. Ticket [07d6a0453d4ed8]. check-in: 179ef816 user: drh tags: trunk
15:24
New test case for block-sorting. check-in: e70cfa28 user: drh tags: orderby-planning
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/select.c.

   533    533   ** Add code to implement the OFFSET
   534    534   */
   535    535   static void codeOffset(
   536    536     Vdbe *v,          /* Generate code into this VM */
   537    537     int iOffset,      /* Register holding the offset counter */
   538    538     int iContinue     /* Jump here to skip the current record */
   539    539   ){
   540         -  if( iOffset>0 && iContinue!=0 ){
          540  +  if( iOffset>0 ){
   541    541       int addr;
   542    542       sqlite3VdbeAddOp2(v, OP_AddImm, iOffset, -1);
   543    543       addr = sqlite3VdbeAddOp1(v, OP_IfNeg, iOffset); VdbeCoverage(v);
   544    544       sqlite3VdbeAddOp2(v, OP_Goto, 0, iContinue);
   545    545       VdbeComment((v, "skip OFFSET records"));
   546    546       sqlite3VdbeJumpHere(v, addr);
   547    547     }
................................................................................
   627    627     int nResultCol;             /* Number of result columns */
   628    628   
   629    629     assert( v );
   630    630     assert( pEList!=0 );
   631    631     hasDistinct = pDistinct ? pDistinct->eTnctType : WHERE_DISTINCT_NOOP;
   632    632     if( pSort && pSort->pOrderBy==0 ) pSort = 0;
   633    633     if( pSort==0 && !hasDistinct ){
          634  +    assert( iContinue!=0 );
   634    635       codeOffset(v, p->iOffset, iContinue);
   635    636     }
   636    637   
   637    638     /* Pull the requested columns.
   638    639     */
   639    640     nResultCol = pEList->nExpr;
   640    641   

Changes to src/where.c.

    43     43   }
    44     44   
    45     45   /*
    46     46   ** Return the VDBE address or label to jump to in order to continue
    47     47   ** immediately with the next row of a WHERE clause.
    48     48   */
    49     49   int sqlite3WhereContinueLabel(WhereInfo *pWInfo){
           50  +  assert( pWInfo->iContinue!=0 );
    50     51     return pWInfo->iContinue;
    51     52   }
    52     53   
    53     54   /*
    54     55   ** Return the VDBE address or label to jump to in order to break
    55     56   ** out of a WHERE loop.
    56     57   */
................................................................................
  5467   5468     }
  5468   5469     pWInfo->aiCurOnePass[0] = pWInfo->aiCurOnePass[1] = -1;
  5469   5470     pWInfo->nLevel = nTabList;
  5470   5471     pWInfo->pParse = pParse;
  5471   5472     pWInfo->pTabList = pTabList;
  5472   5473     pWInfo->pOrderBy = pOrderBy;
  5473   5474     pWInfo->pResultSet = pResultSet;
  5474         -  pWInfo->iBreak = sqlite3VdbeMakeLabel(v);
         5475  +  pWInfo->iBreak = pWInfo->iContinue = sqlite3VdbeMakeLabel(v);
  5475   5476     pWInfo->wctrlFlags = wctrlFlags;
  5476   5477     pWInfo->savedNQueryLoop = pParse->nQueryLoop;
  5477   5478     pMaskSet = &pWInfo->sMaskSet;
  5478   5479     sWLB.pWInfo = pWInfo;
  5479   5480     sWLB.pWC = &pWInfo->sWC;
  5480   5481     sWLB.pNew = (WhereLoop*)(((char*)pWInfo)+nByteWInfo);
  5481   5482     assert( EIGHT_BYTE_ALIGNMENT(sWLB.pNew) );

Changes to test/limit.test.

   611    611   } {32}
   612    612   do_test limit-13.72 {
   613    613     db eval {SELECT z FROM v13c LIMIT 2 OFFSET 7}
   614    614   } {32}
   615    615   do_test limit-13.81 {
   616    616     db eval {SELECT z FROM v13c LIMIT 1 OFFSET 8}
   617    617   } {}
          618  +
          619  +do_execsql_test limit-14.1 {
          620  +  SELECT 123 LIMIT 1 OFFSET 0
          621  +} {123}
          622  +do_execsql_test limit-14.2 {
          623  +  SELECT 123 LIMIT 1 OFFSET 1
          624  +} {}
          625  +do_execsql_test limit-14.3 {
          626  +  SELECT 123 LIMIT 0 OFFSET 0
          627  +} {}
          628  +do_execsql_test limit-14.4 {
          629  +  SELECT 123 LIMIT 0 OFFSET 1
          630  +} {}
          631  +do_execsql_test limit-14.6 {
          632  +  SELECT 123 LIMIT -1 OFFSET 0
          633  +} {123}
          634  +do_execsql_test limit-14.7 {
          635  +  SELECT 123 LIMIT -1 OFFSET 1
          636  +} {}
          637  +
   618    638   
   619    639   finish_test