From 756748ea865afeaa5477cf185785636e9dc54d38 Mon Sep 17 00:00:00 2001 From: drh <> Date: Thu, 13 May 2021 13:43:40 +0000 Subject: [PATCH] The content columns of the index-btree that implements a WITHOUT ROWID table are not ordered and so the query planner should not assume they are ordered. Fix for the issue identified by [forum:/forumpost/6c8960f545|forum post 6c8960f545]. FossilOrigin-Name: c21bc5a2353e660f2acf5ed916921a4ee416910d0b3f2deb512a05c54138d1c0 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 4 ++++ test/without_rowid1.test | 13 +++++++++++++ 4 files changed, 25 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 91007aaa09..19f4d37fde 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Further\ssimplification\sof\sthe\sreverse-order\sscan\slogic\sof\sthe\sprevious\ncheck-in. -D 2021-05-12T22:15:44.517 +C The\scontent\scolumns\sof\sthe\sindex-btree\sthat\simplements\sa\sWITHOUT\sROWID\ntable\sare\snot\sordered\sand\sso\sthe\squery\splanner\sshould\snot\sassume\sthey\nare\sordered.\s\sFix\sfor\sthe\sissue\sidentified\sby\n[forum:/forumpost/6c8960f545|forum\spost\s6c8960f545]. +D 2021-05-13T13:43:40.565 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -630,7 +630,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c c8ec20a1ca161d5635a4f19c2a4efec2e006e19a8a61f272bf6bce1c80ab7436 F src/wal.h c3aa7825bfa2fe0d85bef2db94655f99870a285778baa36307c0a16da32b226a F src/walker.c 6e540867a30d81e00205995fa2dc0e3d25365a7402251c9fd5d19aa4ff5e60b6 -F src/where.c beb01392745d9badba63802c9cf18daa9aa2d99c34dd2d21d62bad217e9d70d4 +F src/where.c 32f41c3c93c6785e0077e3a2cdc669c3ccfe70173787847be77f294c18fc7dc3 F src/whereInt.h 9248161dd004f625ce5d3841ca9b99fed3fc8d61522cf76340fc5217dbe1375b F src/wherecode.c b4c21439f0549bb5c571214e08ddb5ec58d5e972f4b4c87c0cc79351edd43704 F src/whereexpr.c 811f339ca85540157f3a400333ba90237ffbe7a2ba82dac63ce0677f4c4109d0 @@ -1797,7 +1797,7 @@ F test/with4.test 257be66c0c67fee1defbbac0f685c3465e2cad037f21ce65f23f86084f1982 F test/with5.test 6248213c41fab36290b5b73aa3f937309dfba337004d9d8434c3fabc8c7d4be8 F test/with6.test 661d7e416bef6c0a2556b2c9f0c8178a5b15932bed65246abed99723a8d4e7c0 F test/withM.test 693b61765f2b387b5e3e24a4536e2e82de15ff64 -F test/without_rowid1.test e4034c0849ccc2e8bb749c69f15bd69bb9fcf8fe77e8d17ce02369604242fe83 +F test/without_rowid1.test 6abc5d497f634520944dac0a89a6c240a48d2ee0f8353356a750eb70dc1db41a F test/without_rowid2.test af260339f79d13cb220288b67cd287fbcf81ad99 F test/without_rowid3.test 39ab0dd773eaa62e59b17093f875327630f54c4145458f6d2b053d68d4b2f67b F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a @@ -1913,7 +1913,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 f65c929bf189cf5ca5f1cacdbbb8eec014c9960f767b135023bd2323cd26f279 -R af7ea7364cc3c11d08d2a3b8c3f9b4af +P b2b0e23ba885f22c88b03492e42c3cd1cbd59289e452263951bb757a871699f0 +R 764f06f91ab95ce9134e7e810a3df5f2 U drh -Z 50b7760566229c41277c6b46b9e08bf8 +Z 2bf41f499ef008f771df581659494cf8 diff --git a/manifest.uuid b/manifest.uuid index e747964aaa..b0a4922dc2 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b2b0e23ba885f22c88b03492e42c3cd1cbd59289e452263951bb757a871699f0 \ No newline at end of file +c21bc5a2353e660f2acf5ed916921a4ee416910d0b3f2deb512a05c54138d1c0 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 62bf5fbbcb..4062de7eab 100644 --- a/src/where.c +++ b/src/where.c @@ -2513,6 +2513,8 @@ static int whereLoopAddBtreeIndex( if( pProbe->bUnordered ) opMask &= ~(WO_GT|WO_GE|WO_LT|WO_LE); assert( pNew->u.btree.nEqnColumn ); + assert( pNew->u.btree.nEqnKeyCol + || pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY ); saved_nEq = pNew->u.btree.nEq; saved_nBtm = pNew->u.btree.nBtm; @@ -2790,6 +2792,8 @@ static int whereLoopAddBtreeIndex( if( (pNew->wsFlags & WHERE_TOP_LIMIT)==0 && pNew->u.btree.nEqnColumn + && (pNew->u.btree.nEqnKeyCol || + pProbe->idxType!=SQLITE_IDXTYPE_PRIMARYKEY) ){ whereLoopAddBtreeIndex(pBuilder, pSrc, pProbe, nInMul+nIn); } diff --git a/test/without_rowid1.test b/test/without_rowid1.test index 02a089610d..e4e69eb727 100644 --- a/test/without_rowid1.test +++ b/test/without_rowid1.test @@ -452,5 +452,18 @@ do_execsql_test 13.10 { PRAGMA integrity_check; SELECT * FROM t0, t1; } {ok abc xyz abc xyz} + +# 2021-05-13 https://sqlite.org/forum/forumpost/6c8960f545 +reset_db +do_execsql_test 14.1 { + CREATE TABLE t1(a INT PRIMARY KEY) WITHOUT ROWID; + INSERT INTO t1(a) VALUES(10); + ALTER TABLE t1 ADD COLUMN b INT; + SELECT * FROM t1 WHERE a=20 OR (a=10 AND b=10); +} {} +do_execsql_test 14.2 { + CREATE TABLE dual AS SELECT 'X' AS dummy; + EXPLAIN QUERY PLAN SELECT * FROM dual, t1 WHERE a=10 AND b=10; +} {~/b=/} finish_test