Improvements to the vtablog.c extension: Eliminate memory leaks.

More diagnostic output for xBestIndex.

FossilOrigin-Name: 92e9a71bc4daa261d7c9a81fb66f7d7c0f0a74eb9e0c9dec8b4651acc5217bff
This commit is contained in:
drh 2024-03-25 10:55:08 +00:00
parent 55051d661c
commit 4397d28378
3 changed files with 52 additions and 15 deletions

View File

@ -189,15 +189,18 @@ static int vtablogConnectCreate(
for(i=3; i<argc; i++){
const char *z = argv[i];
if( vtablog_string_parameter(pzErr, "schema", z, &zSchema) ){
return SQLITE_ERROR;
rc = SQLITE_ERROR;
goto vtablog_end_connect;
}
if( vtablog_string_parameter(pzErr, "rows", z, &zNRow) ){
return SQLITE_ERROR;
rc = SQLITE_ERROR;
goto vtablog_end_connect;
}
}
if( zSchema==0 ){
zSchema = "CREATE TABLE x(a,b);";
zSchema = sqlite3_mprintf("%s","CREATE TABLE x(a,b);");
}
printf(" schema = '%s'\n", zSchema);
rc = sqlite3_declare_vtab(db, zSchema);
if( rc==SQLITE_OK ){
pNew = sqlite3_malloc( sizeof(*pNew) );
@ -206,9 +209,14 @@ static int vtablogConnectCreate(
memset(pNew, 0, sizeof(*pNew));
pNew->nRow = 10;
if( zNRow ) pNew->nRow = atoi(zNRow);
printf(" nrow = %d\n", pNew->nRow);
pNew->zDb = sqlite3_mprintf("%s", argv[1]);
pNew->zName = sqlite3_mprintf("%s", argv[2]);
}
vtablog_end_connect:
sqlite3_free(zSchema);
sqlite3_free(zNRow);
return rc;
}
static int vtablogCreate(
@ -249,6 +257,7 @@ static int vtablogDisconnect(sqlite3_vtab *pVtab){
static int vtablogDestroy(sqlite3_vtab *pVtab){
vtablog_vtab *pTab = (vtablog_vtab*)pVtab;
printf("%s.%s.xDestroy()\n", pTab->zDb, pTab->zName);
sqlite3_free(pTab->zDb);
sqlite3_free(pTab->zName);
sqlite3_free(pVtab);
return SQLITE_OK;
@ -434,12 +443,37 @@ static int vtablogFilter(
*/
static int vtablogBestIndex(
sqlite3_vtab *tab,
sqlite3_index_info *pIdxInfo
sqlite3_index_info *p
){
vtablog_vtab *pTab = (vtablog_vtab*)tab;
int i;
printf("%s.%s.xBestIndex():\n", pTab->zDb, pTab->zName);
pIdxInfo->estimatedCost = (double)500;
pIdxInfo->estimatedRows = 500;
printf(" colUsed: 0x%016llx\n", p->colUsed);
printf(" nConstraint: %d\n", p->nConstraint);
for(i=0; i<p->nConstraint; i++){
printf(
" constraint[%d]: col=%d termid=%d op=%d usabled=%d collseq=%s\n",
i,
p->aConstraint[i].iColumn,
p->aConstraint[i].iTermOffset,
p->aConstraint[i].op,
p->aConstraint[i].usable,
sqlite3_vtab_collation(p,i));
}
printf(" nOrderBy: %d\n", p->nOrderBy);
for(i=0; i<p->nOrderBy; i++){
printf(" orderby[%d]: col=%d desc=%d\n",
i,
p->aOrderBy[i].iColumn,
p->aOrderBy[i].desc);
}
p->estimatedCost = (double)500;
p->estimatedRows = 500;
printf(" idxNum=%d\n", p->idxNum);
printf(" idxStr=NULL\n");
printf(" orderByConsumed=%d\n", p->orderByConsumed);
printf(" estimatedCost=%g\n", p->estimatedCost);
printf(" estimatedRows=%lld\n", p->estimatedRows);
return SQLITE_OK;
}
@ -524,9 +558,12 @@ static int vtablogRename(sqlite3_vtab *tab, const char *zNew){
return SQLITE_OK;
}
/* Any table name that contains the text "shadow" is seen as a
** shadow table. Nothing else is.
*/
static int vtablogShadowName(const char *zName){
printf("vtablog.xShadowName('%s')\n", zName);
return 0;
return sqlite3_strglob("*shadow*", zName)==0;
}
static int vtablogIntegrity(

View File

@ -1,5 +1,5 @@
C Flag\ssqlite3_trace()\sand\ssqlite3_profile()\sas\sdeprecated\sso\sthat\sthe\sdoc\sgenerator\sfor\sfunclist.html\ssees\sthem\sas\ssuch,\sand\sadd\s'Deprecated'\sto\stheir\spage's\stitle\sfor\sconsistency\swith\sother\sdeprecated\sAPIs.\sComment\schanges\sonly.\sAddresses\s[forum:0901025836|forum\spost\s0901025836].
D 2024-03-25T10:28:10.796
C Improvements\sto\sthe\svtablog.c\sextension:\s\sEliminate\smemory\sleaks.\nMore\sdiagnostic\soutput\sfor\sxBestIndex.
D 2024-03-25T10:55:08.289
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F LICENSE.md df5091916dbb40e6e9686186587125e1b2ff51f022cc334e886c19a0e9982724
@ -426,7 +426,7 @@ F ext/misc/urifuncs.c f71360d14fa9e7626b563f1f781c6148109462741c5235ac63ae0f8917
F ext/misc/uuid.c 5bb2264c1b64d163efa46509544fd7500cb8769cb7c16dd52052da8d961505cf
F ext/misc/vfslog.c 3932ab932eeb2601dbc4447cb14d445aaa9fbe43b863ef5f014401c3420afd20
F ext/misc/vfsstat.c a85df08654743922a19410d7b1e3111de41bb7cd07d20dd16eda4e2b808d269d
F ext/misc/vtablog.c 10b3b8abb57c9e6ad5b9fd7789a15359931f4ae7eea1ce4c42692b5ab458b58d
F ext/misc/vtablog.c 1100250ce8782db37c833e3a9a5c9a3ecf1af5e15b8325572b82e6e0a138ffb5
F ext/misc/vtshim.c 1976e6dd68dd0d64508c91a6dfab8e75f8aaf6cd
F ext/misc/wholenumber.c 0fa0c082676b7868bf2fa918e911133f2b349bcdceabd1198bba5f65b4fc0668
F ext/misc/zipfile.c 64cb3d98b6316586e6056d182051aa9d28fdedfbf4b908e6b7a7d70209b1db11
@ -2182,8 +2182,8 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
P e253bb36a5f4f601c9b08858b55a9ce198239ace8efa8dab7c0ec019028967c1
R 9b310c2f5986c86858424e569b4e6f77
U stephan
Z 6c78d97a358d85a52548c24a097975e6
P 87c54f93f5711739741ed0ff3c1a6fe24ffc8a025b43523bf78c1f6be8c1b4cd
R 5d99a8b46e486ca8140c2e5b9bcd6d3d
U drh
Z 2928903171aaf3fcef9f3546955ace45
# Remove this line to create a well-formed Fossil manifest.

View File

@ -1 +1 @@
87c54f93f5711739741ed0ff3c1a6fe24ffc8a025b43523bf78c1f6be8c1b4cd
92e9a71bc4daa261d7c9a81fb66f7d7c0f0a74eb9e0c9dec8b4651acc5217bff