/ Check-in [0249d9ae]
Login

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

Overview
Comment:Fix the ANALYZE command so that it will process tables whose names begin with "sqlite" as long as they do not being with "sqlite_".
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 0249d9aecf69948d9343feef9291273beef5fc98aa9a8f95b1e35cc2ce8e6cbd
User & Date: drh 2018-03-23 12:59:10
References
2018-03-23
13:18
Fix an error in the CLI in the previous ([0249d9aecf69948]) check-in. Only the pattern to sqlite3_strlike() need to be escaped. check-in: 71d5f6e6 user: drh tags: trunk
Context
2018-03-23
13:18
Fix an error in the CLI in the previous ([0249d9aecf69948]) check-in. Only the pattern to sqlite3_strlike() need to be escaped. check-in: 71d5f6e6 user: drh tags: trunk
12:59
Fix the ANALYZE command so that it will process tables whose names begin with "sqlite" as long as they do not being with "sqlite_". check-in: 0249d9ae user: drh tags: trunk
00:31
Fix harmless compiler warnings seen with MSVC. check-in: 2f2be1b1 user: mistachkin tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/analyze.c.

  1011   1011     if( v==0 || NEVER(pTab==0) ){
  1012   1012       return;
  1013   1013     }
  1014   1014     if( pTab->tnum==0 ){
  1015   1015       /* Do not gather statistics on views or virtual tables */
  1016   1016       return;
  1017   1017     }
  1018         -  if( sqlite3_strlike("sqlite_%", pTab->zName, 0)==0 ){
         1018  +  if( sqlite3_strlike("sqlite\\_%", pTab->zName, '\\')==0 ){
  1019   1019       /* Do not gather statistics on system tables */
  1020   1020       return;
  1021   1021     }
  1022   1022     assert( sqlite3BtreeHoldsAllMutexes(db) );
  1023   1023     iDb = sqlite3SchemaToIndex(db, pTab->pSchema);
  1024   1024     assert( iDb>=0 );
  1025   1025     assert( sqlite3SchemaMutexHeld(db, iDb, 0) );

Changes to src/shell.c.in.

  6617   6617         }else{
  6618   6618           raw_printf(stderr, "Usage: .schema ?--indent? ?LIKE-PATTERN?\n");
  6619   6619           rc = 1;
  6620   6620           goto meta_command_exit;
  6621   6621         }
  6622   6622       }
  6623   6623       if( zName!=0 ){
  6624         -      int isMaster = sqlite3_strlike(zName, "sqlite_master", 0)==0;
  6625         -      if( isMaster || sqlite3_strlike(zName,"sqlite_temp_master",0)==0 ){
         6624  +      int isMaster = sqlite3_strlike(zName, "sqlite\\_master", '\\')==0;
         6625  +      if( isMaster || sqlite3_strlike(zName,"sqlite\\_temp\\_master",'\\')==0 ){
  6626   6626           char *new_argv[2], *new_colv[2];
  6627   6627           new_argv[0] = sqlite3_mprintf(
  6628   6628                         "CREATE TABLE %s (\n"
  6629   6629                         "  type text,\n"
  6630   6630                         "  name text,\n"
  6631   6631                         "  tbl_name text,\n"
  6632   6632                         "  rootpage integer,\n"
................................................................................
  7099   7099         }else if( zLike ){
  7100   7100           raw_printf(stderr, "Usage: .sha3sum ?OPTIONS? ?LIKE-PATTERN?\n");
  7101   7101           rc = 1;
  7102   7102           goto meta_command_exit;
  7103   7103         }else{
  7104   7104           zLike = z;
  7105   7105           bSeparate = 1;
  7106         -        if( sqlite3_strlike("sqlite_%", zLike, 0)==0 ) bSchema = 1;
         7106  +        if( sqlite3_strlike("sqlite\\_%", zLike, '\\')==0 ) bSchema = 1;
  7107   7107         }
  7108   7108       }
  7109   7109       if( bSchema ){
  7110   7110         zSql = "SELECT lower(name) FROM sqlite_master"
  7111   7111                " WHERE type='table' AND coalesce(rootpage,0)>1"
  7112   7112                " UNION ALL SELECT 'sqlite_master'"
  7113   7113                " ORDER BY 1 collate nocase";

Changes to test/analyze.test.

   345    345       "
   346    346     } {t4i1 t4i2 t4}
   347    347   }
   348    348   
   349    349   # This test corrupts the database file so it must be the last test
   350    350   # in the series.
   351    351   #
   352         -do_test analyze-99.1 {
          352  +do_test analyze-5.99 {
   353    353     execsql {
   354    354       PRAGMA writable_schema=on;
   355    355       UPDATE sqlite_master SET sql='nonsense' WHERE name='sqlite_stat1';
   356    356     }
   357    357     db close
   358    358     catch { sqlite3 db test.db }
   359    359     catchsql {
   360    360       ANALYZE
   361    361     }
   362    362   } {1 {malformed database schema (sqlite_stat1)}}
          363  +
          364  +# Verify that tables whose names begin with "sqlite" but not
          365  +# "sqlite_" are analyzed.
          366  +#
          367  +db close
          368  +sqlite3 db :memory:
          369  +do_execsql_test analyze-6.1 {
          370  +  CREATE TABLE sqliteDemo(a);
          371  +  INSERT INTO sqliteDemo(a) VALUES(1),(2),(3),(4),(5);
          372  +  CREATE TABLE SQLiteDemo2(a INTEGER PRIMARY KEY AUTOINCREMENT);
          373  +  INSERT INTO SQLiteDemo2 SELECT * FROM sqliteDemo;
          374  +  CREATE TABLE t1(b);
          375  +  INSERT INTO t1(b) SELECT a FROM sqliteDemo;
          376  +  ANALYZE;
          377  +  SELECT tbl FROM sqlite_stat1 WHERE idx IS NULL ORDER BY tbl;
          378  +} {SQLiteDemo2 sqliteDemo t1}
   363    379   
   364    380   finish_test