/ Check-in [564631f3]
Login

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

Overview
Comment:Make it possible to disable the subquery-by-coroutine optimization using sqlite3_test_control(). Remove an always-false conditional.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | subquery-as-coroutine
Files: files | file ages | folders
SHA1:564631f3e45f8f8a8db69f1e0df0d1dadbad8a2c
User & Date: drh 2012-10-30 14:39:12
Context
2012-10-30
14:44
Fix a typo in the header comment for the OpenPseudo opcode. check-in: 4f106123 user: drh tags: subquery-as-coroutine
14:39
Make it possible to disable the subquery-by-coroutine optimization using sqlite3_test_control(). Remove an always-false conditional. check-in: 564631f3 user: drh tags: subquery-as-coroutine
00:29
Add an optimization that attempts to run a subquery as a coroutine rather than manifesting it into a temporary table. check-in: 7af3acbb user: drh tags: subquery-as-coroutine
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/main.c.

  3015   3015       ** operation N should be 0.  The idea is that a test program (like the
  3016   3016       ** SQL Logic Test or SLT test module) can run the same SQL multiple times
  3017   3017       ** with various optimizations disabled to verify that the same answer
  3018   3018       ** is obtained in every case.
  3019   3019       */
  3020   3020       case SQLITE_TESTCTRL_OPTIMIZATIONS: {
  3021   3021         sqlite3 *db = va_arg(ap, sqlite3*);
  3022         -      db->dbOptFlags = (u8)(va_arg(ap, int) & 0xff);
         3022  +      db->dbOptFlags = (u16)(va_arg(ap, int) & 0xffff);
  3023   3023         break;
  3024   3024       }
  3025   3025   
  3026   3026   #ifdef SQLITE_N_KEYWORD
  3027   3027       /* sqlite3_test_control(SQLITE_TESTCTRL_ISKEYWORD, const char *zWord)
  3028   3028       **
  3029   3029       ** If zWord is a keyword recognized by the parser, then return the

Changes to src/select.c.

  3936   3936       if( flattenSubquery(pParse, p, i, isAgg, isAggSub) ){
  3937   3937         /* This subquery can be absorbed into its parent. */
  3938   3938         if( isAggSub ){
  3939   3939           isAgg = 1;
  3940   3940           p->selFlags |= SF_Aggregate;
  3941   3941         }
  3942   3942         i = -1;
  3943         -    }else if( pTabList->nSrc==1 && (p->selFlags & SF_Materialize)==0 ){
         3943  +    }else if( pTabList->nSrc==1 && (p->selFlags & SF_Materialize)==0
         3944  +      && OptimizationEnabled(db, SQLITE_SubqCoroutine)
         3945  +    ){
  3944   3946         /* Implement a co-routine that will return a single row of the result
  3945   3947         ** set on each invocation.
  3946   3948         */
  3947   3949         int addrTop;
  3948   3950         int addrEof;
  3949   3951         pItem->regReturn = ++pParse->nMem;
  3950   3952         addrEof = ++pParse->nMem;

Changes to src/sqliteInt.h.

   823    823     Db *aDb;                      /* All backends */
   824    824     int nDb;                      /* Number of backends currently in use */
   825    825     int flags;                    /* Miscellaneous flags. See below */
   826    826     i64 lastRowid;                /* ROWID of most recent insert (see above) */
   827    827     unsigned int openFlags;       /* Flags passed to sqlite3_vfs.xOpen() */
   828    828     int errCode;                  /* Most recent error code (SQLITE_*) */
   829    829     int errMask;                  /* & result codes with this before returning */
   830         -  u8 dbOptFlags;                /* Flags to enable/disable optimizations */
          830  +  u16 dbOptFlags;               /* Flags to enable/disable optimizations */
   831    831     u8 autoCommit;                /* The auto-commit flag. */
   832    832     u8 temp_store;                /* 1: file 2: memory 0: default */
   833    833     u8 mallocFailed;              /* True if we have seen a malloc failure */
   834    834     u8 dfltLockMode;              /* Default locking-mode for attached dbs */
   835    835     signed char nextAutovac;      /* Autovac setting after VACUUM if >=0 */
   836    836     u8 suppressErr;               /* Do not issue error messages if true */
   837    837     u8 vtabOnConflict;            /* Value to return for s3_vtab_on_conflict() */
................................................................................
   968    968   #define SQLITE_ColumnCache    0x0002   /* Column cache */
   969    969   #define SQLITE_GroupByOrder   0x0004   /* GROUPBY cover of ORDERBY */
   970    970   #define SQLITE_FactorOutConst 0x0008   /* Constant factoring */
   971    971   #define SQLITE_IdxRealAsInt   0x0010   /* Store REAL as INT in indices */
   972    972   #define SQLITE_DistinctOpt    0x0020   /* DISTINCT using indexes */
   973    973   #define SQLITE_CoverIdxScan   0x0040   /* Covering index scans */
   974    974   #define SQLITE_OrderByIdxJoin 0x0080   /* ORDER BY of joins via index */
   975         -#define SQLITE_AllOpts        0x00ff   /* All optimizations */
          975  +#define SQLITE_SubqCoroutine  0x0100   /* Evaluate subqueries as coroutines */
          976  +#define SQLITE_AllOpts        0xffff   /* All optimizations */
   976    977   
   977    978   /*
   978    979   ** Macros for testing whether or not optimizations are enabled or disabled.
   979    980   */
   980    981   #ifndef SQLITE_OMIT_BUILTIN_TEST
   981    982   #define OptimizationDisabled(db, mask)  (((db)->dbOptFlags&(mask))!=0)
   982    983   #define OptimizationEnabled(db, mask)   (((db)->dbOptFlags&(mask))==0)

Changes to src/vdbe.c.

  2203   2203     ** might be available in the  pC->aRow cache.  Or it might not be.
  2204   2204     ** If the data is unavailable,  zRec is set to NULL.
  2205   2205     **
  2206   2206     ** We also compute the number of columns in the record.  For cursors,
  2207   2207     ** the number of columns is stored in the VdbeCursor.nField element.
  2208   2208     */
  2209   2209     pC = p->apCsr[p1];
  2210         -  if( pC==0 ){
  2211         -    sqlite3VdbeMemSetNull(pDest);
  2212         -    goto op_column_out;
  2213         -  }
         2210  +  assert( pC!=0 );
  2214   2211   #ifndef SQLITE_OMIT_VIRTUALTABLE
  2215   2212     assert( pC->pVtabCursor==0 );
  2216   2213   #endif
  2217   2214     pCrsr = pC->pCursor;
  2218   2215     if( pCrsr!=0 ){
  2219   2216       /* The record is stored in a B-Tree */
  2220   2217       rc = sqlite3VdbeCursorMoveto(pC);