]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
More comments on the EXISTS-to-IN optimization logic. exists-to-in
authordrh <>
Mon, 18 Jan 2021 00:11:20 +0000 (00:11 +0000)
committerdrh <>
Mon, 18 Jan 2021 00:11:20 +0000 (00:11 +0000)
FossilOrigin-Name: 92cc29099f796f5f244dd80ee431c48d36d01eaece6f150119ead5ecd14eaae1

manifest
manifest.uuid
src/whereexpr.c

index 51ebfdca8d6568b462aad95dfaa4db05a33c3be0..c51fc6703bb058f858e9a3bd0630ef55cc4f65c8 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Minor\ssimplification\sof\sthe\sEXISTS-to-IN\slogic.
-D 2021-01-17T00:13:12.097
+C More\scomments\son\sthe\sEXISTS-to-IN\soptimization\slogic.
+D 2021-01-18T00:11:20.813
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@@ -630,7 +630,7 @@ F src/walker.c d9c4e454ebb9499e908aa62d55b8994c375cf5355ac78f60d45af17f7890701c
 F src/where.c 0e6abb22a2323fec80b450825593c26a2ad8f4815d1ee3af9969d8f6144bf681
 F src/whereInt.h 9a3f577619f07700d16d89eeb2f3d94d6b7ed7f109c2dacf0ce8844921549506
 F src/wherecode.c a3a1aff30fe99a818d8e7c607980f033f40c68d890e03ed25838b9dbb7908bee
-F src/whereexpr.c 9886a16b52af66e01ded9e69e3e2913f25d8e34bdeaa5e583d7c8c9a1ffe71d2
+F src/whereexpr.c a022b4f447c0fb0674e172a9a303537ea5055df60d579f99cec7ead18e8c453f
 F src/window.c edd6f5e25a1e8f2b6f5305b7f5f7da7bb35f07f0d432b255b1d4c2fcab4205aa
 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2
 F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627
@@ -1897,7 +1897,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 ef49ee4a3766146963bfb6b013472f9836afb9c5b0d21a8533871cf961139e38
-R ed5d5749a7ed1103ef3bdb4ce2a908bc
+P cac90a9f4ab0a8f3ff77ee1f8549213c2f97169fc3469e55d57caa564079ce2a
+R f533358ab2d88dffa58abcd3bcdbe4bd
 U drh
-Z beb39ea924321eafaa423b5e3b964772
+Z 7271ac9ea9a27eaec7cf5d0a637bfec4
index 7186b19c6eb1b6191643aeb391f9f6ff09c57986..689f037d9015142059894d137273f00d827c32a7 100644 (file)
@@ -1 +1 @@
-cac90a9f4ab0a8f3ff77ee1f8549213c2f97169fc3469e55d57caa564079ce2a
\ No newline at end of file
+92cc29099f796f5f244dd80ee431c48d36d01eaece6f150119ead5ecd14eaae1
\ No newline at end of file
index 584d2d35f590bf90ed6bc4f283bebf3599878e89..5cfdad67c128c1fb4b28d58deb8760b2c082e073 100644 (file)
@@ -1036,13 +1036,26 @@ static int exprUsesSrclistSelectCb(Walker *p, Select *pSelect){
 ** This function always returns true if expression pExpr contains
 ** a sub-select.
 **
-** If there is no sub-select and bUses is 1, then true is returned
-** if the expression contains at least one TK_COLUMN node that refers
-** to a table in pSrc.
+** If there is no sub-select in pExpr, then return true if pExpr
+** contains a TK_COLUMN node for a table that is (bUses==1)
+** or is not (bUses==0) in pSrc.
 **
-** Or, if there is no sub-select and bUses is 0, then true is returned
-** if the expression contains at least one TK_COLUMN node that refers
-** to a table that is not in pSrc.
+** Said another way:
+**
+**   bUses      Return     Meaning
+**   --------   ------     ------------------------------------------------
+**
+**   bUses==1   true       pExpr contains either a sub-select or a
+**                         TK_COLUMN referencing pSrc.
+**
+**   bUses==1   false      pExpr contains no sub-selects and all TK_COLUMN
+**                         nodes reference tables not found in pSrc
+**
+**   bUses==0   true       pExpr contains either a sub-select or a TK_COLUMN
+**                         that references a table not in pSrc.
+**
+**   bUses==0   false      pExpr contains no sub-selects and all TK_COLUMN
+**                         nodes reference pSrc
 */
 static int exprUsesSrclist(SrcList *pSrc, Expr *pExpr, int bUses){
   Walker sWalker;
@@ -1059,11 +1072,11 @@ static int exprUsesSrclist(SrcList *pSrc, Expr *pExpr, int bUses){
 ** expression tree.
 */
 struct ExistsToInCtx {
-  SrcList *pSrc;
-  Expr *pInLhs;
-  Expr *pEq;
-  Expr **ppAnd;
-  Expr **ppParent;
+  SrcList *pSrc;    /* The tables in an EXISTS(SELECT ... FROM <here> ...) */
+  Expr *pInLhs;     /* OUT:  Use this as the LHS of the IN operator */
+  Expr *pEq;        /* OUT:  The == term that include pInLhs */
+  Expr **ppAnd;     /* OUT:  The AND operator that includes pEq as a child */
+  Expr **ppParent;  /* The AND operator currently being examined */
 };
 
 /*
@@ -1131,7 +1144,7 @@ static int exprExistsToInIter(struct ExistsToInCtx *p, Expr **ppExpr){
 ** node within the WHERE expression tree.
 */
 static Expr *exprAnalyzeExistsFindEq(
-  Select *pSel,
+  Select *pSel,                   /* The SELECT of the EXISTS */
   Expr **ppEq,                    /* OUT: == node from WHERE clause */
   Expr ***pppAnd                  /* OUT: Pointer to parent of ==, if any */
 ){