blob: 7277ec29a9015fa849428ab823d1ebf65e66c746 [file] [log] [blame]
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Victor Costan <pwnall@chromium.org>
Date: Fri, 11 Jan 2019 02:30:28 -0800
Subject: [PATCH 10/17] Fix a problem with nested CTEs with the same table.
This backports https://www.sqlite.org/src/info/202dd033019dd274
Bug: 917834
---
third_party/sqlite/src/src/select.c | 11 ++++++++---
1 file changed, 8 insertions(+), 3 deletions(-)
diff --git a/third_party/sqlite/src/src/select.c b/third_party/sqlite/src/src/select.c
index 870c3b5c1739..fab4df68fa17 100644
--- a/third_party/sqlite/src/src/select.c
+++ b/third_party/sqlite/src/src/select.c
@@ -5464,14 +5464,19 @@ static struct SrcList_item *isSelfJoinView(
){
struct SrcList_item *pItem;
for(pItem = pTabList->a; pItem<pThis; pItem++){
+ Select *pS1;
if( pItem->pSelect==0 ) continue;
if( pItem->fg.viaCoroutine ) continue;
if( pItem->zName==0 ) continue;
if( sqlite3_stricmp(pItem->zDatabase, pThis->zDatabase)!=0 ) continue;
if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue;
- if( sqlite3ExprCompare(0,
- pThis->pSelect->pWhere, pItem->pSelect->pWhere, -1)
- ){
+ pS1 = pItem->pSelect;
+ if( pThis->pSelect->selId!=pS1->selId ){
+ /* The query flattener left two different CTE tables with identical
+ ** names in the same FROM clause. */
+ continue;
+ }
+ if( sqlite3ExprCompare(0, pThis->pSelect->pWhere, pS1->pWhere, -1) ){
/* The view was modified by some other optimization such as
** pushDownWhereTerms() */
continue;
--
2.18.0