From 30ad79aeb4cc1243817fdb3c1b0b51a61bbb5f97 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 23 May 2019 16:38:12 +0000 Subject: [PATCH] Improvements to the view-self-join optimization so that it works on all VIEWs, not just on Common Table Expressions. FossilOrigin-Name: d2fe370cafa9b11f6c3eb4e1c3be48d9d2610b9d2f9d9ebf9e50267f9079dfc0 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/select.c | 6 ++++-- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index e1237164ab..5907ed3bd6 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C New\stest\scase\sfor\scheck-in\s[74ef97bf51dd531a]\sthat\stakes\sthe\sfix\sin\sthe\nprevious\scheck-in\sinto\saccount. -D 2019-05-22T23:12:10.524 +C Improvements\sto\sthe\sview-self-join\soptimization\sso\sthat\sit\sworks\son\sall\nVIEWs,\snot\sjust\son\sCommon\sTable\sExpressions. +D 2019-05-23T16:38:12.291 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -522,7 +522,7 @@ F src/printf.c 67f79227273a9009d86a017619717c3f554f50b371294526da59faa6014ed2cd F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c bae0a7562db77b02d87101b587819d5a5dcd8625e477d2d8a228a20bba4fead6 F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93 -F src/select.c 2db13eac09ac2d45b2cfd5dd106d6b9b02fe413db7240731868d55467e981b85 +F src/select.c ccd314a204ef27edadeb58faebc7ded1f967fa83d6b9b858cd422c80ef171643 F src/shell.c.in 6c992809abf20dbb4aad89299d7c15c98ddf2504b23c83ef71eb435ad392cdc3 F src/sqlite.h.in d19c873a17c2effd4417f687fad942b6cc0ab0c64535f669cc2f22a5b05db23b F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 @@ -1828,7 +1828,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P 3cacc4b940fd69776d930deec9512df47a2f22cb04fb955e354a0b25bdec287c -R 9415bbe96dbbe5c29fbec91ac0d8e5a5 +P cb1d06521de5918a2324a41e207b48c5e5149c23b927b9e3e1f3c3b38b82658e +R bc0be58ed799178a68209379d96c86c1 U drh -Z 5378cd632ce316a4e0992ab00bf33b67 +Z c15a1e523efaaf6901adea2e440922c6 diff --git a/manifest.uuid b/manifest.uuid index a214271817..4bbfe56d5b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -cb1d06521de5918a2324a41e207b48c5e5149c23b927b9e3e1f3c3b38b82658e \ No newline at end of file +d2fe370cafa9b11f6c3eb4e1c3be48d9d2610b9d2f9d9ebf9e50267f9079dfc0 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 6e20430c08..b421b0fcff 100644 --- a/src/select.c +++ b/src/select.c @@ -5481,10 +5481,12 @@ static struct SrcList_item *isSelfJoinView( if( pItem->pSelect==0 ) continue; if( pItem->fg.viaCoroutine ) continue; if( pItem->zName==0 ) continue; - if( sqlite3_stricmp(pItem->zDatabase, pThis->zDatabase)!=0 ) continue; + assert( pItem->pTab!=0 ); + assert( pThis->pTab!=0 ); + if( pItem->pTab->pSchema!=pThis->pTab->pSchema ) continue; if( sqlite3_stricmp(pItem->zName, pThis->zName)!=0 ) continue; pS1 = pItem->pSelect; - if( pThis->pSelect->selId!=pS1->selId ){ + if( pItem->pTab->pSchema==0 && pThis->pSelect->selId!=pS1->selId ){ /* The query flattener left two different CTE tables with identical ** names in the same FROM clause. */ continue;