aboutsummaryrefslogtreecommitdiff
path: root/src/select.c
diff options
context:
space:
mode:
authordrh <>2022-04-18 23:20:02 +0000
committerdrh <>2022-04-18 23:20:02 +0000
commit1c2bf41a12cc6101d99fb95732559f98d3981c39 (patch)
treed00145361431001e8e48c33da0bf0b27df1ccdf2 /src/select.c
parentec39c96473ab8607cf47d32d6c9e72f653c781d5 (diff)
downloadsqlite-1c2bf41a12cc6101d99fb95732559f98d3981c39.tar.gz
sqlite-1c2bf41a12cc6101d99fb95732559f98d3981c39.zip
Fix the query flattener so that it does not flatten a RIGHT or FULL JOIN into
any position of the outer query other than the first. FossilOrigin-Name: 837322aa95b1c46201b7dd0c2e6c7b9915b4276d997949f1ecf961fb7f3514cf
Diffstat (limited to 'src/select.c')
-rw-r--r--src/select.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/select.c b/src/select.c
index 6d185a168..d65719e0a 100644
--- a/src/select.c
+++ b/src/select.c
@@ -4122,6 +4122,9 @@ static void renumberCursors(
** (26) The subquery may not be the right operand of a RIGHT JOIN.
** See also (3) for restrictions on LEFT JOIN.
**
+** (27) The subquery may not contain a FULL or RIGHT JOIN unless it
+** is the first element of the parent query.
+**
**
** In this routine, the "p" parameter is a pointer to the outer query.
** The subquery is p->pSrc->a[iFrom]. isAgg is true if the outer query
@@ -4241,6 +4244,11 @@ static int flattenSubquery(
}
#endif
+ assert( pSubSrc->nSrc>0 ); /* True by restriction (7) */
+ if( iFrom>0 && (pSubSrc->a[0].fg.jointype & JT_LTORJ)!=0 ){
+ return 0; /* Restriction (27) */
+ }
+
/* Restriction (17): If the sub-query is a compound SELECT, then it must
** use only the UNION ALL operator. And none of the simple select queries
** that make up the compound SELECT are allowed to be aggregate or distinct