1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-11 01:42:22 +03:00

Do not use a co-routine on a subquery that is participating in a self-join.

FossilOrigin-Name: ea4306a03cd8dd706100dac3f11653068a25c50c5d06c34ad08534aec0a580bc
This commit is contained in:
drh
2022-12-08 13:56:06 +00:00
parent 619ff3f505
commit 05cb9d881e
3 changed files with 22 additions and 13 deletions

View File

@@ -1,5 +1,5 @@
C Merge\sthe\slatest\sfixes\sand\senhancements\sfrom\strunk\sinto\sthe\ncoroutines-exp2\sbranch.
D 2022-12-07T21:19:37.022
C Do\snot\suse\sa\sco-routine\son\sa\ssubquery\sthat\sis\sparticipating\sin\sa\sself-join.
D 2022-12-08T13:56:06.070
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -645,7 +645,7 @@ F src/printf.c e99ee9741e79ae3873458146f59644276657340385ade4e76a5f5d1c25793764
F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c efea4e5fbecfd6d0a9071b0be0d952620991673391b6ffaaf4c277b0bb674633
F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
F src/select.c cbb0ce95039273f436cdad9308251ab3affd69482fd9927495e1c37875afeeb1
F src/select.c 02982768da5a6115a95e2a23778260bb70de326648f4ac72df4b25808b6a9840
F src/shell.c.in bcf8552c82f2c84650e39a6d638373569c2035942c0497b83eef197169e0305a
F src/sqlite.h.in 1fe1836879ecbb2e28f00f44eb6092db09a2a06bf072af351c6c2466bd515496
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
@@ -2067,8 +2067,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P e2318a30bf6ad2aeb4c4cb29661bc24ff78eb51bf07decc4b8da1ecac0015ef0 212927e97e7be7d237de08359dce0dfb9211ac406b32009a6e15afd79c006475
R 595e9e236a565d9694fd65430bde0de2
P 1c5f41986f5af181bf389675361c9f176e9195e847319f07ebd5c87992ded38b
R 849bd6889c31d0dff4fc6b0e1b1e8fd9
U drh
Z 74db0241280ec72e600d83e58941c231
Z 23e16e45b1613dcb72a8da9bb4a744cf
# Remove this line to create a well-formed Fossil manifest.

View File

@@ -1 +1 @@
1c5f41986f5af181bf389675361c9f176e9195e847319f07ebd5c87992ded38b
ea4306a03cd8dd706100dac3f11653068a25c50c5d06c34ad08534aec0a580bc

View File

@@ -6697,18 +6697,23 @@ static void havingToWhere(Parse *pParse, Select *p){
}
/*
** Check to see if the pThis entry of pTabList is a self-join of a prior view.
** If it is, then return the SrcItem for the prior view. If it is not,
** then return 0.
** Check to see if the pThis entry of pTabList is a self-join of another view.
** Search FROM-clause entries in the range of iFirst..iEnd, including iFirst
** but stopping before iEnd.
**
** If pThis is a self-join, then return the SrcItem for the first other
** instance of that view found. If pThis is not a self-join then return 0.
*/
static SrcItem *isSelfJoinView(
SrcList *pTabList, /* Search for self-joins in this FROM clause */
SrcItem *pThis /* Search for prior reference to this subquery */
SrcItem *pThis, /* Search for prior reference to this subquery */
int iFirst, int iEnd /* Range of FROM-clause entries to search. */
){
SrcItem *pItem;
assert( pThis->pSelect!=0 );
if( pThis->pSelect->selFlags & SF_PushDown ) return 0;
for(pItem = pTabList->a; pItem<pThis; pItem++){
while( iFirst<iEnd ){
pItem = &pTabList->a[iFirst++];
Select *pS1;
if( pItem->pSelect==0 ) continue;
if( pItem->fg.viaCoroutine ) continue;
@@ -6873,6 +6878,7 @@ static int sameSrcAlias(SrcItem *p0, SrcList *pSrc){
** (2) The subquery is not a CTE that should be materialized
** (3) The subquery is not part of a left operand for a RIGHT JOIN
** (4) The SQLITE_Coroutine optimization disable flag is not set
** (5) The subquery is not self-joined
*/
static int fromClauseTermCanBeCoroutine(
Parse *pParse, /* Parsing context */
@@ -6883,6 +6889,9 @@ static int fromClauseTermCanBeCoroutine(
if( pItem->fg.isCte && pItem->u2.pCteUse->eM10d==M10d_Yes ) return 0;/* (2) */
if( pTabList->a[0].fg.jointype & JT_LTORJ ) return 0; /* (3) */
if( OptimizationDisabled(pParse->db, SQLITE_Coroutines) ) return 0; /* (4) */
if( isSelfJoinView(pTabList, pItem, i+1, pTabList->nSrc)!=0 ){
return 0; /* (5) */
}
if( i==0 ){
if( pTabList->nSrc==1 ) return 1; /* (1a-i) */
if( pTabList->a[1].fg.jointype & JT_CROSS ) return 1; /* (1a-ii) */
@@ -7319,7 +7328,7 @@ int sqlite3Select(
VdbeComment((v, "%!S", pItem));
}
pSub->nSelectRow = pCteUse->nRowEst;
}else if( (pPrior = isSelfJoinView(pTabList, pItem))!=0 ){
}else if( (pPrior = isSelfJoinView(pTabList, pItem, 0, i))!=0 ){
/* This view has already been materialized by a prior entry in
** this same FROM clause. Reuse it. */
if( pPrior->addrFillSub ){