/ Check-in [9c1747b5]
Login

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

Overview
Comment:Merge trunk changes.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | experimental
Files: files | file ages | folders
SHA1: 9c1747b5ded995e77fdab2fa9d334ec3c17c7c14
User & Date: dan 2014-03-01 19:45:23
Context
2014-03-03
14:45
Merge latest trunk changes. check-in: e00ed717 user: dan tags: experimental
2014-03-01
19:45
Merge trunk changes. check-in: 9c1747b5 user: dan tags: experimental
19:44
Remove the vdbeRecordCompareLargeHeader function. Fix some other details. check-in: 3861e853 user: dan tags: experimental
2014-02-28
20:47
In the command-line shell add the (undocumented and unsupported) ".eqp" command and -eqp command-line option, to cause EXPLAIN QUERY PLAN to be run on each SQL statement as it is evaluated. Intended use is for analysis of the query planner. check-in: e6ecf733 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/shell.c.

    61     61   # define write_history(X)
    62     62   # define stifle_history(X)
    63     63   #endif
    64     64   
    65     65   #if defined(_WIN32) || defined(WIN32)
    66     66   # include <io.h>
    67     67   #define isatty(h) _isatty(h)
    68         -#define access(f,m) _access((f),(m))
           68  +#ifndef access
           69  +# define access(f,m) _access((f),(m))
           70  +#endif
    69     71   #undef popen
    70     72   #define popen _popen
    71     73   #undef pclose
    72     74   #define pclose _pclose
    73     75   #else
    74     76   /* Make sure isatty() has a prototype.
    75     77   */
................................................................................
   440    442   ** An pointer to an instance of this structure is passed from
   441    443   ** the main program to the callback.  This is used to communicate
   442    444   ** state and mode information.
   443    445   */
   444    446   struct callback_data {
   445    447     sqlite3 *db;           /* The database */
   446    448     int echoOn;            /* True to echo input commands */
          449  +  int autoEQP;           /* Run EXPLAIN QUERY PLAN prior to seach SQL statement */
   447    450     int statsOn;           /* True to display memory stats before each finalize */
   448    451     int cnt;               /* Number of records displayed so far */
   449    452     FILE *out;             /* Write results here */
   450    453     FILE *traceOut;        /* Output for sqlite3_trace() */
   451    454     int nErr;              /* Number of errors seen */
   452    455     int mode;              /* An output mode setting */
   453    456     int writableSchema;    /* True if PRAGMA writable_schema=ON */
................................................................................
  1295   1298         }
  1296   1299   
  1297   1300         /* echo the sql statement if echo on */
  1298   1301         if( pArg && pArg->echoOn ){
  1299   1302           const char *zStmtSql = sqlite3_sql(pStmt);
  1300   1303           fprintf(pArg->out, "%s\n", zStmtSql ? zStmtSql : zSql);
  1301   1304         }
         1305  +
         1306  +      /* Show the EXPLAIN QUERY PLAN if .eqp is on */
         1307  +      if( pArg && pArg->autoEQP ){
         1308  +        sqlite3_stmt *pExplain;
         1309  +        char *zEQP = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", sqlite3_sql(pStmt));
         1310  +        rc = sqlite3_prepare_v2(db, zEQP, -1, &pExplain, 0);
         1311  +        if( rc==SQLITE_OK ){
         1312  +          while( sqlite3_step(pExplain)==SQLITE_ROW ){
         1313  +            fprintf(pArg->out,"--EQP-- %d,", sqlite3_column_int(pExplain, 0));
         1314  +            fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 1));
         1315  +            fprintf(pArg->out,"%d,", sqlite3_column_int(pExplain, 2));
         1316  +            fprintf(pArg->out,"%s\n", sqlite3_column_text(pExplain, 3));
         1317  +          }
         1318  +        }
         1319  +        sqlite3_finalize(pExplain);
         1320  +        sqlite3_free(zEQP);
         1321  +      }
  1302   1322   
  1303   1323         /* Output TESTCTRL_EXPLAIN text of requested */
  1304   1324         if( pArg && pArg->mode==MODE_Explain ){
  1305   1325           const char *zExplain = 0;
  1306   1326           sqlite3_test_control(SQLITE_TESTCTRL_EXPLAIN_STMT, pStmt, &zExplain);
  1307   1327           if( zExplain && zExplain[0] ){
  1308   1328             fprintf(pArg->out, "%s", zExplain);
................................................................................
  2294   2314       sqlite3_exec(p->db, "RELEASE dump;", 0, 0, 0);
  2295   2315       fprintf(p->out, p->nErr ? "ROLLBACK; -- due to errors\n" : "COMMIT;\n");
  2296   2316     }else
  2297   2317   
  2298   2318     if( c=='e' && strncmp(azArg[0], "echo", n)==0 && nArg>1 && nArg<3 ){
  2299   2319       p->echoOn = booleanValue(azArg[1]);
  2300   2320     }else
         2321  +
         2322  +  if( c=='e' && strncmp(azArg[0], "eqp", n)==0 && nArg>1 && nArg<3 ){
         2323  +    p->autoEQP = booleanValue(azArg[1]);
         2324  +  }else
  2301   2325   
  2302   2326     if( c=='e' && strncmp(azArg[0], "exit", n)==0 ){
  2303   2327       if( nArg>1 && (rc = (int)integerValue(azArg[1]))!=0 ) exit(rc);
  2304   2328       rc = 2;
  2305   2329     }else
  2306   2330   
  2307   2331     if( c=='e' && strncmp(azArg[0], "explain", n)==0 && nArg<3 ){
................................................................................
  2867   2891       sqlite3_snprintf(sizeof(p->separator), p->separator,
  2868   2892                        "%.*s", (int)sizeof(p->separator)-1, azArg[1]);
  2869   2893     }else
  2870   2894   
  2871   2895     if( c=='s' && strncmp(azArg[0], "show", n)==0 && nArg==1 ){
  2872   2896       int i;
  2873   2897       fprintf(p->out,"%9.9s: %s\n","echo", p->echoOn ? "on" : "off");
         2898  +    fprintf(p->out,"%9.9s: %s\n","eqp", p->autoEQP ? "on" : "off");
  2874   2899       fprintf(p->out,"%9.9s: %s\n","explain", p->explainPrev.valid ? "on" :"off");
  2875   2900       fprintf(p->out,"%9.9s: %s\n","headers", p->showHeader ? "on" : "off");
  2876   2901       fprintf(p->out,"%9.9s: %s\n","mode", modeDescr[p->mode]);
  2877   2902       fprintf(p->out,"%9.9s: ", "nullvalue");
  2878   2903         output_c_string(p->out, p->nullvalue);
  2879   2904         fprintf(p->out, "\n");
  2880   2905       fprintf(p->out,"%9.9s: %s\n","output",
................................................................................
  3704   3729                          "%s",cmdline_option_value(argc,argv,++i));
  3705   3730       }else if( strcmp(z,"-header")==0 ){
  3706   3731         data.showHeader = 1;
  3707   3732       }else if( strcmp(z,"-noheader")==0 ){
  3708   3733         data.showHeader = 0;
  3709   3734       }else if( strcmp(z,"-echo")==0 ){
  3710   3735         data.echoOn = 1;
         3736  +    }else if( strcmp(z,"-eqp")==0 ){
         3737  +      data.autoEQP = 1;
  3711   3738       }else if( strcmp(z,"-stats")==0 ){
  3712   3739         data.statsOn = 1;
  3713   3740       }else if( strcmp(z,"-bail")==0 ){
  3714   3741         bail_on_error = 1;
  3715   3742       }else if( strcmp(z,"-version")==0 ){
  3716   3743         printf("%s %s\n", sqlite3_libversion(), sqlite3_sourceid());
  3717   3744         return 0;