** on stdout when its key interfaces are called. This is intended for
** interactive analysis and debugging of virtual table interfaces.
**
+** HOW TO COMPILE:
+**
** To build this extension as a separately loaded shared library or
** DLL, use compiler command-lines similar to the following:
**
** (mac) clang -fPIC -dynamiclib vtablog.c -o vtablog.dylib
** (windows) cl vtablog.c -link -dll -out:vtablog.dll
**
-** Usage example:
+** USAGE EXAMPLE:
**
** .load ./vtablog
** CREATE VIRTUAL TABLE temp.log USING vtablog(
** rows=25
** );
** SELECT * FROM log;
+**
+** ARGUMENTS TO CREATE VIRTUAL TABLE:
+**
+** In "CREATE VIRTUAL TABLE temp.log AS vtablog(ARGS....)" statement, the
+** ARGS argument is a list of key-value pairs that can be any of the
+** following.
+**
+** schema=TEXT Text is a CREATE TABLE statement that defines
+** the schema of the new virtual table.
+**
+** rows=N The table as N rows.
+**
+** consume_order_by=N If the left-most ORDER BY terms is ASC and
+** against column N (where the leftmost column
+** is #1) then set the orderByConsumed=1 flag in
+** xBestIndex. Or if the left-most ORDER BY is
+** DESC and against column -N, do likewise.
*/
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
char *zName; /* Table name. argv[2] of xConnect/xCreate */
int nRow; /* Number of rows in the table */
int nCursor; /* Number of cursors created */
+ int iConsumeOB; /* Consume the ORDER BY clause if on column N-th
+ ** and consumeOB=N or consumeOB=(-N) and DESC */
};
/* vtablog_cursor is a subclass of sqlite3_vtab_cursor which will
int rc;
char *zSchema = 0;
char *zNRow = 0;
+ char *zConsumeOB = 0;
printf("%s.%s.%s():\n", argv[1], argv[2],
isCreate ? "xCreate" : "xConnect");
rc = SQLITE_ERROR;
goto vtablog_end_connect;
}
+ if( vtablog_string_parameter(pzErr, "consume_order_by", z, &zConsumeOB) ){
+ rc = SQLITE_ERROR;
+ goto vtablog_end_connect;
+ }
}
if( zSchema==0 ){
zSchema = sqlite3_mprintf("%s","CREATE TABLE x(a,b);");
pNew->nRow = 10;
if( zNRow ) pNew->nRow = atoi(zNRow);
printf(" nrow = %d\n", pNew->nRow);
+ if( zConsumeOB ) pNew->iConsumeOB = atoi(zConsumeOB);
+ if( pNew->iConsumeOB ){
+ printf(" consume_order_by = %d\n", pNew->iConsumeOB);
+ }
pNew->zDb = sqlite3_mprintf("%s", argv[1]);
pNew->zName = sqlite3_mprintf("%s", argv[2]);
}
vtablog_end_connect:
sqlite3_free(zSchema);
sqlite3_free(zNRow);
+ sqlite3_free(zConsumeOB);
return rc;
}
static int vtablogCreate(
}
}
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);
+ if( 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);
+ }
+ if( pTab->iConsumeOB ){
+ int N = p->aOrderBy[0].iColumn+1;
+ if( (p->aOrderBy[0].desc && N==-pTab->iConsumeOB)
+ || (!p->aOrderBy[0].desc && N==pTab->iConsumeOB)
+ ){
+ p->orderByConsumed = 1;
+ }
+ }
}
p->estimatedCost = (double)500;
p->estimatedRows = 500;
printf(" idxNum=%d\n", p->idxNum);
printf(" idxStr=NULL\n");
+ printf(" sqlite3_vtab_distinct()=%d\n", sqlite3_vtab_distinct(p));
printf(" orderByConsumed=%d\n", p->orderByConsumed);
printf(" estimatedCost=%g\n", p->estimatedCost);
printf(" estimatedRows=%lld\n", p->estimatedRows);
-C Clarify\sthe\saffect\sof\snCharLimit,\snLineLimit,\sand\snTitleLimit\son\sthe\nxRender\soutput\sfrom\sQRF.
-D 2025-12-15T13:58:41.145
+C Enhance\sthe\svtablog\sextension\sso\sthat\sit\sshows\sthe\svalue\sof\nsqlite3_vtab_distinct()\sin\sxBestIndex,\sand\sso\sthat\sprovides\sthe\snew\nconsume_order_by\soption\sthat\scan\scause\sxBestIndex\sto\sset\sthe\norderByConsumed\sflag.
+D 2025-12-15T17:32:56.417
F .fossil-settings/binary-glob 61195414528fb3ea9693577e1980230d78a1f8b0a54c78cf1b9b24d0a409ed6a x
F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
F ext/misc/vfslog.c 3932ab932eeb2601dbc4447cb14d445aaa9fbe43b863ef5f014401c3420afd20
F ext/misc/vfsstat.c 0b23c0a69a2b63dc0ef0af44f9c1fc977300c480a1f7a9814500369d8211f56e
F ext/misc/vfstrace.c 0e4b8b17ac0675ea90f6d168d8214687e06ca3efbc0060aad4814994d82b41fb
-F ext/misc/vtablog.c 2d04386c2f5a3bb93bc9ae978f0b7dcd5a264e126abd640dd6d82aa9067cbd48
+F ext/misc/vtablog.c 402496fb38add7dd2c50f2a0ad20f83a9916ceab48dcd31e62ad621e663c83ac
F ext/misc/vtshim.c e5bce24ab8c532f4fdc600148718fe1802cb6ed57417f1c1032d8961f72b0e8f
F ext/misc/wholenumber.c 0fa0c082676b7868bf2fa918e911133f2b349bcdceabd1198bba5f65b4fc0668
F ext/misc/windirent.h 02211ce51f3034c675f2dbf4d228194d51b3ee05734678bad5106fff6292e60c
F tool/warnings-clang.sh bbf6a1e685e534c92ec2bfba5b1745f34fb6f0bc2a362850723a9ee87c1b31a7
F tool/warnings.sh d924598cf2f55a4ecbc2aeb055c10bd5f48114793e7ba25f9585435da29e7e98
F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P 5cf9e99ff8279530cb73a24794107591f8dab755fe78acd6c11429e532f3d1bf
-R 61f1b2124f9d7a4acd1b4a3d4268eab3
+P 881534858de8bccffca53e7256a725378a98a354e792374d972b120880c2ae78
+R 516b4041a52e0f6a1c6a30026e823eb8
U drh
-Z d5b44ebdba76bbdfb15b0fa610193449
+Z 2dd134e29e053422231bfb06d9c85c41
# Remove this line to create a well-formed Fossil manifest.