From aa1776f093a94c46d7d95ae120f0350b2137953b Mon Sep 17 00:00:00 2001 From: dan Date: Tue, 26 Nov 2013 18:22:59 +0000 Subject: [PATCH 01/14] Reduce the amount of code used to implement OP_SeekGe and similar. FossilOrigin-Name: 8b12a15a2a8139d75f56a099f3f6af844da3ac9c --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/vdbe.c | 52 +++++++++++++++++++++------------------------------ 3 files changed, 29 insertions(+), 39 deletions(-) diff --git a/manifest b/manifest index d7a8adc696..30adfeecf2 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sa\spossible\sNULL\spointer\sdeference\sin\sthe\swordcount\stest\sprogram. -D 2013-11-26T16:51:13.426 +C Reduce\sthe\samount\sof\scode\sused\sto\simplement\sOP_SeekGe\sand\ssimilar. +D 2013-11-26T18:22:59.246 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -280,7 +280,7 @@ F src/update.c c05a0ee658f1a149e0960dfd110f3b8bd846bcb0 F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269 F src/util.c cbe054290f780fcd472b89d701c7404c51ec9684 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 -F src/vdbe.c 061d30aea5bbe70926236836be259ed217ee65c0 +F src/vdbe.c d9c63f5c5679f6e6c96612264b5674b8020696c4 F src/vdbe.h c06f0813f853566457ce9cfb1a4a4bc39a5da644 F src/vdbeInt.h 05fbda0e061dbc4aaa2709a8cccf3515c245b263 F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed @@ -1143,7 +1143,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P c07caabf2396c84b2ccb0e9f98ae6279ce41c59d -R d1a47818d75d4c09a9dcb48899bdd6d5 -U drh -Z 42f2f4c4e3d27d9172438c5ee2b1524f +P 6f91dca0de908dc2b15130a6593a61c3147a409f +R d3fc734a7145de0774dfe549644c265c +U dan +Z 32a0a7a512d388c26cfa54a9b929b27b diff --git a/manifest.uuid b/manifest.uuid index 50a66e6b11..ffa1d68526 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -6f91dca0de908dc2b15130a6593a61c3147a409f \ No newline at end of file +8b12a15a2a8139d75f56a099f3f6af844da3ac9c \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 71e4d673c0..b402a5e6c0 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -3510,38 +3510,28 @@ case OP_SeekGt: { /* jump, in3 */ pc = pOp->p2 - 1; break; } - /* If we reach this point, then the P3 value must be a floating - ** point number. */ - assert( (pIn3->flags & MEM_Real)!=0 ); - if( (iKey==SMALLEST_INT64 && pIn3->r<(double)iKey) - || (iKey==LARGEST_INT64 && pIn3->r>(double)iKey) - ){ - /* The P3 value is too large in magnitude to be expressed as an - ** integer. */ - res = 1; - if( pIn3->r<0 ){ - if( oc>=OP_SeekGe ){ assert( oc==OP_SeekGe || oc==OP_SeekGt ); - rc = sqlite3BtreeFirst(pC->pCursor, &res); - if( rc!=SQLITE_OK ) goto abort_due_to_error; - } - }else{ - if( oc<=OP_SeekLe ){ assert( oc==OP_SeekLt || oc==OP_SeekLe ); - rc = sqlite3BtreeLast(pC->pCursor, &res); - if( rc!=SQLITE_OK ) goto abort_due_to_error; - } - } - if( res ){ - pc = pOp->p2 - 1; - } - break; - }else if( oc==OP_SeekLt || oc==OP_SeekGe ){ - /* Use the ceiling() function to convert real->int */ - if( pIn3->r > (double)iKey ) iKey++; - }else{ - /* Use the floor() function to convert real->int */ - assert( oc==OP_SeekLe || oc==OP_SeekGt ); - if( pIn3->r < (double)iKey ) iKey--; + /* If the approximation iKey is larger than the actual real search + ** term, substitute >= for > and < for <=. e.g. if the search term + ** is 4.9 and the integer approximation 5: + ** + ** (x > 4.9) -> (x >= 5) + ** (x <= 4.9) -> (x < 5) + */ + if( pIn3->r<(double)iKey ){ + assert( OP_SeekGe==(OP_SeekGt-1) ); + assert( OP_SeekLt==(OP_SeekLe-1) ); + assert( (OP_SeekLe & 0x0001)==(OP_SeekGt & 0x0001) ); + if( (oc & 0x0001)==(OP_SeekGt & 0x0001) ) oc--; + } + + /* If the approximation iKey is smaller than the actual real search + ** term, substitute <= for < and > for >=. */ + else if( pIn3->r>(double)iKey ){ + assert( OP_SeekLe==(OP_SeekLt+1) ); + assert( OP_SeekGt==(OP_SeekGe+1) ); + assert( (OP_SeekLt & 0x0001)==(OP_SeekGe & 0x0001) ); + if( (oc & 0x0001)==(OP_SeekLt & 0x0001) ) oc++; } } rc = sqlite3BtreeMovetoUnpacked(pC->pCursor, 0, (u64)iKey, 0, &res); From 1bcbc6a6d493a2d12d636d47f451eb0575f8e6b0 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 26 Nov 2013 21:18:45 +0000 Subject: [PATCH 02/14] Changing the CAST behavior of REAL values actually changed a documented requirement. So we also have to change the requirement evidence text to match. FossilOrigin-Name: d84aa44e3919e25f9520c5120a35ec21e837a9ea --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/e_expr.test | 8 +++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 30adfeecf2..3c8be252eb 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Reduce\sthe\samount\sof\scode\sused\sto\simplement\sOP_SeekGe\sand\ssimilar. -D 2013-11-26T18:22:59.246 +C Changing\sthe\sCAST\sbehavior\sof\sREAL\svalues\sactually\schanged\sa\sdocumented\nrequirement.\s\sSo\swe\salso\shave\sto\schange\sthe\srequirement\sevidence\stext\sto\nmatch. +D 2013-11-26T21:18:45.278 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -437,7 +437,7 @@ F test/e_createtable.test 3b453432cd14a12732ee9467597d2274ca37ce36 F test/e_delete.test d5186e2f5478b659f16a2c8b66c09892823e542a F test/e_droptrigger.test 3cd080807622c13e5bbb61fc9a57bd7754da2412 F test/e_dropview.test 0c9f7f60989164a70a67a9d9c26d1083bc808306 -F test/e_expr.test 0808bc72c7b2a2fab4291418ecd73f4d09d7d671 +F test/e_expr.test 5cc73445ccac0fa6e16ef05ccb42021c8bdd0c0e F test/e_fkey.test d83a04478bb9c02d2c513518548a69f818869f41 F test/e_fts3.test 5c02288842e4f941896fd44afdef564dd5fc1459 F test/e_insert.test 1e44f84d2abe44d66e4fbf198be4b20e3cc724a0 @@ -1143,7 +1143,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 6f91dca0de908dc2b15130a6593a61c3147a409f -R d3fc734a7145de0774dfe549644c265c -U dan -Z 32a0a7a512d388c26cfa54a9b929b27b +P 8b12a15a2a8139d75f56a099f3f6af844da3ac9c +R 1c9b8ea37e158d8aa056f9d55c189c9f +U drh +Z 4aa8d025d1cf631a0e550b5e09b9ad22 diff --git a/manifest.uuid b/manifest.uuid index ffa1d68526..c276139572 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -8b12a15a2a8139d75f56a099f3f6af844da3ac9c \ No newline at end of file +d84aa44e3919e25f9520c5120a35ec21e837a9ea \ No newline at end of file diff --git a/test/e_expr.test b/test/e_expr.test index eead6a2b93..0f55cb9ae3 100644 --- a/test/e_expr.test +++ b/test/e_expr.test @@ -1602,9 +1602,11 @@ do_expr_test e_expr-31.1.2 { CAST(1.99999 AS INTEGER) } integer 1 do_expr_test e_expr-31.1.3 { CAST(-1.99999 AS INTEGER) } integer -1 do_expr_test e_expr-31.1.4 { CAST(-0.99999 AS INTEGER) } integer 0 -# EVIDENCE-OF: R-49503-28105 If a REAL is too large to be represented as -# an INTEGER then the result of the cast is the largest negative -# integer: -9223372036854775808. +# EVIDENCE-OF: R-51517-40824 If a REAL is greater than the greatest +# possible signed integer (+9223372036854775807) then the result is the +# greatest possible signed integer and if the REAL is less than the +# least possible signed integer (-9223372036854775808) then the result +# is the least possible signed integer. # do_expr_test e_expr-31.2.1 { CAST(2e+50 AS INT) } integer 9223372036854775807 do_expr_test e_expr-31.2.2 { CAST(-2e+50 AS INT) } integer -9223372036854775808 From 2c7e9bfc5013769d1cd149909b1d687173cefd65 Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 26 Nov 2013 22:46:54 +0000 Subject: [PATCH 03/14] Add requirements test cases for determining when an expression is true and when it is false. FossilOrigin-Name: 838654e56304a5788ac384ca506c1938f48af488 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/e_expr.test | 38 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 7 deletions(-) diff --git a/manifest b/manifest index 3c8be252eb..1f5ab57756 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Changing\sthe\sCAST\sbehavior\sof\sREAL\svalues\sactually\schanged\sa\sdocumented\nrequirement.\s\sSo\swe\salso\shave\sto\schange\sthe\srequirement\sevidence\stext\sto\nmatch. -D 2013-11-26T21:18:45.278 +C Add\srequirements\stest\scases\sfor\sdetermining\swhen\san\sexpression\sis\strue\sand\nwhen\sit\sis\sfalse. +D 2013-11-26T22:46:54.424 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -437,7 +437,7 @@ F test/e_createtable.test 3b453432cd14a12732ee9467597d2274ca37ce36 F test/e_delete.test d5186e2f5478b659f16a2c8b66c09892823e542a F test/e_droptrigger.test 3cd080807622c13e5bbb61fc9a57bd7754da2412 F test/e_dropview.test 0c9f7f60989164a70a67a9d9c26d1083bc808306 -F test/e_expr.test 5cc73445ccac0fa6e16ef05ccb42021c8bdd0c0e +F test/e_expr.test a9f7c084ea3648003bcc40dd50861af5d2341fc1 F test/e_fkey.test d83a04478bb9c02d2c513518548a69f818869f41 F test/e_fts3.test 5c02288842e4f941896fd44afdef564dd5fc1459 F test/e_insert.test 1e44f84d2abe44d66e4fbf198be4b20e3cc724a0 @@ -1143,7 +1143,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 8b12a15a2a8139d75f56a099f3f6af844da3ac9c -R 1c9b8ea37e158d8aa056f9d55c189c9f +P d84aa44e3919e25f9520c5120a35ec21e837a9ea +R ceef359da24957280bf0acfc550c26b7 U drh -Z 4aa8d025d1cf631a0e550b5e09b9ad22 +Z 5bb7513aebd7acd760a2df9416ad20ba diff --git a/manifest.uuid b/manifest.uuid index c276139572..05481834be 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -d84aa44e3919e25f9520c5120a35ec21e837a9ea \ No newline at end of file +838654e56304a5788ac384ca506c1938f48af488 \ No newline at end of file diff --git a/test/e_expr.test b/test/e_expr.test index 0f55cb9ae3..ea23a22d7f 100644 --- a/test/e_expr.test +++ b/test/e_expr.test @@ -1849,5 +1849,43 @@ foreach {tn expr} { do_expr_test e_expr-36.4.$tn $expr null {} } +# EVIDENCE-OF: R-62477-06476 For example, the values NULL, 0.0, 0, +# 'english' and '0' are all considered to be false. +# +do_execsql_test e_expr-37.1 { + SELECT CASE WHEN NULL THEN 'true' ELSE 'false' END; +} {false} +do_execsql_test e_expr-37.2 { + SELECT CASE WHEN 0.0 THEN 'true' ELSE 'false' END; +} {false} +do_execsql_test e_expr-37.3 { + SELECT CASE WHEN 0 THEN 'true' ELSE 'false' END; +} {false} +do_execsql_test e_expr-37.4 { + SELECT CASE WHEN 'engligh' THEN 'true' ELSE 'false' END; +} {false} +do_execsql_test e_expr-37.5 { + SELECT CASE WHEN '0' THEN 'true' ELSE 'false' END; +} {false} + +# EVIDENCE-OF: R-55532-10108 Values 1, 1.0, 0.1, -0.1 and '1english' are +# considered to be true. +# +do_execsql_test e_expr-37.6 { + SELECT CASE WHEN 1 THEN 'true' ELSE 'false' END; +} {true} +do_execsql_test e_expr-37.7 { + SELECT CASE WHEN 1.0 THEN 'true' ELSE 'false' END; +} {true} +do_execsql_test e_expr-37.8 { + SELECT CASE WHEN 0.1 THEN 'true' ELSE 'false' END; +} {true} +do_execsql_test e_expr-37.9 { + SELECT CASE WHEN -0.1 THEN 'true' ELSE 'false' END; +} {true} +do_execsql_test e_expr-37.10 { + SELECT CASE WHEN '1english' THEN 'true' ELSE 'false' END; +} {true} + finish_test From bbbb0e8053a82fabc371c32b2a95497378a7d72f Mon Sep 17 00:00:00 2001 From: drh Date: Tue, 26 Nov 2013 23:27:07 +0000 Subject: [PATCH 04/14] Make sure the update hook is not invoked for WITHOUT ROWID tables, as the documentation specifies. This bug was found while adding requirements marks, so a few extraneous requirements marks are included in this check-in. FossilOrigin-Name: 0978bac6b8aee229d7a0d148546f50d380d06a06 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/resolve.c | 4 +++- src/vdbe.c | 13 ++----------- test/e_createtable.test | 8 ++++++++ test/hook.test | 16 ++++++++++++++++ 6 files changed, 39 insertions(+), 22 deletions(-) diff --git a/manifest b/manifest index 1f5ab57756..9ce618374e 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\srequirements\stest\scases\sfor\sdetermining\swhen\san\sexpression\sis\strue\sand\nwhen\sit\sis\sfalse. -D 2013-11-26T22:46:54.424 +C Make\ssure\sthe\supdate\shook\sis\snot\sinvoked\sfor\sWITHOUT\sROWID\stables,\sas\nthe\sdocumentation\sspecifies.\s\sThis\sbug\swas\sfound\swhile\sadding\srequirements\nmarks,\sso\sa\sfew\sextraneous\srequirements\smarks\sare\sincluded\sin\sthis\ncheck-in. +D 2013-11-26T23:27:07.055 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -217,7 +217,7 @@ F src/pragma.c 5ab7279d132143feb77f773688a24ab05da75fd7 F src/prepare.c 359d1a1e9c9bd4488e4dd3a1aaaf2d2ebb9bb768 F src/printf.c da9119eb31a187a4b99f60aa4a225141c0ebb74b F src/random.c 0b2dbc37fdfbfa6bd455b091dfcef5bdb32dba68 -F src/resolve.c a70e32ae6ccb7b780f2b6d3e9e21837affc25ee5 +F src/resolve.c 7eda9097b29fcf3d2b42fdc17d1de672134e09b6 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c d41381d80a22d3a83352aeca274cccf264ac277a F src/shell.c c4d06a9238a515ff4bc86b8626139633c09a00a2 @@ -280,7 +280,7 @@ F src/update.c c05a0ee658f1a149e0960dfd110f3b8bd846bcb0 F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269 F src/util.c cbe054290f780fcd472b89d701c7404c51ec9684 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 -F src/vdbe.c d9c63f5c5679f6e6c96612264b5674b8020696c4 +F src/vdbe.c c2b3cd6baddb224a2f155e410ca69f74e6efc671 F src/vdbe.h c06f0813f853566457ce9cfb1a4a4bc39a5da644 F src/vdbeInt.h 05fbda0e061dbc4aaa2709a8cccf3515c245b263 F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed @@ -433,7 +433,7 @@ F test/descidx3.test 09ddbe3f5295f482d2f8b687cf6db8bad7acd9a2 F test/diskfull.test 106391384780753ea6896b7b4f005d10e9866b6e F test/distinct.test 44028aaf161a5e80a2f229622b3a174d3b352810 F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376 -F test/e_createtable.test 3b453432cd14a12732ee9467597d2274ca37ce36 +F test/e_createtable.test a4561b93062e651d6def99c9e6956969dbf3754c F test/e_delete.test d5186e2f5478b659f16a2c8b66c09892823e542a F test/e_droptrigger.test 3cd080807622c13e5bbb61fc9a57bd7754da2412 F test/e_dropview.test 0c9f7f60989164a70a67a9d9c26d1083bc808306 @@ -587,7 +587,7 @@ F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 -F test/hook.test 45cb22b940c3cc0af616ba7430f666e245711a48 +F test/hook.test 8b24a1a8a1ddf0883c6824825e7577f2636918dc F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/in.test 047c4671328e9032ab95666a67021adbbd36e98e F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 @@ -1143,7 +1143,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P d84aa44e3919e25f9520c5120a35ec21e837a9ea -R ceef359da24957280bf0acfc550c26b7 +P 838654e56304a5788ac384ca506c1938f48af488 +R e178483a3ba4d2f533907e57553db5a6 U drh -Z 5bb7513aebd7acd760a2df9416ad20ba +Z 51c7e3abc8471c6679ba39e030a2dca2 diff --git a/manifest.uuid b/manifest.uuid index 05481834be..91c5fe5dfd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -838654e56304a5788ac384ca506c1938f48af488 \ No newline at end of file +0978bac6b8aee229d7a0d148546f50d380d06a06 \ No newline at end of file diff --git a/src/resolve.c b/src/resolve.c index 2c0907cc47..b0adb86295 100644 --- a/src/resolve.c +++ b/src/resolve.c @@ -352,7 +352,9 @@ static int lookupName( } } if( iCol>=pTab->nCol && sqlite3IsRowid(zCol) && HasRowid(pTab) ){ - iCol = -1; /* IMP: R-44911-55124 */ + /* IMP: R-24309-18625 */ + /* IMP: R-44911-55124 */ + iCol = -1; } if( iColnCol ){ cnt++; diff --git a/src/vdbe.c b/src/vdbe.c index b402a5e6c0..3b27ba144a 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -4109,20 +4109,11 @@ case OP_Delete: { i64 iKey; VdbeCursor *pC; - iKey = 0; assert( pOp->p1>=0 && pOp->p1nCursor ); pC = p->apCsr[pOp->p1]; assert( pC!=0 ); assert( pC->pCursor!=0 ); /* Only valid for real tables, no pseudotables */ - - /* If the update-hook will be invoked, set iKey to the rowid of the - ** row being deleted. - */ - if( db->xUpdateCallback && pOp->p4.z ){ - assert( pC->isTable ); - assert( pC->rowidIsValid ); /* lastRowid set by previous OP_NotFound */ - iKey = pC->lastRowid; - } + iKey = pC->lastRowid; /* Only used for the update hook */ /* The OP_Delete opcode always follows an OP_NotExists or OP_Last or ** OP_Column on the same table without any intervening operations that @@ -4140,7 +4131,7 @@ case OP_Delete: { pC->cacheStatus = CACHE_STALE; /* Invoke the update-hook if required. */ - if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z ){ + if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){ const char *zDb = db->aDb[pC->iDb].zName; const char *zTbl = pOp->p4.z; db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, zTbl, iKey); diff --git a/test/e_createtable.test b/test/e_createtable.test index 8b57c73971..1c8ab7d86e 100644 --- a/test/e_createtable.test +++ b/test/e_createtable.test @@ -1654,6 +1654,10 @@ do_execsql_test 4.19.4 { SELECT * FROM t5 } {} # of the special case-independent names "rowid", "oid", or "_rowid_" in # place of a column name. # +# EVIDENCE-OF: R-06726-07466 A column name can be any of the names +# defined in the CREATE TABLE statement or one of the following special +# identifiers: "ROWID", "OID", or "_ROWID_". +# drop_all_tables do_execsql_test 5.1.0 { CREATE TABLE t1(x, y); @@ -1678,6 +1682,10 @@ do_createtable_tests 5.1 { # explicitly declared column and cannot be used to retrieve the integer # rowid value. # +# EVIDENCE-OF: R-44615-33286 The special identifiers only refer to the +# row key if the CREATE TABLE statement does not define a real column +# with the same name. +# do_execsql_test 5.2.0 { CREATE TABLE t2(oid, b); CREATE TABLE t3(a, _rowid_); diff --git a/test/hook.test b/test/hook.test index 6346cc77a7..a186da3aa7 100644 --- a/test/hook.test +++ b/test/hook.test @@ -135,9 +135,11 @@ do_test hook-4.1.1 { } execsql { CREATE TABLE t1(a INTEGER PRIMARY KEY, b); + CREATE TABLE t1w(a INT PRIMARY KEY, b) WITHOUT ROWID; INSERT INTO t1 VALUES(1, 'one'); INSERT INTO t1 VALUES(2, 'two'); INSERT INTO t1 VALUES(3, 'three'); + INSERT INTO t1w SELECT * FROM t1; } db update_hook [list lappend ::update_hook] } {} @@ -159,6 +161,20 @@ do_test hook-4.1.2 { DELETE main t1 4 \ ] +# EVIDENCE-OF: R-61808-14344 The sqlite3_update_hook() interface does +# not fire callbacks for changes to a WITHOUT ROWID table. +# +do_test hook-4.1.2w { + set ::update_hook {} + execsql { + INSERT INTO t1w VALUES(4, 'four'); + DELETE FROM t1w WHERE b = 'two'; + UPDATE t1w SET b = '' WHERE a = 1 OR a = 3; + DELETE FROM t1w WHERE 1; -- Avoid the truncate optimization (for now) + } + set ::update_hook +} {} + ifcapable trigger { # Update hook is not invoked for changes to sqlite_master # From ef1bd970ef1b54abd889af2dbe8a66a900697927 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Nov 2013 00:45:49 +0000 Subject: [PATCH 05/14] Add additional test cases and requirements evidence marks for WITHOUT ROWID. FossilOrigin-Name: b408d788105efd007e3546f45d5dd15a5dc5688d --- manifest | 17 ++-- manifest.uuid | 2 +- test/hook.test | 36 ++++++- test/lastinsert.test | 11 +++ test/rowid.test | 4 +- test/without_rowid5.test | 201 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 259 insertions(+), 12 deletions(-) create mode 100644 test/without_rowid5.test diff --git a/manifest b/manifest index 9ce618374e..b545f7f91a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sthe\supdate\shook\sis\snot\sinvoked\sfor\sWITHOUT\sROWID\stables,\sas\nthe\sdocumentation\sspecifies.\s\sThis\sbug\swas\sfound\swhile\sadding\srequirements\nmarks,\sso\sa\sfew\sextraneous\srequirements\smarks\sare\sincluded\sin\sthis\ncheck-in. -D 2013-11-26T23:27:07.055 +C Add\sadditional\stest\scases\sand\srequirements\sevidence\smarks\sfor\sWITHOUT\sROWID. +D 2013-11-27T00:45:49.889 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -587,7 +587,7 @@ F test/fuzz_malloc.test 328f70aaca63adf29b4c6f06505ed0cf57ca7c26 F test/fuzzer1.test d4c52aaf3ef923da293a2653cfab33d02f718a36 F test/fuzzerfault.test 8792cd77fd5bce765b05d0c8e01b9edcf8af8536 F test/genesis.tcl 1e2e2e8e5cc4058549a154ff1892fe5c9de19f98 -F test/hook.test 8b24a1a8a1ddf0883c6824825e7577f2636918dc +F test/hook.test 162d7cef7a2d2b04839fe14402934e6a1b79442f F test/icu.test 70df4faca133254c042d02ae342c0a141f2663f4 F test/in.test 047c4671328e9032ab95666a67021adbbd36e98e F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 @@ -643,7 +643,7 @@ F test/jrnlmode.test 9ee3a78f53d52cca737db69293d15dc41c0cbd36 F test/jrnlmode2.test 81610545a4e6ed239ea8fa661891893385e23a1d F test/jrnlmode3.test 556b447a05be0e0963f4311e95ab1632b11c9eaa F test/keyword1.test a2400977a2e4fde43bf33754c2929fda34dbca05 -F test/lastinsert.test 474d519c68cb79d07ecae56a763aa7f322c72f51 +F test/lastinsert.test 42e948fd6442f07d60acbd15d33fb86473e0ef63 F test/laststmtchanges.test ae613f53819206b3222771828d024154d51db200 F test/like.test 935fb4f608e3ea126891496a6e99b9468372bf5c F test/like2.test 3b2ee13149ba4a8a60b59756f4e5d345573852da @@ -756,7 +756,7 @@ F test/releasetest.tcl 06d289d8255794073a58d2850742f627924545ce F test/resolver01.test 33abf37ff8335e6bf98f2b45a0af3e06996ccd9a F test/rollback.test e9504a009a202c3ed711da2e6879ff60c5a4669c F test/rowhash.test 0bc1d31415e4575d10cacf31e1a66b5cc0f8be81 -F test/rowid.test f777404492adb0e00868fd706a3721328fd3af48 +F test/rowid.test b78b30afb9537a73788ca1233a23a32190a3bb1f F test/rtree.test 0c8d9dd458d6824e59683c19ab2ffa9ef946f798 F test/run-wordcount.sh 891e89c4c2d16e629cd45951d4ed899ad12afc09 F test/savepoint.test 6c53f76dffe5df0dd87646efe3e7aa159c36e07b @@ -1091,6 +1091,7 @@ F test/without_rowid1.test aaa26da19d543cd8d3d2d0e686dfa255556c15c8 F test/without_rowid2.test af260339f79d13cb220288b67cd287fbcf81ad99 F test/without_rowid3.test eac3d5c8a1924725b58503a368f2cbd24fd6c8a0 F test/without_rowid4.test 4e08bcbaee0399f35d58b5581881e7a6243d458a +F test/without_rowid5.test b4a639a367f04d382d20e8f44fc1be4f2d57d107 F test/wordcount.c 9915e06cb33d8ca8109b8700791afe80d305afda F test/zeroblob.test caaecfb4f908f7bc086ed238668049f96774d688 F test/zerodamage.test 209d7ed441f44cc5299e4ebffbef06fd5aabfefd @@ -1143,7 +1144,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 838654e56304a5788ac384ca506c1938f48af488 -R e178483a3ba4d2f533907e57553db5a6 +P 0978bac6b8aee229d7a0d148546f50d380d06a06 +R c5e238577bf88ba62aaf207d6ba68ed5 U drh -Z 51c7e3abc8471c6679ba39e030a2dca2 +Z 6729df1882fbf26a3a642e6e52bb3ce5 diff --git a/manifest.uuid b/manifest.uuid index 91c5fe5dfd..8320ba30fd 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -0978bac6b8aee229d7a0d148546f50d380d06a06 \ No newline at end of file +b408d788105efd007e3546f45d5dd15a5dc5688d \ No newline at end of file diff --git a/test/hook.test b/test/hook.test index a186da3aa7..de6fbdd254 100644 --- a/test/hook.test +++ b/test/hook.test @@ -127,23 +127,52 @@ db2 close # depopulation of indices, to make sure the update-hook is not # invoked incorrectly. # +# EVIDENCE-OF: R-21999-45122 The sqlite3_update_hook() interface +# registers a callback function with the database connection identified +# by the first argument to be invoked whenever a row is updated, +# inserted or deleted in a rowid table. # Simple tests -do_test hook-4.1.1 { +do_test hook-4.1.1a { catchsql { DROP TABLE t1; } + unset -nocomplain ::update_hook + set ::update_hook {} + db update_hook [list lappend ::update_hook] + # + # EVIDENCE-OF: R-52223-27275 The update hook is not invoked when + # internal system tables are modified (i.e. sqlite_master and + # sqlite_sequence). + # execsql { CREATE TABLE t1(a INTEGER PRIMARY KEY, b); CREATE TABLE t1w(a INT PRIMARY KEY, b) WITHOUT ROWID; + } + set ::update_hook +} {} +do_test hook-4.1.1b { + execsql { INSERT INTO t1 VALUES(1, 'one'); INSERT INTO t1 VALUES(2, 'two'); INSERT INTO t1 VALUES(3, 'three'); INSERT INTO t1w SELECT * FROM t1; } - db update_hook [list lappend ::update_hook] } {} + +# EVIDENCE-OF: R-15506-57666 The second callback argument is one of +# SQLITE_INSERT, SQLITE_DELETE, or SQLITE_UPDATE, depending on the +# operation that caused the callback to be invoked. +# +# EVIDENCE-OF: R-29213-61195 The third and fourth arguments to the +# callback contain pointers to the database and table name containing +# the affected row. +# +# EVIDENCE-OF: R-30809-57812 The final callback parameter is the rowid +# of the row. +# do_test hook-4.1.2 { + set ::update_hook {} execsql { INSERT INTO t1 VALUES(4, 'four'); DELETE FROM t1 WHERE b = 'two'; @@ -164,6 +193,9 @@ do_test hook-4.1.2 { # EVIDENCE-OF: R-61808-14344 The sqlite3_update_hook() interface does # not fire callbacks for changes to a WITHOUT ROWID table. # +# EVIDENCE-OF: R-33257-44249 The update hook is not invoked when WITHOUT +# ROWID tables are modified. +# do_test hook-4.1.2w { set ::update_hook {} execsql { diff --git a/test/lastinsert.test b/test/lastinsert.test index adeb79860b..c5bc267d1a 100644 --- a/test/lastinsert.test +++ b/test/lastinsert.test @@ -36,6 +36,17 @@ do_test lastinsert-1.1 { } } {0 3} +# EVIDENCE-OF: R-47220-63683 The sqlite3_last_insert_rowid() function +# does not work for WITHOUT ROWID tables. +# +do_test lastinsert-1.1w { + catchsql { + create table t1w (k integer primary key) WITHOUT ROWID; + insert into t1w values (123456); + select last_insert_rowid(); -- returns 3 from above. + } +} {0 3} + # LIRID unchanged after an update on a table do_test lastinsert-1.2 { catchsql { diff --git a/test/rowid.test b/test/rowid.test index 5daf581ea6..6d068d79bb 100644 --- a/test/rowid.test +++ b/test/rowid.test @@ -12,7 +12,9 @@ # focus of this file is testing the magic ROWID column that is # found on all tables. # -# $Id: rowid.test,v 1.21 2009/06/26 15:14:55 drh Exp $ +# EVIDENCE-OF: R-36924-43758 By default, every row in SQLite has a +# special column, usually called the "rowid", that uniquely identifies +# that row within the table. set testdir [file dirname $argv0] source $testdir/tester.tcl diff --git a/test/without_rowid5.test b/test/without_rowid5.test new file mode 100644 index 0000000000..45e047befe --- /dev/null +++ b/test/without_rowid5.test @@ -0,0 +1,201 @@ +# 2013-11-26 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# Requirements testing for WITHOUT ROWID tables. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + + +# EVIDENCE-OF: R-36924-43758 By default, every row in SQLite has a +# special column, usually called the "rowid", that uniquely identifies +# that row within the table. +# +# EVIDENCE-OF: R-32341-39358 However if the phrase "WITHOUT ROWID" is +# added to the end of a CREATE TABLE statement, then the special "rowid" +# column is omitted. +# +do_execsql_test without_rowid5-1.1 { + CREATE TABLE t1(a PRIMARY KEY,b,c); + CREATE TABLE t1w(a PRIMARY KEY,b,c) WITHOUT ROWID; + INSERT INTO t1 VALUES(1565,681,1148),(1429,1190,1619),(425,358,1306); + INSERT INTO t1w SELECT a,b,c FROM t1; + SELECT rowid, _rowid_, oid FROM t1 ORDER BY a DESC; +} {1 1 1 2 2 2 3 3 3} +do_catchsql_test without_rowid5-1.2 { + SELECT rowid FROM t1w; +} {1 {no such column: rowid}} +do_catchsql_test without_rowid5-1.3 { + SELECT _rowid_ FROM t1w; +} {1 {no such column: _rowid_}} +do_catchsql_test without_rowid5-1.4 { + SELECT oid FROM t1w; +} {1 {no such column: oid}} + +# EVIDENCE-OF: R-00217-01605 To create a WITHOUT ROWID table, simply add +# the keywords "WITHOUT ROWID" to the end of the CREATE TABLE statement. +# For example: CREATE TABLE IF NOT EXISTS wordcount( word TEXT PRIMARY +# KEY, cnt INTEGER ) WITHOUT ROWID; +# +do_execsql_test without_rowid5-2.1 { + CREATE TABLE IF NOT EXISTS wordcount( + word TEXT PRIMARY KEY, + cnt INTEGER + ) WITHOUT ROWID; + INSERT INTO wordcount VALUES('one',1); +} {} +do_catchsql_test without_rowid5-2.2 { + SELECT rowid FROM wordcount; +} {1 {no such column: rowid}} + +# EVIDENCE-OF: R-24770-17719 As with all SQL syntax, the case of the +# keywords does not matter. One can write "WITHOUT rowid" or "without +# rowid" or "WiThOuT rOwId" and it will mean the same thing. +# +do_execsql_test without_rowid5-2.3 { + CREATE TABLE IF NOT EXISTS wordcount_b( + word TEXT PRIMARY KEY, + cnt INTEGER + ) WITHOUT rowid; + INSERT INTO wordcount_b VALUES('one',1); +} {} +do_catchsql_test without_rowid5-2.4 { + SELECT rowid FROM wordcount_b; +} {1 {no such column: rowid}} +do_execsql_test without_rowid5-2.5 { + CREATE TABLE IF NOT EXISTS wordcount_c( + word TEXT PRIMARY KEY, + cnt INTEGER + ) without rowid; + INSERT INTO wordcount_c VALUES('one',1); +} {} +do_catchsql_test without_rowid5-2.6 { + SELECT rowid FROM wordcount_c; +} {1 {no such column: rowid}} +do_execsql_test without_rowid5-2.7 { + CREATE TABLE IF NOT EXISTS wordcount_d( + word TEXT PRIMARY KEY, + cnt INTEGER + ) WITHOUT rowid; + INSERT INTO wordcount_d VALUES('one',1); +} {} +do_catchsql_test without_rowid5-2.8 { + SELECT rowid FROM wordcount_d; +} {1 {no such column: rowid}} + +# EVIDENCE-OF: R-01418-51310 However, only "rowid" works as the keyword +# in the CREATE TABLE statement. +# +do_catchsql_test without_rowid5-3.1 { + CREATE TABLE IF NOT EXISTS error1( + word TEXT PRIMARY KEY, + cnt INTEGER + ) WITHOUT _rowid_; +} {1 {unknown table option: _rowid_}} +do_catchsql_test without_rowid5-3.2 { + CREATE TABLE IF NOT EXISTS error2( + word TEXT PRIMARY KEY, + cnt INTEGER + ) WITHOUT oid; +} {1 {unknown table option: oid}} + +# EVIDENCE-OF: R-58033-17334 An error is raised if a CREATE TABLE +# statement with the WITHOUT ROWID clause lacks a PRIMARY KEY. +# +# EVIDENCE-OF: R-63443-09418 Every WITHOUT ROWID table must have a +# PRIMARY KEY. +# +# EVIDENCE-OF: R-27966-31616 An attempt to create a WITHOUT ROWID table +# without a PRIMARY KEY results in an error. +# +do_catchsql_test without_rowid5-4.1 { + CREATE TABLE IF NOT EXISTS error3( + word TEXT UNIQUE, + cnt INTEGER + ) WITHOUT ROWID; +} {1 {PRIMARY KEY missing on table error3}} + +# EVIDENCE-OF: R-48230-36247 The special behaviors associated "INTEGER +# PRIMARY KEY" do not apply on WITHOUT ROWID tables. +# +do_execsql_test without_rowid5-5.1 { + CREATE TABLE ipk(key INTEGER PRIMARY KEY, val TEXT) WITHOUT ROWID; + INSERT INTO ipk VALUES('rival','bonus'); -- ok to insert non-integer key + SELECT * FROM ipk; +} {rival bonus} +do_catchsql_test without_rowid5-5.2 { + INSERT INTO ipk VALUES(NULL,'sample'); -- no automatic generation of keys +} {1 {NOT NULL constraint failed: ipk.key}} + +# EVIDENCE-OF: R-33142-02092 AUTOINCREMENT does not work on WITHOUT +# ROWID tables. +# +# EVIDENCE-OF: R-53084-07740 An error is raised if the "AUTOINCREMENT" +# keyword is used in the CREATE TABLE statement for a WITHOUT ROWID +# table. +# +do_catchsql_test without_rowid5-5.3 { + CREATE TABLE ipk2(key INTEGER PRIMARY KEY AUTOINCREMENT, val TEXT)WITHOUT ROWID; +} {1 {AUTOINCREMENT not allowed on WITHOUT ROWID tables}} + +# EVIDENCE-OF: R-27831-00579 NOT NULL is enforced on every column of the +# PRIMARY KEY in a WITHOUT ROWID table. +# +# EVIDENCE-OF: R-29781-51289 So, ordinary rowid tables in SQLite violate +# the SQL standard and allow NULL values in PRIMARY KEY fields. +# +# EVIDENCE-OF: R-27472-62612 But WITHOUT ROWID tables do follow the +# standard and will throw an error on any attempt to insert a NULL into +# a PRIMARY KEY column. +# +do_execsql_test without_rowid5-5.4 { + CREATE TABLE nn(a, b, c, d, e, PRIMARY KEY(c,a,e)); + CREATE TABLE nnw(a, b, c, d, e, PRIMARY KEY(c,a,e)) WITHOUT ROWID; + INSERT INTO nn VALUES(1,2,3,4,5); + INSERT INTO nnw VALUES(1,2,3,4,5); +} {} +do_execsql_test without_rowid5-5.5 { + INSERT INTO nn VALUES(NULL, 3,4,5,6); + INSERT INTO nn VALUES(3,4,NULL,7,8); + INSERT INTO nn VALUES(4,5,6,7,NULL); + SELECT count(*) FROM nn; +} {4} +do_catchsql_test without_rowid5-5.6 { + INSERT INTO nnw VALUES(NULL, 3,4,5,6); +} {1 {NOT NULL constraint failed: nnw.a}} +do_catchsql_test without_rowid5-5.7 { + INSERT INTO nnw VALUES(3,4,NULL,7,8) +} {1 {NOT NULL constraint failed: nnw.c}} +do_catchsql_test without_rowid5-5.8 { + INSERT INTO nnw VALUES(4,5,6,7,NULL) +} {1 {NOT NULL constraint failed: nnw.e}} +do_execsql_test without_rowid5-5.9 { + SELECT count(*) FROM nnw; +} {1} + +# EVIDENCE-OF: R-12643-30541 The incremental blob I/O mechanism does not +# work for WITHOUT ROWID tables. +# +# EVIDENCE-OF: R-25760-33257 The sqlite3_blob_open() interface will fail +# for a WITHOUT ROWID table. +# +do_execsql_test without_rowid5-6.1 { + CREATE TABLE b1(a INTEGER PRIMARY KEY, b BLOB) WITHOUT ROWID; + INSERT INTO b1 VALUES(1,x'0102030405060708090a0b0c0d0e0f'); +} {} +do_test without_rowid5-6.2 { + set rc [catch {db incrblob b1 b 1} msg] + lappend rc $msg +} {1 {cannot open table without rowid: b1}} + + +finish_test From 21236679d15fd11ebd78b5cbfd7eca66a72f3a29 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Nov 2013 01:23:53 +0000 Subject: [PATCH 06/14] Add additional test cases for skip-scan. FossilOrigin-Name: 1ae4915d4d08ee5ce526c04d1d0cda1078641793 --- manifest | 11 ++-- manifest.uuid | 2 +- test/skipscan2.test | 150 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 157 insertions(+), 6 deletions(-) create mode 100644 test/skipscan2.test diff --git a/manifest b/manifest index b545f7f91a..f3db92f644 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sadditional\stest\scases\sand\srequirements\sevidence\smarks\sfor\sWITHOUT\sROWID. -D 2013-11-27T00:45:49.889 +C Add\sadditional\stest\scases\sfor\sskip-scan. +D 2013-11-27T01:23:53.318 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -808,6 +808,7 @@ F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/shrink.test 8c70f62b6e8eb4d54533de6d65bd06b1b9a17868 F test/sidedelete.test f0ad71abe6233e3b153100f3b8d679b19a488329 F test/skipscan1.test 6bb4891c2cc5efd5690a9da9e7508e53d4a68e10 +F test/skipscan2.test c1e21a19ec8fa3674e9ccd0475f20ef82c275838 F test/soak.test 0b5b6375c9f4110c828070b826b3b4b0bb65cd5f F test/softheap1.test 40562fe6cac6d9827b7b42b86d45aedf12c15e24 F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5 @@ -1144,7 +1145,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 0978bac6b8aee229d7a0d148546f50d380d06a06 -R c5e238577bf88ba62aaf207d6ba68ed5 +P b408d788105efd007e3546f45d5dd15a5dc5688d +R d4fd41c1f94c9f73ab9606b0e58d8a6b U drh -Z 6729df1882fbf26a3a642e6e52bb3ce5 +Z 5fe0b4019eaac7439aed9d81168a0a2a diff --git a/manifest.uuid b/manifest.uuid index 8320ba30fd..74f91dc909 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -b408d788105efd007e3546f45d5dd15a5dc5688d \ No newline at end of file +1ae4915d4d08ee5ce526c04d1d0cda1078641793 \ No newline at end of file diff --git a/test/skipscan2.test b/test/skipscan2.test new file mode 100644 index 0000000000..3858ed5e07 --- /dev/null +++ b/test/skipscan2.test @@ -0,0 +1,150 @@ +# 2013-11-27 +# +# The author disclaims copyright to this source code. In place of +# a legal notice, here is a blessing: +# +# May you do good and not evil. +# May you find forgiveness for yourself and forgive others. +# May you share freely, never taking more than you give. +# +#*********************************************************************** +# +# This file implements tests of the "skip-scan" query strategy. +# +# The test cases in this file are derived from the description of +# the skip-scan query strategy in the "optoverview.html" document. +# + +set testdir [file dirname $argv0] +source $testdir/tester.tcl + +do_execsql_test skipscan2-1.1 { + CREATE TABLE people( + name TEXT PRIMARY KEY, + role TEXT NOT NULL, + height INT NOT NULL, -- in cm + CHECK( role IN ('student','teacher') ) + ); + CREATE INDEX people_idx1 ON people(role, height); +} {} +do_execsql_test skipscan2-1.2 { + INSERT INTO people VALUES('Alice','student',156); + INSERT INTO people VALUES('Bob','student',161); + INSERT INTO people VALUES('Cindy','student',155); + INSERT INTO people VALUES('David','student',181); + INSERT INTO people VALUES('Emily','teacher',158); + INSERT INTO people VALUES('Fred','student',163); + INSERT INTO people VALUES('Ginny','student',169); + INSERT INTO people VALUES('Harold','student',172); + INSERT INTO people VALUES('Imma','student',179); + INSERT INTO people VALUES('Jack','student',181); + INSERT INTO people VALUES('Karen','student',163); + INSERT INTO people VALUES('Logan','student',177); + INSERT INTO people VALUES('Megan','teacher',159); + INSERT INTO people VALUES('Nathan','student',163); + INSERT INTO people VALUES('Olivia','student',161); + INSERT INTO people VALUES('Patrick','teacher',180); + INSERT INTO people VALUES('Quiana','student',182); + INSERT INTO people VALUES('Robert','student',159); + INSERT INTO people VALUES('Sally','student',166); + INSERT INTO people VALUES('Tom','student',171); + INSERT INTO people VALUES('Ursula','student',170); + INSERT INTO people VALUES('Vance','student',179); + INSERT INTO people VALUES('Willma','student',175); + INSERT INTO people VALUES('Xavier','teacher',185); + INSERT INTO people VALUES('Yvonne','student',149); + INSERT INTO people VALUES('Zach','student',170); +} + +# Without ANALYZE, a skip-scan is not used +# +do_execsql_test skipscan2-1.3 { + SELECT name FROM people WHERE height>=180 ORDER BY +name; +} {David Jack Patrick Quiana Xavier} +do_execsql_test skipscan2-1.3eqp { + EXPLAIN QUERY PLAN + SELECT name FROM people WHERE height>=180 ORDER BY +name; +} {~/*INDEX people_idx1 */} + +# Now do an ANALYZE. A skip-scan can be used after ANALYZE. +# +do_execsql_test skipscan2-1.4 { + ANALYZE; + -- We do not have enough people above to actually force the use + -- of a skip-scan. So make a manual adjustment to the stat1 table + -- to make it seem like there are many more. + UPDATE sqlite_stat1 SET stat='10000 5000 20' WHERE idx='people_idx1'; + ANALYZE sqlite_master; +} +db cache flush +do_execsql_test skipscan2-1.5 { + SELECT name FROM people WHERE height>=180 ORDER BY +name; +} {David Jack Patrick Quiana Xavier} +do_execsql_test skipscan2-1.5eqp { + EXPLAIN QUERY PLAN + SELECT name FROM people WHERE height>=180 ORDER BY +name; +} {/*INDEX people_idx1 */} + +# Same answer with other formulations of the same query +# +do_execsql_test skipscan2-1.6 { + SELECT name FROM people + WHERE role IN (SELECT DISTINCT role FROM people) + AND height>=180 ORDER BY +name; +} {David Jack Patrick Quiana Xavier} +do_execsql_test skipscan2-1.7 { + SELECT name FROM people WHERE role='teacher' AND height>=180 + UNION ALL + SELECT name FROM people WHERE role='student' AND height>=180 + ORDER BY 1; +} {David Jack Patrick Quiana Xavier} + +# Repeat using a WITHOUT ROWID table. +# +do_execsql_test skipscan2-2.1 { + CREATE TABLE peoplew( + name TEXT PRIMARY KEY, + role TEXT NOT NULL, + height INT NOT NULL, -- in cm + CHECK( role IN ('student','teacher') ) + ) WITHOUT ROWID; + CREATE INDEX peoplew_idx1 ON peoplew(role, height); + INSERT INTO peoplew(name,role,height) + SELECT name, role, height FROM people; + DROP TABLE people; + SELECT name FROM peoplew WHERE height>=180 ORDER BY +name; +} {David Jack Patrick Quiana Xavier} +do_execsql_test skipscan2-2.2 { + SELECT name FROM peoplew + WHERE role IN (SELECT DISTINCT role FROM peoplew) + AND height>=180 ORDER BY +name; +} {David Jack Patrick Quiana Xavier} +do_execsql_test skipscan2-2.2 { + SELECT name FROM peoplew WHERE role='teacher' AND height>=180 + UNION ALL + SELECT name FROM peoplew WHERE role='student' AND height>=180 + ORDER BY 1; +} {David Jack Patrick Quiana Xavier} + +# Now do an ANALYZE. A skip-scan can be used after ANALYZE. +# +do_execsql_test skipscan2-2.4 { + ANALYZE; + -- We do not have enough people above to actually force the use + -- of a skip-scan. So make a manual adjustment to the stat1 table + -- to make it seem like there are many more. + UPDATE sqlite_stat1 SET stat='10000 5000 20' WHERE idx='peoplew_idx1'; + ANALYZE sqlite_master; +} +db cache flush +do_execsql_test skipscan2-2.5 { + SELECT name FROM peoplew WHERE height>=180 ORDER BY +name; +} {David Jack Patrick Quiana Xavier} +do_execsql_test skipscan2-2.5eqp { + EXPLAIN QUERY PLAN + SELECT name FROM peoplew WHERE height>=180 ORDER BY +name; +} {/*INDEX peoplew_idx1 */} + + + +finish_test From 0f7e08e0e2b57236d1b2d94f20c66971004d6032 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 27 Nov 2013 03:01:34 +0000 Subject: [PATCH 07/14] Avoid using the GetVersionEx functions if they are considered deprecated. FossilOrigin-Name: 0ea9e4722be10221c99cce5bc48d13c7b34e739f --- manifest | 17 ++++++++++------- manifest.uuid | 2 +- src/os_win.c | 41 +++++++++++++++++++++++++++++++++++------ 3 files changed, 46 insertions(+), 14 deletions(-) diff --git a/manifest b/manifest index f3db92f644..16c9cab3ac 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Add\sadditional\stest\scases\sfor\sskip-scan. -D 2013-11-27T01:23:53.318 +C Avoid\susing\sthe\sGetVersionEx\sfunctions\sif\sthey\sare\sconsidered\sdeprecated. +D 2013-11-27T03:01:34.176 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -206,7 +206,7 @@ F src/os.c b4ad71336fd96f97776f75587cd9e8218288f5be F src/os.h 4a46270a64e9193af4a0aaa3bc2c66dc07c29b3f F src/os_common.h 92815ed65f805560b66166e3583470ff94478f04 F src/os_unix.c 143624d9eabb3b997c59cf594e0d06c56edd43e9 -F src/os_win.c cb3f26205ea785a63ea5bdc21a9c9f9ae3972d0f +F src/os_win.c 4323dd0bac4f7a7037fc4cf87fb4692d17f0b108 F src/pager.c 2aa4444ffe86e9282d03bc349a4a5e49bd77c0e8 F src/pager.h f094af9f6ececfaa8a1e93876905a4f34233fb0c F src/parse.y acee1a9958539e21263362b194594c5255ad2fca @@ -1145,7 +1145,10 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P b408d788105efd007e3546f45d5dd15a5dc5688d -R d4fd41c1f94c9f73ab9606b0e58d8a6b -U drh -Z 5fe0b4019eaac7439aed9d81168a0a2a +P 1ae4915d4d08ee5ce526c04d1d0cda1078641793 +R 1408bb35546f8304605f0cd70b3a2cef +T *branch * vs2013 +T *sym-vs2013 * +T -sym-trunk * +U mistachkin +Z f9b9e39c0c1855e6c7f8a373135be4dd diff --git a/manifest.uuid b/manifest.uuid index 74f91dc909..ed05f28047 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1ae4915d4d08ee5ce526c04d1d0cda1078641793 \ No newline at end of file +0ea9e4722be10221c99cce5bc48d13c7b34e739f \ No newline at end of file diff --git a/src/os_win.c b/src/os_win.c index 31c4b69df0..22052a3fe7 100644 --- a/src/os_win.c +++ b/src/os_win.c @@ -59,6 +59,34 @@ must be defined." #endif +/* +** Define the required Windows SDK version constants if they are not +** already available. +*/ +#ifndef NTDDI_WIN8 +# define NTDDI_WIN8 0x06020000 +#endif + +#ifndef NTDDI_WINBLUE +# define NTDDI_WINBLUE 0x06030000 +#endif + +/* +** Check if the GetVersionEx[AW] functions should be considered deprecated +** and avoid using them in that case. It should be noted here that if the +** value of the SQLITE_WIN32_GETVERSIONEX pre-processor macro is zero +** (whether via this block or via being manually specified), that implies +** the underlying operating system will always be based on the Windows NT +** Kernel. +*/ +#ifndef SQLITE_WIN32_GETVERSIONEX +# if defined(NTDDI_VERSION) && NTDDI_VERSION >= NTDDI_WINBLUE +# define SQLITE_WIN32_GETVERSIONEX 0 +# else +# define SQLITE_WIN32_GETVERSIONEX 1 +# endif +#endif + /* ** This constant should already be defined (in the "WinDef.h" SDK file). */ @@ -694,7 +722,8 @@ static struct win_syscall { #define osGetTickCount ((DWORD(WINAPI*)(VOID))aSyscall[33].pCurrent) -#if defined(SQLITE_WIN32_HAS_ANSI) +#if defined(SQLITE_WIN32_HAS_ANSI) && defined(SQLITE_WIN32_GETVERSIONEX) && \ + SQLITE_WIN32_GETVERSIONEX { "GetVersionExA", (SYSCALL)GetVersionExA, 0 }, #else { "GetVersionExA", (SYSCALL)0, 0 }, @@ -703,7 +732,8 @@ static struct win_syscall { #define osGetVersionExA ((BOOL(WINAPI*)( \ LPOSVERSIONINFOA))aSyscall[34].pCurrent) -#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) +#if !SQLITE_OS_WINRT && defined(SQLITE_WIN32_HAS_WIDE) && \ + defined(SQLITE_WIN32_GETVERSIONEX) && SQLITE_WIN32_GETVERSIONEX { "GetVersionExW", (SYSCALL)GetVersionExW, 0 }, #else { "GetVersionExW", (SYSCALL)0, 0 }, @@ -1260,11 +1290,10 @@ void sqlite3_win32_sleep(DWORD milliseconds){ ** WinNT/2K/XP so that we will know whether or not we can safely call ** the LockFileEx() API. */ -#ifndef NTDDI_WIN8 -# define NTDDI_WIN8 0x06020000 -#endif -#if SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI) +#if !defined(SQLITE_WIN32_GETVERSIONEX) || !SQLITE_WIN32_GETVERSIONEX +# define osIsNT() (1) +#elif SQLITE_OS_WINCE || SQLITE_OS_WINRT || !defined(SQLITE_WIN32_HAS_ANSI) # define osIsNT() (1) #elif !defined(SQLITE_WIN32_HAS_WIDE) # define osIsNT() (0) From c964c39fb02e9495ae3783f79865aae5df0d487d Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Nov 2013 04:22:27 +0000 Subject: [PATCH 08/14] Lower the threshold for using skip-scan from 50 to 18, based on experiments that show that 18 is the approximate break-even point for a variety of schemas. FossilOrigin-Name: 83c0bb9913838d18ba355033afde6e38b4690842 --- manifest | 14 +++++++------- manifest.uuid | 2 +- src/where.c | 6 ++++-- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index 4d6b73bdbd..2854113f03 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Avoid\susing\sthe\sGetVersionEx\sfunctions\sif\sthey\sare\sconsidered\sdeprecated. -D 2013-11-27T04:00:32.164 +C Lower\sthe\sthreshold\sfor\susing\sskip-scan\sfrom\s50\sto\s18,\sbased\son\sexperiments\nthat\sshow\sthat\s18\sis\sthe\sapproximate\sbreak-even\spoint\sfor\sa\svariety\sof\nschemas. +D 2013-11-27T04:22:27.199 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -293,7 +293,7 @@ F src/vtab.c 21b932841e51ebd7d075e2d0ad1415dce8d2d5fd F src/wal.c 7dc3966ef98b74422267e7e6e46e07ff6c6eb1b4 F src/wal.h df01efe09c5cb8c8e391ff1715cca294f89668a4 F src/walker.c e9e593d5bb798c3e67fc3893dfe7055c9e7d8d74 -F src/where.c e558bfa67009ab7de08a7a1960ae0dd443241cdd +F src/where.c e0a9909a58eee7dcde1d1bd5cf6381b0dbc83389 F src/whereInt.h 96a75c61f1d2b9d4a8e4bb17d89deb0cf7cba358 F test/8_3_names.test ebbb5cd36741350040fd28b432ceadf495be25b2 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 @@ -1145,7 +1145,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 1ae4915d4d08ee5ce526c04d1d0cda1078641793 0ea9e4722be10221c99cce5bc48d13c7b34e739f -R 1408bb35546f8304605f0cd70b3a2cef -U mistachkin -Z 11a83dbec42d946c53dc2adfcd9de746 +P afdca29966805ed0d49fd61a161eb3a3919b5963 +R 7f77bcc3aede19c7431a578762bf35fa +U drh +Z 4656cf413e484f30bbac5ec324b067a0 diff --git a/manifest.uuid b/manifest.uuid index 5dcbdd9cc3..ad77d07941 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -afdca29966805ed0d49fd61a161eb3a3919b5963 \ No newline at end of file +83c0bb9913838d18ba355033afde6e38b4690842 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 101ca1a7c6..7ec6cfaae7 100644 --- a/src/where.c +++ b/src/where.c @@ -3921,12 +3921,14 @@ static int whereLoopAddBtreeIndex( /* Consider using a skip-scan if there are no WHERE clause constraints ** available for the left-most terms of the index, and if the average - ** number of repeats in the left-most terms is at least 50. + ** number of repeats in the left-most terms is at least 18. The magic + ** number 18 was found by experimentation to be the payoff point where + ** skip-scan become faster than a full-scan. */ if( pTerm==0 && saved_nEq==saved_nSkip && saved_nEq+1nKeyCol - && pProbe->aiRowEst[saved_nEq+1]>50 /* TUNING: Minimum for skip-scan */ + && pProbe->aiRowEst[saved_nEq+1]>=18 /* TUNING: Minimum for skip-scan */ ){ LogEst nIter; pNew->u.btree.nEq++; From ac68ced162f6e29ce1fc0fa15b0c0ef1b67b0c83 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Nov 2013 13:24:18 +0000 Subject: [PATCH 09/14] Make sure the colWidth array is correctly initialized in the ".explain" command of the shell. FossilOrigin-Name: ceebcdcaf1acf409b77b4cc2903b4570001f098a --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/shell.c | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/manifest b/manifest index 2854113f03..9d807e7a96 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Lower\sthe\sthreshold\sfor\susing\sskip-scan\sfrom\s50\sto\s18,\sbased\son\sexperiments\nthat\sshow\sthat\s18\sis\sthe\sapproximate\sbreak-even\spoint\sfor\sa\svariety\sof\nschemas. -D 2013-11-27T04:22:27.199 +C Make\ssure\sthe\scolWidth\sarray\sis\scorrectly\sinitialized\sin\sthe\s".explain"\ncommand\sof\sthe\sshell. +D 2013-11-27T13:24:18.470 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -220,7 +220,7 @@ F src/random.c 0b2dbc37fdfbfa6bd455b091dfcef5bdb32dba68 F src/resolve.c 7eda9097b29fcf3d2b42fdc17d1de672134e09b6 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c d41381d80a22d3a83352aeca274cccf264ac277a -F src/shell.c c4d06a9238a515ff4bc86b8626139633c09a00a2 +F src/shell.c 936a72ff784efff3832cce274a96ed0b036e6758 F src/sqlite.h.in a8328969be639b6cd8d9225ed2a51d9d624fff5f F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc @@ -1145,7 +1145,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P afdca29966805ed0d49fd61a161eb3a3919b5963 -R 7f77bcc3aede19c7431a578762bf35fa +P 83c0bb9913838d18ba355033afde6e38b4690842 +R 67ef9465051c6a15a8474ed69b1e156e U drh -Z 4656cf413e484f30bbac5ec324b067a0 +Z 9742934aff6856eb16d7b29615a17978 diff --git a/manifest.uuid b/manifest.uuid index ad77d07941..1f8d47bbde 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -83c0bb9913838d18ba355033afde6e38b4690842 \ No newline at end of file +ceebcdcaf1acf409b77b4cc2903b4570001f098a \ No newline at end of file diff --git a/src/shell.c b/src/shell.c index 1db1e64e7e..480ec5b455 100644 --- a/src/shell.c +++ b/src/shell.c @@ -2096,7 +2096,7 @@ static int do_meta_command(char *zLine, struct callback_data *p){ */ p->mode = MODE_Explain; p->showHeader = 1; - memset(p->colWidth,0,ArraySize(p->colWidth)); + memset(p->colWidth,0,sizeof(p->colWidth)); p->colWidth[0] = 4; /* addr */ p->colWidth[1] = 13; /* opcode */ p->colWidth[2] = 4; /* P1 */ From ce00a8378511791f557b19b35f780c9b7924b3f9 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Nov 2013 13:48:02 +0000 Subject: [PATCH 10/14] Additional test cases for skip-scan. FossilOrigin-Name: ce70803f5e1bfb4dc495d3a0c2ddd5ee6c3a10fe --- manifest | 12 +++++------ manifest.uuid | 2 +- test/skipscan2.test | 52 +++++++++++++++++++++++++++++++++++++++------ 3 files changed, 53 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 9d807e7a96..1f661d4044 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Make\ssure\sthe\scolWidth\sarray\sis\scorrectly\sinitialized\sin\sthe\s".explain"\ncommand\sof\sthe\sshell. -D 2013-11-27T13:24:18.470 +C Additional\stest\scases\sfor\sskip-scan. +D 2013-11-27T13:48:02.795 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -808,7 +808,7 @@ F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3 F test/shrink.test 8c70f62b6e8eb4d54533de6d65bd06b1b9a17868 F test/sidedelete.test f0ad71abe6233e3b153100f3b8d679b19a488329 F test/skipscan1.test 6bb4891c2cc5efd5690a9da9e7508e53d4a68e10 -F test/skipscan2.test c1e21a19ec8fa3674e9ccd0475f20ef82c275838 +F test/skipscan2.test 5a4db0799c338ddbacb154aaa5589c0254b36a8d F test/soak.test 0b5b6375c9f4110c828070b826b3b4b0bb65cd5f F test/softheap1.test 40562fe6cac6d9827b7b42b86d45aedf12c15e24 F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5 @@ -1145,7 +1145,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P 83c0bb9913838d18ba355033afde6e38b4690842 -R 67ef9465051c6a15a8474ed69b1e156e +P ceebcdcaf1acf409b77b4cc2903b4570001f098a +R bcfcf6f48c85e4fa706276f8ed169192 U drh -Z 9742934aff6856eb16d7b29615a17978 +Z 88c6067bf128a26cfad7d97b15ea7137 diff --git a/manifest.uuid b/manifest.uuid index 1f8d47bbde..eb9f0afe6d 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ceebcdcaf1acf409b77b4cc2903b4570001f098a \ No newline at end of file +ce70803f5e1bfb4dc495d3a0c2ddd5ee6c3a10fe \ No newline at end of file diff --git a/test/skipscan2.test b/test/skipscan2.test index 3858ed5e07..e39b16ed27 100644 --- a/test/skipscan2.test +++ b/test/skipscan2.test @@ -99,6 +99,51 @@ do_execsql_test skipscan2-1.7 { ORDER BY 1; } {David Jack Patrick Quiana Xavier} +# Add 8 more people, bringing the total to 34. Then the number of +# duplicates in the left-column of the index will be 17 and +# skip-scan should not be used after an (unfudged) ANALYZE. +# +do_execsql_test skipscan2-1.8 { + INSERT INTO people VALUES('Angie','student',166); + INSERT INTO people VALUES('Brad','student',176); + INSERT INTO people VALUES('Claire','student',168); + INSERT INTO people VALUES('Donald','student',162); + INSERT INTO people VALUES('Elaine','student',177); + INSERT INTO people VALUES('Frazier','student',159); + INSERT INTO people VALUES('Grace','student',179); + INSERT INTO people VALUES('Horace','student',166); + ANALYZE; + SELECT stat FROM sqlite_stat1 WHERE idx='people_idx1'; +} {{34 17 2}} +db cache flush +do_execsql_test skipscan2-1.9 { + SELECT name FROM people WHERE height>=180 ORDER BY +name; +} {David Jack Patrick Quiana Xavier} +do_execsql_test skipscan2-1.9eqp { + EXPLAIN QUERY PLAN + SELECT name FROM people WHERE height>=180 ORDER BY +name; +} {~/*INDEX people_idx1 */} + +# Add 2 more people, bringing the total to 36. Then the number of +# duplicates in the left-column of the index will be 18 and +# skip-scan will be used after an (unfudged) ANALYZE. +# +do_execsql_test skipscan2-1.10 { + INSERT INTO people VALUES('Ingrad','student',155); + INSERT INTO people VALUES('Jacob','student',179); + ANALYZE; + SELECT stat FROM sqlite_stat1 WHERE idx='people_idx1'; +} {{36 18 2}} +db cache flush +do_execsql_test skipscan2-1.11 { + SELECT name FROM people WHERE height>=180 ORDER BY +name; +} {David Jack Patrick Quiana Xavier} +do_execsql_test skipscan2-1.11eqp { + EXPLAIN QUERY PLAN + SELECT name FROM people WHERE height>=180 ORDER BY +name; +} {/*INDEX people_idx1 */} + + # Repeat using a WITHOUT ROWID table. # do_execsql_test skipscan2-2.1 { @@ -111,7 +156,7 @@ do_execsql_test skipscan2-2.1 { CREATE INDEX peoplew_idx1 ON peoplew(role, height); INSERT INTO peoplew(name,role,height) SELECT name, role, height FROM people; - DROP TABLE people; + ALTER TABLE people RENAME TO old_people; SELECT name FROM peoplew WHERE height>=180 ORDER BY +name; } {David Jack Patrick Quiana Xavier} do_execsql_test skipscan2-2.2 { @@ -130,11 +175,6 @@ do_execsql_test skipscan2-2.2 { # do_execsql_test skipscan2-2.4 { ANALYZE; - -- We do not have enough people above to actually force the use - -- of a skip-scan. So make a manual adjustment to the stat1 table - -- to make it seem like there are many more. - UPDATE sqlite_stat1 SET stat='10000 5000 20' WHERE idx='peoplew_idx1'; - ANALYZE sqlite_master; } db cache flush do_execsql_test skipscan2-2.5 { From dcb5fa06e8f2c05f3f0ffe3b6a876d33ca612c68 Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Nov 2013 14:50:51 +0000 Subject: [PATCH 11/14] Fix some harmless compiler warnings in speedtest1.exe. FossilOrigin-Name: c75f561f337a56c14335366ed9990e44bc9fc594 --- manifest | 12 ++++++------ manifest.uuid | 2 +- test/speedtest1.c | 8 ++++---- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/manifest b/manifest index 1f661d4044..d5cd277511 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Additional\stest\scases\sfor\sskip-scan. -D 2013-11-27T13:48:02.795 +C Fix\ssome\sharmless\scompiler\swarnings\sin\sspeedtest1.exe. +D 2013-11-27T14:50:51.106 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -820,7 +820,7 @@ F test/speed3.test d32043614c08c53eafdc80f33191d5bd9b920523 F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715 F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa F test/speed4p.test 0e51908951677de5a969b723e03a27a1c45db38b -F test/speedtest1.c aa08ae8e3591bf5c028be9396a84237640761d8c +F test/speedtest1.c 39921e422974a0330f3efde03797795947e648b2 F test/spellfix.test 8c40b169b104086d8795781f670ba3c786d6d8be F test/sqllimits1.test b1aae27cc98eceb845e7f7adf918561256e31298 F test/stat.test c8eccfe8fcd3f3cfc864ce22d5b9e803a3c69940 @@ -1145,7 +1145,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P ceebcdcaf1acf409b77b4cc2903b4570001f098a -R bcfcf6f48c85e4fa706276f8ed169192 +P ce70803f5e1bfb4dc495d3a0c2ddd5ee6c3a10fe +R 095247e62fa36b05416c8693f0a2370e U drh -Z 88c6067bf128a26cfad7d97b15ea7137 +Z 29cf28ff7ccc2664a2648cb15c3f491d diff --git a/manifest.uuid b/manifest.uuid index eb9f0afe6d..855d4e4e29 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ce70803f5e1bfb4dc495d3a0c2ddd5ee6c3a10fe \ No newline at end of file +c75f561f337a56c14335366ed9990e44bc9fc594 \ No newline at end of file diff --git a/test/speedtest1.c b/test/speedtest1.c index b15f65cfe9..932943912f 100644 --- a/test/speedtest1.c +++ b/test/speedtest1.c @@ -122,8 +122,8 @@ static int integerValue(const char *zArg){ break; } } - if( v>=2147483648 ) fatal_error("parameter to large - max 2147483648"); - return isNeg? -v : v; + if( v>0x7fffffff ) fatal_error("parameter to large - max 2147483648"); + return (int)(isNeg? -v : v); } /* Return the current wall-clock time, in milliseconds */ @@ -256,8 +256,8 @@ void speedtest1_begin_test(int iTestNum, const char *zTestName, ...){ sqlite3_free(zName); g.nResult = 0; g.iStart = speedtest1_timestamp(); - g.x = 2903710987; - g.y = 1157229256; + g.x = 0xad131d0b; + g.y = 0x44f9eac8; } /* Complete a test case */ From b87875ac4098b3048b3a9c42b8ef60087af2c675 Mon Sep 17 00:00:00 2001 From: mistachkin Date: Wed, 27 Nov 2013 18:00:20 +0000 Subject: [PATCH 12/14] Fix spelling typo in speedtest1.exe. FossilOrigin-Name: ae90300e8e3221c208343e5e0d5e5f2381f38107 --- manifest | 14 +++++++------- manifest.uuid | 2 +- test/speedtest1.c | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/manifest b/manifest index d5cd277511..65efc4bad0 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\ssome\sharmless\scompiler\swarnings\sin\sspeedtest1.exe. -D 2013-11-27T14:50:51.106 +C Fix\sspelling\stypo\sin\sspeedtest1.exe. +D 2013-11-27T18:00:20.146 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -820,7 +820,7 @@ F test/speed3.test d32043614c08c53eafdc80f33191d5bd9b920523 F test/speed4.test abc0ad3399dcf9703abed2fff8705e4f8e416715 F test/speed4p.explain 6b5f104ebeb34a038b2f714150f51d01143e59aa F test/speed4p.test 0e51908951677de5a969b723e03a27a1c45db38b -F test/speedtest1.c 39921e422974a0330f3efde03797795947e648b2 +F test/speedtest1.c 184ded13ffe61df44d6e2ac9985b61a6417d5311 F test/spellfix.test 8c40b169b104086d8795781f670ba3c786d6d8be F test/sqllimits1.test b1aae27cc98eceb845e7f7adf918561256e31298 F test/stat.test c8eccfe8fcd3f3cfc864ce22d5b9e803a3c69940 @@ -1145,7 +1145,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P ce70803f5e1bfb4dc495d3a0c2ddd5ee6c3a10fe -R 095247e62fa36b05416c8693f0a2370e -U drh -Z 29cf28ff7ccc2664a2648cb15c3f491d +P c75f561f337a56c14335366ed9990e44bc9fc594 +R 8fc0b17785407e52a1dbc354b6661932 +U mistachkin +Z 8afea8796306e0cb7f61a719616561e8 diff --git a/manifest.uuid b/manifest.uuid index 855d4e4e29..85d5c872a5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c75f561f337a56c14335366ed9990e44bc9fc594 \ No newline at end of file +ae90300e8e3221c208343e5e0d5e5f2381f38107 \ No newline at end of file diff --git a/test/speedtest1.c b/test/speedtest1.c index 932943912f..ea9ec2e351 100644 --- a/test/speedtest1.c +++ b/test/speedtest1.c @@ -122,7 +122,7 @@ static int integerValue(const char *zArg){ break; } } - if( v>0x7fffffff ) fatal_error("parameter to large - max 2147483648"); + if( v>0x7fffffff ) fatal_error("parameter too large - max 2147483648"); return (int)(isNeg? -v : v); } From 9338642ca6432dcd5e874ef959b7ca2ee0725e4e Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Nov 2013 19:17:49 +0000 Subject: [PATCH 13/14] Update documentation of sqlite3_column() for clarity. Update evidence marks on test cases. FossilOrigin-Name: ec2d47a1db2349d5c9b4fe465506e0e347f77921 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/sqlite.h.in | 16 ++++++++-------- test/e_createtable.test | 2 +- test/e_expr.test | 15 +++++++++------ 5 files changed, 28 insertions(+), 25 deletions(-) diff --git a/manifest b/manifest index 65efc4bad0..c6966974e7 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Fix\sspelling\stypo\sin\sspeedtest1.exe. -D 2013-11-27T18:00:20.146 +C Update\sdocumentation\sof\ssqlite3_column()\sfor\sclarity.\s\sUpdate\sevidence\smarks\non\stest\scases. +D 2013-11-27T19:17:49.817 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -221,7 +221,7 @@ F src/resolve.c 7eda9097b29fcf3d2b42fdc17d1de672134e09b6 F src/rowset.c 64655f1a627c9c212d9ab497899e7424a34222e0 F src/select.c d41381d80a22d3a83352aeca274cccf264ac277a F src/shell.c 936a72ff784efff3832cce274a96ed0b036e6758 -F src/sqlite.h.in a8328969be639b6cd8d9225ed2a51d9d624fff5f +F src/sqlite.h.in af7f4349f939c40848bdfa217855d0bb88f3a581 F src/sqlite3.rc 11094cc6a157a028b301a9f06b3d03089ea37c3e F src/sqlite3ext.h 886f5a34de171002ad46fae8c36a7d8051c190fc F src/sqliteInt.h 9d586cb37572cd9e0a48242d449c6a69c2e74e72 @@ -433,11 +433,11 @@ F test/descidx3.test 09ddbe3f5295f482d2f8b687cf6db8bad7acd9a2 F test/diskfull.test 106391384780753ea6896b7b4f005d10e9866b6e F test/distinct.test 44028aaf161a5e80a2f229622b3a174d3b352810 F test/distinctagg.test 1a6ef9c87a58669438fc771450d7a72577417376 -F test/e_createtable.test a4561b93062e651d6def99c9e6956969dbf3754c +F test/e_createtable.test ee95d48664503d40f6cc9ef4a7d03216188e2ada F test/e_delete.test d5186e2f5478b659f16a2c8b66c09892823e542a F test/e_droptrigger.test 3cd080807622c13e5bbb61fc9a57bd7754da2412 F test/e_dropview.test 0c9f7f60989164a70a67a9d9c26d1083bc808306 -F test/e_expr.test a9f7c084ea3648003bcc40dd50861af5d2341fc1 +F test/e_expr.test 5c71d183fbf519a4769fd2e2124afdc70b5b1f42 F test/e_fkey.test d83a04478bb9c02d2c513518548a69f818869f41 F test/e_fts3.test 5c02288842e4f941896fd44afdef564dd5fc1459 F test/e_insert.test 1e44f84d2abe44d66e4fbf198be4b20e3cc724a0 @@ -1145,7 +1145,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P c75f561f337a56c14335366ed9990e44bc9fc594 -R 8fc0b17785407e52a1dbc354b6661932 -U mistachkin -Z 8afea8796306e0cb7f61a719616561e8 +P ae90300e8e3221c208343e5e0d5e5f2381f38107 +R b6ce75ba6132c1ec93bb8b6dc747cf97 +U drh +Z 0aae2730740447c74aeda3d2db2e7487 diff --git a/manifest.uuid b/manifest.uuid index 85d5c872a5..95dfd63b81 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ae90300e8e3221c208343e5e0d5e5f2381f38107 \ No newline at end of file +ec2d47a1db2349d5c9b4fe465506e0e347f77921 \ No newline at end of file diff --git a/src/sqlite.h.in b/src/sqlite.h.in index f5565cf210..228d9cca36 100644 --- a/src/sqlite.h.in +++ b/src/sqlite.h.in @@ -3775,19 +3775,19 @@ int sqlite3_data_count(sqlite3_stmt *pStmt); ** ** NULL INTEGER Result is 0 ** NULL FLOAT Result is 0.0 -** NULL TEXT Result is NULL pointer -** NULL BLOB Result is NULL pointer +** NULL TEXT Result is a NULL pointer +** NULL BLOB Result is a NULL pointer ** INTEGER FLOAT Convert from integer to float ** INTEGER TEXT ASCII rendering of the integer ** INTEGER BLOB Same as INTEGER->TEXT -** FLOAT INTEGER Convert from float to integer +** FLOAT INTEGER [CAST] to INTEGER ** FLOAT TEXT ASCII rendering of the float -** FLOAT BLOB Same as FLOAT->TEXT -** TEXT INTEGER Use atoi() -** TEXT FLOAT Use atof() +** FLOAT BLOB [CAST] to BLOB +** TEXT INTEGER [CAST] to INTEGER +** TEXT FLOAT [CAST] to REAL ** TEXT BLOB No change -** BLOB INTEGER Convert to TEXT then use atoi() -** BLOB FLOAT Convert to TEXT then use atof() +** BLOB INTEGER [CAST] to INTEGER +** BLOB FLOAT [CAST] to REAL ** BLOB TEXT Add a zero terminator if needed ** ** )^ diff --git a/test/e_createtable.test b/test/e_createtable.test index 1c8ab7d86e..2cd63280df 100644 --- a/test/e_createtable.test +++ b/test/e_createtable.test @@ -1103,7 +1103,7 @@ do_catchsql_test e_createtable-3.11.5 { # EVIDENCE-OF: R-52382-54248 Each table in SQLite may have at most one # PRIMARY KEY. # -# EVIDENCE-OF: R-62315-57691 An error is rasied if more than one PRIMARY +# EVIDENCE-OF: R-31826-01813 An error is raised if more than one PRIMARY # KEY clause appears in a CREATE TABLE statement. # # To test the two above, show that zero primary keys is Ok, one primary diff --git a/test/e_expr.test b/test/e_expr.test index ea23a22d7f..a743c0c390 100644 --- a/test/e_expr.test +++ b/test/e_expr.test @@ -1407,10 +1407,12 @@ do_test e_expr-26.1.6 { set ::evalcount } {5} #------------------------------------------------------------------------- # Test statements related to CAST expressions. # -# EVIDENCE-OF: R-65079-31758 Application of a CAST expression is -# different to application of a column affinity, as with a CAST -# expression the storage class conversion is forced even if it is lossy -# and irrreversible. +# EVIDENCE-OF: R-20854-17109 A CAST conversion is similar to the +# conversion that takes place when a column affinity is applied to a +# value except that with the CAST operator the conversion always takes +# place even if the conversion lossy and irreversible, whereas column +# affinity only changes the data type of a value if the change is +# lossless and reversible. # do_execsql_test e_expr-27.1.1 { CREATE TABLE t3(a TEXT, b REAL, c INTEGER); @@ -1594,8 +1596,9 @@ do_expr_test e_expr-30.4.1 { CAST('' AS INTEGER) } integer 0 do_expr_test e_expr-30.4.2 { CAST('not a number' AS INTEGER) } integer 0 do_expr_test e_expr-30.4.3 { CAST('XXI' AS INTEGER) } integer 0 -# EVIDENCE-OF: R-00741-38776 A cast of a REAL value into an INTEGER will -# truncate the fractional part of the REAL. +# EVIDENCE-OF: R-02752-50091 A cast of a REAL value into an INTEGER +# results in the integer between the REAL value and zero that is closest +# to the REAL value. # do_expr_test e_expr-31.1.1 { CAST(3.14159 AS INTEGER) } integer 3 do_expr_test e_expr-31.1.2 { CAST(1.99999 AS INTEGER) } integer 1 From 2c77be054aece16f91fea60aeb3df86bf91ab17b Mon Sep 17 00:00:00 2001 From: drh Date: Wed, 27 Nov 2013 21:07:03 +0000 Subject: [PATCH 14/14] Remove unnecessary local variables from sqlite3VdbeExec() in order to reduce stack-space requirements of that routine. FossilOrigin-Name: 81891288d9f281cf2ceb4cd701c0c3231b1bab19 --- manifest | 12 ++++++------ manifest.uuid | 2 +- src/vdbe.c | 5 ++--- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/manifest b/manifest index c6966974e7..2b11db792d 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C Update\sdocumentation\sof\ssqlite3_column()\sfor\sclarity.\s\sUpdate\sevidence\smarks\non\stest\scases. -D 2013-11-27T19:17:49.817 +C Remove\sunnecessary\slocal\svariables\sfrom\ssqlite3VdbeExec()\sin\sorder\sto\nreduce\sstack-space\srequirements\sof\sthat\sroutine. +D 2013-11-27T21:07:03.594 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in e1a9b4258bbde53f5636f4e238c65b7e11459e2b F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -280,7 +280,7 @@ F src/update.c c05a0ee658f1a149e0960dfd110f3b8bd846bcb0 F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269 F src/util.c cbe054290f780fcd472b89d701c7404c51ec9684 F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179 -F src/vdbe.c c2b3cd6baddb224a2f155e410ca69f74e6efc671 +F src/vdbe.c 54894fde8dc806d259e015ac7c9680145e725835 F src/vdbe.h c06f0813f853566457ce9cfb1a4a4bc39a5da644 F src/vdbeInt.h 05fbda0e061dbc4aaa2709a8cccf3515c245b263 F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed @@ -1145,7 +1145,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01 F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff -P ae90300e8e3221c208343e5e0d5e5f2381f38107 -R b6ce75ba6132c1ec93bb8b6dc747cf97 +P ec2d47a1db2349d5c9b4fe465506e0e347f77921 +R 7567a16f49e2bdddacaa25bcadbc50b4 U drh -Z 0aae2730740447c74aeda3d2db2e7487 +Z d833492813320be0733490cbebae9751 diff --git a/manifest.uuid b/manifest.uuid index 95dfd63b81..d8103977d6 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -ec2d47a1db2349d5c9b4fe465506e0e347f77921 \ No newline at end of file +81891288d9f281cf2ceb4cd701c0c3231b1bab19 \ No newline at end of file diff --git a/src/vdbe.c b/src/vdbe.c index 3b27ba144a..8ae4ce484c 100644 --- a/src/vdbe.c +++ b/src/vdbe.c @@ -4132,9 +4132,8 @@ case OP_Delete: { /* Invoke the update-hook if required. */ if( rc==SQLITE_OK && db->xUpdateCallback && pOp->p4.z && pC->isTable ){ - const char *zDb = db->aDb[pC->iDb].zName; - const char *zTbl = pOp->p4.z; - db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, zDb, zTbl, iKey); + db->xUpdateCallback(db->pUpdateArg, SQLITE_DELETE, + db->aDb[pC->iDb].zName, pOp->p4.z, iKey); assert( pC->iDb>=0 ); } if( pOp->p2 & OPFLAG_NCHANGE ) p->nChange++;