aboutsummaryrefslogtreecommitdiff
path: root/src/printf.c
diff options
context:
space:
mode:
authordrh <>2021-03-23 01:06:02 +0000
committerdrh <>2021-03-23 01:06:02 +0000
commita7fc252b0a19e9f147b36f6b5cd8825522c2c239 (patch)
treede92cf9b96369bf12594923f676bc000d352cb1c /src/printf.c
parentf93ff6b9f465dcc24b2655f8eabf28af166a7c03 (diff)
parente3e8f5ce9c852032ffca77c84d7e056b3ec01b4e (diff)
downloadsqlite-a7fc252b0a19e9f147b36f6b5cd8825522c2c239.tar.gz
sqlite-a7fc252b0a19e9f147b36f6b5cd8825522c2c239.zip
Enhance the EXPLAIN QUERY PLAN output to use symbolic names to describe
subqueries, where possible, instead of cryptic subquery index numbers. And in other ways, make the EQP output cleaner and easier to read. Little code is changed, but many of the test results had to be tweaked to align with the new output format. FossilOrigin-Name: f8e28308fdb45fbdef30003320d653410d69bb8ec92eef35c4245a99e2d0603b
Diffstat (limited to 'src/printf.c')
-rw-r--r--src/printf.c35
1 files changed, 22 insertions, 13 deletions
diff --git a/src/printf.c b/src/printf.c
index 9aab863ed..6f3b5681a 100644
--- a/src/printf.c
+++ b/src/printf.c
@@ -29,7 +29,7 @@
#define etSQLESCAPE2 10 /* Strings with '\'' doubled and enclosed in '',
NULL pointers replaced by SQL NULL. %Q */
#define etTOKEN 11 /* a pointer to a Token structure */
-#define etSRCLIST 12 /* a pointer to a SrcList */
+#define etSRCITEM 12 /* a pointer to a SrcItem */
#define etPOINTER 13 /* The %p conversion */
#define etSQLESCAPE3 14 /* %w -> Strings with '\"' doubled */
#define etORDINAL 15 /* %r -> 1st, 2nd, 3rd, 4th, etc. English only */
@@ -95,10 +95,16 @@ static const et_info fmtinfo[] = {
/* All the rest are undocumented and are for internal use only */
{ 'T', 0, 0, etTOKEN, 0, 0 },
- { 'S', 0, 0, etSRCLIST, 0, 0 },
+ { 'S', 0, 0, etSRCITEM, 0, 0 },
{ 'r', 10, 1, etORDINAL, 0, 0 },
};
+/* Notes:
+**
+** %S Takes a pointer to SrcItem. Shows name or database.name
+** %!S Like %S but prefer the zName over the zAlias
+*/
+
/* Floating point constants used for rounding */
static const double arRound[] = {
5.0e-01, 5.0e-02, 5.0e-03, 5.0e-04, 5.0e-05,
@@ -853,21 +859,24 @@ void sqlite3_str_vappendf(
length = width = 0;
break;
}
- case etSRCLIST: {
- SrcList *pSrc;
- int k;
+ case etSRCITEM: {
SrcItem *pItem;
if( (pAccum->printfFlags & SQLITE_PRINTF_INTERNAL)==0 ) return;
- pSrc = va_arg(ap, SrcList*);
- k = va_arg(ap, int);
- pItem = &pSrc->a[k];
+ pItem = va_arg(ap, SrcItem*);
assert( bArgList==0 );
- assert( k>=0 && k<pSrc->nSrc );
- if( pItem->zDatabase ){
- sqlite3_str_appendall(pAccum, pItem->zDatabase);
- sqlite3_str_append(pAccum, ".", 1);
+ if( pItem->zAlias && !flag_altform2 ){
+ sqlite3_str_appendall(pAccum, pItem->zAlias);
+ }else if( pItem->zName ){
+ if( pItem->zDatabase ){
+ sqlite3_str_appendall(pAccum, pItem->zDatabase);
+ sqlite3_str_append(pAccum, ".", 1);
+ }
+ sqlite3_str_appendall(pAccum, pItem->zName);
+ }else if( pItem->zAlias ){
+ sqlite3_str_appendall(pAccum, pItem->zAlias);
+ }else if( pItem->pSelect ){
+ sqlite3_str_appendf(pAccum, "SUBQUERY %u", pItem->pSelect->selId);
}
- sqlite3_str_appendall(pAccum, pItem->zName);
length = width = 0;
break;
}