diff options
author | drh <> | 2023-02-16 15:54:55 +0000 |
---|---|---|
committer | drh <> | 2023-02-16 15:54:55 +0000 |
commit | 90b7af77152f2b39ee3de40777487862a83597f3 (patch) | |
tree | dd9cda558e335438ac8b688ba91f10b4d41d042c /src | |
parent | 6945ba787f11eb165ec9f25c359b4c91993643a5 (diff) | |
download | sqlite-90b7af77152f2b39ee3de40777487862a83597f3.tar.gz sqlite-90b7af77152f2b39ee3de40777487862a83597f3.zip |
Do not perform the omit-unused-subquery-columns optimizations on a
subquery that is DISTINCT, as that can lead to incorrect results.
FossilOrigin-Name: cc148503db8ef180bce984328da7e84959afadd6a9613c2d03bc1eafeb95dfad
Diffstat (limited to 'src')
-rw-r--r-- | src/select.c | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/src/select.c b/src/select.c index dc187dfa6..ae320b697 100644 --- a/src/select.c +++ b/src/select.c @@ -5253,10 +5253,15 @@ static int disableUnusedSubqueryResultColumns(SrcItem *pItem){ assert( pItem!=0 ); assert( pItem->pTab!=0 ); pTab = pItem->pTab; - if( pTab->tabFlags & TF_Ephemeral ) return 0; + if( pTab->tabFlags & TF_Ephemeral ){ + return 0; + } assert( pItem->pSelect!=0 ); pSub = pItem->pSelect; assert( pSub->pEList->nExpr==pTab->nCol ); + if( pSub->selFlags & SF_Distinct ){ + return 0; + } for(pX=pSub; pX; pX=pX->pPrior){ if( pX->pPrior && pX->op!=TK_ALL ){ /* This optimization does not work for compound subqueries that |