/ Check-in [64f97530ad]
Login

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

Overview
Comment:Where possible, avoid loading all schemas into memory for PRAGMA statements.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | reuse-schema
Files: files | file ages | folders
SHA3-256: 64f97530ad387655767b5205fb9a9c723210cd4975176ab6fb71bca0cb585a74
User & Date: dan 2019-02-25 17:54:23
Wiki:reuse-schema
Context
2019-02-25
18:07
Merge latest trunk changes into this branch. check-in: 5c1cf30859 user: dan tags: reuse-schema
17:54
Where possible, avoid loading all schemas into memory for PRAGMA statements. check-in: 64f97530ad user: dan tags: reuse-schema
2019-02-22
17:44
Merge latest trunk changes into this branch. check-in: 001771afd0 user: dan tags: reuse-schema
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/build.c.

   304    304         && DbHasProperty(db, iDb, DB_SchemaLoaded)==0 
   305    305         && (db->init.busy==0 || (iDb!=1 && db->init.iDb==1))
   306    306     ){
   307    307       struct sqlite3InitInfo sv = db->init;
   308    308       memset(&db->init, 0, sizeof(struct sqlite3InitInfo));
   309    309       rc = sqlite3InitOne(db, iDb, pzErr, 0);
   310    310       db->init = sv;
   311         -    *pbUnload = (rc==SQLITE_OK && (iDb!=1));
          311  +    if( pbUnload ) *pbUnload = (rc==SQLITE_OK && (iDb!=1));
   312    312     }
   313    313     return rc;
   314    314   }
   315    315   
   316    316   /*
   317    317   ** Locate the in-memory structure that describes a particular database
   318    318   ** table given the name of that table and (optionally) the name of the

Changes to src/callback.c.

   790    790       if( i!=1 ){
   791    791         Db *pDb = &db->aDb[i];
   792    792         if( pDb->pSPool && DbHasProperty(db,i,DB_SchemaLoaded) ){
   793    793           schemaRelease(db, pDb);
   794    794         }
   795    795       }
   796    796     }
   797         -  db->flags &= ~DBFLAG_FreeSchema;
          797  +  db->mDbFlags &= ~DBFLAG_FreeSchema;
   798    798     sqlite3_mutex_leave( sqlite3_mutex_alloc(SQLITE_MUTEX_STATIC_MASTER) );
   799    799   }
   800    800   
   801    801   /*
   802    802   ** Release any sharable schema held by connection iDb of database handle
   803    803   ** db. Db.pSchema is left pointing to the static, empty, Schema object
   804    804   ** owned by the schema-pool.

Changes to src/pragma.c.

   416    416   
   417    417     /* Locate the pragma in the lookup table */
   418    418     pPragma = pragmaLocate(zLeft);
   419    419     if( pPragma==0 ) goto pragma_out;
   420    420   
   421    421     /* Make sure the database schema is loaded if the pragma requires that */
   422    422     if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){
   423         -    if( sqlite3ReadSchema(pParse) ) goto pragma_out;
          423  +    if( IsReuseSchema(db) && (zDb || (pPragma->mPragFlg & PragFlg_OneSchema)) ){
          424  +      assert( iDb>=0 && iDb<db->nDb );
          425  +      pParse->rc = sqlite3SchemaLoad(db, iDb, 0, &pParse->zErrMsg);
          426  +      if( pParse->rc ) goto pragma_out;
          427  +    }else{
          428  +      if( sqlite3ReadSchema(pParse) ) goto pragma_out;
          429  +    }
   424    430     }
   425    431   
   426    432     /* Register the result column names for pragmas that return results */
   427    433     if( (pPragma->mPragFlg & PragFlg_NoColumns)==0 
   428    434      && ((pPragma->mPragFlg & PragFlg_NoColumns1)==0 || zRight==0)
   429    435     ){
   430    436       setPragmaResultColumnNames(v, pPragma);
................................................................................
  1798   1804     ** the schema-version is potentially dangerous and may lead to program
  1799   1805     ** crashes or database corruption. Use with caution!
  1800   1806     **
  1801   1807     ** The user-version is not used internally by SQLite. It may be used by
  1802   1808     ** applications for any purpose.
  1803   1809     */
  1804   1810     case PragTyp_HEADER_VALUE: {
  1805         -    int iCookie = pPragma->iArg;  /* Which cookie to read or write */
         1811  +    int iCookie;                  /* Which cookie to read or write */
         1812  +    iCookie = pPragma->iArg & PRAGMA_HEADER_VALUE_MASK;     
  1806   1813       sqlite3VdbeUsesBtree(v, iDb);
  1807         -    if( zRight && (pPragma->mPragFlg & PragFlg_ReadOnly)==0 ){
         1814  +    if( zRight && (pPragma->iArg & PRAGMA_HEADER_VALUE_READONLY)==0 ){
  1808   1815         /* Write the specified cookie value */
  1809   1816         static const VdbeOpList setCookie[] = {
  1810   1817           { OP_Transaction,    0,  1,  0},    /* 0 */
  1811   1818           { OP_SetCookie,      0,  0,  0},    /* 1 */
  1812   1819         };
  1813   1820         VdbeOp *aOp;
  1814   1821         sqlite3VdbeVerifyNoMallocRequired(v, ArraySize(setCookie));

Changes to src/pragma.h.

    51     51   #define PragTyp_LOCK_STATUS                   43
    52     52   #define PragTyp_STATS                         44
    53     53   
    54     54   /* Property flags associated with various pragma. */
    55     55   #define PragFlg_NeedSchema 0x01 /* Force schema load before running */
    56     56   #define PragFlg_NoColumns  0x02 /* OP_ResultRow called with zero columns */
    57     57   #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */
    58         -#define PragFlg_ReadOnly   0x08 /* Read-only HEADER_VALUE */
           58  +#define PragFlg_OneSchema  0x08 /* Only a single schema required */
    59     59   #define PragFlg_Result0    0x10 /* Acts as query when no argument */
    60     60   #define PragFlg_Result1    0x20 /* Acts as query when has one argument */
    61     61   #define PragFlg_SchemaOpt  0x40 /* Schema restricts name search if present */
    62     62   #define PragFlg_SchemaReq  0x80 /* Schema required - "main" is default */
           63  +
           64  +/* For PragTyp_HEADER_VALUE pragmas the Pragma.iArg value is set
           65  +** to the index of the header field to access (always 10 or less).
           66  +** Ored with HEADER_VALUE_READONLY if the field is read only. */
           67  +#define PRAGMA_HEADER_VALUE_READONLY 0x0100
           68  +#define PRAGMA_HEADER_VALUE_MASK 0x00FF
           69  +
    63     70   
    64     71   /* Names of columns for pragmas that return multi-column result
    65     72   ** or that return single-column results where the name of the
    66     73   ** result column is different from the name of the pragma
    67     74   */
    68     75   static const char *const pragCName[] = {
    69     76     /*   0 */ "id",          /* Used by: foreign_key_list */
................................................................................
   142    149     /* ePragFlg:  */ PragFlg_NoColumns1|PragFlg_Result0,
   143    150     /* ColNames:  */ 0, 0,
   144    151     /* iArg:      */ BTREE_APPLICATION_ID },
   145    152   #endif
   146    153   #if !defined(SQLITE_OMIT_AUTOVACUUM)
   147    154    {/* zName:     */ "auto_vacuum",
   148    155     /* ePragTyp:  */ PragTyp_AUTO_VACUUM,
   149         -  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
          156  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1|PragFlg_OneSchema,
   150    157     /* ColNames:  */ 0, 0,
   151    158     /* iArg:      */ 0 },
   152    159   #endif
   153    160   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   154    161   #if !defined(SQLITE_OMIT_AUTOMATIC_INDEX)
   155    162    {/* zName:     */ "automatic_index",
   156    163     /* ePragTyp:  */ PragTyp_FLAG,
................................................................................
   163    170     /* ePragTyp:  */ PragTyp_BUSY_TIMEOUT,
   164    171     /* ePragFlg:  */ PragFlg_Result0,
   165    172     /* ColNames:  */ 46, 1,
   166    173     /* iArg:      */ 0 },
   167    174   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   168    175    {/* zName:     */ "cache_size",
   169    176     /* ePragTyp:  */ PragTyp_CACHE_SIZE,
   170         -  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
          177  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1|PragFlg_OneSchema,
   171    178     /* ColNames:  */ 0, 0,
   172    179     /* iArg:      */ 0 },
   173    180   #endif
   174    181   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   175    182    {/* zName:     */ "cache_spill",
   176    183     /* ePragTyp:  */ PragTyp_CACHE_SPILL,
   177    184     /* ePragFlg:  */ PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
................................................................................
   222    229     /* ePragFlg:  */ PragFlg_NoColumns1,
   223    230     /* ColNames:  */ 0, 0,
   224    231     /* iArg:      */ 0 },
   225    232   #endif
   226    233   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   227    234    {/* zName:     */ "data_version",
   228    235     /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   229         -  /* ePragFlg:  */ PragFlg_ReadOnly|PragFlg_Result0,
          236  +  /* ePragFlg:  */ PragFlg_Result0,
   230    237     /* ColNames:  */ 0, 0,
   231         -  /* iArg:      */ BTREE_DATA_VERSION },
          238  +  /* iArg:      */ BTREE_DATA_VERSION|PRAGMA_HEADER_VALUE_READONLY },
   232    239   #endif
   233    240   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   234    241    {/* zName:     */ "database_list",
   235    242     /* ePragTyp:  */ PragTyp_DATABASE_LIST,
   236         -  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0,
          243  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_OneSchema,
   237    244     /* ColNames:  */ 35, 3,
   238    245     /* iArg:      */ 0 },
   239    246   #endif
   240    247   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
   241    248    {/* zName:     */ "default_cache_size",
   242    249     /* ePragTyp:  */ PragTyp_DEFAULT_CACHE_SIZE,
   243         -  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
          250  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1|PragFlg_OneSchema,
   244    251     /* ColNames:  */ 45, 1,
   245    252     /* iArg:      */ 0 },
   246    253   #endif
   247    254   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   248    255   #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   249    256    {/* zName:     */ "defer_foreign_keys",
   250    257     /* ePragTyp:  */ PragTyp_FLAG,
................................................................................
   266    273     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   267    274     /* ColNames:  */ 0, 0,
   268    275     /* iArg:      */ 0 },
   269    276   #endif
   270    277   #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   271    278    {/* zName:     */ "foreign_key_check",
   272    279     /* ePragTyp:  */ PragTyp_FOREIGN_KEY_CHECK,
   273         -  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0,
          280  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_OneSchema,
   274    281     /* ColNames:  */ 31, 4,
   275    282     /* iArg:      */ 0 },
   276    283   #endif
   277    284   #if !defined(SQLITE_OMIT_FOREIGN_KEY)
   278    285    {/* zName:     */ "foreign_key_list",
   279    286     /* ePragTyp:  */ PragTyp_FOREIGN_KEY_LIST,
   280         -  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
          287  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt|PragFlg_OneSchema,
   281    288     /* ColNames:  */ 0, 8,
   282    289     /* iArg:      */ 0 },
   283    290   #endif
   284    291   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   285    292   #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   286    293    {/* zName:     */ "foreign_keys",
   287    294     /* ePragTyp:  */ PragTyp_FLAG,
................................................................................
   289    296     /* ColNames:  */ 0, 0,
   290    297     /* iArg:      */ SQLITE_ForeignKeys },
   291    298   #endif
   292    299   #endif
   293    300   #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   294    301    {/* zName:     */ "freelist_count",
   295    302     /* ePragTyp:  */ PragTyp_HEADER_VALUE,
   296         -  /* ePragFlg:  */ PragFlg_ReadOnly|PragFlg_Result0,
          303  +  /* ePragFlg:  */ PragFlg_Result0,
   297    304     /* ColNames:  */ 0, 0,
   298         -  /* iArg:      */ BTREE_FREE_PAGE_COUNT },
          305  +  /* iArg:      */ BTREE_FREE_PAGE_COUNT|PRAGMA_HEADER_VALUE_READONLY },
   299    306   #endif
   300    307   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   301    308    {/* zName:     */ "full_column_names",
   302    309     /* ePragTyp:  */ PragTyp_FLAG,
   303    310     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   304    311     /* ColNames:  */ 0, 0,
   305    312     /* iArg:      */ SQLITE_FullColNames },
................................................................................
   338    345     /* ColNames:  */ 0, 0,
   339    346     /* iArg:      */ SQLITE_IgnoreChecks },
   340    347   #endif
   341    348   #endif
   342    349   #if !defined(SQLITE_OMIT_AUTOVACUUM)
   343    350    {/* zName:     */ "incremental_vacuum",
   344    351     /* ePragTyp:  */ PragTyp_INCREMENTAL_VACUUM,
   345         -  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_NoColumns,
          352  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_NoColumns|PragFlg_OneSchema,
   346    353     /* ColNames:  */ 0, 0,
   347    354     /* iArg:      */ 0 },
   348    355   #endif
   349    356   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   350    357    {/* zName:     */ "index_info",
   351    358     /* ePragTyp:  */ PragTyp_INDEX_INFO,
   352    359     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
................................................................................
   369    376     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_Result1,
   370    377     /* ColNames:  */ 0, 0,
   371    378     /* iArg:      */ 0 },
   372    379   #endif
   373    380   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   374    381    {/* zName:     */ "journal_mode",
   375    382     /* ePragTyp:  */ PragTyp_JOURNAL_MODE,
   376         -  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
          383  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_OneSchema,
   377    384     /* ColNames:  */ 0, 0,
   378    385     /* iArg:      */ 0 },
   379    386    {/* zName:     */ "journal_size_limit",
   380    387     /* ePragTyp:  */ PragTyp_JOURNAL_SIZE_LIMIT,
   381    388     /* ePragFlg:  */ PragFlg_Result0|PragFlg_SchemaReq,
   382    389     /* ColNames:  */ 0, 0,
   383    390     /* iArg:      */ 0 },
................................................................................
   419    426    {/* zName:     */ "locking_mode",
   420    427     /* ePragTyp:  */ PragTyp_LOCKING_MODE,
   421    428     /* ePragFlg:  */ PragFlg_Result0|PragFlg_SchemaReq,
   422    429     /* ColNames:  */ 0, 0,
   423    430     /* iArg:      */ 0 },
   424    431    {/* zName:     */ "max_page_count",
   425    432     /* ePragTyp:  */ PragTyp_PAGE_COUNT,
   426         -  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
          433  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_OneSchema,
   427    434     /* ColNames:  */ 0, 0,
   428    435     /* iArg:      */ 0 },
   429    436    {/* zName:     */ "mmap_size",
   430    437     /* ePragTyp:  */ PragTyp_MMAP_SIZE,
   431    438     /* ePragFlg:  */ 0,
   432    439     /* ColNames:  */ 0, 0,
   433    440     /* iArg:      */ 0 },
................................................................................
   447    454     /* ePragTyp:  */ PragTyp_OPTIMIZE,
   448    455     /* ePragFlg:  */ PragFlg_Result1|PragFlg_NeedSchema,
   449    456     /* ColNames:  */ 0, 0,
   450    457     /* iArg:      */ 0 },
   451    458   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   452    459    {/* zName:     */ "page_count",
   453    460     /* ePragTyp:  */ PragTyp_PAGE_COUNT,
   454         -  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
          461  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_OneSchema,
   455    462     /* ColNames:  */ 0, 0,
   456    463     /* iArg:      */ 0 },
   457    464    {/* zName:     */ "page_size",
   458    465     /* ePragTyp:  */ PragTyp_PAGE_SIZE,
   459    466     /* ePragFlg:  */ PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
   460    467     /* ColNames:  */ 0, 0,
   461    468     /* iArg:      */ 0 },
................................................................................
   555    562     /* ColNames:  */ 0, 0,
   556    563     /* iArg:      */ SQLITE_SqlTrace },
   557    564   #endif
   558    565   #endif
   559    566   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
   560    567    {/* zName:     */ "stats",
   561    568     /* ePragTyp:  */ PragTyp_STATS,
   562         -  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq,
          569  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_OneSchema,
   563    570     /* ColNames:  */ 21, 5,
   564    571     /* iArg:      */ 0 },
   565    572   #endif
   566    573   #if !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   567    574    {/* zName:     */ "synchronous",
   568    575     /* ePragTyp:  */ PragTyp_SYNCHRONOUS,
   569         -  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1,
          576  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_SchemaReq|PragFlg_NoColumns1|PragFlg_OneSchema,
   570    577     /* ColNames:  */ 0, 0,
   571    578     /* iArg:      */ 0 },
   572    579   #endif
   573    580   #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   574    581    {/* zName:     */ "table_info",
   575    582     /* ePragTyp:  */ PragTyp_TABLE_INFO,
   576    583     /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_Result1|PragFlg_SchemaOpt,
................................................................................
   651    658    {/* zName:     */ "wal_autocheckpoint",
   652    659     /* ePragTyp:  */ PragTyp_WAL_AUTOCHECKPOINT,
   653    660     /* ePragFlg:  */ 0,
   654    661     /* ColNames:  */ 0, 0,
   655    662     /* iArg:      */ 0 },
   656    663    {/* zName:     */ "wal_checkpoint",
   657    664     /* ePragTyp:  */ PragTyp_WAL_CHECKPOINT,
   658         -  /* ePragFlg:  */ PragFlg_NeedSchema,
          665  +  /* ePragFlg:  */ PragFlg_NeedSchema|PragFlg_OneSchema,
   659    666     /* ColNames:  */ 38, 3,
   660    667     /* iArg:      */ 0 },
   661    668   #endif
   662    669   #if !defined(SQLITE_OMIT_FLAG_PRAGMAS)
   663    670    {/* zName:     */ "writable_schema",
   664    671     /* ePragTyp:  */ PragTyp_FLAG,
   665    672     /* ePragFlg:  */ PragFlg_Result0|PragFlg_NoColumns1,
   666    673     /* ColNames:  */ 0, 0,
   667    674     /* iArg:      */ SQLITE_WriteSchema|SQLITE_NoSchemaError },
   668    675   #endif
   669    676   };
   670    677   /* Number of pragmas: 62 on by default, 81 total. */

Changes to test/reuse4.test.

   110    110       SELECT * FROM main.x3; SELECT 'xxx';
   111    111     } {
   112    112       3 3 4 4 5 5 6 6 7 7 8 8 3 3 5 5 7 7 xxx 
   113    113       123 456 xxx 
   114    114       xxx
   115    115     }
   116    116   }
          117  +
          118  +#-------------------------------------------------------------------------
          119  +# Test some PRAGMA statements with shared-schema connections.
          120  +#
          121  +reset_db
          122  +do_execsql_test 2.0 {
          123  +  CREATE TABLE t1(a, b, c);
          124  +  CREATE INDEX t1abc ON t1(a, b, c);
          125  +}
          126  +
          127  +foreach {tn pragma nSchema nDelete} {
          128  +  1 "PRAGMA synchronous = OFF"     1 0
          129  +  2 "PRAGMA cache_size = 200"      1 0
          130  +  3 "PRAGMA aux2.integrity_check"  1 0
          131  +  4 "PRAGMA      integrity_check"  1 5
          132  +  5 "PRAGMA index_info=t1abc"      1 5
          133  +  6 "PRAGMA aux3.index_info=t1abc" 1 0
          134  +  7 "PRAGMA journal_mode"          1 0
          135  +  8 "PRAGMA aux2.wal_checkpoint"   1 0
          136  +  9 "PRAGMA wal_checkpoint"        1 0
          137  +} {
          138  +  do_test 2.$tn.1 {
          139  +    catch { db close }
          140  +    catch { db2 close }
          141  +    for {set i 1} {$i < 6} {incr i} {
          142  +      forcedelete "test.db$i" "test.db${i}-wal" "test.db${i}-journal"
          143  +      forcecopy test.db test.db$i
          144  +    }
          145  +    sqlite3 db2 test.db -shared-schema 1
          146  +    for {set i 1} {$i < 6} {incr i} {
          147  +      execsql "ATTACH 'test.db$i' AS aux$i" db2
          148  +    }
          149  +  } {}
          150  +
          151  +  sqlite3 db test.db
          152  +  register_schemapool_module db
          153  +
          154  +  do_test 2.$tn.2 {
          155  +    execsql $pragma db2
          156  +    execsql { SELECT 'nschema='||nschema, 'ndelete='||nDelete FROM schemapool }
          157  +  } "nschema=$nSchema ndelete=$nDelete"
          158  +
          159  +  do_test 2.$tn.3 {
          160  +    execsql {
          161  +      SELECT * FROM main.t1,aux1.t1,aux2.t1,aux3.t1,aux4.t1,aux5.t1
          162  +    } db2
          163  +    execsql { SELECT 'nschema=' || nschema, 'nref=' || nref FROM schemapool }
          164  +  } "nschema=6 nref=6"
          165  +}
   117    166   
   118    167   finish_test
   119    168   

Changes to tool/mkpragmatab.tcl.

     8      8   # the lookup table needed for pragma name lookup in the pragma.c module.
     9      9   # Then add the extra "case PragTyp_XXXXX:" and subsequent code for the
    10     10   # new pragma in ../src/pragma.c.
    11     11   #
    12     12   
    13     13   # Flag meanings:
    14     14   set flagMeaning(NeedSchema) {Force schema load before running}
    15         -set flagMeaning(ReadOnly)   {Read-only HEADER_VALUE}
           15  +set flagMeaning(OneSchema)  {Only a single schema required}
    16     16   set flagMeaning(Result0)    {Acts as query when no argument}
    17     17   set flagMeaning(Result1)    {Acts as query when has one argument}
    18     18   set flagMeaning(SchemaReq)  {Schema required - "main" is default}
    19     19   set flagMeaning(SchemaOpt)  {Schema restricts name search if present}
    20     20   set flagMeaning(NoColumns)  {OP_ResultRow called with zero columns}
    21     21   set flagMeaning(NoColumns1) {zero columns if RHS argument is present}
    22     22   
................................................................................
   146    146     IF:   !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   147    147   
   148    148     NAME: cell_size_check
   149    149     TYPE: FLAG
   150    150     ARG:  SQLITE_CellSizeCk
   151    151   
   152    152     NAME: default_cache_size
   153         -  FLAG: NeedSchema Result0 SchemaReq NoColumns1
          153  +  FLAG: NeedSchema Result0 SchemaReq NoColumns1 OneSchema
   154    154     COLS: cache_size
   155    155     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS) && !defined(SQLITE_OMIT_DEPRECATED)
   156    156   
   157    157     NAME: page_size
   158    158     FLAG: Result0 SchemaReq NoColumns1
   159    159     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   160    160   
   161    161     NAME: secure_delete
   162    162     FLAG: Result0
   163    163     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   164    164   
   165    165     NAME: page_count
   166         -  FLAG: NeedSchema Result0 SchemaReq
          166  +  FLAG: NeedSchema Result0 SchemaReq OneSchema
   167    167     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   168    168   
   169    169     NAME: max_page_count
   170    170     TYPE: PAGE_COUNT
   171         -  FLAG: NeedSchema Result0 SchemaReq
          171  +  FLAG: NeedSchema Result0 SchemaReq OneSchema
   172    172     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   173    173   
   174    174     NAME: locking_mode
   175    175     FLAG: Result0 SchemaReq
   176    176     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   177    177   
   178    178     NAME: journal_mode
   179         -  FLAG: NeedSchema Result0 SchemaReq
          179  +  FLAG: NeedSchema Result0 SchemaReq OneSchema
   180    180     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   181    181   
   182    182     NAME: journal_size_limit
   183    183     FLAG: Result0 SchemaReq
   184    184     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   185    185   
   186    186     NAME: cache_size
   187         -  FLAG: NeedSchema Result0 SchemaReq NoColumns1
          187  +  FLAG: NeedSchema Result0 SchemaReq NoColumns1 OneSchema
   188    188     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   189    189   
   190    190     NAME: mmap_size
   191    191     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   192    192   
   193    193     NAME: auto_vacuum
   194         -  FLAG: NeedSchema Result0 SchemaReq NoColumns1
          194  +  FLAG: NeedSchema Result0 SchemaReq NoColumns1 OneSchema
   195    195     IF:   !defined(SQLITE_OMIT_AUTOVACUUM)
   196    196   
   197    197     NAME: incremental_vacuum
   198         -  FLAG: NeedSchema NoColumns
          198  +  FLAG: NeedSchema NoColumns OneSchema
   199    199     IF:   !defined(SQLITE_OMIT_AUTOVACUUM)
   200    200   
   201    201     NAME: temp_store
   202    202     FLAG: Result0 NoColumns1
   203    203     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   204    204   
   205    205     NAME: temp_store_directory
................................................................................
   211    211     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_OS_WIN
   212    212   
   213    213     NAME: lock_proxy_file
   214    214     FLAG: NoColumns1
   215    215     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS) && SQLITE_ENABLE_LOCKING_STYLE
   216    216   
   217    217     NAME: synchronous
   218         -  FLAG: NeedSchema Result0 SchemaReq NoColumns1
          218  +  FLAG: NeedSchema Result0 SchemaReq NoColumns1 OneSchema
   219    219     IF:   !defined(SQLITE_OMIT_PAGER_PRAGMAS)
   220    220   
   221    221     NAME: table_info
   222    222     FLAG: NeedSchema Result1 SchemaOpt
   223    223     ARG:  0
   224    224     COLS: cid name type notnull dflt_value pk
   225    225     IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
................................................................................
   228    228     TYPE: TABLE_INFO
   229    229     FLAG: NeedSchema Result1 SchemaOpt
   230    230     ARG:  1
   231    231     COLS: cid name type notnull dflt_value pk hidden
   232    232     IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   233    233   
   234    234     NAME: stats
   235         -  FLAG: NeedSchema Result0 SchemaReq
          235  +  FLAG: NeedSchema Result0 SchemaReq OneSchema
   236    236     COLS: tbl idx wdth hght flgs
   237    237     IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG)
   238    238   
   239    239     NAME: index_info
   240    240     TYPE: INDEX_INFO
   241    241     ARG:  0
   242    242     FLAG: NeedSchema Result1 SchemaOpt
................................................................................
   252    252   
   253    253     NAME: index_list
   254    254     FLAG: NeedSchema Result1 SchemaOpt
   255    255     COLS: seq name unique origin partial
   256    256     IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   257    257   
   258    258     NAME: database_list
   259         -  FLAG: NeedSchema Result0
          259  +  FLAG: NeedSchema Result0 OneSchema
   260    260     COLS: seq name file
   261    261     IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   262    262   
   263    263     NAME: function_list
   264    264     FLAG: Result0
   265    265     COLS: name builtin
   266    266     IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
................................................................................
   280    280   
   281    281     NAME: collation_list
   282    282     FLAG: Result0
   283    283     COLS: seq name
   284    284     IF:   !defined(SQLITE_OMIT_SCHEMA_PRAGMAS)
   285    285   
   286    286     NAME: foreign_key_list
   287         -  FLAG: NeedSchema Result1 SchemaOpt
          287  +  FLAG: NeedSchema Result1 SchemaOpt OneSchema
   288    288     COLS: id seq table from to on_update on_delete match
   289    289     IF:   !defined(SQLITE_OMIT_FOREIGN_KEY)
   290    290   
   291    291     NAME: foreign_key_check
   292         -  FLAG: NeedSchema Result0
          292  +  FLAG: NeedSchema Result0 OneSchema
   293    293     COLS: table rowid parent fkid
   294    294     IF:   !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER)
   295    295   
   296    296     NAME: parser_trace
   297    297     TYPE: FLAG
   298    298     ARG:  SQLITE_ParserTrace
   299    299     IF:   !defined(SQLITE_OMIT_FLAG_PRAGMAS)
................................................................................
   325    325     TYPE: HEADER_VALUE
   326    326     ARG:  BTREE_USER_VERSION
   327    327     FLAG: NoColumns1 Result0
   328    328     IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   329    329   
   330    330     NAME: data_version
   331    331     TYPE: HEADER_VALUE
   332         -  ARG:  BTREE_DATA_VERSION
   333         -  FLAG: ReadOnly Result0
          332  +  ARG:  BTREE_DATA_VERSION|PRAGMA_HEADER_VALUE_READONLY
          333  +  FLAG: Result0
   334    334     IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   335    335   
   336    336     NAME: freelist_count
   337    337     TYPE: HEADER_VALUE
   338         -  ARG:  BTREE_FREE_PAGE_COUNT
   339         -  FLAG: ReadOnly Result0
          338  +  ARG:  BTREE_FREE_PAGE_COUNT|PRAGMA_HEADER_VALUE_READONLY
          339  +  FLAG: Result0
   340    340     IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   341    341   
   342    342     NAME: application_id
   343    343     TYPE: HEADER_VALUE
   344    344     ARG:  BTREE_APPLICATION_ID
   345    345     FLAG: NoColumns1 Result0
   346    346     IF:   !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS)
   347    347   
   348    348     NAME: compile_options
   349    349     FLAG: Result0
   350    350     IF:   !defined(SQLITE_OMIT_COMPILEOPTION_DIAGS)
   351    351   
   352    352     NAME: wal_checkpoint
   353         -  FLAG: NeedSchema
          353  +  FLAG: NeedSchema OneSchema
   354    354     COLS: busy log checkpointed
   355    355     IF:   !defined(SQLITE_OMIT_WAL)
   356    356   
   357    357     NAME: wal_autocheckpoint
   358    358     IF:   !defined(SQLITE_OMIT_WAL)
   359    359   
   360    360     NAME: shrink_memory
................................................................................
   528    528   puts $fd "\n/* Property flags associated with various pragma. */"
   529    529   set fv 1
   530    530   foreach f [lsort [array names allflags]] {
   531    531     puts $fd [format {#define PragFlg_%-10s 0x%02x /* %s */} \
   532    532                $f $fv $flagMeaning($f)]
   533    533     set fv [expr {$fv*2}]
   534    534   }
          535  +
          536  +puts $fd "\n/* For PragTyp_HEADER_VALUE pragmas the Pragma.iArg value is set"
          537  +puts $fd "** to the index of the header field to access (always 10 or less)."
          538  +puts $fd "** Ored with HEADER_VALUE_READONLY if the field is read only. */"
          539  +puts $fd "#define PRAGMA_HEADER_VALUE_READONLY 0x0100"
          540  +puts $fd "#define PRAGMA_HEADER_VALUE_MASK 0x00FF\n"
   535    541   
   536    542   # Sort the column lists so that longer column lists occur first
   537    543   #
   538    544   proc colscmp {a b} {
   539    545     return [expr {[llength $b] - [llength $a]}]
   540    546   }
   541    547   set cols_list [lsort -command colscmp $cols_list]