From: drh Date: Fri, 15 Nov 2019 00:52:13 +0000 (+0000) Subject: Fix table-valued functions so that they will work as the right table X-Git-Tag: version-3.31.0~321 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8103a03607878504d2ada2a975b37b837e8825f3;p=thirdparty%2Fsqlite.git Fix table-valued functions so that they will work as the right table in a LEFT JOIN. Ticket [2ae0c599b735d59e] FossilOrigin-Name: 2c35d3f67b67a53ead08b1c395e7ca8e5bf65f94a5a962a0562994a3c66c95d9 --- diff --git a/manifest b/manifest index 94f80612a0..c765e5ce6f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\ssupport\sfor\sthe\ssqlite3_hard_heap_limit64()\sinterface\sand\sthe\nhard_heap_limit\spragma. -D 2019-11-14T18:07:28.161 +C Fix\stable-valued\sfunctions\sso\sthat\sthey\swill\swork\sas\sthe\sright\stable\nin\sa\sLEFT\sJOIN.\s\sTicket\s[2ae0c599b735d59e] +D 2019-11-15T00:52:13.066 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -526,12 +526,12 @@ F src/printf.c 9be6945837c839ba57837b4bc3af349eba630920fa5532aa518816defe42a7d4 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c cf2391c93d425455388389e7a47674b9da107d2ed69ebf49979044d70dbeb045 F src/rowset.c d977b011993aaea002cab3e0bb2ce50cf346000dff94e944d547b989f4b1fe93 -F src/select.c 887c3096566e22d28c6cc1a09ac0f6eb9636e5f38eb55e296e39e282c56fda65 +F src/select.c 50ccaf5fc3566b897fd3090b63bd60605f2f3f38ac5709fda6c482510d71aa6c F src/shell.c.in c06961f202f3cc50b819744b7331d3caea3d79d958402f4900b0668248557468 F src/sqlite.h.in 95f50dc42fddab20064bf308c6756fcf2fdd84998dda15ae404a89c5c8d2cd10 F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 72af51aa4e912e14cd495fb6e7fac65f0940db80ed950d90911aff292cc47ce2 -F src/sqliteInt.h 3a1d168099ceff8565702ac302d99b377db52ce95d57ff59286d4959ff66399a +F src/sqliteInt.h 70facb03d2544a79aceb47c268c99ec2cd773a086c20f0f47cfb78e4a00fb8ca F src/sqliteLimit.h 1513bfb7b20378aa0041e7022d04acb73525de35b80b252f1b83fedb4de6a76b F src/status.c 46e7aec11f79dad50965a5ca5fa9de009f7d6bde08be2156f1538a0a296d4d0e F src/table.c b46ad567748f24a326d9de40e5b9659f96ffff34 @@ -615,7 +615,7 @@ F src/walker.c d5a94907dcac990e31976be9dc769d17f6a806782593d6aec9d760ee01ec22cd F src/where.c 874845fb5d93b3bc07123df8fee805e9650bd091e3ed62988273c7e2141ab8bd F src/whereInt.h 4a296fd4fa79fdcbc2b5e8c1b898901617655811223e1082b899c23ecb092217 F src/wherecode.c 9b84737fd68134249a439813d27b1c61de17a01e121eb98949548d1e7f8e400a -F src/whereexpr.c 0705f608f6dbbd4e95d440528d6c760b91b6f402ba4eb8b8d964c110e2010780 +F src/whereexpr.c 39b6a538804c6e1248c22b33e09d00f89ae6a099c849c4d841ce3995562287b4 F src/window.c ea53cef29a5c32aa37ea22e87c247cf8e999fa3b70c6268d266af84608cb77f4 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/affinity2.test ce1aafc86e110685b324e9a763eab4f2a73f737842ec3b687bd965867de90627 @@ -1393,7 +1393,7 @@ F test/sync.test 89539f4973c010eda5638407e71ca7fddbcd8e0594f4c9980229f804d433309 F test/sync2.test 8f9f7d4f6d5be8ca8941a8dadcc4299e558cb6a1ff653a9469146c7a76ef2039 F test/syscall.test a39d9a36f852ae6e4800f861bc2f2e83f68bbc2112d9399931ecfadeabd2d69d F test/sysfault.test c9f2b0d8d677558f74de750c75e12a5454719d04 -F test/tabfunc01.test 20e98ffe55f35d8d33fd834ca8bf9d4b637e560af8fcd00464b4154d90a4db45 +F test/tabfunc01.test 5ca6d004157a3e886a55a9387b960cc0db41acd88753eb597ff409ec6cfb1be0 F test/table.test eb3463b7add9f16a5bb836badf118cf391b809d09fdccd1f79684600d07ec132 F test/tableapi.test ecbcc29c4ab62c1912c3717c48ea5c5e59f7d64e4a91034e6148bd2b82f177f4 F test/tableopts.test dba698ba97251017b7c80d738c198d39ab747930 @@ -1849,8 +1849,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 5baffcda7d5a42a99fa905faa834f14b94b1e2a26b5221f15d8ae8f1f5e3236a 33fd0c3abcad5555a150990a22d9c1bab99e79be01143fccb9fafc9b52cf92c8 -R 4e80a787b37e9567df232e950e42c798 -T +closed 33fd0c3abcad5555a150990a22d9c1bab99e79be01143fccb9fafc9b52cf92c8 +P 6399c47ea89c5766274bd6abdc9b6a85fe5b7f6c1078972c2f58e624bae59b7c +R 0ce092e60687f1b9234aa96daa0d2db9 U drh -Z e24996a01ae32dd885b41938acef0f5f +Z 7c06b7375fe7d9dee3bcbbcdfd1114e1 diff --git a/manifest.uuid b/manifest.uuid index a08cb8b4ca..aad9c8d01b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6399c47ea89c5766274bd6abdc9b6a85fe5b7f6c1078972c2f58e624bae59b7c \ No newline at end of file +2c35d3f67b67a53ead08b1c395e7ca8e5bf65f94a5a962a0562994a3c66c95d9 \ No newline at end of file diff --git a/src/select.c b/src/select.c index 269469485f..5f51074a04 100644 --- a/src/select.c +++ b/src/select.c @@ -385,7 +385,7 @@ static void addWhereTerm( ** after the t1 loop and rows with t1.x!=5 will never appear in ** the output, which is incorrect. */ -static void setJoinExpr(Expr *p, int iTable){ +void sqlite3SetJoinExpr(Expr *p, int iTable){ while( p ){ ExprSetProperty(p, EP_FromJoin); assert( !ExprHasProperty(p, EP_TokenOnly|EP_Reduced) ); @@ -394,15 +394,15 @@ static void setJoinExpr(Expr *p, int iTable){ if( p->op==TK_FUNCTION && p->x.pList ){ int i; for(i=0; ix.pList->nExpr; i++){ - setJoinExpr(p->x.pList->a[i].pExpr, iTable); + sqlite3SetJoinExpr(p->x.pList->a[i].pExpr, iTable); } } - setJoinExpr(p->pLeft, iTable); + sqlite3SetJoinExpr(p->pLeft, iTable); p = p->pRight; } } -/* Undo the work of setJoinExpr(). In the expression tree p, convert every +/* Undo the work of sqlite3SetJoinExpr(). In the expression p, convert every ** term that is marked with EP_FromJoin and iRightJoinTable==iTable into ** an ordinary term that omits the EP_FromJoin mark. ** @@ -489,7 +489,7 @@ static int sqliteProcessJoin(Parse *pParse, Select *p){ ** an AND operator. */ if( pRight->pOn ){ - if( isOuter ) setJoinExpr(pRight->pOn, pRight->iCursor); + if( isOuter ) sqlite3SetJoinExpr(pRight->pOn, pRight->iCursor); p->pWhere = sqlite3ExprAnd(pParse, p->pWhere, pRight->pOn); pRight->pOn = 0; } @@ -4055,7 +4055,7 @@ static int flattenSubquery( pWhere = pSub->pWhere; pSub->pWhere = 0; if( isLeftJoin>0 ){ - setJoinExpr(pWhere, iNewParent); + sqlite3SetJoinExpr(pWhere, iNewParent); } pParent->pWhere = sqlite3ExprAnd(pParse, pWhere, pParent->pWhere); if( db->mallocFailed==0 ){ diff --git a/src/sqliteInt.h b/src/sqliteInt.h index 666b8a827d..73dbdbfc70 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -4248,6 +4248,7 @@ void sqlite3MaterializeView(Parse*, Table*, Expr*, ExprList*,Expr*,int); #endif int sqlite3JoinType(Parse*, Token*, Token*, Token*); +void sqlite3SetJoinExpr(Expr*,int); void sqlite3CreateForeignKey(Parse*, ExprList*, Token*, ExprList*, int); void sqlite3DeferForeignKey(Parse*, int); #ifndef SQLITE_OMIT_AUTHORIZATION diff --git a/src/whereexpr.c b/src/whereexpr.c index 7daf7508c7..16bbf4468a 100644 --- a/src/whereexpr.c +++ b/src/whereexpr.c @@ -1594,6 +1594,9 @@ void sqlite3WhereTabFuncArgs( pRhs = sqlite3PExpr(pParse, TK_UPLUS, sqlite3ExprDup(pParse->db, pArgs->a[j].pExpr, 0), 0); pTerm = sqlite3PExpr(pParse, TK_EQ, pColRef, pRhs); + if( pItem->fg.jointype & JT_LEFT ){ + sqlite3SetJoinExpr(pTerm, pItem->iCursor); + } whereClauseInsert(pWC, pTerm, TERM_DYNAMIC); } } diff --git a/test/tabfunc01.test b/test/tabfunc01.test index 49f0df889e..04bc6f42ad 100644 --- a/test/tabfunc01.test +++ b/test/tabfunc01.test @@ -218,6 +218,15 @@ do_test tabfunc01-750 { } } {5.0 x5 | 7.0 x7 | 13.0 x13 | 17.0 x17 | 23.0 x23 |} +# ticket https://www.sqlite.org/src/info/2ae0c599b735d59e +do_test tabfunc01-751 { + db eval { + SELECT aa.value, bb.value, '|' + FROM carray(inttoptr($PTR4),5,'double') AS aa + LEFT JOIN carray(inttoptr($PTR5),5,'char*') AS bb ON aa.rowid=bb.rowid; + } +} {5.0 x5 | 7.0 x7 | 13.0 x13 | 17.0 x17 | 23.0 x23 |} + # Free up memory allocations intarray_addr int64array_addr