Skip to content

Commit

Permalink
Fix the whereKeyStats() routine (part of STAT4 processing only) so th…
Browse files Browse the repository at this point in the history
…at it

is able to cope with row-value comparisons against the primary key index
of a WITHOUT ROWID table.
[forum:/forumpost/3607259d3c|Forum post 3607259d3c].

FossilOrigin-Name: 2a6f761864a462de5c2d5bc666b82fb0b7e124a03443cd1482620dde344b34bb
  • Loading branch information
drh committed Jul 15, 2022
1 parent 8d65601 commit effc07e
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 12 deletions.
18 changes: 9 additions & 9 deletions manifest
@@ -1,5 +1,5 @@
C Update\ssome\sfaulty\sassert()\sstatements\sin\sfts3.
D 2022-07-15T12:07:25.826
C Fix\sthe\swhereKeyStats()\sroutine\s(part\sof\sSTAT4\sprocessing\sonly)\sso\sthat\sit\nis\sable\sto\scope\swith\srow-value\scomparisons\sagainst\sthe\sprimary\skey\sindex\nof\sa\sWITHOUT\sROWID\stable.\n[forum:/forumpost/3607259d3c|Forum\spost\s3607259d3c].
D 2022-07-15T12:34:31.538
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
Expand Down Expand Up @@ -657,7 +657,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 9a44063e60d8f42dd9dc8147b8e8dcfc315bbd13e25c395211292c36d828c869
F src/where.c db20d4b51ffcbab9e2c6d35ab56b83b130f4c9e4fbe0ca8f3b06ce89fde20519
F src/whereInt.h b48ca529ffe293c18cbfa8326af18a09e39910de66fb3e96ef788c7cbf8ef3a7
F src/wherecode.c 0b09abfcb88c61c6a6984a3e065786631ff35495e9bdf865e6b74ab0a1299c5b
F src/whereexpr.c 55a39f42aaf982574fbf52906371a84cceed98a994422198dfd03db4fce4cc46
Expand Down Expand Up @@ -1357,7 +1357,7 @@ F test/round1.test 768018b04522ca420b1aba8a24bd76091d269f3bce3902af3ec6ebcee41ab
F test/rowallock.test 3f88ec6819489d0b2341c7a7528ae17c053ab7cc
F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81
F test/rowid.test e29025be95baf6b32f0d5edef59a7633028325896a98f1caa8019559ca910350
F test/rowvalue.test ff1ffa31cebe12feb6f989e09263f3b1e8c560db94b40fe006126a8435fd6832
F test/rowvalue.test baf4fa3ec1a8c1c920c3faa5fd25959cb454bbd99ac8960397c34549d9fc4abe
F test/rowvalue2.test 060d238b7e5639a7c5630cb5e63e311b44efef2b
F test/rowvalue3.test 1347e25ca11c547c5a6ff0cc5626f95aa9740e9275bfaec096029f57cb2130ce
F test/rowvalue4.test 441e7e366ac6d939a3a95a574031c56ec2a854077a91d66eee5ff1d86cb5be58
Expand Down Expand Up @@ -1978,9 +1978,9 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P c4dbcb282d28bcc9b8001f387d0fc605be928453b3f61d2f5150f529647027b2
Q +b072851be1a5e49441469dbfa4580e132ebb1d8bc2de98fe1aa67bb9c7cf13a3
R f1cd0e29f633591834066a5c15626f9b
U dan
Z c3eab0a8c14ecb46deac4e924f53f3c0
P 958d104bcfb63b53b1f7ed745fafed8f392b71ed8b694675502473da735fc6a0
Q +0620e419a927a3da6ebe921aaa3471686f0fdc2e485f4c2d5c88f32092228724
R 3a023551686c9d6dffb884715f18739f
U drh
Z d1a0e900c64ece149fb75aa0198e998d
# Remove this line to create a well-formed Fossil manifest.
2 changes: 1 addition & 1 deletion manifest.uuid
@@ -1 +1 @@
958d104bcfb63b53b1f7ed745fafed8f392b71ed8b694675502473da735fc6a0
2a6f761864a462de5c2d5bc666b82fb0b7e124a03443cd1482620dde344b34bb
4 changes: 2 additions & 2 deletions src/where.c
Expand Up @@ -1433,7 +1433,7 @@ static int whereKeyStats(
#endif
assert( pRec!=0 );
assert( pIdx->nSample>0 );
assert( pRec->nField>0 && pRec->nField<=pIdx->nSampleCol );
assert( pRec->nField>0 );

/* Do a binary search to find the first sample greater than or equal
** to pRec. If pRec contains a single field, the set of samples to search
Expand Down Expand Up @@ -1479,7 +1479,7 @@ static int whereKeyStats(
** it is extended to two fields. The duplicates that this creates do not
** cause any problems.
*/
nField = pRec->nField;
nField = MIN(pRec->nField, pIdx->nSample);
iCol = 0;
iSample = pIdx->nSample * nField;
do{
Expand Down
31 changes: 31 additions & 0 deletions test/rowvalue.test
Expand Up @@ -751,4 +751,35 @@ do_execsql_test 32.1 {
WHERE a=1234 OR a<=567;
} {500 502}

# 2022-07-15
# https://sqlite.org/forum/forumpost/3607259d3c
#
reset_db
do_execsql_test 33.1 {
CREATE TABLE t1(a INT, b INT PRIMARY KEY) WITHOUT ROWID;
INSERT INTO t1(a, b) VALUES (0, 1),(15,-7),(3,100);
ANALYZE;
} {}
do_execsql_test 33.2 {
SELECT * FROM t1 WHERE (b,a) BETWEEN (0,5) AND (99,-2);
} {0 1}
do_execsql_test 33.3 {
SELECT * FROM t1 WHERE (b,a) BETWEEN (-8,5) AND (0,-2);
} {15 -7}
do_execsql_test 33.3 {
SELECT * FROM t1 WHERE (b,a) BETWEEN (3,5) AND (100,4);
} {3 100}
do_execsql_test 33.3 {
SELECT * FROM t1 WHERE (b,a) BETWEEN (3,5) AND (100,2);
} {}
do_execsql_test 33.3 {
SELECT * FROM t1 WHERE (a,b) BETWEEN (-2,99) AND (1,0);
} {0 1}
do_execsql_test 33.3 {
SELECT * FROM t1 WHERE (a,b) BETWEEN (14,99) AND (16,0);
} {15 -7}
do_execsql_test 33.3 {
SELECT * FROM t1 WHERE (a,b) BETWEEN (2,99) AND (4,0);
} {3 100}

finish_test

0 comments on commit effc07e

Please sign in to comment.