From bb130c9223397ab9b29f2c4cc6de28e5623e0f0e Mon Sep 17 00:00:00 2001 From: dan Date: Mon, 20 Mar 2023 14:59:19 +0000 Subject: [PATCH] Fix a problem causing a cursor to retain an out-of-date cell-info cache when processing a DISTINCT query on values that are identical according to their collation sequence, but different on disk. [forum:/forumpost/e132e6cde44fb505|Forum post e123e6cde4]. FossilOrigin-Name: 1b3abc1daeac29714256b5a1d5a07a75dc986f1089054a8bee44a00583b7383a --- manifest | 17 ++++++++--------- manifest.uuid | 2 +- src/btree.c | 2 +- test/distinct2.test | 12 ++++++++++++ 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 55f4c5fe5b..aa2e57ba8f 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Back\sout\sthe\sextra\smargin\sadded\sto\sthe\sinput\sbuffer\sof\sthe\sCLI,\sas\sit\sis\snot\nneeded. -D 2023-03-20T10:43:52.546 +C Fix\sa\sproblem\scausing\sa\scursor\sto\sretain\san\sout-of-date\scell-info\scache\swhen\sprocessing\sa\sDISTINCT\squery\son\svalues\sthat\sare\sidentical\saccording\sto\stheir\scollation\ssequence,\sbut\sdifferent\son\sdisk.\s[forum:/forumpost/e132e6cde44fb505|Forum\spost\se123e6cde4]. +D 2023-03-20T14:59:19.115 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724 @@ -564,7 +564,7 @@ F src/auth.c f4fa91b6a90bbc8e0d0f738aa284551739c9543a367071f55574681e0f24f8cf F src/backup.c a2891172438e385fdbe97c11c9745676bec54f518d4447090af97189fd8e52d7 F src/bitvec.c 7c849aac407230278445cb069bebc5f89bf2ddd87c5ed9459b070a9175707b3d F src/btmutex.c 6ffb0a22c19e2f9110be0964d0731d2ef1c67b5f7fabfbaeb7b9dabc4b7740ca -F src/btree.c 9192990bb78806df33ac680df47cb4100b5dbe5d298c3d0abffc82cd31ca6634 +F src/btree.c 8c04a7ed24642970158ae9fbf0d146d9625615094f84a4a24e0a6ed2d9f3fd62 F src/btree.h aa354b9bad4120af71e214666b35132712b8f2ec11869cb2315c52c81fad45cc F src/btreeInt.h 06bb2c1a07172d5a1cd27a2a5d617b93b1e976c5873709c31964786f86365a6e F src/build.c 8357d6ca9a8c9afc297c431df28bc2af407b47f3ef2311875276c944b30c4d54 @@ -938,7 +938,7 @@ F test/descidx2.test a0ba347037ff3b811f4c6ceca5fd0f9d5d72e74e59f2d9de346a9d2f6ad F test/descidx3.test 953c831df7ea219c73826dfbf2f6ee02d95040725aa88ccb4fa43d1a1999b926 F test/diskfull.test 106391384780753ea6896b7b4f005d10e9866b6e F test/distinct.test 691c9e850b0d0b56b66e7e235453198cb4cf0760e324b7403d3c5abbeab0a014 -F test/distinct2.test cd1d15a4a2abf579298f7161e821ed50c0119136fe0424db85c52cf0adc230d1 +F test/distinct2.test bb71cc7b5e58e895787f9910a788c254f679928d324732d063fe9bc202ecbe71 F test/distinctagg.test 14ec5026e684eddd414c61c08692b43773e224ac92efbed6ec08c6994bc39723 F test/e_blobbytes.test 4c01dfe4f12087b92b20705a3fdfded45dc4ed16d5a211fed4e1d2786ba68a52 F test/e_blobclose.test 692fc02a058476c2222a63d97e3f3b2b809c1842e5525ded7f854d540ac2e075 @@ -2051,9 +2051,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 770b3e67c89ca16b08a9234acb626917a26ea414b3bc0340f9601644cb7504f2 -Q -741af08af1b93406a120580379d13e514524af627da5387ecfa6e442d004bfdd -R 6fce8a37edd3eccfb817f05a356bd030 -U drh -Z 0c2311a8849988977130c5a153101397 +P ac8d1e5de5da35fa93c3f9241a7817285920431c66f4e4593d4d5c2db9f2b960 +R ba20ce5c356b9d123e09b3173425d3de +U dan +Z f96e7e21af2385632fea87093dba304b # Remove this line to create a well-formed Fossil manifest. diff --git a/manifest.uuid b/manifest.uuid index ce4eb878f2..bb80796c5b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ac8d1e5de5da35fa93c3f9241a7817285920431c66f4e4593d4d5c2db9f2b960 \ No newline at end of file +1b3abc1daeac29714256b5a1d5a07a75dc986f1089054a8bee44a00583b7383a \ No newline at end of file diff --git a/src/btree.c b/src/btree.c index 918388a64a..2fbceb7d2a 100644 --- a/src/btree.c +++ b/src/btree.c @@ -9261,6 +9261,7 @@ int sqlite3BtreeInsert( assert( szNew==pPage->xCellSize(pPage, newCell) ); assert( szNew <= MX_CELL_SIZE(p->pBt) ); idx = pCur->ix; + pCur->info.nSize = 0; if( loc==0 ){ CellInfo info; assert( idx>=0 ); @@ -9333,7 +9334,6 @@ int sqlite3BtreeInsert( ** larger than the largest existing key, it is possible to insert the ** row without seeking the cursor. This can be a big performance boost. */ - pCur->info.nSize = 0; if( pPage->nOverflow ){ assert( rc==SQLITE_OK ); pCur->curFlags &= ~(BTCF_ValidNKey); diff --git a/test/distinct2.test b/test/distinct2.test index 46eace6f0f..958d9634fd 100644 --- a/test/distinct2.test +++ b/test/distinct2.test @@ -301,4 +301,16 @@ do_execsql_test 3030 { {} 1 a } +#------------------------------------------------------------------------- +# +reset_db + +do_execsql_test 4010 { + CREATE TABLE t1(a, b COLLATE RTRIM); + INSERT INTO t1 VALUES(1, ''), (2, ' '), (3, ' '); +} +do_execsql_test 4020 { + SELECT b FROM t1 UNION SELECT 1; +} {1 { }} + finish_test