aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <>2024-08-22 16:22:08 +0000
committerdrh <>2024-08-22 16:22:08 +0000
commitd55ab844513ab13ebbd8e6b483a75e8bdaefa98b (patch)
tree3ce182a828ef83fa20c89e17871321450a593fa0 /src
parent889ce8ee907502771fcc66cb815a06c1254b34a8 (diff)
downloadsqlite-d55ab844513ab13ebbd8e6b483a75e8bdaefa98b.tar.gz
sqlite-d55ab844513ab13ebbd8e6b483a75e8bdaefa98b.zip
Add the SQLITE_INDEX_SCAN_HEX bit to the sqlite3_index_info.idxFlags bitmask.
When set, this bit causes the EXPLAIN QUERY PLAN output to show the idxNum value in hex rather than in decimal. This is purely a debugging aid. FossilOrigin-Name: 6c00e88ebdb41d6317bb8758825521614dedc2e6e6289ff415c5f0406eed815b
Diffstat (limited to 'src')
-rw-r--r--src/dbstat.c1
-rw-r--r--src/sqlite.h.in12
-rw-r--r--src/where.c1
-rw-r--r--src/whereInt.h1
-rw-r--r--src/wherecode.c4
5 files changed, 14 insertions, 5 deletions
diff --git a/src/dbstat.c b/src/dbstat.c
index c70d80637..d635a8297 100644
--- a/src/dbstat.c
+++ b/src/dbstat.c
@@ -279,6 +279,7 @@ static int statBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
pIdxInfo->orderByConsumed = 1;
pIdxInfo->idxNum |= 0x08;
}
+ pIdxInfo->idxFlags |= SQLITE_INDEX_SCAN_HEX;
return SQLITE_OK;
}
diff --git a/src/sqlite.h.in b/src/sqlite.h.in
index 3c98e95d9..810ccecc9 100644
--- a/src/sqlite.h.in
+++ b/src/sqlite.h.in
@@ -7427,9 +7427,11 @@ struct sqlite3_module {
** will be returned by the strategy.
**
** The xBestIndex method may optionally populate the idxFlags field with a
-** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag -
-** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite
-** assumes that the strategy may visit at most one row.
+** mask of SQLITE_INDEX_SCAN_* flags. One such flag is
+** [SQLITE_INDEX_SCAN_HEX], which if set causes the [EXPLAIN QUERY PLAN]
+** output to show the idxNum has hex instead of as decimal. Another flag is
+** SQLITE_INDEX_SCAN_UNIQUE, which if set indicates that the query plan will
+** return at most one row.
**
** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then
** SQLite also assumes that if a call to the xUpdate() method is made as
@@ -7493,7 +7495,9 @@ struct sqlite3_index_info {
** [sqlite3_index_info].idxFlags field to some combination of
** these bits.
*/
-#define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */
+#define SQLITE_INDEX_SCAN_UNIQUE 0x00000001 /* Scan visits at most 1 row */
+#define SQLITE_INDEX_SCAN_HEX 0x00000002 /* Display idxNum as hex */
+ /* in EXPLAIN QUERY PLAN */
/*
** CAPI3REF: Virtual Table Constraint Operator Codes
diff --git a/src/where.c b/src/where.c
index 6e494850c..a82f0305b 100644
--- a/src/where.c
+++ b/src/where.c
@@ -4349,6 +4349,7 @@ static int whereLoopAddVirtualOne(
pNew->u.vtab.idxStr = pIdxInfo->idxStr;
pNew->u.vtab.isOrdered = (i8)(pIdxInfo->orderByConsumed ?
pIdxInfo->nOrderBy : 0);
+ pNew->u.vtab.bIdxNumHex = (pIdxInfo->idxFlags&SQLITE_INDEX_SCAN_HEX)!=0;
pNew->rSetup = 0;
pNew->rRun = sqlite3LogEstFromDouble(pIdxInfo->estimatedCost);
pNew->nOut = sqlite3LogEst(pIdxInfo->estimatedRows);
diff --git a/src/whereInt.h b/src/whereInt.h
index c9afed267..8247528a9 100644
--- a/src/whereInt.h
+++ b/src/whereInt.h
@@ -149,6 +149,7 @@ struct WhereLoop {
int idxNum; /* Index number */
u32 needFree : 1; /* True if sqlite3_free(idxStr) is needed */
u32 bOmitOffset : 1; /* True to let virtual table handle offset */
+ u32 bIdxNumHex : 1; /* Show idxNum as hex in EXPLAIN QUERY PLAN */
i8 isOrdered; /* True if satisfies ORDER BY */
u16 omitMask; /* Terms that may be omitted */
char *idxStr; /* Index identifier string */
diff --git a/src/wherecode.c b/src/wherecode.c
index b0c0d9aed..0951e5e20 100644
--- a/src/wherecode.c
+++ b/src/wherecode.c
@@ -200,7 +200,9 @@ int sqlite3WhereExplainOneScan(
}
#ifndef SQLITE_OMIT_VIRTUALTABLE
else if( (flags & WHERE_VIRTUALTABLE)!=0 ){
- sqlite3_str_appendf(&str, " VIRTUAL TABLE INDEX %d:%s",
+ sqlite3_str_appendall(&str, " VIRTUAL TABLE INDEX ");
+ sqlite3_str_appendf(&str,
+ pLoop->u.vtab.bIdxNumHex ? "0x%x:%s" : "%d:%s",
pLoop->u.vtab.idxNum, pLoop->u.vtab.idxStr);
}
#endif