Small simplification to the query flattener logic.

FossilOrigin-Name: cbfe3f0c84eecef4308e1904cce4fe013ee1986ab6c85e82f92736fc80c0a358
This commit is contained in:
drh
2025-08-23 18:18:03 +00:00
3 changed files with 12 additions and 16 deletions
+7 -6
View File
@@ -1,5 +1,5 @@
C Fix\scksumvfs\stest\scase\sadded\sby\s[e3bd1feccaee8ff2]\sso\sthat\sit\sworks\nwith\svarying\spage\ssizes.\s\sTest\scase\schange\sonly\s-\sno\schanges\sto\scode.
D 2025-08-23T11:09:53.644
C Small\ssimplification\sto\sthe\squery\sflattener\slogic.
D 2025-08-23T18:18:03.949
F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
@@ -741,7 +741,7 @@ F src/printf.c 5f0c957af9699e849d786e8fbaa3baab648ca5612230dc17916434c14bc8698f
F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c f8d1d011aba0964ff1bdccd049d4d2c2fec217efd90d202a4bb775e926b2c25d
F src/rowset.c 8432130e6c344b3401a8874c3cb49fefe6873fec593294de077afea2dce5ec97
F src/select.c 5cf61d7633a0f94772f8b06484f23745d7dcd58ef8eabe944d0cc4c8bd06d235
F src/select.c 62855ca3335dfb1fec366b5b646a9e98bd920aa4d6499698d74520cec08986a6
F src/shell.c.in 0636915df0dbac6c780f04959f5d1055f206fb281b2c8fc8b113fe7bfc7d44ef
F src/sqlite.h.in ebfc0358de0e18aabee7fa918f2f846894e23bebc74160fbe265c99046ee61b8
F src/sqlite3.rc 015537e6ac1eec6c7050e17b616c2ffe6f70fca241835a84a4f0d5937383c479
@@ -2169,8 +2169,9 @@ F tool/version-info.c 3b36468a90faf1bbd59c65fd0eb66522d9f941eedd364fabccd7227350
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
F tool/warnings.sh 1ad0169b022b280bcaaf94a7fa231591be96b514230ab5c98fbf15cd7df842dd
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
P a4107c947c03ed48de3ab3f516cec8a3c092cec8ee19145fb564152e5cd16c85
R 7bb8ae11370c4eb3328c3ab20cdb528a
P b6f8f086dacd11f57bdb0eef79f25bce209816a0748f16009372c62dc3edd5ae 953ea637d51192a6fb9c2ae84e097ae14e8a9c7fa7c98db90a39819b5f97f60e
R 28e8a355765b7de9dedf350dc172fb64
T +closed 953ea637d51192a6fb9c2ae84e097ae14e8a9c7fa7c98db90a39819b5f97f60e
U drh
Z 51b73666e6bb82bd74288a44304c3efe
Z d899009af7c6cd5eeaf562d9512dda24
# Remove this line to create a well-formed Fossil manifest.
+1 -1
View File
@@ -1 +1 @@
b6f8f086dacd11f57bdb0eef79f25bce209816a0748f16009372c62dc3edd5ae
cbfe3f0c84eecef4308e1904cce4fe013ee1986ab6c85e82f92736fc80c0a358
+4 -9
View File
@@ -4705,17 +4705,12 @@ static int flattenSubquery(
pSub = pSub1;
for(pParent=p; pParent; pParent=pParent->pPrior, pSub=pSub->pPrior){
int nSubSrc;
u8 jointype = 0;
u8 ltorj = pSrc->a[iFrom].fg.jointype & JT_LTORJ;
u8 jointype = pSubitem->fg.jointype;
assert( pSub!=0 );
pSubSrc = pSub->pSrc; /* FROM clause of subquery */
nSubSrc = pSubSrc->nSrc; /* Number of terms in subquery FROM clause */
pSrc = pParent->pSrc; /* FROM clause of the outer query */
if( pParent==p ){
jointype = pSubitem->fg.jointype; /* First time through the loop */
}
/* The subquery uses a single slot of the FROM clause of the outer
** query. If the subquery has more than one element in its FROM clause,
** then expand the outer query to make space for it to hold all elements
@@ -4735,6 +4730,7 @@ static int flattenSubquery(
pSrc = sqlite3SrcListEnlarge(pParse, pSrc, nSubSrc-1,iFrom+1);
if( pSrc==0 ) break;
pParent->pSrc = pSrc;
pSubitem = &pSrc->a[iFrom];
}
/* Transfer the FROM clause terms from the subquery into the
@@ -4749,11 +4745,10 @@ static int flattenSubquery(
|| pItem->u4.zDatabase==0 );
if( pItem->fg.isUsing ) sqlite3IdListDelete(db, pItem->u3.pUsing);
*pItem = pSubSrc->a[i];
pItem->fg.jointype |= ltorj;
pItem->fg.jointype |= (jointype & JT_LTORJ);
memset(&pSubSrc->a[i], 0, sizeof(pSubSrc->a[i]));
}
pSrc->a[iFrom].fg.jointype &= JT_LTORJ;
pSrc->a[iFrom].fg.jointype |= jointype | ltorj;
pSubitem->fg.jointype |= jointype;
/* Now begin substituting subquery result set expressions for
** references to the iParent in the outer query.