mirror of
https://github.com/sqlite/sqlite.git
synced 2025-11-16 23:02:26 +03:00
Add the reverse_unordered_selects pragma. (CVS 6314)
FossilOrigin-Name: bc078e0007b6c3dc07722820bb53798b643212b3
This commit is contained in:
24
src/where.c
24
src/where.c
@@ -16,7 +16,7 @@
|
||||
** so is applicable. Because this module is responsible for selecting
|
||||
** indices, you might also think of this module as the "query optimizer".
|
||||
**
|
||||
** $Id: where.c,v 1.370 2009/02/20 10:58:42 danielk1977 Exp $
|
||||
** $Id: where.c,v 1.371 2009/02/23 16:52:08 drh Exp $
|
||||
*/
|
||||
#include "sqliteInt.h"
|
||||
|
||||
@@ -1837,7 +1837,15 @@ static void bestIndex(
|
||||
cost += cost*estLog(cost);
|
||||
WHERETRACE(("... sorting increases cost to %.9g\n", cost));
|
||||
}
|
||||
}else if( pParse->db->flags & SQLITE_ReverseOrder ){
|
||||
/* For application testing, randomly reverse the output order for
|
||||
** SELECT statements that omit the ORDER BY clause. This will help
|
||||
** to find cases where
|
||||
*/
|
||||
wsFlags |= WHERE_REVERSE;
|
||||
}
|
||||
|
||||
/* Remember this case if it is the best so far */
|
||||
if( cost<pCost->rCost ){
|
||||
pCost->rCost = cost;
|
||||
pCost->nRow = nRow;
|
||||
@@ -1987,6 +1995,12 @@ static void bestIndex(
|
||||
cost += cost*estLog(cost);
|
||||
WHERETRACE(("...... orderby increases cost to %.9g\n", cost));
|
||||
}
|
||||
}else if( pParse->db->flags & SQLITE_ReverseOrder ){
|
||||
/* For application testing, randomly reverse the output order for
|
||||
** SELECT statements that omit the ORDER BY clause. This will help
|
||||
** to find cases where
|
||||
*/
|
||||
wsFlags |= WHERE_REVERSE;
|
||||
}
|
||||
|
||||
/* Check to see if we can get away with using just the index without
|
||||
@@ -2747,11 +2761,13 @@ static Bitmask codeOneLoopStart(
|
||||
/* Case 5: There is no usable index. We must do a complete
|
||||
** scan of the entire table.
|
||||
*/
|
||||
static const u8 aStep[] = { OP_Next, OP_Prev };
|
||||
static const u8 aStart[] = { OP_Rewind, OP_Last };
|
||||
assert( bRev==0 || bRev==1 );
|
||||
assert( omitTable==0 );
|
||||
assert( bRev==0 );
|
||||
pLevel->op = OP_Next;
|
||||
pLevel->op = aStep[bRev];
|
||||
pLevel->p1 = iCur;
|
||||
pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, OP_Rewind, iCur, addrBrk);
|
||||
pLevel->p2 = 1 + sqlite3VdbeAddOp2(v, aStart[bRev], iCur, addrBrk);
|
||||
pLevel->p5 = SQLITE_STMTSTATUS_FULLSCAN_STEP;
|
||||
codeRowSetEarly = 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user