]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Use compile-time options SQLITE_QUERY_PLANNER_LIMIT and
authordrh <drh@noemail.net>
Mon, 24 Sep 2018 12:37:01 +0000 (12:37 +0000)
committerdrh <drh@noemail.net>
Mon, 24 Sep 2018 12:37:01 +0000 (12:37 +0000)
SQLITE_QUERY_PLANNER_LIMIT_INCR to control the value for
WhereLoopBuilder.iPlanLimit, rather than embedding magic numbers in the
code.

FossilOrigin-Name: 903e501894b2a5dd7055b5154d74d4a47a619f76e66485a4d62b6259f10723d6

manifest
manifest.uuid
src/where.c
src/whereInt.h

index ddb5e7f46119cd4b09ae9bb91248c464f9e185f7..fced9da4c10a05828438cb87c42d8962f3b3112d 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Increase\sthe\sinitial\svalue\sof\sWhereLoopBuilder.iPlanLimit\sto\s20K.\s\sIssue\na\swarning\sif\sthe\siPlanLimit\sreaches\szero.
-D 2018-09-24T10:47:33.898
+C Use\scompile-time\soptions\sSQLITE_QUERY_PLANNER_LIMIT\sand\nSQLITE_QUERY_PLANNER_LIMIT_INCR\sto\scontrol\sthe\svalue\sfor\nWhereLoopBuilder.iPlanLimit,\srather\sthan\sembedding\smagic\snumbers\sin\sthe\ncode.
+D 2018-09-24T12:37:01.477
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in 01e95208a78b57d056131382c493c963518f36da4c42b12a97eb324401b3a334
@@ -587,8 +587,8 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9
 F src/wal.c 3f4f653daf234fe713edbcbca3fec2350417d159d28801feabc702a22c4e213f
 F src/wal.h 606292549f5a7be50b6227bd685fa76e3a4affad71bb8ac5ce4cb5c79f6a176a
 F src/walker.c fb94aadc9099ff9c6506d0a8b88d51266005bcaa265403f3d7caf732a562eb66
-F src/where.c 49022d3c155a3af14298459d6990c0c9f096f42afa1edb6d86e8f4ac45a6301e
-F src/whereInt.h 2c4d99faf71c35339a33b20d11c5cb8921416a21d6816d830b85df320303e5bd
+F src/where.c a54a3d639bcd751d1474deff58e239b2e475a96e1b8f9178aa7864df8782a4e3
+F src/whereInt.h f125f29fca80890768e0b2caa14f95db74b2dacd3a122a168f97aa7b64d6968f
 F src/wherecode.c 3df0a541373d5f999684d761e4bd700d57adb46c7d39da4e77b767b5adcd5893
 F src/whereexpr.c 1b5a5a7876997f65232bbf19c5c1eeb47eb328b8fa5b28c865543052904cde00
 F src/window.c a28d8d42c51c7e31136a42f3e245282049d4a9466b36d7bd765772991472df41
@@ -1769,7 +1769,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P 2fd62fccd13e326dbd7dd730112542c6faa56e466bf4f7b8e22ced543031280c
-R 1d4c0a2fb381695de9f503d180db0edc
+P 3dd35f51187574f47f860405309877cdbf9dc5710703dfd98cf98073b771140c
+R 0a5c287a2221a9c37c274db4cfcb24c3
 U drh
-Z 063489dbcea38420d3799029994c4f5a
+Z d1e830ee2a4fd61d34b42065fcc1584a
index 54605332425c9e459e79ee1a3c00ca4307801663..7a3767f11f994fbe3e077055a052b86301a81c90 100644 (file)
@@ -1 +1 @@
-3dd35f51187574f47f860405309877cdbf9dc5710703dfd98cf98073b771140c
\ No newline at end of file
+903e501894b2a5dd7055b5154d74d4a47a619f76e66485a4d62b6259f10723d6
\ No newline at end of file
index c911dcc9c272e188a55a2b159b7e48a21df0f5f5..bfc11eec18eda4ec73fc91a69878422741eb2c74 100644 (file)
@@ -3540,17 +3540,11 @@ static int whereLoopAddAll(WhereLoopBuilder *pBuilder){
   /* Loop over the tables in the join, from left to right */
   pNew = pBuilder->pNew;
   whereLoopInit(pNew);
-  /* Some pathological queries provide an unreasonable number of indexing
-  ** options. The iPlanLimit value prevents these queries from taking up
-  ** too much time in the planner. When iPlanLimit reaches zero, no further
-  ** index+constraint options are considered. Seed iPlanLimit to 20K but
-  ** also add an extra 1K to each table of the join, to ensure that each
-  ** table at least gets 1K opportunities. */
-  pBuilder->iPlanLimit = 20000;
+  pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT;
   for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
     Bitmask mUnusable = 0;
     pNew->iTab = iTab;
-    pBuilder->iPlanLimit += 1000;  /* 1000 bonus for each table in the join */
+    pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
     pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
     if( ((pItem->fg.jointype|priorJointype) & (JT_LEFT|JT_CROSS))!=0 ){
       /* This condition is true when pItem is the FROM clause term on the
index a34708df4070400fe24943bbb519367570bdabce..209ac42ee26d8abf21512a8943b1e345966adaa7 100644 (file)
@@ -409,6 +409,26 @@ struct WhereLoopBuilder {
 #define SQLITE_BLDF_INDEXED  0x0001   /* An index is used */
 #define SQLITE_BLDF_UNIQUE   0x0002   /* All keys of a UNIQUE index used */
 
+/* The WhereLoopBuilder.iPlanLimit is used to limit the number of
+** index+constraint combinations the query planner will consider for a
+** particular query.  If this parameter is unlimited, then certain
+** pathological queries can spend excess time in the sqlite3WhereBegin()
+** routine.  The limit is high enough that is should not impact real-world
+** queries.
+**
+** SQLITE_QUERY_PLANNER_LIMIT is the baseline limit.  The limit is
+** increased by SQLITE_QUERY_PLANNER_LIMIT_INCR before each term of the FROM
+** clause is processed, so that every table in a join is guaranteed to be
+** able to propose a some index+constraint combinations even if the initial
+** baseline limit was exhausted by prior tables of the join.
+*/
+#ifndef SQLITE_QUERY_PLANNER_LIMIT
+# define SQLITE_QUERY_PLANNER_LIMIT 20000
+#endif
+#ifndef SQLITE_QUERY_PLANNER_LIMIT_INCR
+# define SQLITE_QUERY_PLANNER_LIMIT_INCR 1000
+#endif
+
 /*
 ** The WHERE clause processing routine has two halves.  The
 ** first part does the start of the WHERE loop and the second