Test some example code from documentation page eqp.html.
FossilOrigin-Name: 547bc2c232cbf7b7ff295287ab8fddb880e517f9
This commit is contained in:
parent
4f48d644e9
commit
91da6b8397
26
manifest
26
manifest
@ -1,8 +1,5 @@
|
||||
-----BEGIN PGP SIGNED MESSAGE-----
|
||||
Hash: SHA1
|
||||
|
||||
C Merge\sthe\sEXPLAIN\sQUERY\sPLAN\schanges\sfrom\sexperimental\sinto\strunk.
|
||||
D 2010-11-15T14:44:30
|
||||
C Test\ssome\sexample\scode\sfrom\sdocumentation\spage\seqp.html.
|
||||
D 2010-11-15T14:51:33
|
||||
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
|
||||
F Makefile.in e7a59672eaeb04408d1fa8501618d7501a3c5e39
|
||||
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
|
||||
@ -186,7 +183,7 @@ F src/sqliteLimit.h a17dcd3fb775d63b64a43a55c54cb282f9726f44
|
||||
F src/status.c 496913d4e8441195f6f2a75b1c95993a45b9b30b
|
||||
F src/table.c 2cd62736f845d82200acfa1287e33feb3c15d62e
|
||||
F src/tclsqlite.c e1c485fa323e3ef02e5b10fe6a016e7638013eb9
|
||||
F src/test1.c 9e1fe842f72aa41af48ab7b21c3a12975b4c5b37
|
||||
F src/test1.c a1339ecea631f3287b7dafcc8d55d343f7c5d193
|
||||
F src/test2.c 80d323d11e909cf0eb1b6fbb4ac22276483bcf31
|
||||
F src/test3.c 056093cfef69ff4227a6bdb9108564dc7f45e4bc
|
||||
F src/test4.c 0528360b5025688002a5feb6be906ddce52eaaee
|
||||
@ -368,7 +365,7 @@ F test/enc.test e54531cd6bf941ee6760be041dff19a104c7acea
|
||||
F test/enc2.test 6d91a5286f59add0cfcbb2d0da913b76f2242398
|
||||
F test/enc3.test 5c550d59ff31dccdba5d1a02ae11c7047d77c041
|
||||
F test/enc4.test 4b575ef09e0eff896e73bd24076f96c2aa6a42de
|
||||
F test/eqp.test 8f8e8ca502267bd34841f66564c1154aecc4fcc4
|
||||
F test/eqp.test 32567e06a0dc02a158d93571fdc843bb33824fc7
|
||||
F test/eval.test bc269c365ba877554948441e91ad5373f9f91be3
|
||||
F test/exclusive.test 53e1841b422e554cecf0160f937c473d6d0e3062
|
||||
F test/exclusive2.test 76e63c05349cb70d09d60b99d2ae625525ff5155
|
||||
@ -889,14 +886,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
|
||||
F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
|
||||
F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
|
||||
F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
|
||||
P a397ed162246fef32b8c5db36d995bf9a8005a2e 6611b76b0296875fb9903b25dfaa783a9c12eaa1
|
||||
R 1e73ae4c8823ab0663e26456987bae7c
|
||||
U drh
|
||||
Z b8229a6177e36bec8618f3cb97f45755
|
||||
-----BEGIN PGP SIGNATURE-----
|
||||
Version: GnuPG v1.4.6 (GNU/Linux)
|
||||
|
||||
iD8DBQFM4UdRoxKgR168RlERAqhcAKCDlGd+bkF6B7sQTpZQqbxAI/toQgCfXUHJ
|
||||
Rco8nRCLvqh3phYwbsb2VlE=
|
||||
=MBq+
|
||||
-----END PGP SIGNATURE-----
|
||||
P ce27bf38405ce805dad95ec22cbe68ddc7af544a
|
||||
R 1facb0207f6324270040270a0296fb61
|
||||
U dan
|
||||
Z d4c8887d4bb41a227b698c81727e9001
|
||||
|
@ -1 +1 @@
|
||||
ce27bf38405ce805dad95ec22cbe68ddc7af544a
|
||||
547bc2c232cbf7b7ff295287ab8fddb880e517f9
|
63
src/test1.c
63
src/test1.c
@ -5231,6 +5231,64 @@ static int runAsObjProc(
|
||||
return cmdInfo.objProc(cmdInfo.objClientData, interp, objc-1, objv+1);
|
||||
}
|
||||
|
||||
#ifndef SQLITE_OMIT_EXPLAIN
|
||||
/*
|
||||
** WARNING: The following function, printExplainQueryPlan() is an exact
|
||||
** copy of example code from eqp.in (eqp.html). If this code is modified,
|
||||
** then the documentation copy needs to be modified as well.
|
||||
*/
|
||||
/*
|
||||
** Argument pStmt is a prepared SQL statement. This function compiles
|
||||
** an EXPLAIN QUERY PLAN command to report on the prepared statement,
|
||||
** and prints the report to stdout using printf().
|
||||
*/
|
||||
int printExplainQueryPlan(sqlite3_stmt *pStmt){
|
||||
const char *zSql; /* Input SQL */
|
||||
char *zExplain; /* SQL with EXPLAIN QUERY PLAN prepended */
|
||||
sqlite3_stmt *pExplain; /* Compiled EXPLAIN QUERY PLAN command */
|
||||
int rc; /* Return code from sqlite3_prepare_v2() */
|
||||
|
||||
zSql = sqlite3_sql(pStmt);
|
||||
if( zSql==0 ) return SQLITE_ERROR;
|
||||
|
||||
zExplain = sqlite3_mprintf("EXPLAIN QUERY PLAN %s", zSql);
|
||||
if( zExplain==0 ) return SQLITE_NOMEM;
|
||||
|
||||
rc = sqlite3_prepare_v2(sqlite3_db_handle(pStmt), zExplain, -1, &pExplain, 0);
|
||||
sqlite3_free(zExplain);
|
||||
if( rc!=SQLITE_OK ) return rc;
|
||||
|
||||
while( SQLITE_ROW==sqlite3_step(pExplain) ){
|
||||
int iSelectid = sqlite3_column_int(pExplain, 0);
|
||||
int iOrder = sqlite3_column_int(pExplain, 1);
|
||||
int iFrom = sqlite3_column_int(pExplain, 2);
|
||||
const char *zDetail = (const char *)sqlite3_column_text(pExplain, 3);
|
||||
|
||||
printf("%d %d %d %s\n", iSelectid, iOrder, iFrom, zDetail);
|
||||
}
|
||||
|
||||
return sqlite3_finalize(pExplain);
|
||||
}
|
||||
|
||||
static int test_print_eqp(
|
||||
void * clientData,
|
||||
Tcl_Interp *interp,
|
||||
int objc,
|
||||
Tcl_Obj *CONST objv[]
|
||||
){
|
||||
int rc;
|
||||
sqlite3_stmt *pStmt;
|
||||
|
||||
if( objc!=2 ){
|
||||
Tcl_WrongNumArgs(interp, 1, objv, "STMT");
|
||||
return TCL_ERROR;
|
||||
}
|
||||
if( getStmtPointer(interp, Tcl_GetString(objv[1]), &pStmt) ) return TCL_ERROR;
|
||||
rc = printExplainQueryPlan(pStmt);
|
||||
Tcl_SetResult(interp, (char *)t1ErrorName(rc), 0);
|
||||
return TCL_OK;
|
||||
}
|
||||
#endif /* SQLITE_OMIT_EXPLAIN */
|
||||
|
||||
/*
|
||||
** Register commands with the TCL interpreter.
|
||||
@ -5426,8 +5484,9 @@ int Sqlitetest1_Init(Tcl_Interp *interp){
|
||||
#ifdef SQLITE_ENABLE_UNLOCK_NOTIFY
|
||||
{ "sqlite3_unlock_notify", test_unlock_notify, 0 },
|
||||
#endif
|
||||
{ "sqlite3_wal_checkpoint", test_wal_checkpoint, 0 },
|
||||
{ "test_sqlite3_log", test_sqlite3_log, 0 },
|
||||
{ "sqlite3_wal_checkpoint", test_wal_checkpoint, 0 },
|
||||
{ "test_sqlite3_log", test_sqlite3_log, 0 },
|
||||
{ "print_explain_query_plan", test_print_eqp, 0 },
|
||||
};
|
||||
static int bitmask_size = sizeof(Bitmask)*8;
|
||||
int i;
|
||||
|
@ -454,6 +454,45 @@ det 5.13 "SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1" {
|
||||
}
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
# The following tests - eqp-6.* - test that the example C code on
|
||||
# documentation page eqp.html works. The C code is duplicated in test1.c
|
||||
# and wrapped in Tcl command [print_explain_query_plan]
|
||||
#
|
||||
set boilerplate {
|
||||
proc explain_query_plan {db sql} {
|
||||
set stmt [sqlite3_prepare_v2 db $sql -1 DUMMY]
|
||||
print_explain_query_plan $stmt
|
||||
sqlite3_finalize $stmt
|
||||
}
|
||||
sqlite3 db test.db
|
||||
explain_query_plan db {%SQL%}
|
||||
db close
|
||||
exit
|
||||
}
|
||||
|
||||
proc do_peqp_test {tn sql res} {
|
||||
set fd [open script.tcl w]
|
||||
puts $fd [string map [list %SQL% $sql] $::boilerplate]
|
||||
close $fd
|
||||
|
||||
uplevel do_test $tn [list {
|
||||
set fd [open "|[info nameofexec] script.tcl"]
|
||||
set data [read $fd]
|
||||
close $fd
|
||||
set data
|
||||
}] [list $res]
|
||||
}
|
||||
|
||||
do_peqp_test 6.1 {
|
||||
SELECT a FROM t1 EXCEPT SELECT d FROM t2 ORDER BY 1
|
||||
} [string trimleft {
|
||||
1 0 0 SCAN TABLE t1 USING COVERING INDEX i2 (~1000000 rows)
|
||||
2 0 0 SCAN TABLE t2 (~1000000 rows)
|
||||
2 0 0 USE TEMP B-TREE FOR ORDER BY
|
||||
0 0 0 COMPOUND SUBQUERIES 1 AND 2 (EXCEPT)
|
||||
}]
|
||||
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user