/ Check-in [903e5018]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment: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.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 903e501894b2a5dd7055b5154d74d4a47a619f76e66485a4d62b6259f10723d6
User & Date: drh 2018-09-24 12:37:01
Context
2018-09-24
14:10
Allow a writable virtual table to have a schema with an INTEGER PRIMARY KEY and WITHOUT ROWID. This fixes ticket [f25d5ceebe1d710ff61a571e395356869d8272ef]. Test case in TH3. check-in: 5a38d928 user: drh tags: trunk
12:37
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. check-in: 903e5018 user: drh tags: trunk
10:47
Increase the initial value of WhereLoopBuilder.iPlanLimit to 20K. Issue a warning if the iPlanLimit reaches zero. check-in: 3dd35f51 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  3536   3536     int rc = SQLITE_OK;
  3537   3537     WhereLoop *pNew;
  3538   3538     u8 priorJointype = 0;
  3539   3539   
  3540   3540     /* Loop over the tables in the join, from left to right */
  3541   3541     pNew = pBuilder->pNew;
  3542   3542     whereLoopInit(pNew);
  3543         -  /* Some pathological queries provide an unreasonable number of indexing
  3544         -  ** options. The iPlanLimit value prevents these queries from taking up
  3545         -  ** too much time in the planner. When iPlanLimit reaches zero, no further
  3546         -  ** index+constraint options are considered. Seed iPlanLimit to 20K but
  3547         -  ** also add an extra 1K to each table of the join, to ensure that each
  3548         -  ** table at least gets 1K opportunities. */
  3549         -  pBuilder->iPlanLimit = 20000;
         3543  +  pBuilder->iPlanLimit = SQLITE_QUERY_PLANNER_LIMIT;
  3550   3544     for(iTab=0, pItem=pTabList->a; pItem<pEnd; iTab++, pItem++){
  3551   3545       Bitmask mUnusable = 0;
  3552   3546       pNew->iTab = iTab;
  3553         -    pBuilder->iPlanLimit += 1000;  /* 1000 bonus for each table in the join */
         3547  +    pBuilder->iPlanLimit += SQLITE_QUERY_PLANNER_LIMIT_INCR;
  3554   3548       pNew->maskSelf = sqlite3WhereGetMask(&pWInfo->sMaskSet, pItem->iCursor);
  3555   3549       if( ((pItem->fg.jointype|priorJointype) & (JT_LEFT|JT_CROSS))!=0 ){
  3556   3550         /* This condition is true when pItem is the FROM clause term on the
  3557   3551         ** right-hand-side of a LEFT or CROSS JOIN.  */
  3558   3552         mPrereq = mPrior;
  3559   3553       }
  3560   3554       priorJointype = pItem->fg.jointype;

Changes to src/whereInt.h.

   404    404     unsigned int bldFlags;    /* SQLITE_BLDF_* flags */
   405    405     unsigned int iPlanLimit;  /* Search limiter */
   406    406   };
   407    407   
   408    408   /* Allowed values for WhereLoopBuider.bldFlags */
   409    409   #define SQLITE_BLDF_INDEXED  0x0001   /* An index is used */
   410    410   #define SQLITE_BLDF_UNIQUE   0x0002   /* All keys of a UNIQUE index used */
          411  +
          412  +/* The WhereLoopBuilder.iPlanLimit is used to limit the number of
          413  +** index+constraint combinations the query planner will consider for a
          414  +** particular query.  If this parameter is unlimited, then certain
          415  +** pathological queries can spend excess time in the sqlite3WhereBegin()
          416  +** routine.  The limit is high enough that is should not impact real-world
          417  +** queries.
          418  +**
          419  +** SQLITE_QUERY_PLANNER_LIMIT is the baseline limit.  The limit is
          420  +** increased by SQLITE_QUERY_PLANNER_LIMIT_INCR before each term of the FROM
          421  +** clause is processed, so that every table in a join is guaranteed to be
          422  +** able to propose a some index+constraint combinations even if the initial
          423  +** baseline limit was exhausted by prior tables of the join.
          424  +*/
          425  +#ifndef SQLITE_QUERY_PLANNER_LIMIT
          426  +# define SQLITE_QUERY_PLANNER_LIMIT 20000
          427  +#endif
          428  +#ifndef SQLITE_QUERY_PLANNER_LIMIT_INCR
          429  +# define SQLITE_QUERY_PLANNER_LIMIT_INCR 1000
          430  +#endif
   411    431   
   412    432   /*
   413    433   ** The WHERE clause processing routine has two halves.  The
   414    434   ** first part does the start of the WHERE loop and the second
   415    435   ** half does the tail of the WHERE loop.  An instance of
   416    436   ** this structure is returned by the first half and passed
   417    437   ** into the second half to give some continuity.