1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Improved estimate on the number of output rows in a recursive common table expression

that uses the UNION operator.  Follow-up to [f911f1c4977fbcae] and it's output row
estimate changes associated with DISTINCT queries.

FossilOrigin-Name: 92513f6bce7ecc778e78af3a77bc66ff65585fffa2e3138f8acb9e617121eeb0
This commit is contained in:
drh
2025-04-14 19:43:30 +00:00
parent c801f8954e
commit 483e1181c5
5 changed files with 56 additions and 11 deletions

View File

@@ -8119,6 +8119,12 @@ int sqlite3Select(
if( pWInfo==0 ) goto select_end;
if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
if( pDest->eDest<=SRT_DistQueue && pDest->eDest>=SRT_DistFifo ){
/* TUNING: For a UNION CTE, because UNION is implies DISTINCT,
** reduce the estimated output row count by 8 (LogEst 30).
** Search for tag-20250414a to see other cases */
p->nSelectRow -= 30;
}
}
if( sDistinct.isTnct && sqlite3WhereIsDistinct(pWInfo) ){
sDistinct.eTnctType = sqlite3WhereIsDistinct(pWInfo);

View File

@@ -6934,7 +6934,8 @@ WhereInfo *sqlite3WhereBegin(
}
/* TUNING: Assume that a DISTINCT clause on a subquery reduces
** the output size by a factor of 8 (LogEst -30).
** the output size by a factor of 8 (LogEst -30). Search for
** tag-20250414a to see other cases.
*/
if( (pWInfo->wctrlFlags & WHERE_WANT_DISTINCT)!=0 ){
WHERETRACE(0x0080,("nRowOut reduced from %d to %d due to DISTINCT\n",