Do not use indexed expressions to replace the expression being indexed on a

RIGHT JOIN as that leads to problems, as shown by
dbsqlfuzz a644e70d7683a7ca59c71861a153c1dccf8850b9.

FossilOrigin-Name: f113eebdbe68246fd38d640b0cdf0fd73ab5d2abad9226274dfa2e41fe286bf0
This commit is contained in:
drh 2022-12-20 01:48:43 +00:00
parent 73e460c932
commit 98164c3452
7 changed files with 32 additions and 15 deletions

View File

@ -1,5 +1,5 @@
C Fix\sa\sfaulty\sassert()\sin\sfts5.
D 2022-12-19T20:14:22.085
C Do\snot\suse\sindexed\sexpressions\sto\sreplace\sthe\sexpression\sbeing\sindexed\son\sa\nRIGHT\sJOIN\sas\sthat\sleads\sto\sproblems,\sas\sshown\sby\ndbsqlfuzz\sa644e70d7683a7ca59c71861a153c1dccf8850b9.
D 2022-12-20T01:48:43.300
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -595,7 +595,7 @@ F src/date.c 94ce83b4cd848a387680a5f920c9018c16655db778c4d36525af0a0f34679ac5
F src/dbpage.c f1a87f4ebcf22284e0aaf0697862f4ccfc120dcd6db3d8dfa3b049b2580c01d8
F src/dbstat.c a56a7ad1163a9888d46cd5820be2e65354fb1aa04ed6909f7c3e5831e0ee2c29
F src/delete.c 86573edae75e3d3e9a8b590d87db8e47222103029df4f3e11fa56044459b514e
F src/expr.c dcf31acfea9a9ae305c30d46179e7b06a8478e9ea202ac0c828cc42903fb1874
F src/expr.c 64399751983f8e27284141faf95d7d647d6d6a54741e984fe01039bf9b504e1f
F src/fault.c 460f3e55994363812d9d60844b2a6de88826e007
F src/fkey.c 722f20779f5342a787922deded3628d8c74b5249cab04098cf17ee2f2aaff002
F src/func.c 7e86074afc4dc702691a29b7801f6dcc191db092b52e8bbe69dcd2f7be52194d
@ -645,12 +645,12 @@ F src/printf.c e99ee9741e79ae3873458146f59644276657340385ade4e76a5f5d1c25793764
F src/random.c 606b00941a1d7dd09c381d3279a058d771f406c5213c9932bbd93d5587be4b9c
F src/resolve.c efea4e5fbecfd6d0a9071b0be0d952620991673391b6ffaaf4c277b0bb674633
F src/rowset.c ba9515a922af32abe1f7d39406b9d35730ed65efab9443dc5702693b60854c92
F src/select.c 4e80cb95a428716a5127a91d7d3d3433d0eb8f4ff8deb1d093c0a1f7f3674087
F src/select.c 83de67e4857be2866d048c98e93f65461d8a0408ca4ce88fec68ebfe030997ae
F src/shell.c.in 24e0c75947dd8a3426473d90dfc4887f42553c8b57dff02a6865f04c5efcf864
F src/sqlite.h.in e752f82b9d71f1d42b259b1900e4b1caf0965e844d756cd5cc91cc2cf45ed925
F src/sqlite3.rc 5121c9e10c3964d5755191c80dd1180c122fc3a8
F src/sqlite3ext.h c4b9fa7a7e2bcdf850cfeb4b8a91d5ec47b7a00033bc996fd2ee96cbf2741f5f
F src/sqliteInt.h 4bcf6f13b8195de4fd020cd58ebb605a27752b3d82d0d5071d4435a446f00487
F src/sqliteInt.h 3a1e92597b2f34a770f349b80008b28647cc1ddfe72d8dba5594ebaeae3f85c3
F src/sqliteLimit.h d7323ffea5208c6af2734574bae933ca8ed2ab728083caa117c9738581a31657
F src/status.c 160c445d7d28c984a0eae38c144f6419311ed3eace59b44ac6dafc20db4af749
F src/table.c 0f141b58a16de7e2fbe81c308379e7279f4c6b50eb08efeec5892794a0ba30d1
@ -732,7 +732,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
F src/wal.c b9df133a705093da8977da5eb202eaadb844839f1c7297c08d33471f5491843d
F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a
F src/walker.c f890a3298418d7cba3b69b8803594fdc484ea241206a8dfa99db6dd36f8cbb3b
F src/where.c 1425edc179cce7db5e7e9626b01716fed8498cc1f63875e96905d515e5e90bec
F src/where.c 72d7f87dee67b5356a12d9c50faa79aa4459d5994f72d18cf89f6baff9a1ebf2
F src/whereInt.h e25203e5bfee149f5f1225ae0166cfb4f1e65490c998a024249e98bb0647377c
F src/wherecode.c 76bca3379219880d2527493b71a3be49e696f75396d3481e4de5d4ceec7886b2
F src/whereexpr.c 05295b44b54eea76d1ba766f0908928d0e20e990c249344c9521454d3d09c7ae
@ -1635,7 +1635,7 @@ F test/tkt-868145d012.test a5f941107ece6a64410ca4755c6329b7eb57a356
F test/tkt-8c63ff0ec.test 258b7fc8d7e4e1cb5362c7d65c143528b9c4cbed
F test/tkt-91e2e8ba6f.test 08c4f94ae07696b05c9b822da0b4e5337a2f54c5
F test/tkt-94c04eaadb.test f738c57c7f68ab8be1c054415af7774617cb6223
F test/tkt-99378177930f87bd.test 0f932e85fa1d41f30532cb7be9718d82e491e953123b8c4c85cf025f36ffe34b
F test/tkt-99378177930f87bd.test 697acf5474abf1545a7d3239facd3b5c7aaf521fb720f6f8aa6d02defb4396a6
F test/tkt-9a8b09f8e6.test b2ef151d0984b2ebf237760dbeaa50724e5a0667
F test/tkt-9d68c883.test 16f7cb96781ba579bc2e19bb14b4ad609d9774b6
F test/tkt-9f2eb3abac.test cb6123ac695a08b4454c3792fbe85108f67fabf8
@ -2067,8 +2067,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P 5c4d94147d290d4a68ac0d5ae8f9e6bbfe7522ad58b2298e387f8c699048e111
R cdb15e0661195b8c62c31eded160eb23
U dan
Z 563da3999947a18106cd894745cad872
P 569018170b928cadfa0745db631981084e595d90a8c3d1e236c42adae161018f
R e709a8c3b500ac798734e29d78700b49
U drh
Z eb4716a01822edf54dfcaa2219a6ff52
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
569018170b928cadfa0745db631981084e595d90a8c3d1e236c42adae161018f
f113eebdbe68246fd38d640b0cdf0fd73ab5d2abad9226274dfa2e41fe286bf0

View File

@ -6384,6 +6384,7 @@ static void findOrCreateAggInfoColumn(
}
fix_up_expr:
ExprSetVVAProperty(pExpr, EP_NoReduce);
assert( pExpr->pAggInfo==0 || pExpr->pAggInfo==pAggInfo );
pExpr->pAggInfo = pAggInfo;
if( pExpr->op==TK_COLUMN ){
pExpr->op = TK_AGG_COLUMN;
@ -6419,6 +6420,7 @@ static int analyzeAggregate(Walker *pWalker, Expr *pExpr){
}
if( pIEpr==0 ) break;
if( NEVER(!ExprUseYTab(pExpr)) ) break;
assert( pExpr->pAggInfo==0 );
/* If we reach this point, it means that expression pExpr can be
** translated into a reference to an index column as described by

View File

@ -7685,6 +7685,9 @@ int sqlite3Select(
goto select_end;
}
pAggInfo->selId = p->selId;
#ifdef SQLITE_DEBUG
pAggInfo->pSelect = p;
#endif
memset(&sNC, 0, sizeof(sNC));
sNC.pParse = pParse;
sNC.pSrcList = pTabList;

View File

@ -2795,6 +2795,9 @@ struct AggInfo {
} *aFunc;
int nFunc; /* Number of entries in aFunc[] */
u32 selId; /* Select to which this AggInfo belongs */
#ifdef SQLITE_DEBUG
Select *pSelect; /* SELECT statement that this AggInfo supports */
#endif
};
/*

View File

@ -6240,7 +6240,10 @@ WhereInfo *sqlite3WhereBegin(
op = OP_ReopenIdx;
}else{
iIndexCur = pParse->nTab++;
if( pIx->bHasExpr && OptimizationEnabled(db, SQLITE_IndexedExpr) ){
if( pIx->bHasExpr
&& OptimizationEnabled(db, SQLITE_IndexedExpr)
&& (pTabItem->fg.jointype & (JT_LTORJ|JT_RIGHT))==0
){
whereAddIndexedExpr(pParse, pIx, iIndexCur, pTabItem);
}
}

View File

@ -148,7 +148,13 @@ do_execsql_test tkt-99378-240 {
GROUP BY a;
} {~/Function/}
# 2022-12-20 dbsqlfuzz a644e70d7683a7ca59c71861a153c1dccf8850b9
#
do_execsql_test tkt-99378-300 {
DROP TABLE IF EXISTS t1;
CREATE TABLE t1(a);
CREATE INDEX i1 ON t1(a,a+a,a<a,a=a);
SELECT * FROM (SELECT * FROM t1) NATURAL JOIN t1 WHERE a=1 OR ((SELECT avg((SELECT * FROM (SELECT * FROM (SELECT * FROM t1 NATURAL JOIN t1 WHERE 1||a OR ((SELECT sum(a)OVER(ORDER BY a)) AND a<=10)) WHERE a=1 OR ((SELECT sum((SELECT 1 FROM t1 NATURAL RIGHT JOIN t1 WHERE a=a))) AND a<=10)) WHERE a=1 OR ((SELECT sum(a)OVER(ORDER BY a)))))) AND a>10);
} {}
finish_test