diff options
author | drh <> | 2023-09-15 19:00:47 +0000 |
---|---|---|
committer | drh <> | 2023-09-15 19:00:47 +0000 |
commit | c09701db9b7c63fe10f8cc2e8ef89ec33b28351e (patch) | |
tree | 56e5e5e35289ce41017ce480174b44d643f19b30 /src | |
parent | 20220d4682c0d22a36ad5eb19a6a15f92b6a85c3 (diff) | |
download | sqlite-c09701db9b7c63fe10f8cc2e8ef89ec33b28351e.tar.gz sqlite-c09701db9b7c63fe10f8cc2e8ef89ec33b28351e.zip |
Do not reduce subquery output row count estimates due to DISTINCT until
after the decision of whether or not to use an index for ORDER BY has been
made.
FossilOrigin-Name: 27390051e86ad86fb35219329d359be9e83073f59782631af7fc519225e10565
Diffstat (limited to 'src')
-rw-r--r-- | src/where.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/where.c b/src/where.c index 79ec7f690..c10ab27a8 100644 --- a/src/where.c +++ b/src/where.c @@ -5353,15 +5353,6 @@ static int wherePathSolver(WhereInfo *pWInfo, LogEst nRowEst){ pWInfo->nRowOut = pFrom->nRow; - /* TUNING: Assume that a DISTINCT clause on a subquery reduces - ** the output size by a factor of 8 (LogEst -30) - */ - if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0 - && pWInfo->nRowOut>30 - ){ - pWInfo->nRowOut -= 30; - } - /* Free temporary memory and return success */ sqlite3StackFreeNN(pParse->db, pSpace); return SQLITE_OK; @@ -6141,6 +6132,18 @@ WhereInfo *sqlite3WhereBegin( wherePathSolver(pWInfo, pWInfo->nRowOut+1); if( db->mallocFailed ) goto whereBeginError; } + + /* TUNING: Assume that a DISTINCT clause on a subquery reduces + ** the output size by a factor of 8 (LogEst -30) + */ + if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0 + && pWInfo->nRowOut>=40 + ){ + WHERETRACE(0x0080,("nRowOut reduced from %d to %d due to DISTINCT\n", + pWInfo->nRowOut, pWInfo->nRowOut-30)); + pWInfo->nRowOut -= 30; + } + } assert( pWInfo->pTabList!=0 ); if( pWInfo->pOrderBy==0 && (db->flags & SQLITE_ReverseOrder)!=0 ){ |