From 46fe138d98664b30ada114b1f76b52e95d00575c Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 19 Aug 2020 23:32:06 +0000 Subject: [PATCH] Do not skip over TK_IF_NULL_ROW operators when bypassing TK_COLLATE operators. Fix to check-in [ac31edd3eeafcef4] which was itself a fix for ticket [45f4bf4eb4ffd788]. FossilOrigin-Name: 871f2ddcfbb9196dbd851a350e3471ee6d242d86bbd755201f7e2406fce3ac55 --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/expr.c | 6 +++--- src/select.c | 2 +- src/sqliteInt.h | 2 +- test/join2.test | 17 ++++++++++++++++- 6 files changed, 32 insertions(+), 17 deletions(-) diff --git a/manifest b/manifest index 6cd0f2a5c0..5c133b0db5 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sreleasetest_data.tcl\sso\sthat\sthe\s"Fast-One"\sconfiguration\sruns\sbigmmap.test\sas\spart\sof\srelease\stesting. -D 2020-08-19T15:24:19.261 +C Do\snot\sskip\sover\sTK_IF_NULL_ROW\soperators\swhen\sbypassing\sTK_COLLATE\soperators.\nFix\sto\scheck-in\s[ac31edd3eeafcef4]\swhich\swas\sitself\sa\sfix\sfor\sticket\n[45f4bf4eb4ffd788]. +D 2020-08-19T23:32:06.595 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -487,7 +487,7 @@ F src/date.c dace306a10d9b02ee553d454c8e1cf8d3c9b932e137738a6b15b90253a9bfc10 F src/dbpage.c 8a01e865bf8bc6d7b1844b4314443a6436c07c3efe1d488ed89e81719047833a F src/dbstat.c 3aa79fc3aed7ce906e4ea6c10e85d657299e304f6049861fe300053ac57de36c F src/delete.c a2a603ab07cced8560065b0e2c4c9c842f2c5a2fd43d87355f95eb53bae7fe21 -F src/expr.c 58c06940d964c2cf455b979cf66a648499d294a5ee6dadcaeaed447257c1dc75 +F src/expr.c 616244b0f99ca50320b44c547972ed8de7e92c2088b300810b9ac804c40fbc9c F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007 F src/fkey.c 83372403298e6a7dd989a47aaacdbaa5b4307b5199dbd56e07d4896066b3de72 F src/func.c 2333eb4277f55a5efdc12ef754e7d7ec9105d257b2fd00301d23ce1e8fa67dc0 @@ -535,12 +535,12 @@ F src/printf.c 9efcd4e984f22bcccb1ded37a1178cac98f6e3a0534e1e0629f64899971f8838 F src/random.c 80f5d666f23feb3e6665a6ce04c7197212a88384 F src/resolve.c d74715aceed2a8f493ba244d535646fa93132042a4400a29dfd26ec841514048 F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92 -F src/select.c 510fdf819f218be3dac2683d3eaaf64e5080f548061a4dd12205590beda976bb +F src/select.c 233e884d7da6601486c7b93aedb97fd29302ae5c03742d0e0eccb4790638bb77 F src/shell.c.in b6d5d6ebeb8903e4946f23f0886f24133e0a9b6ecbc4cf90ede422ba297e73d5 F src/sqlite.h.in d2c03414a8ee5d4a6855c04dd7cd5998e45139b0fe66b65bae86d4223edd091f F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8 F src/sqlite3ext.h 2d1af80082edffd71c6f96f70ad1ce6a4fb46615ad10291fc77fe0dea9ff0197 -F src/sqliteInt.h 86ad0f9164cbadb2ba9598cc6cf5b32bdb47b343c0da5ca62f3d73b60be55b65 +F src/sqliteInt.h 7dd1f3a93e801c90cf108149d041c6cc32d3e9503d66aa415455dae1614b6b53 F src/sqliteLimit.h 95cb8479ca459496d9c1c6a9f76b38aee12203a56ce1092fe13e50ae2454c032 F src/status.c 4b8bc2a6905163a38b739854a35b826c737333fab5b1f8e03fa7eb9a4799c4c1 F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1 @@ -1103,7 +1103,7 @@ F test/ioerr5.test 2edfa4fb0f896f733071303b42224df8bedd9da4 F test/ioerr6.test a395a6ab144b26a9e3e21059a1ab6a7149cca65b F test/istrue.test 06f92ea38750fa74df7dbbe6920205251c2310861fbbe23a3adfa918a2e2ba74 F test/join.test bca044589e94bb466e4c1e91fb6fecdc3f3326ca6b3f590f555f1958156eb321 -F test/join2.test 7d24d095ab88d3910228d53a3b548b7baf2e0e7d8aac6731a273e300e1b34b61 +F test/join2.test 21fc30e54ab35ed66bf51b89cec18729205497f5cc43c83bc042f96a73721593 F test/join3.test 6f0c774ff1ba0489e6c88a3e77b9d3528fb4fda0 F test/join4.test 1a352e4e267114444c29266ce79e941af5885916 F test/join5.test 3a96dc62f0b45402d7207e22d1993fe0c2fce1c57644a11439891dd62b990eb7 @@ -1879,7 +1879,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 d8e47382160e98be646ce3ba568578493088d1bb11d513ded3e00b576fb07f06 -R ea1afde48f0d02557391a4047adf2310 -U dan -Z d5829a9d86564dfb4bfa4de08f611888 +P a0aa35aaa5694a96638a7c7b1cd69c7523750cbe95831a13c1ee5a6d48256b76 +R 75dc1e0cc2548901d96acdc048327264 +U drh +Z 82ae660e681a73fcc0f28cd7c0e29f86 diff --git a/manifest.uuid b/manifest.uuid index aad562bbea..01783fafbc 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -a0aa35aaa5694a96638a7c7b1cd69c7523750cbe95831a13c1ee5a6d48256b76 \ No newline at end of file +871f2ddcfbb9196dbd851a350e3471ee6d242d86bbd755201f7e2406fce3ac55 \ No newline at end of file diff --git a/src/expr.c b/src/expr.c index b64ea28bf5..244412b384 100644 --- a/src/expr.c +++ b/src/expr.c @@ -44,7 +44,7 @@ char sqlite3TableColumnAffinity(Table *pTab, int iCol){ */ char sqlite3ExprAffinity(const Expr *pExpr){ int op; - while( ExprHasProperty(pExpr, EP_Skip) ){ + while( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){ assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW ); pExpr = pExpr->pLeft; assert( pExpr!=0 ); @@ -115,7 +115,7 @@ Expr *sqlite3ExprAddCollateString(Parse *pParse, Expr *pExpr, const char *zC){ */ Expr *sqlite3ExprSkipCollate(Expr *pExpr){ while( pExpr && ExprHasProperty(pExpr, EP_Skip) ){ - assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW ); + assert( pExpr->op==TK_COLLATE ); pExpr = pExpr->pLeft; } return pExpr; @@ -134,7 +134,7 @@ Expr *sqlite3ExprSkipCollateAndLikely(Expr *pExpr){ assert( pExpr->op==TK_FUNCTION ); pExpr = pExpr->x.pList->a[0].pExpr; }else{ - assert( pExpr->op==TK_COLLATE || pExpr->op==TK_IF_NULL_ROW ); + assert( pExpr->op==TK_COLLATE ); pExpr = pExpr->pLeft; } } diff --git a/src/select.c b/src/select.c index 8b1fae75a5..9568dbadc9 100644 --- a/src/select.c +++ b/src/select.c @@ -3506,7 +3506,7 @@ static Expr *substExpr( ifNullRow.op = TK_IF_NULL_ROW; ifNullRow.pLeft = pCopy; ifNullRow.iTable = pSubst->iNewTable; - ifNullRow.flags = EP_Skip; + ifNullRow.flags = EP_IfNullRow; pCopy = &ifNullRow; } testcase( ExprHasProperty(pCopy, EP_Subquery) ); diff --git a/src/sqliteInt.h b/src/sqliteInt.h index a5d108b6c7..f2c4f63c0d 100644 --- a/src/sqliteInt.h +++ b/src/sqliteInt.h @@ -2715,7 +2715,7 @@ struct Expr { #define EP_TokenOnly 0x004000 /* Expr struct EXPR_TOKENONLYSIZE bytes only */ #define EP_Win 0x008000 /* Contains window functions */ #define EP_MemToken 0x010000 /* Need to sqlite3DbFree() Expr.zToken */ - /* 0x020000 // available for reuse */ +#define EP_IfNullRow 0x020000 /* The TK_IF_NULL_ROW opcode */ #define EP_Unlikely 0x040000 /* unlikely() or likelihood() function */ #define EP_ConstFunc 0x080000 /* A SQLITE_FUNC_CONSTANT or _SLOCHNG function */ #define EP_CanBeNull 0x100000 /* Can be null despite NOT NULL constraint */ diff --git a/test/join2.test b/test/join2.test index 82d597c584..f004fda071 100644 --- a/test/join2.test +++ b/test/join2.test @@ -294,7 +294,10 @@ do_execsql_test 8.1 { } #------------------------------------------------------------------------- -# Ticket [45f4bf4eb]. +# Ticket [45f4bf4eb] reported by Manuel Rigger (2020-04-25) +# +# Follow up error reported by Eric Speckman on the SQLite forum +# https://sqlite.org/forum/info/c49496d24d35bd7c (2020-08-19) # reset_db do_execsql_test 9.0 { @@ -324,5 +327,17 @@ do_execsql_test 9.5 { UNION SELECT 0,0 WHERE 0; } {0 0} +do_execsql_test 9.10 { + CREATE TABLE t1 (aaa); + INSERT INTO t1 VALUES(23456); + CREATE TABLE t2(bbb); + CREATE VIEW v2(ccc) AS SELECT bbb IS 1234 FROM t2; + SELECT ccc, ccc IS NULL AS ddd FROM t1 LEFT JOIN v2; +} {{} 1} +optimization_control db query-flattener 0 +do_execsql_test 9.11 { + SELECT ccc, ccc IS NULL AS ddd FROM t1 LEFT JOIN v2; +} {{} 1} + finish_test