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 |
Timelines: | family | ancestors | descendants | both | reuse-schema |
Files: | files | file ages | folders |
SHA3-256: |
64f97530ad387655767b5205fb9a9c72 |
User & Date: | dan 2019-02-25 17:54:23.054 |
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
Changes to src/build.c.
︙ | |||
304 305 306 307 308 309 310 | 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | - + | && DbHasProperty(db, iDb, DB_SchemaLoaded)==0 && (db->init.busy==0 || (iDb!=1 && db->init.iDb==1)) ){ struct sqlite3InitInfo sv = db->init; memset(&db->init, 0, sizeof(struct sqlite3InitInfo)); rc = sqlite3InitOne(db, iDb, pzErr, 0); db->init = sv; |
︙ |
Changes to src/callback.c.
︙ | |||
790 791 792 793 794 795 796 | 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 | - + | if( i!=1 ){ Db *pDb = &db->aDb[i]; if( pDb->pSPool && DbHasProperty(db,i,DB_SchemaLoaded) ){ schemaRelease(db, pDb); } } } |
︙ |
Changes to src/pragma.c.
︙ | |||
416 417 418 419 420 421 422 | 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 | + + + + + - + + | /* Locate the pragma in the lookup table */ pPragma = pragmaLocate(zLeft); if( pPragma==0 ) goto pragma_out; /* Make sure the database schema is loaded if the pragma requires that */ if( (pPragma->mPragFlg & PragFlg_NeedSchema)!=0 ){ if( IsReuseSchema(db) && (zDb || (pPragma->mPragFlg & PragFlg_OneSchema)) ){ assert( iDb>=0 && iDb<db->nDb ); pParse->rc = sqlite3SchemaLoad(db, iDb, 0, &pParse->zErrMsg); if( pParse->rc ) goto pragma_out; }else{ |
︙ | |||
1798 1799 1800 1801 1802 1803 1804 | 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 | - + + - + | ** the schema-version is potentially dangerous and may lead to program ** crashes or database corruption. Use with caution! ** ** The user-version is not used internally by SQLite. It may be used by ** applications for any purpose. */ case PragTyp_HEADER_VALUE: { |
︙ |
Changes to src/pragma.h.
︙ | |||
51 52 53 54 55 56 57 | 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | - + + + + + + + + | #define PragTyp_LOCK_STATUS 43 #define PragTyp_STATS 44 /* Property flags associated with various pragma. */ #define PragFlg_NeedSchema 0x01 /* Force schema load before running */ #define PragFlg_NoColumns 0x02 /* OP_ResultRow called with zero columns */ #define PragFlg_NoColumns1 0x04 /* zero columns if RHS argument is present */ |
︙ | |||
142 143 144 145 146 147 148 | 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | - + - + | /* ePragFlg: */ PragFlg_NoColumns1|PragFlg_Result0, /* ColNames: */ 0, 0, /* iArg: */ BTREE_APPLICATION_ID }, #endif #if !defined(SQLITE_OMIT_AUTOVACUUM) {/* zName: */ "auto_vacuum", /* ePragTyp: */ PragTyp_AUTO_VACUUM, |
︙ | |||
222 223 224 225 226 227 228 | 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 | - + - + - + - + | /* ePragFlg: */ PragFlg_NoColumns1, /* ColNames: */ 0, 0, /* iArg: */ 0 }, #endif #if !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) {/* zName: */ "data_version", /* ePragTyp: */ PragTyp_HEADER_VALUE, |
︙ | |||
266 267 268 269 270 271 272 | 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 | - + - + - + - + | /* ePragFlg: */ PragFlg_Result0|PragFlg_NoColumns1, /* ColNames: */ 0, 0, /* iArg: */ 0 }, #endif #if !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) {/* zName: */ "foreign_key_check", /* ePragTyp: */ PragTyp_FOREIGN_KEY_CHECK, |
︙ | |||
338 339 340 341 342 343 344 | 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 | - + | /* ColNames: */ 0, 0, /* iArg: */ SQLITE_IgnoreChecks }, #endif #endif #if !defined(SQLITE_OMIT_AUTOVACUUM) {/* zName: */ "incremental_vacuum", /* ePragTyp: */ PragTyp_INCREMENTAL_VACUUM, |
︙ | |||
369 370 371 372 373 374 375 | 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 | - + | /* ePragFlg: */ PragFlg_NeedSchema|PragFlg_Result0|PragFlg_Result1, /* ColNames: */ 0, 0, /* iArg: */ 0 }, #endif #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) {/* zName: */ "journal_mode", /* ePragTyp: */ PragTyp_JOURNAL_MODE, |
︙ | |||
419 420 421 422 423 424 425 | 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | - + | {/* zName: */ "locking_mode", /* ePragTyp: */ PragTyp_LOCKING_MODE, /* ePragFlg: */ PragFlg_Result0|PragFlg_SchemaReq, /* ColNames: */ 0, 0, /* iArg: */ 0 }, {/* zName: */ "max_page_count", /* ePragTyp: */ PragTyp_PAGE_COUNT, |
︙ | |||
447 448 449 450 451 452 453 | 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 | - + | /* ePragTyp: */ PragTyp_OPTIMIZE, /* ePragFlg: */ PragFlg_Result1|PragFlg_NeedSchema, /* ColNames: */ 0, 0, /* iArg: */ 0 }, #if !defined(SQLITE_OMIT_PAGER_PRAGMAS) {/* zName: */ "page_count", /* ePragTyp: */ PragTyp_PAGE_COUNT, |
︙ | |||
555 556 557 558 559 560 561 | 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 | - + - + | /* ColNames: */ 0, 0, /* iArg: */ SQLITE_SqlTrace }, #endif #endif #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && defined(SQLITE_DEBUG) {/* zName: */ "stats", /* ePragTyp: */ PragTyp_STATS, |
︙ | |||
651 652 653 654 655 656 657 | 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | - + | {/* zName: */ "wal_autocheckpoint", /* ePragTyp: */ PragTyp_WAL_AUTOCHECKPOINT, /* ePragFlg: */ 0, /* ColNames: */ 0, 0, /* iArg: */ 0 }, {/* zName: */ "wal_checkpoint", /* ePragTyp: */ PragTyp_WAL_CHECKPOINT, |
Changes to test/reuse4.test.
︙ | |||
110 111 112 113 114 115 116 117 118 119 | 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 | + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + | SELECT * FROM main.x3; SELECT 'xxx'; } { 3 3 4 4 5 5 6 6 7 7 8 8 3 3 5 5 7 7 xxx 123 456 xxx xxx } } #------------------------------------------------------------------------- # Test some PRAGMA statements with shared-schema connections. # reset_db do_execsql_test 2.0 { CREATE TABLE t1(a, b, c); CREATE INDEX t1abc ON t1(a, b, c); } foreach {tn pragma nSchema nDelete} { 1 "PRAGMA synchronous = OFF" 1 0 2 "PRAGMA cache_size = 200" 1 0 3 "PRAGMA aux2.integrity_check" 1 0 4 "PRAGMA integrity_check" 1 5 5 "PRAGMA index_info=t1abc" 1 5 6 "PRAGMA aux3.index_info=t1abc" 1 0 7 "PRAGMA journal_mode" 1 0 8 "PRAGMA aux2.wal_checkpoint" 1 0 9 "PRAGMA wal_checkpoint" 1 0 } { do_test 2.$tn.1 { catch { db close } catch { db2 close } for {set i 1} {$i < 6} {incr i} { forcedelete "test.db$i" "test.db${i}-wal" "test.db${i}-journal" forcecopy test.db test.db$i } sqlite3 db2 test.db -shared-schema 1 for {set i 1} {$i < 6} {incr i} { execsql "ATTACH 'test.db$i' AS aux$i" db2 } } {} sqlite3 db test.db register_schemapool_module db do_test 2.$tn.2 { execsql $pragma db2 execsql { SELECT 'nschema='||nschema, 'ndelete='||nDelete FROM schemapool } } "nschema=$nSchema ndelete=$nDelete" do_test 2.$tn.3 { execsql { SELECT * FROM main.t1,aux1.t1,aux2.t1,aux3.t1,aux4.t1,aux5.t1 } db2 execsql { SELECT 'nschema=' || nschema, 'nref=' || nref FROM schemapool } } "nschema=6 nref=6" } finish_test |
Changes to tool/mkpragmatab.tcl.
︙ | |||
8 9 10 11 12 13 14 | 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | - + | # the lookup table needed for pragma name lookup in the pragma.c module. # Then add the extra "case PragTyp_XXXXX:" and subsequent code for the # new pragma in ../src/pragma.c. # # Flag meanings: set flagMeaning(NeedSchema) {Force schema load before running} |
︙ | |||
146 147 148 149 150 151 152 | 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 | - + - + - + - + - + - + - + - + - + | IF: !defined(SQLITE_OMIT_FOREIGN_KEY) && !defined(SQLITE_OMIT_TRIGGER) NAME: cell_size_check TYPE: FLAG ARG: SQLITE_CellSizeCk NAME: default_cache_size |
︙ | |||
252 253 254 255 256 257 258 | 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 | - + | NAME: index_list FLAG: NeedSchema Result1 SchemaOpt COLS: seq name unique origin partial IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) NAME: database_list |
︙ | |||
280 281 282 283 284 285 286 | 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | - + - + | NAME: collation_list FLAG: Result0 COLS: seq name IF: !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) NAME: foreign_key_list |
︙ | |||
325 326 327 328 329 330 331 | 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 | - - + + - - + + - + | TYPE: HEADER_VALUE ARG: BTREE_USER_VERSION FLAG: NoColumns1 Result0 IF: !defined(SQLITE_OMIT_SCHEMA_VERSION_PRAGMAS) NAME: data_version TYPE: HEADER_VALUE |
︙ | |||
528 529 530 531 532 533 534 535 536 537 538 539 540 541 | 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 | + + + + + + | puts $fd "\n/* Property flags associated with various pragma. */" set fv 1 foreach f [lsort [array names allflags]] { puts $fd [format {#define PragFlg_%-10s 0x%02x /* %s */} \ $f $fv $flagMeaning($f)] set fv [expr {$fv*2}] } puts $fd "\n/* For PragTyp_HEADER_VALUE pragmas the Pragma.iArg value is set" puts $fd "** to the index of the header field to access (always 10 or less)." puts $fd "** Ored with HEADER_VALUE_READONLY if the field is read only. */" puts $fd "#define PRAGMA_HEADER_VALUE_READONLY 0x0100" puts $fd "#define PRAGMA_HEADER_VALUE_MASK 0x00FF\n" # Sort the column lists so that longer column lists occur first # proc colscmp {a b} { return [expr {[llength $b] - [llength $a]}] } set cols_list [lsort -command colscmp $cols_list] |
︙ |