From: drh Date: Mon, 24 Sep 2018 12:37:01 +0000 (+0000) Subject: Use compile-time options SQLITE_QUERY_PLANNER_LIMIT and X-Git-Tag: version-3.26.0~132 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6fb5d358a8e35481e19ba20b27e75922a41b3fb4;p=thirdparty%2Fsqlite.git Use compile-time options SQLITE_QUERY_PLANNER_LIMIT and SQLITE_QUERY_PLANNER_LIMIT_INCR to control the value for WhereLoopBuilder.iPlanLimit, rather than embedding magic numbers in the code. FossilOrigin-Name: 903e501894b2a5dd7055b5154d74d4a47a619f76e66485a4d62b6259f10723d6 --- diff --git a/manifest b/manifest index ddb5e7f461..fced9da4c1 100644 --- 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 diff --git a/manifest.uuid b/manifest.uuid index 5460533242..7a3767f11f 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -3dd35f51187574f47f860405309877cdbf9dc5710703dfd98cf98073b771140c \ No newline at end of file +903e501894b2a5dd7055b5154d74d4a47a619f76e66485a4d62b6259f10723d6 \ No newline at end of file diff --git a/src/where.c b/src/where.c index c911dcc9c2..bfc11eec18 100644 --- a/src/where.c +++ b/src/where.c @@ -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; pItemiTab = 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 diff --git a/src/whereInt.h b/src/whereInt.h index a34708df40..209ac42ee2 100644 --- a/src/whereInt.h +++ b/src/whereInt.h @@ -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