aboutsummaryrefslogtreecommitdiff
path: root/src/where.c
diff options
context:
space:
mode:
authordrh <>2023-08-02 13:29:01 +0000
committerdrh <>2023-08-02 13:29:01 +0000
commit26cf4af5d79775af5ebfb19c46ea9a71655916ef (patch)
tree6b607dc1daf6b9cda1590f5cc59c7c9b3906783f /src/where.c
parentaa250db66aed4ed8f969d61f05bc374aa8c2c2e6 (diff)
downloadsqlite-26cf4af5d79775af5ebfb19c46ea9a71655916ef.tar.gz
sqlite-26cf4af5d79775af5ebfb19c46ea9a71655916ef.zip
Remove a condition from query flattening that is now taken care of by
the caller. Factor out the reverse_unordered_selects processing from the main loop of sqlite3WhereBegin() for performance. FossilOrigin-Name: f068f105fb158634321bf6401f0774c81059932d213a18b627ae98bcffc10912
Diffstat (limited to 'src/where.c')
-rw-r--r--src/where.c42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/where.c b/src/where.c
index 9992b2053..213df4223 100644
--- a/src/where.c
+++ b/src/where.c
@@ -5759,6 +5759,28 @@ static SQLITE_NOINLINE void whereAddIndexedExpr(
}
/*
+** Set the reverse-scan order mask to one for all tables in the query
+** with the exception of MATERIALIZED common table expressions that have
+** their own internal ORDER BY clauses.
+**
+** This implements the PRAGMA reverse_unordered_selects=ON setting.
+** (Also SQLITE_DBCONFIG_REVERSE_SCANORDER).
+*/
+static SQLITE_NOINLINE void whereReverseScanOrder(WhereInfo *pWInfo){
+ int ii;
+ for(ii=0; ii<pWInfo->pTabList->nSrc; ii++){
+ SrcItem *pItem = &pWInfo->pTabList->a[ii];
+ if( !pItem->fg.isCte
+ || pItem->u2.pCteUse->eM10d!=M10d_Yes
+ || NEVER(pItem->pSelect==0)
+ || pItem->pSelect->pOrderBy==0
+ ){
+ pWInfo->revMask |= MASKBIT(ii);
+ }
+ }
+}
+
+/*
** Generate the beginning of the loop used for WHERE clause processing.
** The return value is a pointer to an opaque structure that contains
** information needed to terminate the loop. Later, the calling routine
@@ -6124,25 +6146,7 @@ WhereInfo *sqlite3WhereBegin(
}
assert( pWInfo->pTabList!=0 );
if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){
- for(ii=0; ii<pWInfo->pTabList->nSrc; ii++){
- /* The PRAGMA reverse_unordered_selects=ON setting (also accessible
- ** using SQLITE_DBCONFIG_REVERSE_SCANORDER) means to reverse the scan
- ** order for any table that is part of a query that does not have an
- ** ORDER BY clause.
- **
- ** Except, do not reverse the output from MATERIALIZED common table
- ** expression that has an internal ORDER BY clause, because a
- ** MATERIALIZED common table expression is an optimization fence.
- */
- SrcItem *pItem = &pWInfo->pTabList->a[ii];
- if( !pItem->fg.isCte
- || pItem->u2.pCteUse->eM10d!=M10d_Yes
- || NEVER(pItem->pSelect==0)
- || pItem->pSelect->pOrderBy==0
- ){
- pWInfo->revMask |= MASKBIT(ii);
- }
- }
+ whereReverseScanOrder(pWInfo);
}
if( pParse->nErr ){
goto whereBeginError;