From 75ad260c2d05d881c9a44150737e3ba607936584 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 21 Oct 2010 02:05:06 +0000 Subject: [PATCH 1/4] Fix the query planner so that it uses the multi-index OR-clause solution if that is the lowest cost estimate. A prior bug cause the multi-index solution to be ignored in some circumstances. FossilOrigin-Name: 28ba6255282b1419b8b165e8461018d257b1f6c2 --- manifest | 18 +++++++++--------- manifest.uuid | 2 +- src/where.c | 7 ++++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/manifest b/manifest index 1a93e47329..1453abb12e 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 -C Avoid\staking\slocks\son\sunused\sdatabase\sconnections\swhen\scommitting\sa\nread\stransaction. -D 2010-10-14T01:17:30 +C Fix\sthe\squery\splanner\sso\sthat\sit\suses\sthe\smulti-index\sOR-clause\ssolution\sif\nthat\sis\sthe\slowest\scost\sestimate.\s\sA\sprior\sbug\scause\sthe\smulti-index\ssolution\nto\sbe\signored\sin\ssome\scircumstances. +D 2010-10-21T02:05:06 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in b01fdfcfecf8a0716c29867a67959f6148b79961 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -240,7 +240,7 @@ F src/vtab.c 6c90e3e65b2f026fc54703a8f3c917155f419d87 F src/wal.c 0dc7eb9e907a2c280cdcde876d313e07ea4ad811 F src/wal.h 96669b645e27cd5a111ba59f0cae7743a207bc3c F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f -F src/where.c 204cdfb66eb82ee17a8fc0a9b12c1ab402755cbb +F src/where.c 4ca22dea63424d61680021ebdc9248b4f5797666 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87 F test/all.test 6745008c144bd2956d58864d21f7b304689c1cce @@ -876,14 +876,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P ea8c2f5f8a890dcb422e9e46298ae6ca378c74b7 -R 03d2b3a92f9647a3db71aa9ca75489f4 +P c0ee614fd988f445c4884a37f494479bdd669185 +R 6e8c0a60de16e5bdb6a605bd3f1b39aa U drh -Z c2cdb52e62b9c570a5e1c8427f4ce5c4 +Z b859e44913d29246f2a51ec2ec0453b6 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) -iD8DBQFMtlotoxKgR168RlERAuf0AJ96F+hVDOt4y4GU2wooqTHtO4kKZgCeKIVj -dUPTQwgWJgqAaN5BweGLucY= -=QYIr +iD8DBQFMv5/WoxKgR168RlERAgmkAKCN96esWxQzRMXwPF6yb6e9uTWrlQCfYhIV +wi7V06O0ntyNXUrzsFmI5dw= +=a2Wv -----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index 4e2a5db003..c178568b65 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -c0ee614fd988f445c4884a37f494479bdd669185 \ No newline at end of file +28ba6255282b1419b8b165e8461018d257b1f6c2 \ No newline at end of file diff --git a/src/where.c b/src/where.c index 226055b472..7b3cfce43d 100644 --- a/src/where.c +++ b/src/where.c @@ -235,7 +235,7 @@ struct WhereCost { #define WHERE_COLUMN_IN 0x00040000 /* x IN (...) */ #define WHERE_COLUMN_NULL 0x00080000 /* x IS NULL */ #define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */ -#define WHERE_NOT_FULLSCAN 0x000f3000 /* Does not do a full table scan */ +#define WHERE_NOT_FULLSCAN 0x100f3000 /* Does not do a full table scan */ #define WHERE_IN_ABLE 0x000f1000 /* Able to support an IN operator */ #define WHERE_TOP_LIMIT 0x00100000 /* xEXPR or x>=EXPR constraint */ @@ -1581,8 +1581,9 @@ static void bestOrClauseIndex( WhereTerm * const pWCEnd = &pWC->a[pWC->nTerm]; /* End of pWC->a[] */ WhereTerm *pTerm; /* A single term of the WHERE clause */ - /* No OR-clause optimization allowed if the NOT INDEXED clause is used */ - if( pSrc->notIndexed ){ + /* No OR-clause optimization allowed if the INDEXED BY or NOT INDEXED clauses + ** are used */ + if( pSrc->notIndexed || pSrc->pIndex!=0 ){ return; } From 020efb166619bf22854f3073822ecc408c072fe1 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 21 Oct 2010 03:13:58 +0000 Subject: [PATCH 2/4] Add new WHERETRACE macros for better diagnostics of the query planner. Added a new test case for the performance regression fixed by the previous check-in. FossilOrigin-Name: 1e0db99797be2821716de7138931ebd5cf8fa63b --- manifest | 20 ++++++++++---------- manifest.uuid | 2 +- src/where.c | 13 +++++++++---- test/where7.test | 45 ++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 64 insertions(+), 16 deletions(-) diff --git a/manifest b/manifest index 1453abb12e..a608e3fcb8 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,8 @@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 -C Fix\sthe\squery\splanner\sso\sthat\sit\suses\sthe\smulti-index\sOR-clause\ssolution\sif\nthat\sis\sthe\slowest\scost\sestimate.\s\sA\sprior\sbug\scause\sthe\smulti-index\ssolution\nto\sbe\signored\sin\ssome\scircumstances. -D 2010-10-21T02:05:06 +C Add\snew\sWHERETRACE\smacros\sfor\sbetter\sdiagnostics\sof\sthe\squery\splanner.\nAdded\sa\snew\stest\scase\sfor\sthe\sperformance\sregression\sfixed\sby\sthe\sprevious\ncheck-in. +D 2010-10-21T03:13:59 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in b01fdfcfecf8a0716c29867a67959f6148b79961 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -240,7 +240,7 @@ F src/vtab.c 6c90e3e65b2f026fc54703a8f3c917155f419d87 F src/wal.c 0dc7eb9e907a2c280cdcde876d313e07ea4ad811 F src/wal.h 96669b645e27cd5a111ba59f0cae7743a207bc3c F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f -F src/where.c 4ca22dea63424d61680021ebdc9248b4f5797666 +F src/where.c d9a31eb3d59466b6c53567c8c9a6c2fe68bbd565 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87 F test/all.test 6745008c144bd2956d58864d21f7b304689c1cce @@ -836,7 +836,7 @@ F test/where3.test 3a72db38e8804b210e9f72001ea16830fea74b4b F test/where4.test e9b9e2f2f98f00379e6031db6a6fca29bae782a2 F test/where5.test fdf66f96d29a064b63eb543e28da4dfdccd81ad2 F test/where6.test 5da5a98cec820d488e82708301b96cb8c18a258b -F test/where7.test a0a92b8ce48d9c027fbdd7b764c7de1e1213575a +F test/where7.test 221fd05b26be4529647c72ef7de5df646482c675 F test/where8.test a6c740fd286d7883e274e17b6230a9d672a7ab1f F test/where8m.test da346596e19d54f0aba35ebade032a7c47d79739 F test/where9.test be19e1a92f80985c1a121b4678bf7d2123eaa623 @@ -876,14 +876,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P c0ee614fd988f445c4884a37f494479bdd669185 -R 6e8c0a60de16e5bdb6a605bd3f1b39aa +P 28ba6255282b1419b8b165e8461018d257b1f6c2 +R 356faab25a033ed6868509f3a1892bd9 U drh -Z b859e44913d29246f2a51ec2ec0453b6 +Z 6b64c97bbd923b9a49e2113bdc5fc21f -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) -iD8DBQFMv5/WoxKgR168RlERAgmkAKCN96esWxQzRMXwPF6yb6e9uTWrlQCfYhIV -wi7V06O0ntyNXUrzsFmI5dw= -=a2Wv +iD8DBQFMv6/7oxKgR168RlERArQqAJsHLWslgz2gwl1++DmjsYaRL73uAgCghxuU +YoUJK40zLY6RYViwah2V2A4= +=KADs -----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index c178568b65..baf776c133 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -28ba6255282b1419b8b165e8461018d257b1f6c2 \ No newline at end of file +1e0db99797be2821716de7138931ebd5cf8fa63b \ No newline at end of file diff --git a/src/where.c b/src/where.c index 7b3cfce43d..eb0e8ead76 100644 --- a/src/where.c +++ b/src/where.c @@ -4067,6 +4067,7 @@ WhereInfo *sqlite3WhereBegin( memset(&bestPlan, 0, sizeof(bestPlan)); bestPlan.rCost = SQLITE_BIG_DBL; + WHERETRACE(("*** Begin search for loop %d ***\n", i)); /* Loop through the remaining entries in the FROM clause to find the ** next nested loop. The loop tests all FROM clause entries @@ -4131,6 +4132,8 @@ WhereInfo *sqlite3WhereBegin( pOrderBy = ((i==0 && ppOrderBy )?*ppOrderBy:0); if( pTabItem->pIndex==0 ) nUnconstrained++; + WHERETRACE(("=== trying table %d with isOptimal=%d ===\n", + j, isOptimal)); assert( pTabItem->pTab ); #ifndef SQLITE_OMIT_VIRTUALTABLE if( IsVirtual(pTabItem->pTab) ){ @@ -4183,8 +4186,9 @@ WhereInfo *sqlite3WhereBegin( && (bestJ<0 || sCost.rCost=0 ); assert( notReady & getMask(pMaskSet, pTabList->a[bestJ].iCursor) ); - WHERETRACE(("*** Optimizer selects table %d for loop %d\n", bestJ, - pLevel-pWInfo->a)); + WHERETRACE(("*** Optimizer selects table %d for loop %d" + " with cost=%g and nRow=%g\n", + bestJ, pLevel-pWInfo->a, bestPlan.rCost, bestPlan.nRow)); if( (bestPlan.plan.wsFlags & WHERE_ORDERBY)!=0 ){ *ppOrderBy = 0; } diff --git a/test/where7.test b/test/where7.test index dbb9bc6b68..07aba9e60d 100644 --- a/test/where7.test +++ b/test/where7.test @@ -23299,6 +23299,49 @@ do_test where7-2.1001.2 { OR a=91 } } {2 22 23 28 54 80 91 scan 0 sort 0} -finish_test + +# test case for the performance regression fixed by +# check-in 28ba6255282b on 2010-10-21 02:05:06 +# +# The test case that follows is code from an actual +# application with identifiers change and unused columns +# remove. +# +do_test where7-3.1 { + db eval { + CREATE TABLE t301 ( + c8 INTEGER PRIMARY KEY, + c6 INTEGER, + c4 INTEGER, + c7 INTEGER, + FOREIGN KEY (c4) REFERENCES series(c4) + ); + CREATE INDEX t301_c6 on t301(c6); + CREATE INDEX t301_c4 on t301(c4); + CREATE INDEX t301_c7 on t301(c7); + + CREATE TABLE t302 ( + c1 INTEGER PRIMARY KEY, + c8 INTEGER, + c5 INTEGER, + c3 INTEGER, + c2 INTEGER, + c4 INTEGER, + FOREIGN KEY (c8) REFERENCES t301(c8) + ); + CREATE INDEX t302_c3 on t302(c3); + CREATE INDEX t302_c8_c3 on t302(c8, c3); + CREATE INDEX t302_c5 on t302(c5); + + EXPLAIN QUERY PLAN + SELECT t302.c1 + FROM t302 JOIN t301 ON t302.c8 = t301.c8 + WHERE t302.c2 = 19571 + AND t302.c3 > 1287603136 + AND (t301.c4 = 1407449685622784 + OR t301.c8 = 1407424651264000) + ORDER BY t302.c5 LIMIT 200; + } +} {0 1 {TABLE t301 VIA MULTI-INDEX UNION} 1 0 {TABLE t302 WITH INDEX t302_c8_c3} 0 0 {TABLE t301 WITH INDEX t301_c4} 0 0 {TABLE t301 USING PRIMARY KEY}} finish_test From 3edd8a555d4f45e9778fe709c0be6ab3ab9c9a75 Mon Sep 17 00:00:00 2001 From: drh Date: Thu, 21 Oct 2010 12:34:29 +0000 Subject: [PATCH 3/4] Fix a typo-bug that prevented --disable-amalgamation from working in Makefile.in. Also fix an overly long line in Makfile.in. FossilOrigin-Name: 2c3c4ba035e548e97101142692133cf685da16bc --- Makefile.in | 5 +++-- manifest | 18 +++++++++--------- manifest.uuid | 2 +- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/Makefile.in b/Makefile.in index 8e57e40ce4..3659e944bd 100644 --- a/Makefile.in +++ b/Makefile.in @@ -167,7 +167,8 @@ USE_AMALGAMATION = @USE_AMALGAMATION@ # LIBOBJS0 = alter.lo analyze.lo attach.lo auth.lo \ backup.lo bitvec.lo btmutex.lo btree.lo build.lo \ - callback.lo complete.lo ctime.lo date.lo delete.lo expr.lo fault.lo fkey.lo \ + callback.lo complete.lo ctime.lo date.lo delete.lo \ + expr.lo fault.lo fkey.lo \ fts3.lo fts3_expr.lo fts3_hash.lo fts3_icu.lo fts3_porter.lo \ fts3_snippet.lo fts3_tokenizer.lo fts3_tokenizer1.lo fts3_write.lo \ func.lo global.lo hash.lo \ @@ -181,7 +182,7 @@ LIBOBJS0 = alter.lo analyze.lo attach.lo auth.lo \ table.lo tokenize.lo trigger.lo \ update.lo util.lo vacuum.lo \ vdbe.lo vdbeapi.lo vdbeaux.lo vdbeblob.lo vdbemem.lo vdbetrace.lo \ - wal.lo walker.lo where.lo utf.o vtab.lo + wal.lo walker.lo where.lo utf.lo vtab.lo # Object files for the amalgamation. # diff --git a/manifest b/manifest index a608e3fcb8..9c53322e8d 100644 --- a/manifest +++ b/manifest @@ -1,10 +1,10 @@ -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 -C Add\snew\sWHERETRACE\smacros\sfor\sbetter\sdiagnostics\sof\sthe\squery\splanner.\nAdded\sa\snew\stest\scase\sfor\sthe\sperformance\sregression\sfixed\sby\sthe\sprevious\ncheck-in. -D 2010-10-21T03:13:59 +C Fix\sa\stypo-bug\sthat\sprevented\s--disable-amalgamation\sfrom\sworking\sin\nMakefile.in.\s\sAlso\sfix\san\soverly\slong\sline\sin\sMakfile.in. +D 2010-10-21T12:34:30 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f -F Makefile.in b01fdfcfecf8a0716c29867a67959f6148b79961 +F Makefile.in 2c8cefd962eca0147132c7cf9eaa4bb24c656f3f F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 F Makefile.vxworks c85ec1d8597fe2f7bc225af12ac1666e21379151 F README cd04a36fbc7ea56932a4052d7d0b7f09f27c33d6 @@ -876,14 +876,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 28ba6255282b1419b8b165e8461018d257b1f6c2 -R 356faab25a033ed6868509f3a1892bd9 +P 1e0db99797be2821716de7138931ebd5cf8fa63b +R 27c980fabcc9224b8f93e2c194859c02 U drh -Z 6b64c97bbd923b9a49e2113bdc5fc21f +Z 5cd8cc8e5437bb048203dc5411dcdfb2 -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) -iD8DBQFMv6/7oxKgR168RlERArQqAJsHLWslgz2gwl1++DmjsYaRL73uAgCghxuU -YoUJK40zLY6RYViwah2V2A4= -=KADs +iD4DBQFMwDNdoxKgR168RlERAhyoAJ9KXMEZDSgWeuiZ9fcEOsaX+xwW5ACYv6SC +dUoJE9sYCjU60A5b4LhubA== +=UcdN -----END PGP SIGNATURE----- diff --git a/manifest.uuid b/manifest.uuid index baf776c133..748615b34b 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -1e0db99797be2821716de7138931ebd5cf8fa63b \ No newline at end of file +2c3c4ba035e548e97101142692133cf685da16bc \ No newline at end of file From 06b5db0e3934d8a3dad7ca44257cb4f3c02b4208 Mon Sep 17 00:00:00 2001 From: dan Date: Thu, 21 Oct 2010 15:12:44 +0000 Subject: [PATCH 4/4] Fix some segfaults that could occur in obscure circumstances where error messages contained characters that could be mistaken for printf format specifiers. FossilOrigin-Name: f91471e7234db490f97298b1ccb8d6c7fc45b089 --- manifest | 30 ++++++++++-------------------- manifest.uuid | 2 +- src/vdbeblob.c | 4 ++-- src/vtab.c | 2 +- test/incrblob.test | 9 +++++++++ test/vtab1.test | 15 +++++++++++++++ 6 files changed, 38 insertions(+), 24 deletions(-) diff --git a/manifest b/manifest index 9c53322e8d..f1ff38cd7f 100644 --- a/manifest +++ b/manifest @@ -1,8 +1,5 @@ ------BEGIN PGP SIGNED MESSAGE----- -Hash: SHA1 - -C Fix\sa\stypo-bug\sthat\sprevented\s--disable-amalgamation\sfrom\sworking\sin\nMakefile.in.\s\sAlso\sfix\san\soverly\slong\sline\sin\sMakfile.in. -D 2010-10-21T12:34:30 +C Fix\ssome\ssegfaults\sthat\scould\soccur\sin\sobscure\scircumstances\swhere\serror\smessages\scontained\scharacters\sthat\scould\sbe\smistaken\sfor\sprintf\sformat\sspecifiers. +D 2010-10-21T15:12:44 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in 2c8cefd962eca0147132c7cf9eaa4bb24c656f3f F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@ -233,10 +230,10 @@ F src/vdbe.h 4de0efb4b0fdaaa900cf419b35c458933ef1c6d2 F src/vdbeInt.h 7f4cf1b2b69bef3a432b1f23dfebef57275436b4 F src/vdbeapi.c 5368714fa750270cf6430160287c21adff44582d F src/vdbeaux.c de0b06b11a25293e820a49159eca9f1c51a64716 -F src/vdbeblob.c 258a6010ba7a82b72b327fb24c55790655689256 +F src/vdbeblob.c 6e10c214efa3514ca2f1714773cc4cc5c7b05175 F src/vdbemem.c 23723a12cd3ba7ab3099193094cbb2eb78956aa9 F src/vdbetrace.c 864cef96919323482ebd9986f2132435115e9cc2 -F src/vtab.c 6c90e3e65b2f026fc54703a8f3c917155f419d87 +F src/vtab.c b297e8fa656ab5e66244ab15680d68db0adbec30 F src/wal.c 0dc7eb9e907a2c280cdcde876d313e07ea4ad811 F src/wal.h 96669b645e27cd5a111ba59f0cae7743a207bc3c F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f @@ -459,7 +456,7 @@ F test/in.test 19b642bb134308980a92249750ea4ce3f6c75c2d F test/in2.test 5d4c61d17493c832f7d2d32bef785119e87bde75 F test/in3.test 3cbf58c87f4052cee3a58b37b6389777505aa0c0 F test/in4.test 64f3cc1acde1b9161ccdd8e5bde3daefdb5b2617 -F test/incrblob.test fa2cd937f59f5231bfdc2aa152ee184bf254ca02 +F test/incrblob.test 76e787ca3301d9bfa6906031c626d26f8dd707de F test/incrblob2.test edc3a96e557bd61fb39acc8d2edd43371fbbaa19 F test/incrblob_err.test c577c91d4ed9e8336cdb188b15d6ee2a6fe9604e F test/incrvacuum.test 453d1e490d8f5ad2c9b3a54282a0690d6ae56462 @@ -797,7 +794,7 @@ F test/vacuum4.test d3f8ecff345f166911568f397d2432c16d2867d9 F test/varint.test ab7b110089a08b9926ed7390e7e97bdefeb74102 F test/veryquick.test 7701bb609fe8bf6535514e8b849a309e8f00573b F test/view.test 45f518205ecdb6dd23a86dd4a99bb4ae945e625d -F test/vtab1.test 9bc4a349a1989bcd064eb3b8fac2f06aca64297a +F test/vtab1.test 7b79832824cbae37ff01a06ed155027f7c15bf9e F test/vtab2.test 7bcffc050da5c68f4f312e49e443063e2d391c0d F test/vtab3.test baad99fd27217f5d6db10660522e0b7192446de1 F test/vtab4.test 942f8b8280b3ea8a41dae20e7822d065ca1cb275 @@ -876,14 +873,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f -P 1e0db99797be2821716de7138931ebd5cf8fa63b -R 27c980fabcc9224b8f93e2c194859c02 -U drh -Z 5cd8cc8e5437bb048203dc5411dcdfb2 ------BEGIN PGP SIGNATURE----- -Version: GnuPG v1.4.6 (GNU/Linux) - -iD4DBQFMwDNdoxKgR168RlERAhyoAJ9KXMEZDSgWeuiZ9fcEOsaX+xwW5ACYv6SC -dUoJE9sYCjU60A5b4LhubA== -=UcdN ------END PGP SIGNATURE----- +P 2c3c4ba035e548e97101142692133cf685da16bc +R 18a7b139ced85b4a9a48c95f0f44b0f9 +U dan +Z ed59bb88307b21a6af9f1327c9400518 diff --git a/manifest.uuid b/manifest.uuid index 748615b34b..2ff27688e5 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -2c3c4ba035e548e97101142692133cf685da16bc \ No newline at end of file +f91471e7234db490f97298b1ccb8d6c7fc45b089 \ No newline at end of file diff --git a/src/vdbeblob.c b/src/vdbeblob.c index b2b9f0ed00..38587ee567 100644 --- a/src/vdbeblob.c +++ b/src/vdbeblob.c @@ -231,7 +231,7 @@ int sqlite3_blob_open( nAttempt++; rc = sqlite3_finalize((sqlite3_stmt *)v); sqlite3DbFree(db, zErr); - zErr = sqlite3MPrintf(db, sqlite3_errmsg(db)); + zErr = sqlite3MPrintf(db, "%s", sqlite3_errmsg(db)); v = 0; } } while( nAttempt<5 && rc==SQLITE_SCHEMA ); @@ -278,7 +278,7 @@ blob_open_out: if( v && (rc!=SQLITE_OK || db->mallocFailed) ){ sqlite3VdbeFinalize(v); } - sqlite3Error(db, rc, zErr); + sqlite3Error(db, rc, (zErr ? "%s" : 0), zErr); sqlite3DbFree(db, zErr); sqlite3StackFree(db, pParse); rc = sqlite3ApiExit(db, rc); diff --git a/src/vtab.c b/src/vtab.c index 4d0595f2bf..e460ee59e3 100644 --- a/src/vtab.c +++ b/src/vtab.c @@ -672,7 +672,7 @@ int sqlite3_declare_vtab(sqlite3 *db, const char *zCreateTable){ } db->pVTab = 0; }else{ - sqlite3Error(db, SQLITE_ERROR, zErr); + sqlite3Error(db, SQLITE_ERROR, (zErr ? "%s" : 0), zErr); sqlite3DbFree(db, zErr); rc = SQLITE_ERROR; } diff --git a/test/incrblob.test b/test/incrblob.test index e0b2787792..9c9389eb4c 100644 --- a/test/incrblob.test +++ b/test/incrblob.test @@ -677,5 +677,14 @@ do_test incrblob-8.7 { execsql {SELECT b FROM t1 WHERE a = 314159} } {etilqs} +# The following test case exposes an instance in the blob code where +# an error message was set using a call similar to sqlite3_mprintf(zErr), +# where zErr is an arbitrary string. This is no good if the string contains +# characters that can be mistaken for printf() formatting directives. +# +do_test incrblob-9.1 { + list [catch { db incrblob t1 "A tricky column name %s%s" 1 } msg] $msg +} {1 {no such column: "A tricky column name %s%s"}} + finish_test diff --git a/test/vtab1.test b/test/vtab1.test index bafd29ae2d..a9aca503c4 100644 --- a/test/vtab1.test +++ b/test/vtab1.test @@ -1163,5 +1163,20 @@ ifcapable altertable { incr tn } +# The following test case exposes an instance in sqlite3_declare_vtab() +# an error message was set using a call similar to sqlite3_mprintf(zErr), +# where zErr is an arbitrary string. This is no good if the string contains +# characters that can be mistaken for printf() formatting directives. +# +do_test vtab1-17.1 { + execsql { + PRAGMA writable_schema = 1; + INSERT INTO sqlite_master VALUES( + 'table', 't3', 't3', 0, 'INSERT INTO "%s%s" VALUES(1)' + ); + } + catchsql { CREATE VIRTUAL TABLE t4 USING echo(t3); } +} {1 {vtable constructor failed: t4}} + unset -nocomplain echo_module_begin_fail finish_test