Fossil SCM

Update the built-in SQLite to the latest 3.41.0 alpha that includes various query planner enhancements. This is done in order to test the enhancements to SQLite, to help ensure that they are working correctly in a real-world application.

drh 2022-12-15 15:39 trunk
Commit 7010ce23917586d614efa11524944497bb2a800d842fa2013bd28f048c7fca11
3 files changed +273 -46 +782 -280 +66 -43
+273 -46
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -483,12 +483,99 @@
483483
484484
/*
485485
** Prompt strings. Initialized in main. Settable with
486486
** .prompt main continue
487487
*/
488
-static char mainPrompt[20]; /* First line prompt. default: "sqlite> "*/
489
-static char continuePrompt[20]; /* Continuation prompt. default: " ...> " */
488
+#define PROMPT_LEN_MAX 20
489
+/* First line prompt. default: "sqlite> " */
490
+static char mainPrompt[PROMPT_LEN_MAX];
491
+/* Continuation prompt. default: " ...> " */
492
+static char continuePrompt[PROMPT_LEN_MAX];
493
+
494
+/*
495
+** Optionally disable dynamic continuation prompt.
496
+** Unless disabled, the continuation prompt shows open SQL lexemes if any,
497
+** or open parentheses level if non-zero, or continuation prompt as set.
498
+** This facility interacts with the scanner and process_input() where the
499
+** below 5 macros are used.
500
+*/
501
+#ifdef SQLITE_OMIT_DYNAPROMPT
502
+# define CONTINUATION_PROMPT continuePrompt
503
+# define CONTINUE_PROMPT_RESET
504
+# define CONTINUE_PROMPT_AWAITS(p,s)
505
+# define CONTINUE_PROMPT_AWAITC(p,c)
506
+# define CONTINUE_PAREN_INCR(p,n)
507
+# define CONTINUE_PROMPT_PSTATE 0
508
+typedef void *t_NoDynaPrompt;
509
+# define SCAN_TRACKER_REFTYPE t_NoDynaPrompt
510
+#else
511
+# define CONTINUATION_PROMPT dynamicContinuePrompt()
512
+# define CONTINUE_PROMPT_RESET \
513
+ do {setLexemeOpen(&dynPrompt,0,0); trackParenLevel(&dynPrompt,0);} while(0)
514
+# define CONTINUE_PROMPT_AWAITS(p,s) \
515
+ if(p && stdin_is_interactive) setLexemeOpen(p, s, 0)
516
+# define CONTINUE_PROMPT_AWAITC(p,c) \
517
+ if(p && stdin_is_interactive) setLexemeOpen(p, 0, c)
518
+# define CONTINUE_PAREN_INCR(p,n) \
519
+ if(p && stdin_is_interactive) (trackParenLevel(p,n))
520
+# define CONTINUE_PROMPT_PSTATE (&dynPrompt)
521
+typedef struct DynaPrompt *t_DynaPromptRef;
522
+# define SCAN_TRACKER_REFTYPE t_DynaPromptRef
523
+
524
+static struct DynaPrompt {
525
+ char dynamicPrompt[PROMPT_LEN_MAX];
526
+ char acAwait[2];
527
+ int inParenLevel;
528
+ char *zScannerAwaits;
529
+} dynPrompt = { {0}, {0}, 0, 0 };
530
+
531
+/* Record parenthesis nesting level change, or force level to 0. */
532
+static void trackParenLevel(struct DynaPrompt *p, int ni){
533
+ p->inParenLevel += ni;
534
+ if( ni==0 ) p->inParenLevel = 0;
535
+ p->zScannerAwaits = 0;
536
+}
537
+
538
+/* Record that a lexeme is opened, or closed with args==0. */
539
+static void setLexemeOpen(struct DynaPrompt *p, char *s, char c){
540
+ if( s!=0 || c==0 ){
541
+ p->zScannerAwaits = s;
542
+ p->acAwait[0] = 0;
543
+ }else{
544
+ p->acAwait[0] = c;
545
+ p->zScannerAwaits = p->acAwait;
546
+ }
547
+}
548
+
549
+/* Upon demand, derive the continuation prompt to display. */
550
+static char *dynamicContinuePrompt(void){
551
+ if( continuePrompt[0]==0
552
+ || (dynPrompt.zScannerAwaits==0 && dynPrompt.inParenLevel == 0) ){
553
+ return continuePrompt;
554
+ }else{
555
+ if( dynPrompt.zScannerAwaits ){
556
+ size_t ncp = strlen(continuePrompt), ndp = strlen(dynPrompt.zScannerAwaits);
557
+ if( ndp > ncp-3 ) return continuePrompt;
558
+ strcpy(dynPrompt.dynamicPrompt, dynPrompt.zScannerAwaits);
559
+ while( ndp<3 ) dynPrompt.dynamicPrompt[ndp++] = ' ';
560
+ strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
561
+ PROMPT_LEN_MAX-4);
562
+ }else{
563
+ if( dynPrompt.inParenLevel>9 ){
564
+ strncpy(dynPrompt.dynamicPrompt, "(..", 4);
565
+ }else if( dynPrompt.inParenLevel<0 ){
566
+ strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
567
+ }else{
568
+ strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
569
+ dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
570
+ }
571
+ strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3, PROMPT_LEN_MAX-4);
572
+ }
573
+ }
574
+ return dynPrompt.dynamicPrompt;
575
+}
576
+#endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
490577
491578
/*
492579
** Render output like fprintf(). Except, if the output is going to the
493580
** console and if this is running on a Windows machine, translate the
494581
** output from UTF-8 into MBCS.
@@ -745,11 +832,11 @@
745832
char *zPrompt;
746833
char *zResult;
747834
if( in!=0 ){
748835
zResult = local_getline(zPrior, in);
749836
}else{
750
- zPrompt = isContinuation ? continuePrompt : mainPrompt;
837
+ zPrompt = isContinuation ? CONTINUATION_PROMPT : mainPrompt;
751838
#if SHELL_USE_LOCAL_GETLINE
752839
printf("%s", zPrompt);
753840
fflush(stdout);
754841
zResult = local_getline(zPrior, stdin);
755842
#else
@@ -16484,11 +16571,11 @@
1648416571
}
1648516572
1648616573
/*
1648716574
** Display and reset the EXPLAIN QUERY PLAN data
1648816575
*/
16489
-static void eqp_render(ShellState *p){
16576
+static void eqp_render(ShellState *p, i64 nCycle){
1649016577
EQPGraphRow *pRow = p->sGraph.pRow;
1649116578
if( pRow ){
1649216579
if( pRow->zText[0]=='-' ){
1649316580
if( pRow->pNext==0 ){
1649416581
eqp_reset(p);
@@ -16495,10 +16582,12 @@
1649516582
return;
1649616583
}
1649716584
utf8_printf(p->out, "%s\n", pRow->zText+3);
1649816585
p->sGraph.pRow = pRow->pNext;
1649916586
sqlite3_free(pRow);
16587
+ }else if( nCycle>0 ){
16588
+ utf8_printf(p->out, "QUERY PLAN (cycles=%lld [100%%])\n", nCycle);
1650016589
}else{
1650116590
utf8_printf(p->out, "QUERY PLAN\n");
1650216591
}
1650316592
p->sGraph.zPrefix[0] = 0;
1650416593
eqp_render_level(p, 0);
@@ -17372,10 +17461,39 @@
1737217461
/* Do not remove this machine readable comment: extra-stats-output-here */
1737317462
1737417463
return 0;
1737517464
}
1737617465
17466
+
17467
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
17468
+static int scanStatsHeight(sqlite3_stmt *p, int iEntry){
17469
+ int iPid = 0;
17470
+ int ret = 1;
17471
+ sqlite3_stmt_scanstatus_v2(p, iEntry,
17472
+ SQLITE_SCANSTAT_SELECTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iPid
17473
+ );
17474
+ while( iPid!=0 ){
17475
+ int ii;
17476
+ for(ii=0; 1; ii++){
17477
+ int iId;
17478
+ int res;
17479
+ res = sqlite3_stmt_scanstatus_v2(p, ii,
17480
+ SQLITE_SCANSTAT_SELECTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iId
17481
+ );
17482
+ if( res ) break;
17483
+ if( iId==iPid ){
17484
+ sqlite3_stmt_scanstatus_v2(p, ii,
17485
+ SQLITE_SCANSTAT_PARENTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iPid
17486
+ );
17487
+ }
17488
+ }
17489
+ ret++;
17490
+ }
17491
+ return ret;
17492
+}
17493
+#endif
17494
+
1737717495
/*
1737817496
** Display scan stats.
1737917497
*/
1738017498
static void display_scanstats(
1738117499
sqlite3 *db, /* Database to query */
@@ -17383,44 +17501,81 @@
1738317501
){
1738417502
#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
1738517503
UNUSED_PARAMETER(db);
1738617504
UNUSED_PARAMETER(pArg);
1738717505
#else
17388
- int i, k, n, mx;
17389
- raw_printf(pArg->out, "-------- scanstats --------\n");
17390
- mx = 0;
17391
- for(k=0; k<=mx; k++){
17392
- double rEstLoop = 1.0;
17393
- for(i=n=0; 1; i++){
17394
- sqlite3_stmt *p = pArg->pStmt;
17395
- sqlite3_int64 nLoop, nVisit;
17396
- double rEst;
17397
- int iSid;
17398
- const char *zExplain;
17399
- if( sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NLOOP, (void*)&nLoop) ){
17400
- break;
17401
- }
17402
- sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_SELECTID, (void*)&iSid);
17403
- if( iSid>mx ) mx = iSid;
17404
- if( iSid!=k ) continue;
17405
- if( n==0 ){
17406
- rEstLoop = (double)nLoop;
17407
- if( k>0 ) raw_printf(pArg->out, "-------- subquery %d -------\n", k);
17408
- }
17409
- n++;
17410
- sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NVISIT, (void*)&nVisit);
17411
- sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EST, (void*)&rEst);
17412
- sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EXPLAIN, (void*)&zExplain);
17413
- utf8_printf(pArg->out, "Loop %2d: %s\n", n, zExplain);
17414
- rEstLoop *= rEst;
17415
- raw_printf(pArg->out,
17416
- " nLoop=%-8lld nRow=%-8lld estRow=%-8lld estRow/Loop=%-8g\n",
17417
- nLoop, nVisit, (sqlite3_int64)(rEstLoop+0.5), rEst
17506
+ static const int f = SQLITE_SCANSTAT_COMPLEX;
17507
+ sqlite3_stmt *p = pArg->pStmt;
17508
+ int ii = 0;
17509
+ i64 nTotal = 0;
17510
+ int nWidth = 0;
17511
+ eqp_reset(pArg);
17512
+
17513
+ for(ii=0; 1; ii++){
17514
+ const char *z = 0;
17515
+ int n = 0;
17516
+ if( sqlite3_stmt_scanstatus_v2(p,ii,SQLITE_SCANSTAT_EXPLAIN,f,(void*)&z) ){
17517
+ break;
17518
+ }
17519
+ n = strlen(z) + scanStatsHeight(p, ii)*3;
17520
+ if( n>nWidth ) nWidth = n;
17521
+ }
17522
+ nWidth += 4;
17523
+
17524
+ sqlite3_stmt_scanstatus_v2(p, -1, SQLITE_SCANSTAT_NCYCLE, f, (void*)&nTotal);
17525
+ for(ii=0; 1; ii++){
17526
+ i64 nLoop = 0;
17527
+ i64 nRow = 0;
17528
+ i64 nCycle = 0;
17529
+ int iId = 0;
17530
+ int iPid = 0;
17531
+ const char *z = 0;
17532
+ const char *zName = 0;
17533
+ char *zText = 0;
17534
+ double rEst = 0.0;
17535
+
17536
+ if( sqlite3_stmt_scanstatus_v2(p,ii,SQLITE_SCANSTAT_EXPLAIN,f,(void*)&z) ){
17537
+ break;
17538
+ }
17539
+ sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_EST,f,(void*)&rEst);
17540
+ sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_NLOOP,f,(void*)&nLoop);
17541
+ sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_NVISIT,f,(void*)&nRow);
17542
+ sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_NCYCLE,f,(void*)&nCycle);
17543
+ sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_SELECTID,f,(void*)&iId);
17544
+ sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_PARENTID,f,(void*)&iPid);
17545
+ sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_NAME,f,(void*)&zName);
17546
+
17547
+ zText = sqlite3_mprintf("%s", z);
17548
+ if( nCycle>=0 || nLoop>=0 || nRow>=0 ){
17549
+ char *z = 0;
17550
+ if( nCycle>=0 && nTotal>0 ){
17551
+ z = sqlite3_mprintf("%zcycles=%lld [%d%%]", z,
17552
+ nCycle, ((nCycle*100)+nTotal/2) / nTotal
17553
+ );
17554
+ }
17555
+ if( nLoop>=0 ){
17556
+ z = sqlite3_mprintf("%z%sloops=%lld", z, z ? " " : "", nLoop);
17557
+ }
17558
+ if( nRow>=0 ){
17559
+ z = sqlite3_mprintf("%z%srows=%lld", z, z ? " " : "", nRow);
17560
+ }
17561
+
17562
+ if( zName && pArg->scanstatsOn>1 ){
17563
+ double rpl = (double)nRow / (double)nLoop;
17564
+ z = sqlite3_mprintf("%z rpl=%.1f est=%.1f", z, rpl, rEst);
17565
+ }
17566
+
17567
+ zText = sqlite3_mprintf(
17568
+ "% *z (%z)", -1*(nWidth-scanStatsHeight(p, ii)*3), zText, z
1741817569
);
1741917570
}
17571
+
17572
+ eqp_append(pArg, iId, iPid, zText);
17573
+ sqlite3_free(zText);
1742017574
}
17421
- raw_printf(pArg->out, "---------------------------\n");
17575
+
17576
+ eqp_render(pArg, nTotal);
1742217577
#endif
1742317578
}
1742417579
1742517580
/*
1742617581
** Parameter azArray points to a zero-terminated array of strings. zStr
@@ -18340,14 +18495,14 @@
1834018495
while( sqlite3_step(pExplain)==SQLITE_ROW ){
1834118496
const char *zEQPLine = (const char*)sqlite3_column_text(pExplain,3);
1834218497
int iEqpId = sqlite3_column_int(pExplain, 0);
1834318498
int iParentId = sqlite3_column_int(pExplain, 1);
1834418499
if( zEQPLine==0 ) zEQPLine = "";
18345
- if( zEQPLine[0]=='-' ) eqp_render(pArg);
18500
+ if( zEQPLine[0]=='-' ) eqp_render(pArg, 0);
1834618501
eqp_append(pArg, iEqpId, iParentId, zEQPLine);
1834718502
}
18348
- eqp_render(pArg);
18503
+ eqp_render(pArg, 0);
1834918504
}
1835018505
sqlite3_finalize(pExplain);
1835118506
sqlite3_free(zEQP);
1835218507
if( pArg->autoEQP>=AUTOEQP_full ){
1835318508
/* Also do an EXPLAIN for ".eqp full" mode */
@@ -18392,11 +18547,11 @@
1839218547
}
1839318548
1839418549
bind_prepared_stmt(pArg, pStmt);
1839518550
exec_prepared_stmt(pArg, pStmt);
1839618551
explain_data_delete(pArg);
18397
- eqp_render(pArg);
18552
+ eqp_render(pArg, 0);
1839818553
1839918554
/* print usage stats if stats on */
1840018555
if( pArg && pArg->statsOn ){
1840118556
display_stats(db, pArg, 0);
1840218557
}
@@ -18932,11 +19087,11 @@
1893219087
#endif
1893319088
#ifndef SQLITE_SHELL_FIDDLE
1893419089
".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
1893519090
".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
1893619091
#endif
18937
- ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off",
19092
+ ".scanstats on|off|est Turn sqlite3_stmt_scanstatus() metrics on or off",
1893819093
".schema ?PATTERN? Show the CREATE statements matching PATTERN",
1893919094
" Options:",
1894019095
" --indent Try to pretty-print the schema",
1894119096
" --nosys Omit objects whose names start with \"sqlite_\"",
1894219097
".selftest ?OPTIONS? Run tests defined in the SELFTEST table",
@@ -23961,16 +24116,20 @@
2396124116
}else
2396224117
#endif /* !defined(SQLITE_SHELL_FIDDLE) */
2396324118
2396424119
if( c=='s' && cli_strncmp(azArg[0], "scanstats", n)==0 ){
2396524120
if( nArg==2 ){
23966
- p->scanstatsOn = (u8)booleanValue(azArg[1]);
24121
+ if( cli_strcmp(azArg[1], "est")==0 ){
24122
+ p->scanstatsOn = 2;
24123
+ }else{
24124
+ p->scanstatsOn = (u8)booleanValue(azArg[1]);
24125
+ }
2396724126
#ifndef SQLITE_ENABLE_STMT_SCANSTATUS
2396824127
raw_printf(stderr, "Warning: .scanstats not available in this build.\n");
2396924128
#endif
2397024129
}else{
23971
- raw_printf(stderr, "Usage: .scanstats on|off\n");
24130
+ raw_printf(stderr, "Usage: .scanstats on|off|est\n");
2397224131
rc = 1;
2397324132
}
2397424133
}else
2397524134
2397624135
if( c=='s' && cli_strncmp(azArg[0], "schema", n)==0 ){
@@ -24516,16 +24675,16 @@
2451624675
bSeparate = 1;
2451724676
if( sqlite3_strlike("sqlite\\_%", zLike, '\\')==0 ) bSchema = 1;
2451824677
}
2451924678
}
2452024679
if( bSchema ){
24521
- zSql = "SELECT lower(name) FROM sqlite_schema"
24680
+ zSql = "SELECT lower(name) as tname FROM sqlite_schema"
2452224681
" WHERE type='table' AND coalesce(rootpage,0)>1"
2452324682
" UNION ALL SELECT 'sqlite_schema'"
2452424683
" ORDER BY 1 collate nocase";
2452524684
}else{
24526
- zSql = "SELECT lower(name) FROM sqlite_schema"
24685
+ zSql = "SELECT lower(name) as tname FROM sqlite_schema"
2452724686
" WHERE type='table' AND coalesce(rootpage,0)>1"
2452824687
" AND name NOT LIKE 'sqlite_%'"
2452924688
" ORDER BY 1 collate nocase";
2453024689
}
2453124690
sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
@@ -24582,10 +24741,62 @@
2458224741
if( bDebug ){
2458324742
utf8_printf(p->out, "%s\n", zSql);
2458424743
}else{
2458524744
shell_exec(p, zSql, 0);
2458624745
}
24746
+#if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && !defined(SQLITE_OMIT_VIRTUALTABLE)
24747
+ {
24748
+ int lrc;
24749
+ char *zRevText = /* Query for reversible to-blob-to-text check */
24750
+ "SELECT lower(name) as tname FROM sqlite_schema\n"
24751
+ "WHERE type='table' AND coalesce(rootpage,0)>1\n"
24752
+ "AND name NOT LIKE 'sqlite_%%'%s\n"
24753
+ "ORDER BY 1 collate nocase";
24754
+ zRevText = sqlite3_mprintf(zRevText, zLike? " AND name LIKE $tspec" : "");
24755
+ zRevText = sqlite3_mprintf(
24756
+ /* lower-case query is first run, producing upper-case query. */
24757
+ "with tabcols as materialized(\n"
24758
+ "select tname, cname\n"
24759
+ "from ("
24760
+ " select ss.tname as tname, ti.name as cname\n"
24761
+ " from (%z) ss\n inner join pragma_table_info(tname) ti))\n"
24762
+ "select 'SELECT total(bad_text_count) AS bad_text_count\n"
24763
+ "FROM ('||group_concat(query, ' UNION ALL ')||')' as btc_query\n"
24764
+ " from (select 'SELECT COUNT(*) AS bad_text_count\n"
24765
+ "FROM '||tname||' WHERE '\n"
24766
+ "||group_concat('CAST(CAST('||cname||' AS BLOB) AS TEXT)<>'||cname\n"
24767
+ "|| ' AND typeof('||cname||')=''text'' ',\n"
24768
+ "' OR ') as query, tname from tabcols group by tname)"
24769
+ , zRevText);
24770
+ shell_check_oom(zRevText);
24771
+ if( bDebug ) utf8_printf(p->out, "%s\n", zRevText);
24772
+ lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0);
24773
+ assert(lrc==SQLITE_OK);
24774
+ if( zLike ) sqlite3_bind_text(pStmt,1,zLike,-1,SQLITE_STATIC);
24775
+ lrc = SQLITE_ROW==sqlite3_step(pStmt);
24776
+ if( lrc ){
24777
+ const char *zGenQuery = (char*)sqlite3_column_text(pStmt,0);
24778
+ sqlite3_stmt *pCheckStmt;
24779
+ lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0);
24780
+ if( bDebug ) utf8_printf(p->out, "%s\n", zGenQuery);
24781
+ if( SQLITE_OK==lrc ){
24782
+ if( SQLITE_ROW==sqlite3_step(pCheckStmt) ){
24783
+ double countIrreversible = sqlite3_column_double(pCheckStmt, 0);
24784
+ if( countIrreversible>0 ){
24785
+ int sz = (int)(countIrreversible + 0.5);
24786
+ utf8_printf(stderr,
24787
+ "Digest includes %d invalidly encoded text field%s.\n",
24788
+ sz, (sz>1)? "s": "");
24789
+ }
24790
+ }
24791
+ sqlite3_finalize(pCheckStmt);
24792
+ }
24793
+ sqlite3_finalize(pStmt);
24794
+ }
24795
+ sqlite3_free(zRevText);
24796
+ }
24797
+#endif /* !defined(*_OMIT_SCHEMA_PRAGMAS) && !defined(*_OMIT_VIRTUALTABLE) */
2458724798
sqlite3_free(zSql);
2458824799
}else
2458924800
2459024801
#if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
2459124802
if( c=='s'
@@ -25309,11 +25520,12 @@
2530925520
/*
2531025521
** Scan line for classification to guide shell's handling.
2531125522
** The scan is resumable for subsequent lines when prior
2531225523
** return values are passed as the 2nd argument.
2531325524
*/
25314
-static QuickScanState quickscan(char *zLine, QuickScanState qss){
25525
+static QuickScanState quickscan(char *zLine, QuickScanState qss,
25526
+ SCAN_TRACKER_REFTYPE pst){
2531525527
char cin;
2531625528
char cWait = (char)qss; /* intentional narrowing loss */
2531725529
if( cWait==0 ){
2531825530
PlainScan:
2531925531
assert( cWait==0 );
@@ -25333,10 +25545,11 @@
2533325545
continue;
2533425546
case '/':
2533525547
if( *zLine=='*' ){
2533625548
++zLine;
2533725549
cWait = '*';
25550
+ CONTINUE_PROMPT_AWAITS(pst, "/*");
2533825551
qss = QSS_SETV(qss, cWait);
2533925552
goto TermScan;
2534025553
}
2534125554
break;
2534225555
case '[':
@@ -25343,11 +25556,18 @@
2534325556
cin = ']';
2534425557
/* fall thru */
2534525558
case '`': case '\'': case '"':
2534625559
cWait = cin;
2534725560
qss = QSS_HasDark | cWait;
25561
+ CONTINUE_PROMPT_AWAITC(pst, cin);
2534825562
goto TermScan;
25563
+ case '(':
25564
+ CONTINUE_PAREN_INCR(pst, 1);
25565
+ break;
25566
+ case ')':
25567
+ CONTINUE_PAREN_INCR(pst, -1);
25568
+ break;
2534925569
default:
2535025570
break;
2535125571
}
2535225572
qss = (qss & ~QSS_EndingSemi) | QSS_HasDark;
2535325573
}
@@ -25359,20 +25579,23 @@
2535925579
case '*':
2536025580
if( *zLine != '/' )
2536125581
continue;
2536225582
++zLine;
2536325583
cWait = 0;
25584
+ CONTINUE_PROMPT_AWAITC(pst, 0);
2536425585
qss = QSS_SETV(qss, 0);
2536525586
goto PlainScan;
2536625587
case '`': case '\'': case '"':
2536725588
if(*zLine==cWait){
25589
+ /* Swallow doubled end-delimiter.*/
2536825590
++zLine;
2536925591
continue;
2537025592
}
2537125593
/* fall thru */
2537225594
case ']':
2537325595
cWait = 0;
25596
+ CONTINUE_PROMPT_AWAITC(pst, 0);
2537425597
qss = QSS_SETV(qss, 0);
2537525598
goto PlainScan;
2537625599
default: assert(0);
2537725600
}
2537825601
}
@@ -25392,11 +25615,11 @@
2539225615
zLine += 1; /* Oracle */
2539325616
else if ( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o' )
2539425617
zLine += 2; /* SQL Server */
2539525618
else
2539625619
return 0;
25397
- return quickscan(zLine, QSS_Start)==QSS_Start;
25620
+ return quickscan(zLine, QSS_Start, 0)==QSS_Start;
2539825621
}
2539925622
2540025623
/*
2540125624
** The CLI needs a working sqlite3_complete() to work properly. So error
2540225625
** out of the build if compiling with SQLITE_OMIT_COMPLETE.
@@ -25532,10 +25755,11 @@
2553225755
" Check recursion.\n", MAX_INPUT_NESTING, p->lineno);
2553325756
return 1;
2553425757
}
2553525758
++p->inputNesting;
2553625759
p->lineno = 0;
25760
+ CONTINUE_PROMPT_RESET;
2553725761
while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
2553825762
fflush(p->out);
2553925763
zLine = one_input_line(p->in, zLine, nSql>0);
2554025764
if( zLine==0 ){
2554125765
/* End of input */
@@ -25550,18 +25774,19 @@
2555025774
if( QSS_INPLAIN(qss)
2555125775
&& line_is_command_terminator(zLine)
2555225776
&& line_is_complete(zSql, nSql) ){
2555325777
memcpy(zLine,";",2);
2555425778
}
25555
- qss = quickscan(zLine, qss);
25779
+ qss = quickscan(zLine, qss, CONTINUE_PROMPT_PSTATE);
2555625780
if( QSS_PLAINWHITE(qss) && nSql==0 ){
2555725781
/* Just swallow single-line whitespace */
2555825782
echo_group_input(p, zLine);
2555925783
qss = QSS_Start;
2556025784
continue;
2556125785
}
2556225786
if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){
25787
+ CONTINUE_PROMPT_RESET;
2556325788
echo_group_input(p, zLine);
2556425789
if( zLine[0]=='.' ){
2556525790
rc = do_meta_command(zLine, p);
2556625791
if( rc==2 ){ /* exit requested */
2556725792
break;
@@ -25593,10 +25818,11 @@
2559325818
nSql += nLine;
2559425819
}
2559525820
if( nSql && QSS_SEMITERM(qss) && sqlite3_complete(zSql) ){
2559625821
echo_group_input(p, zSql);
2559725822
errCnt += runOneSqlLine(p, zSql, p->in, startline);
25823
+ CONTINUE_PROMPT_RESET;
2559825824
nSql = 0;
2559925825
if( p->outCount ){
2560025826
output_reset(p);
2560125827
p->outCount = 0;
2560225828
}else{
@@ -25612,10 +25838,11 @@
2561225838
}
2561325839
if( nSql ){
2561425840
/* This may be incomplete. Let the SQL parser deal with that. */
2561525841
echo_group_input(p, zSql);
2561625842
errCnt += runOneSqlLine(p, zSql, p->in, startline);
25843
+ CONTINUE_PROMPT_RESET;
2561725844
}
2561825845
free(zSql);
2561925846
free(zLine);
2562025847
--p->inputNesting;
2562125848
return errCnt>0;
2562225849
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -483,12 +483,99 @@
483
484 /*
485 ** Prompt strings. Initialized in main. Settable with
486 ** .prompt main continue
487 */
488 static char mainPrompt[20]; /* First line prompt. default: "sqlite> "*/
489 static char continuePrompt[20]; /* Continuation prompt. default: " ...> " */
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
490
491 /*
492 ** Render output like fprintf(). Except, if the output is going to the
493 ** console and if this is running on a Windows machine, translate the
494 ** output from UTF-8 into MBCS.
@@ -745,11 +832,11 @@
745 char *zPrompt;
746 char *zResult;
747 if( in!=0 ){
748 zResult = local_getline(zPrior, in);
749 }else{
750 zPrompt = isContinuation ? continuePrompt : mainPrompt;
751 #if SHELL_USE_LOCAL_GETLINE
752 printf("%s", zPrompt);
753 fflush(stdout);
754 zResult = local_getline(zPrior, stdin);
755 #else
@@ -16484,11 +16571,11 @@
16484 }
16485
16486 /*
16487 ** Display and reset the EXPLAIN QUERY PLAN data
16488 */
16489 static void eqp_render(ShellState *p){
16490 EQPGraphRow *pRow = p->sGraph.pRow;
16491 if( pRow ){
16492 if( pRow->zText[0]=='-' ){
16493 if( pRow->pNext==0 ){
16494 eqp_reset(p);
@@ -16495,10 +16582,12 @@
16495 return;
16496 }
16497 utf8_printf(p->out, "%s\n", pRow->zText+3);
16498 p->sGraph.pRow = pRow->pNext;
16499 sqlite3_free(pRow);
 
 
16500 }else{
16501 utf8_printf(p->out, "QUERY PLAN\n");
16502 }
16503 p->sGraph.zPrefix[0] = 0;
16504 eqp_render_level(p, 0);
@@ -17372,10 +17461,39 @@
17372 /* Do not remove this machine readable comment: extra-stats-output-here */
17373
17374 return 0;
17375 }
17376
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17377 /*
17378 ** Display scan stats.
17379 */
17380 static void display_scanstats(
17381 sqlite3 *db, /* Database to query */
@@ -17383,44 +17501,81 @@
17383 ){
17384 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
17385 UNUSED_PARAMETER(db);
17386 UNUSED_PARAMETER(pArg);
17387 #else
17388 int i, k, n, mx;
17389 raw_printf(pArg->out, "-------- scanstats --------\n");
17390 mx = 0;
17391 for(k=0; k<=mx; k++){
17392 double rEstLoop = 1.0;
17393 for(i=n=0; 1; i++){
17394 sqlite3_stmt *p = pArg->pStmt;
17395 sqlite3_int64 nLoop, nVisit;
17396 double rEst;
17397 int iSid;
17398 const char *zExplain;
17399 if( sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NLOOP, (void*)&nLoop) ){
17400 break;
17401 }
17402 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_SELECTID, (void*)&iSid);
17403 if( iSid>mx ) mx = iSid;
17404 if( iSid!=k ) continue;
17405 if( n==0 ){
17406 rEstLoop = (double)nLoop;
17407 if( k>0 ) raw_printf(pArg->out, "-------- subquery %d -------\n", k);
17408 }
17409 n++;
17410 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_NVISIT, (void*)&nVisit);
17411 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EST, (void*)&rEst);
17412 sqlite3_stmt_scanstatus(p, i, SQLITE_SCANSTAT_EXPLAIN, (void*)&zExplain);
17413 utf8_printf(pArg->out, "Loop %2d: %s\n", n, zExplain);
17414 rEstLoop *= rEst;
17415 raw_printf(pArg->out,
17416 " nLoop=%-8lld nRow=%-8lld estRow=%-8lld estRow/Loop=%-8g\n",
17417 nLoop, nVisit, (sqlite3_int64)(rEstLoop+0.5), rEst
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17418 );
17419 }
 
 
 
17420 }
17421 raw_printf(pArg->out, "---------------------------\n");
 
17422 #endif
17423 }
17424
17425 /*
17426 ** Parameter azArray points to a zero-terminated array of strings. zStr
@@ -18340,14 +18495,14 @@
18340 while( sqlite3_step(pExplain)==SQLITE_ROW ){
18341 const char *zEQPLine = (const char*)sqlite3_column_text(pExplain,3);
18342 int iEqpId = sqlite3_column_int(pExplain, 0);
18343 int iParentId = sqlite3_column_int(pExplain, 1);
18344 if( zEQPLine==0 ) zEQPLine = "";
18345 if( zEQPLine[0]=='-' ) eqp_render(pArg);
18346 eqp_append(pArg, iEqpId, iParentId, zEQPLine);
18347 }
18348 eqp_render(pArg);
18349 }
18350 sqlite3_finalize(pExplain);
18351 sqlite3_free(zEQP);
18352 if( pArg->autoEQP>=AUTOEQP_full ){
18353 /* Also do an EXPLAIN for ".eqp full" mode */
@@ -18392,11 +18547,11 @@
18392 }
18393
18394 bind_prepared_stmt(pArg, pStmt);
18395 exec_prepared_stmt(pArg, pStmt);
18396 explain_data_delete(pArg);
18397 eqp_render(pArg);
18398
18399 /* print usage stats if stats on */
18400 if( pArg && pArg->statsOn ){
18401 display_stats(db, pArg, 0);
18402 }
@@ -18932,11 +19087,11 @@
18932 #endif
18933 #ifndef SQLITE_SHELL_FIDDLE
18934 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
18935 ".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
18936 #endif
18937 ".scanstats on|off Turn sqlite3_stmt_scanstatus() metrics on or off",
18938 ".schema ?PATTERN? Show the CREATE statements matching PATTERN",
18939 " Options:",
18940 " --indent Try to pretty-print the schema",
18941 " --nosys Omit objects whose names start with \"sqlite_\"",
18942 ".selftest ?OPTIONS? Run tests defined in the SELFTEST table",
@@ -23961,16 +24116,20 @@
23961 }else
23962 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
23963
23964 if( c=='s' && cli_strncmp(azArg[0], "scanstats", n)==0 ){
23965 if( nArg==2 ){
23966 p->scanstatsOn = (u8)booleanValue(azArg[1]);
 
 
 
 
23967 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
23968 raw_printf(stderr, "Warning: .scanstats not available in this build.\n");
23969 #endif
23970 }else{
23971 raw_printf(stderr, "Usage: .scanstats on|off\n");
23972 rc = 1;
23973 }
23974 }else
23975
23976 if( c=='s' && cli_strncmp(azArg[0], "schema", n)==0 ){
@@ -24516,16 +24675,16 @@
24516 bSeparate = 1;
24517 if( sqlite3_strlike("sqlite\\_%", zLike, '\\')==0 ) bSchema = 1;
24518 }
24519 }
24520 if( bSchema ){
24521 zSql = "SELECT lower(name) FROM sqlite_schema"
24522 " WHERE type='table' AND coalesce(rootpage,0)>1"
24523 " UNION ALL SELECT 'sqlite_schema'"
24524 " ORDER BY 1 collate nocase";
24525 }else{
24526 zSql = "SELECT lower(name) FROM sqlite_schema"
24527 " WHERE type='table' AND coalesce(rootpage,0)>1"
24528 " AND name NOT LIKE 'sqlite_%'"
24529 " ORDER BY 1 collate nocase";
24530 }
24531 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
@@ -24582,10 +24741,62 @@
24582 if( bDebug ){
24583 utf8_printf(p->out, "%s\n", zSql);
24584 }else{
24585 shell_exec(p, zSql, 0);
24586 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24587 sqlite3_free(zSql);
24588 }else
24589
24590 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
24591 if( c=='s'
@@ -25309,11 +25520,12 @@
25309 /*
25310 ** Scan line for classification to guide shell's handling.
25311 ** The scan is resumable for subsequent lines when prior
25312 ** return values are passed as the 2nd argument.
25313 */
25314 static QuickScanState quickscan(char *zLine, QuickScanState qss){
 
25315 char cin;
25316 char cWait = (char)qss; /* intentional narrowing loss */
25317 if( cWait==0 ){
25318 PlainScan:
25319 assert( cWait==0 );
@@ -25333,10 +25545,11 @@
25333 continue;
25334 case '/':
25335 if( *zLine=='*' ){
25336 ++zLine;
25337 cWait = '*';
 
25338 qss = QSS_SETV(qss, cWait);
25339 goto TermScan;
25340 }
25341 break;
25342 case '[':
@@ -25343,11 +25556,18 @@
25343 cin = ']';
25344 /* fall thru */
25345 case '`': case '\'': case '"':
25346 cWait = cin;
25347 qss = QSS_HasDark | cWait;
 
25348 goto TermScan;
 
 
 
 
 
 
25349 default:
25350 break;
25351 }
25352 qss = (qss & ~QSS_EndingSemi) | QSS_HasDark;
25353 }
@@ -25359,20 +25579,23 @@
25359 case '*':
25360 if( *zLine != '/' )
25361 continue;
25362 ++zLine;
25363 cWait = 0;
 
25364 qss = QSS_SETV(qss, 0);
25365 goto PlainScan;
25366 case '`': case '\'': case '"':
25367 if(*zLine==cWait){
 
25368 ++zLine;
25369 continue;
25370 }
25371 /* fall thru */
25372 case ']':
25373 cWait = 0;
 
25374 qss = QSS_SETV(qss, 0);
25375 goto PlainScan;
25376 default: assert(0);
25377 }
25378 }
@@ -25392,11 +25615,11 @@
25392 zLine += 1; /* Oracle */
25393 else if ( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o' )
25394 zLine += 2; /* SQL Server */
25395 else
25396 return 0;
25397 return quickscan(zLine, QSS_Start)==QSS_Start;
25398 }
25399
25400 /*
25401 ** The CLI needs a working sqlite3_complete() to work properly. So error
25402 ** out of the build if compiling with SQLITE_OMIT_COMPLETE.
@@ -25532,10 +25755,11 @@
25532 " Check recursion.\n", MAX_INPUT_NESTING, p->lineno);
25533 return 1;
25534 }
25535 ++p->inputNesting;
25536 p->lineno = 0;
 
25537 while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
25538 fflush(p->out);
25539 zLine = one_input_line(p->in, zLine, nSql>0);
25540 if( zLine==0 ){
25541 /* End of input */
@@ -25550,18 +25774,19 @@
25550 if( QSS_INPLAIN(qss)
25551 && line_is_command_terminator(zLine)
25552 && line_is_complete(zSql, nSql) ){
25553 memcpy(zLine,";",2);
25554 }
25555 qss = quickscan(zLine, qss);
25556 if( QSS_PLAINWHITE(qss) && nSql==0 ){
25557 /* Just swallow single-line whitespace */
25558 echo_group_input(p, zLine);
25559 qss = QSS_Start;
25560 continue;
25561 }
25562 if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){
 
25563 echo_group_input(p, zLine);
25564 if( zLine[0]=='.' ){
25565 rc = do_meta_command(zLine, p);
25566 if( rc==2 ){ /* exit requested */
25567 break;
@@ -25593,10 +25818,11 @@
25593 nSql += nLine;
25594 }
25595 if( nSql && QSS_SEMITERM(qss) && sqlite3_complete(zSql) ){
25596 echo_group_input(p, zSql);
25597 errCnt += runOneSqlLine(p, zSql, p->in, startline);
 
25598 nSql = 0;
25599 if( p->outCount ){
25600 output_reset(p);
25601 p->outCount = 0;
25602 }else{
@@ -25612,10 +25838,11 @@
25612 }
25613 if( nSql ){
25614 /* This may be incomplete. Let the SQL parser deal with that. */
25615 echo_group_input(p, zSql);
25616 errCnt += runOneSqlLine(p, zSql, p->in, startline);
 
25617 }
25618 free(zSql);
25619 free(zLine);
25620 --p->inputNesting;
25621 return errCnt>0;
25622
--- extsrc/shell.c
+++ extsrc/shell.c
@@ -483,12 +483,99 @@
483
484 /*
485 ** Prompt strings. Initialized in main. Settable with
486 ** .prompt main continue
487 */
488 #define PROMPT_LEN_MAX 20
489 /* First line prompt. default: "sqlite> " */
490 static char mainPrompt[PROMPT_LEN_MAX];
491 /* Continuation prompt. default: " ...> " */
492 static char continuePrompt[PROMPT_LEN_MAX];
493
494 /*
495 ** Optionally disable dynamic continuation prompt.
496 ** Unless disabled, the continuation prompt shows open SQL lexemes if any,
497 ** or open parentheses level if non-zero, or continuation prompt as set.
498 ** This facility interacts with the scanner and process_input() where the
499 ** below 5 macros are used.
500 */
501 #ifdef SQLITE_OMIT_DYNAPROMPT
502 # define CONTINUATION_PROMPT continuePrompt
503 # define CONTINUE_PROMPT_RESET
504 # define CONTINUE_PROMPT_AWAITS(p,s)
505 # define CONTINUE_PROMPT_AWAITC(p,c)
506 # define CONTINUE_PAREN_INCR(p,n)
507 # define CONTINUE_PROMPT_PSTATE 0
508 typedef void *t_NoDynaPrompt;
509 # define SCAN_TRACKER_REFTYPE t_NoDynaPrompt
510 #else
511 # define CONTINUATION_PROMPT dynamicContinuePrompt()
512 # define CONTINUE_PROMPT_RESET \
513 do {setLexemeOpen(&dynPrompt,0,0); trackParenLevel(&dynPrompt,0);} while(0)
514 # define CONTINUE_PROMPT_AWAITS(p,s) \
515 if(p && stdin_is_interactive) setLexemeOpen(p, s, 0)
516 # define CONTINUE_PROMPT_AWAITC(p,c) \
517 if(p && stdin_is_interactive) setLexemeOpen(p, 0, c)
518 # define CONTINUE_PAREN_INCR(p,n) \
519 if(p && stdin_is_interactive) (trackParenLevel(p,n))
520 # define CONTINUE_PROMPT_PSTATE (&dynPrompt)
521 typedef struct DynaPrompt *t_DynaPromptRef;
522 # define SCAN_TRACKER_REFTYPE t_DynaPromptRef
523
524 static struct DynaPrompt {
525 char dynamicPrompt[PROMPT_LEN_MAX];
526 char acAwait[2];
527 int inParenLevel;
528 char *zScannerAwaits;
529 } dynPrompt = { {0}, {0}, 0, 0 };
530
531 /* Record parenthesis nesting level change, or force level to 0. */
532 static void trackParenLevel(struct DynaPrompt *p, int ni){
533 p->inParenLevel += ni;
534 if( ni==0 ) p->inParenLevel = 0;
535 p->zScannerAwaits = 0;
536 }
537
538 /* Record that a lexeme is opened, or closed with args==0. */
539 static void setLexemeOpen(struct DynaPrompt *p, char *s, char c){
540 if( s!=0 || c==0 ){
541 p->zScannerAwaits = s;
542 p->acAwait[0] = 0;
543 }else{
544 p->acAwait[0] = c;
545 p->zScannerAwaits = p->acAwait;
546 }
547 }
548
549 /* Upon demand, derive the continuation prompt to display. */
550 static char *dynamicContinuePrompt(void){
551 if( continuePrompt[0]==0
552 || (dynPrompt.zScannerAwaits==0 && dynPrompt.inParenLevel == 0) ){
553 return continuePrompt;
554 }else{
555 if( dynPrompt.zScannerAwaits ){
556 size_t ncp = strlen(continuePrompt), ndp = strlen(dynPrompt.zScannerAwaits);
557 if( ndp > ncp-3 ) return continuePrompt;
558 strcpy(dynPrompt.dynamicPrompt, dynPrompt.zScannerAwaits);
559 while( ndp<3 ) dynPrompt.dynamicPrompt[ndp++] = ' ';
560 strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3,
561 PROMPT_LEN_MAX-4);
562 }else{
563 if( dynPrompt.inParenLevel>9 ){
564 strncpy(dynPrompt.dynamicPrompt, "(..", 4);
565 }else if( dynPrompt.inParenLevel<0 ){
566 strncpy(dynPrompt.dynamicPrompt, ")x!", 4);
567 }else{
568 strncpy(dynPrompt.dynamicPrompt, "(x.", 4);
569 dynPrompt.dynamicPrompt[2] = (char)('0'+dynPrompt.inParenLevel);
570 }
571 strncpy(dynPrompt.dynamicPrompt+3, continuePrompt+3, PROMPT_LEN_MAX-4);
572 }
573 }
574 return dynPrompt.dynamicPrompt;
575 }
576 #endif /* !defined(SQLITE_OMIT_DYNAPROMPT) */
577
578 /*
579 ** Render output like fprintf(). Except, if the output is going to the
580 ** console and if this is running on a Windows machine, translate the
581 ** output from UTF-8 into MBCS.
@@ -745,11 +832,11 @@
832 char *zPrompt;
833 char *zResult;
834 if( in!=0 ){
835 zResult = local_getline(zPrior, in);
836 }else{
837 zPrompt = isContinuation ? CONTINUATION_PROMPT : mainPrompt;
838 #if SHELL_USE_LOCAL_GETLINE
839 printf("%s", zPrompt);
840 fflush(stdout);
841 zResult = local_getline(zPrior, stdin);
842 #else
@@ -16484,11 +16571,11 @@
16571 }
16572
16573 /*
16574 ** Display and reset the EXPLAIN QUERY PLAN data
16575 */
16576 static void eqp_render(ShellState *p, i64 nCycle){
16577 EQPGraphRow *pRow = p->sGraph.pRow;
16578 if( pRow ){
16579 if( pRow->zText[0]=='-' ){
16580 if( pRow->pNext==0 ){
16581 eqp_reset(p);
@@ -16495,10 +16582,12 @@
16582 return;
16583 }
16584 utf8_printf(p->out, "%s\n", pRow->zText+3);
16585 p->sGraph.pRow = pRow->pNext;
16586 sqlite3_free(pRow);
16587 }else if( nCycle>0 ){
16588 utf8_printf(p->out, "QUERY PLAN (cycles=%lld [100%%])\n", nCycle);
16589 }else{
16590 utf8_printf(p->out, "QUERY PLAN\n");
16591 }
16592 p->sGraph.zPrefix[0] = 0;
16593 eqp_render_level(p, 0);
@@ -17372,10 +17461,39 @@
17461 /* Do not remove this machine readable comment: extra-stats-output-here */
17462
17463 return 0;
17464 }
17465
17466
17467 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
17468 static int scanStatsHeight(sqlite3_stmt *p, int iEntry){
17469 int iPid = 0;
17470 int ret = 1;
17471 sqlite3_stmt_scanstatus_v2(p, iEntry,
17472 SQLITE_SCANSTAT_SELECTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iPid
17473 );
17474 while( iPid!=0 ){
17475 int ii;
17476 for(ii=0; 1; ii++){
17477 int iId;
17478 int res;
17479 res = sqlite3_stmt_scanstatus_v2(p, ii,
17480 SQLITE_SCANSTAT_SELECTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iId
17481 );
17482 if( res ) break;
17483 if( iId==iPid ){
17484 sqlite3_stmt_scanstatus_v2(p, ii,
17485 SQLITE_SCANSTAT_PARENTID, SQLITE_SCANSTAT_COMPLEX, (void*)&iPid
17486 );
17487 }
17488 }
17489 ret++;
17490 }
17491 return ret;
17492 }
17493 #endif
17494
17495 /*
17496 ** Display scan stats.
17497 */
17498 static void display_scanstats(
17499 sqlite3 *db, /* Database to query */
@@ -17383,44 +17501,81 @@
17501 ){
17502 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
17503 UNUSED_PARAMETER(db);
17504 UNUSED_PARAMETER(pArg);
17505 #else
17506 static const int f = SQLITE_SCANSTAT_COMPLEX;
17507 sqlite3_stmt *p = pArg->pStmt;
17508 int ii = 0;
17509 i64 nTotal = 0;
17510 int nWidth = 0;
17511 eqp_reset(pArg);
17512
17513 for(ii=0; 1; ii++){
17514 const char *z = 0;
17515 int n = 0;
17516 if( sqlite3_stmt_scanstatus_v2(p,ii,SQLITE_SCANSTAT_EXPLAIN,f,(void*)&z) ){
17517 break;
17518 }
17519 n = strlen(z) + scanStatsHeight(p, ii)*3;
17520 if( n>nWidth ) nWidth = n;
17521 }
17522 nWidth += 4;
17523
17524 sqlite3_stmt_scanstatus_v2(p, -1, SQLITE_SCANSTAT_NCYCLE, f, (void*)&nTotal);
17525 for(ii=0; 1; ii++){
17526 i64 nLoop = 0;
17527 i64 nRow = 0;
17528 i64 nCycle = 0;
17529 int iId = 0;
17530 int iPid = 0;
17531 const char *z = 0;
17532 const char *zName = 0;
17533 char *zText = 0;
17534 double rEst = 0.0;
17535
17536 if( sqlite3_stmt_scanstatus_v2(p,ii,SQLITE_SCANSTAT_EXPLAIN,f,(void*)&z) ){
17537 break;
17538 }
17539 sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_EST,f,(void*)&rEst);
17540 sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_NLOOP,f,(void*)&nLoop);
17541 sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_NVISIT,f,(void*)&nRow);
17542 sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_NCYCLE,f,(void*)&nCycle);
17543 sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_SELECTID,f,(void*)&iId);
17544 sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_PARENTID,f,(void*)&iPid);
17545 sqlite3_stmt_scanstatus_v2(p, ii, SQLITE_SCANSTAT_NAME,f,(void*)&zName);
17546
17547 zText = sqlite3_mprintf("%s", z);
17548 if( nCycle>=0 || nLoop>=0 || nRow>=0 ){
17549 char *z = 0;
17550 if( nCycle>=0 && nTotal>0 ){
17551 z = sqlite3_mprintf("%zcycles=%lld [%d%%]", z,
17552 nCycle, ((nCycle*100)+nTotal/2) / nTotal
17553 );
17554 }
17555 if( nLoop>=0 ){
17556 z = sqlite3_mprintf("%z%sloops=%lld", z, z ? " " : "", nLoop);
17557 }
17558 if( nRow>=0 ){
17559 z = sqlite3_mprintf("%z%srows=%lld", z, z ? " " : "", nRow);
17560 }
17561
17562 if( zName && pArg->scanstatsOn>1 ){
17563 double rpl = (double)nRow / (double)nLoop;
17564 z = sqlite3_mprintf("%z rpl=%.1f est=%.1f", z, rpl, rEst);
17565 }
17566
17567 zText = sqlite3_mprintf(
17568 "% *z (%z)", -1*(nWidth-scanStatsHeight(p, ii)*3), zText, z
17569 );
17570 }
17571
17572 eqp_append(pArg, iId, iPid, zText);
17573 sqlite3_free(zText);
17574 }
17575
17576 eqp_render(pArg, nTotal);
17577 #endif
17578 }
17579
17580 /*
17581 ** Parameter azArray points to a zero-terminated array of strings. zStr
@@ -18340,14 +18495,14 @@
18495 while( sqlite3_step(pExplain)==SQLITE_ROW ){
18496 const char *zEQPLine = (const char*)sqlite3_column_text(pExplain,3);
18497 int iEqpId = sqlite3_column_int(pExplain, 0);
18498 int iParentId = sqlite3_column_int(pExplain, 1);
18499 if( zEQPLine==0 ) zEQPLine = "";
18500 if( zEQPLine[0]=='-' ) eqp_render(pArg, 0);
18501 eqp_append(pArg, iEqpId, iParentId, zEQPLine);
18502 }
18503 eqp_render(pArg, 0);
18504 }
18505 sqlite3_finalize(pExplain);
18506 sqlite3_free(zEQP);
18507 if( pArg->autoEQP>=AUTOEQP_full ){
18508 /* Also do an EXPLAIN for ".eqp full" mode */
@@ -18392,11 +18547,11 @@
18547 }
18548
18549 bind_prepared_stmt(pArg, pStmt);
18550 exec_prepared_stmt(pArg, pStmt);
18551 explain_data_delete(pArg);
18552 eqp_render(pArg, 0);
18553
18554 /* print usage stats if stats on */
18555 if( pArg && pArg->statsOn ){
18556 display_stats(db, pArg, 0);
18557 }
@@ -18932,11 +19087,11 @@
19087 #endif
19088 #ifndef SQLITE_SHELL_FIDDLE
19089 ".restore ?DB? FILE Restore content of DB (default \"main\") from FILE",
19090 ".save ?OPTIONS? FILE Write database to FILE (an alias for .backup ...)",
19091 #endif
19092 ".scanstats on|off|est Turn sqlite3_stmt_scanstatus() metrics on or off",
19093 ".schema ?PATTERN? Show the CREATE statements matching PATTERN",
19094 " Options:",
19095 " --indent Try to pretty-print the schema",
19096 " --nosys Omit objects whose names start with \"sqlite_\"",
19097 ".selftest ?OPTIONS? Run tests defined in the SELFTEST table",
@@ -23961,16 +24116,20 @@
24116 }else
24117 #endif /* !defined(SQLITE_SHELL_FIDDLE) */
24118
24119 if( c=='s' && cli_strncmp(azArg[0], "scanstats", n)==0 ){
24120 if( nArg==2 ){
24121 if( cli_strcmp(azArg[1], "est")==0 ){
24122 p->scanstatsOn = 2;
24123 }else{
24124 p->scanstatsOn = (u8)booleanValue(azArg[1]);
24125 }
24126 #ifndef SQLITE_ENABLE_STMT_SCANSTATUS
24127 raw_printf(stderr, "Warning: .scanstats not available in this build.\n");
24128 #endif
24129 }else{
24130 raw_printf(stderr, "Usage: .scanstats on|off|est\n");
24131 rc = 1;
24132 }
24133 }else
24134
24135 if( c=='s' && cli_strncmp(azArg[0], "schema", n)==0 ){
@@ -24516,16 +24675,16 @@
24675 bSeparate = 1;
24676 if( sqlite3_strlike("sqlite\\_%", zLike, '\\')==0 ) bSchema = 1;
24677 }
24678 }
24679 if( bSchema ){
24680 zSql = "SELECT lower(name) as tname FROM sqlite_schema"
24681 " WHERE type='table' AND coalesce(rootpage,0)>1"
24682 " UNION ALL SELECT 'sqlite_schema'"
24683 " ORDER BY 1 collate nocase";
24684 }else{
24685 zSql = "SELECT lower(name) as tname FROM sqlite_schema"
24686 " WHERE type='table' AND coalesce(rootpage,0)>1"
24687 " AND name NOT LIKE 'sqlite_%'"
24688 " ORDER BY 1 collate nocase";
24689 }
24690 sqlite3_prepare_v2(p->db, zSql, -1, &pStmt, 0);
@@ -24582,10 +24741,62 @@
24741 if( bDebug ){
24742 utf8_printf(p->out, "%s\n", zSql);
24743 }else{
24744 shell_exec(p, zSql, 0);
24745 }
24746 #if !defined(SQLITE_OMIT_SCHEMA_PRAGMAS) && !defined(SQLITE_OMIT_VIRTUALTABLE)
24747 {
24748 int lrc;
24749 char *zRevText = /* Query for reversible to-blob-to-text check */
24750 "SELECT lower(name) as tname FROM sqlite_schema\n"
24751 "WHERE type='table' AND coalesce(rootpage,0)>1\n"
24752 "AND name NOT LIKE 'sqlite_%%'%s\n"
24753 "ORDER BY 1 collate nocase";
24754 zRevText = sqlite3_mprintf(zRevText, zLike? " AND name LIKE $tspec" : "");
24755 zRevText = sqlite3_mprintf(
24756 /* lower-case query is first run, producing upper-case query. */
24757 "with tabcols as materialized(\n"
24758 "select tname, cname\n"
24759 "from ("
24760 " select ss.tname as tname, ti.name as cname\n"
24761 " from (%z) ss\n inner join pragma_table_info(tname) ti))\n"
24762 "select 'SELECT total(bad_text_count) AS bad_text_count\n"
24763 "FROM ('||group_concat(query, ' UNION ALL ')||')' as btc_query\n"
24764 " from (select 'SELECT COUNT(*) AS bad_text_count\n"
24765 "FROM '||tname||' WHERE '\n"
24766 "||group_concat('CAST(CAST('||cname||' AS BLOB) AS TEXT)<>'||cname\n"
24767 "|| ' AND typeof('||cname||')=''text'' ',\n"
24768 "' OR ') as query, tname from tabcols group by tname)"
24769 , zRevText);
24770 shell_check_oom(zRevText);
24771 if( bDebug ) utf8_printf(p->out, "%s\n", zRevText);
24772 lrc = sqlite3_prepare_v2(p->db, zRevText, -1, &pStmt, 0);
24773 assert(lrc==SQLITE_OK);
24774 if( zLike ) sqlite3_bind_text(pStmt,1,zLike,-1,SQLITE_STATIC);
24775 lrc = SQLITE_ROW==sqlite3_step(pStmt);
24776 if( lrc ){
24777 const char *zGenQuery = (char*)sqlite3_column_text(pStmt,0);
24778 sqlite3_stmt *pCheckStmt;
24779 lrc = sqlite3_prepare_v2(p->db, zGenQuery, -1, &pCheckStmt, 0);
24780 if( bDebug ) utf8_printf(p->out, "%s\n", zGenQuery);
24781 if( SQLITE_OK==lrc ){
24782 if( SQLITE_ROW==sqlite3_step(pCheckStmt) ){
24783 double countIrreversible = sqlite3_column_double(pCheckStmt, 0);
24784 if( countIrreversible>0 ){
24785 int sz = (int)(countIrreversible + 0.5);
24786 utf8_printf(stderr,
24787 "Digest includes %d invalidly encoded text field%s.\n",
24788 sz, (sz>1)? "s": "");
24789 }
24790 }
24791 sqlite3_finalize(pCheckStmt);
24792 }
24793 sqlite3_finalize(pStmt);
24794 }
24795 sqlite3_free(zRevText);
24796 }
24797 #endif /* !defined(*_OMIT_SCHEMA_PRAGMAS) && !defined(*_OMIT_VIRTUALTABLE) */
24798 sqlite3_free(zSql);
24799 }else
24800
24801 #if !defined(SQLITE_NOHAVE_SYSTEM) && !defined(SQLITE_SHELL_FIDDLE)
24802 if( c=='s'
@@ -25309,11 +25520,12 @@
25520 /*
25521 ** Scan line for classification to guide shell's handling.
25522 ** The scan is resumable for subsequent lines when prior
25523 ** return values are passed as the 2nd argument.
25524 */
25525 static QuickScanState quickscan(char *zLine, QuickScanState qss,
25526 SCAN_TRACKER_REFTYPE pst){
25527 char cin;
25528 char cWait = (char)qss; /* intentional narrowing loss */
25529 if( cWait==0 ){
25530 PlainScan:
25531 assert( cWait==0 );
@@ -25333,10 +25545,11 @@
25545 continue;
25546 case '/':
25547 if( *zLine=='*' ){
25548 ++zLine;
25549 cWait = '*';
25550 CONTINUE_PROMPT_AWAITS(pst, "/*");
25551 qss = QSS_SETV(qss, cWait);
25552 goto TermScan;
25553 }
25554 break;
25555 case '[':
@@ -25343,11 +25556,18 @@
25556 cin = ']';
25557 /* fall thru */
25558 case '`': case '\'': case '"':
25559 cWait = cin;
25560 qss = QSS_HasDark | cWait;
25561 CONTINUE_PROMPT_AWAITC(pst, cin);
25562 goto TermScan;
25563 case '(':
25564 CONTINUE_PAREN_INCR(pst, 1);
25565 break;
25566 case ')':
25567 CONTINUE_PAREN_INCR(pst, -1);
25568 break;
25569 default:
25570 break;
25571 }
25572 qss = (qss & ~QSS_EndingSemi) | QSS_HasDark;
25573 }
@@ -25359,20 +25579,23 @@
25579 case '*':
25580 if( *zLine != '/' )
25581 continue;
25582 ++zLine;
25583 cWait = 0;
25584 CONTINUE_PROMPT_AWAITC(pst, 0);
25585 qss = QSS_SETV(qss, 0);
25586 goto PlainScan;
25587 case '`': case '\'': case '"':
25588 if(*zLine==cWait){
25589 /* Swallow doubled end-delimiter.*/
25590 ++zLine;
25591 continue;
25592 }
25593 /* fall thru */
25594 case ']':
25595 cWait = 0;
25596 CONTINUE_PROMPT_AWAITC(pst, 0);
25597 qss = QSS_SETV(qss, 0);
25598 goto PlainScan;
25599 default: assert(0);
25600 }
25601 }
@@ -25392,11 +25615,11 @@
25615 zLine += 1; /* Oracle */
25616 else if ( ToLower(zLine[0])=='g' && ToLower(zLine[1])=='o' )
25617 zLine += 2; /* SQL Server */
25618 else
25619 return 0;
25620 return quickscan(zLine, QSS_Start, 0)==QSS_Start;
25621 }
25622
25623 /*
25624 ** The CLI needs a working sqlite3_complete() to work properly. So error
25625 ** out of the build if compiling with SQLITE_OMIT_COMPLETE.
@@ -25532,10 +25755,11 @@
25755 " Check recursion.\n", MAX_INPUT_NESTING, p->lineno);
25756 return 1;
25757 }
25758 ++p->inputNesting;
25759 p->lineno = 0;
25760 CONTINUE_PROMPT_RESET;
25761 while( errCnt==0 || !bail_on_error || (p->in==0 && stdin_is_interactive) ){
25762 fflush(p->out);
25763 zLine = one_input_line(p->in, zLine, nSql>0);
25764 if( zLine==0 ){
25765 /* End of input */
@@ -25550,18 +25774,19 @@
25774 if( QSS_INPLAIN(qss)
25775 && line_is_command_terminator(zLine)
25776 && line_is_complete(zSql, nSql) ){
25777 memcpy(zLine,";",2);
25778 }
25779 qss = quickscan(zLine, qss, CONTINUE_PROMPT_PSTATE);
25780 if( QSS_PLAINWHITE(qss) && nSql==0 ){
25781 /* Just swallow single-line whitespace */
25782 echo_group_input(p, zLine);
25783 qss = QSS_Start;
25784 continue;
25785 }
25786 if( zLine && (zLine[0]=='.' || zLine[0]=='#') && nSql==0 ){
25787 CONTINUE_PROMPT_RESET;
25788 echo_group_input(p, zLine);
25789 if( zLine[0]=='.' ){
25790 rc = do_meta_command(zLine, p);
25791 if( rc==2 ){ /* exit requested */
25792 break;
@@ -25593,10 +25818,11 @@
25818 nSql += nLine;
25819 }
25820 if( nSql && QSS_SEMITERM(qss) && sqlite3_complete(zSql) ){
25821 echo_group_input(p, zSql);
25822 errCnt += runOneSqlLine(p, zSql, p->in, startline);
25823 CONTINUE_PROMPT_RESET;
25824 nSql = 0;
25825 if( p->outCount ){
25826 output_reset(p);
25827 p->outCount = 0;
25828 }else{
@@ -25612,10 +25838,11 @@
25838 }
25839 if( nSql ){
25840 /* This may be incomplete. Let the SQL parser deal with that. */
25841 echo_group_input(p, zSql);
25842 errCnt += runOneSqlLine(p, zSql, p->in, startline);
25843 CONTINUE_PROMPT_RESET;
25844 }
25845 free(zSql);
25846 free(zLine);
25847 --p->inputNesting;
25848 return errCnt>0;
25849
+782 -280
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452452
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453453
** [sqlite_version()] and [sqlite_source_id()].
454454
*/
455455
#define SQLITE_VERSION "3.41.0"
456456
#define SQLITE_VERSION_NUMBER 3041000
457
-#define SQLITE_SOURCE_ID "2022-12-05 02:52:37 1b779afa3ed2f35a110e460fc6ed13cba744db85b9924149ab028b100d1e1e12"
457
+#define SQLITE_SOURCE_ID "2022-12-15 15:37:52 751e344f4cd2045caf97920cc9f4571caf0de1ba83b94ded902a03b36c10a389"
458458
459459
/*
460460
** CAPI3REF: Run-Time Library Version Numbers
461461
** KEYWORDS: sqlite3_version sqlite3_sourceid
462462
**
@@ -867,10 +867,11 @@
867867
#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
868868
#define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
869869
#define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))
870870
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
871871
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
872
+#define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8))
872873
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
873874
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
874875
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
875876
#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
876877
@@ -2488,11 +2489,11 @@
24882489
** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
24892490
** rounded down to the next smaller multiple of 8. ^(The lookaside memory
24902491
** configuration for a database connection can only be changed when that
24912492
** connection is not currently using lookaside memory, or in other words
24922493
** when the "current value" returned by
2493
-** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
2494
+** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero.
24942495
** Any attempt to change the lookaside memory configuration when lookaside
24952496
** memory is in use leaves the configuration unchanged and returns
24962497
** [SQLITE_BUSY].)^</dd>
24972498
**
24982499
** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
@@ -2638,12 +2639,16 @@
26382639
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
26392640
** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
26402641
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
26412642
** </ol>
26422643
** Because resetting a database is destructive and irreversible, the
2643
-** process requires the use of this obscure API and multiple steps to help
2644
-** ensure that it does not happen by accident.
2644
+** process requires the use of this obscure API and multiple steps to
2645
+** help ensure that it does not happen by accident. Because this
2646
+** feature must be capable of resetting corrupt databases, and
2647
+** shutting down virtual tables may require access to that corrupt
2648
+** storage, the library must abandon any installed virtual tables
2649
+** without calling their xDestroy() methods.
26452650
**
26462651
** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
26472652
** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
26482653
** "defensive" flag for a database connection. When the defensive
26492654
** flag is enabled, language features that allow ordinary SQL to
@@ -7318,19 +7323,10 @@
73187323
** ^This interface disables all automatic extensions previously
73197324
** registered using [sqlite3_auto_extension()].
73207325
*/
73217326
SQLITE_API void sqlite3_reset_auto_extension(void);
73227327
7323
-/*
7324
-** The interface to the virtual-table mechanism is currently considered
7325
-** to be experimental. The interface might change in incompatible ways.
7326
-** If this is a problem for you, do not use the interface at this time.
7327
-**
7328
-** When the virtual-table mechanism stabilizes, we will declare the
7329
-** interface fixed, support it indefinitely, and remove this comment.
7330
-*/
7331
-
73327328
/*
73337329
** Structures used by the virtual table interface
73347330
*/
73357331
typedef struct sqlite3_vtab sqlite3_vtab;
73367332
typedef struct sqlite3_index_info sqlite3_index_info;
@@ -7568,11 +7564,11 @@
75687564
**
75697565
** The collating sequence to be used for comparison can be found using
75707566
** the [sqlite3_vtab_collation()] interface. For most real-world virtual
75717567
** tables, the collating sequence of constraints does not matter (for example
75727568
** because the constraints are numeric) and so the sqlite3_vtab_collation()
7573
-** interface is no commonly needed.
7569
+** interface is not commonly needed.
75747570
*/
75757571
#define SQLITE_INDEX_CONSTRAINT_EQ 2
75767572
#define SQLITE_INDEX_CONSTRAINT_GT 4
75777573
#define SQLITE_INDEX_CONSTRAINT_LE 8
75787574
#define SQLITE_INDEX_CONSTRAINT_LT 16
@@ -7727,20 +7723,10 @@
77277723
** purpose is to be a placeholder function that can be overloaded
77287724
** by a [virtual table].
77297725
*/
77307726
SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
77317727
7732
-/*
7733
-** The interface to the virtual-table mechanism defined above (back up
7734
-** to a comment remarkably similar to this one) is currently considered
7735
-** to be experimental. The interface might change in incompatible ways.
7736
-** If this is a problem for you, do not use the interface at this time.
7737
-**
7738
-** When the virtual-table mechanism stabilizes, we will declare the
7739
-** interface fixed, support it indefinitely, and remove this comment.
7740
-*/
7741
-
77427728
/*
77437729
** CAPI3REF: A Handle To An Open BLOB
77447730
** KEYWORDS: {BLOB handle} {BLOB handles}
77457731
**
77467732
** An instance of this object represents an open BLOB on which
@@ -9940,11 +9926,11 @@
99409926
** statement that was passed into [sqlite3_declare_vtab()], then the
99419927
** name of that alternative collating sequence is returned.
99429928
** <li><p> Otherwise, "BINARY" is returned.
99439929
** </ol>
99449930
*/
9945
-SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9931
+SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
99469932
99479933
/*
99489934
** CAPI3REF: Determine if a virtual table query is DISTINCT
99499935
** METHOD: sqlite3_index_info
99509936
**
@@ -10209,10 +10195,14 @@
1020910195
**
1021010196
** When the value returned to V is a string, space to hold that string is
1021110197
** managed by the prepared statement S and will be automatically freed when
1021210198
** S is finalized.
1021310199
**
10200
+** Not all values are available for all query elements. When a value is
10201
+** not available, the output variable is set to -1 if the value is numeric,
10202
+** or to NULL if it is a string (SQLITE_SCANSTAT_NAME).
10203
+**
1021410204
** <dl>
1021510205
** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
1021610206
** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
1021710207
** set to the total number of times that the X-th loop has run.</dd>
1021810208
**
@@ -10236,30 +10226,44 @@
1023610226
** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
1023710227
** <dd>^The "const char *" variable pointed to by the V parameter will be set
1023810228
** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
1023910229
** description for the X-th loop.
1024010230
**
10241
-** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
10231
+** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
1024210232
** <dd>^The "int" variable pointed to by the V parameter will be set to the
10243
-** "select-id" for the X-th loop. The select-id identifies which query or
10244
-** subquery the loop is part of. The main query has a select-id of zero.
10245
-** The select-id is the same value as is output in the first column
10246
-** of an [EXPLAIN QUERY PLAN] query.
10233
+** id for the X-th query plan element. The id value is unique within the
10234
+** statement. The select-id is the same value as is output in the first
10235
+** column of an [EXPLAIN QUERY PLAN] query.
1024710236
** </dl>
10237
+**
10238
+** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
10239
+** <dd>The "int" variable pointed to by the V parameter will be set to the
10240
+** the id of the parent of the current query element, if applicable, or
10241
+** to zero if the query element has no parent. This is the same value as
10242
+** returned in the second column of an [EXPLAIN QUERY PLAN] query.
10243
+**
10244
+** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
10245
+** <dd>The sqlite3_int64 output value is set to the number of cycles,
10246
+** according to the processor time-stamp counter, that elapsed while the
10247
+** query element was being processed. This value is not available for
10248
+** all query elements - if it is unavailable the output variable is
10249
+** set to -1.
1024810250
*/
1024910251
#define SQLITE_SCANSTAT_NLOOP 0
1025010252
#define SQLITE_SCANSTAT_NVISIT 1
1025110253
#define SQLITE_SCANSTAT_EST 2
1025210254
#define SQLITE_SCANSTAT_NAME 3
1025310255
#define SQLITE_SCANSTAT_EXPLAIN 4
1025410256
#define SQLITE_SCANSTAT_SELECTID 5
10257
+#define SQLITE_SCANSTAT_PARENTID 6
10258
+#define SQLITE_SCANSTAT_NCYCLE 7
1025510259
1025610260
/*
1025710261
** CAPI3REF: Prepared Statement Scan Status
1025810262
** METHOD: sqlite3_stmt
1025910263
**
10260
-** This interface returns information about the predicted and measured
10264
+** These interfaces return information about the predicted and measured
1026110265
** performance for pStmt. Advanced applications can use this
1026210266
** interface to compare the predicted and the measured performance and
1026310267
** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
1026410268
**
1026510269
** Since this interface is expected to be rarely used, it is only
@@ -10266,32 +10270,51 @@
1026610270
** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
1026710271
** compile-time option.
1026810272
**
1026910273
** The "iScanStatusOp" parameter determines which status information to return.
1027010274
** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
10271
-** of this interface is undefined.
10272
-** ^The requested measurement is written into a variable pointed to by
10273
-** the "pOut" parameter.
10274
-** Parameter "idx" identifies the specific loop to retrieve statistics for.
10275
-** Loops are numbered starting from zero. ^If idx is out of range - less than
10276
-** zero or greater than or equal to the total number of loops used to implement
10277
-** the statement - a non-zero value is returned and the variable that pOut
10278
-** points to is unchanged.
10275
+** of this interface is undefined. ^The requested measurement is written into
10276
+** a variable pointed to by the "pOut" parameter.
1027910277
**
10280
-** ^Statistics might not be available for all loops in all statements. ^In cases
10281
-** where there exist loops with no available statistics, this function behaves
10282
-** as if the loop did not exist - it returns non-zero and leave the variable
10283
-** that pOut points to unchanged.
10278
+** The "flags" parameter must be passed a mask of flags. At present only
10279
+** one flag is defined - SQLITE_SCANSTAT_COMPLEX. If SQLITE_SCANSTAT_COMPLEX
10280
+** is specified, then status information is available for all elements
10281
+** of a query plan that are reported by "EXPLAIN QUERY PLAN" output. If
10282
+** SQLITE_SCANSTAT_COMPLEX is not specified, then only query plan elements
10283
+** that correspond to query loops (the "SCAN..." and "SEARCH..." elements of
10284
+** the EXPLAIN QUERY PLAN output) are available. Invoking API
10285
+** sqlite3_stmt_scanstatus() is equivalent to calling
10286
+** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
10287
+**
10288
+** Parameter "idx" identifies the specific query element to retrieve statistics
10289
+** for. Query elements are numbered starting from zero. A value of -1 may be
10290
+** to query for statistics regarding the entire query. ^If idx is out of range
10291
+** - less than -1 or greater than or equal to the total number of query
10292
+** elements used to implement the statement - a non-zero value is returned and
10293
+** the variable that pOut points to is unchanged.
1028410294
**
1028510295
** See also: [sqlite3_stmt_scanstatus_reset()]
1028610296
*/
1028710297
SQLITE_API int sqlite3_stmt_scanstatus(
1028810298
sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
1028910299
int idx, /* Index of loop to report on */
1029010300
int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
1029110301
void *pOut /* Result written here */
1029210302
);
10303
+SQLITE_API int sqlite3_stmt_scanstatus_v2(
10304
+ sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
10305
+ int idx, /* Index of loop to report on */
10306
+ int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
10307
+ int flags, /* Mask of flags defined below */
10308
+ void *pOut /* Result written here */
10309
+);
10310
+
10311
+/*
10312
+** CAPI3REF: Prepared Statement Scan Status
10313
+** KEYWORDS: {scan status flags}
10314
+*/
10315
+#define SQLITE_SCANSTAT_COMPLEX 0x0001
1029310316
1029410317
/*
1029510318
** CAPI3REF: Zero Scan-Status Counters
1029610319
** METHOD: sqlite3_stmt
1029710320
**
@@ -15901,17 +15924,17 @@
1590115924
#endif
1590215925
} p4;
1590315926
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
1590415927
char *zComment; /* Comment to improve readability */
1590515928
#endif
15906
-#ifdef VDBE_PROFILE
15907
- u32 cnt; /* Number of times this instruction was executed */
15908
- u64 cycles; /* Total time spent executing this instruction */
15909
-#endif
1591015929
#ifdef SQLITE_VDBE_COVERAGE
1591115930
u32 iSrcLine; /* Source-code line that generated this opcode
1591215931
** with flags in the upper 8 bits */
15932
+#endif
15933
+#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
15934
+ u64 nExec;
15935
+ u64 nCycle;
1591315936
#endif
1591415937
};
1591515938
typedef struct VdbeOp VdbeOp;
1591615939
1591715940
@@ -16199,33 +16222,34 @@
1619916222
#define OPFLG_IN1 0x02 /* in1: P1 is an input */
1620016223
#define OPFLG_IN2 0x04 /* in2: P2 is an input */
1620116224
#define OPFLG_IN3 0x08 /* in3: P3 is an input */
1620216225
#define OPFLG_OUT2 0x10 /* out2: P2 is an output */
1620316226
#define OPFLG_OUT3 0x20 /* out3: P3 is an output */
16227
+#define OPFLG_NCYCLE 0x40 /* ncycle:Cycles count against P1 */
1620416228
#define OPFLG_INITIALIZER {\
16205
-/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
16229
+/* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x41, 0x00,\
1620616230
/* 8 */ 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01,\
16207
-/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x09, 0x09, 0x09,\
16208
-/* 24 */ 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
16209
-/* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
16210
-/* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x01, 0x23, 0x0b,\
16231
+/* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x49, 0x49, 0x49,\
16232
+/* 24 */ 0x49, 0x01, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49,\
16233
+/* 32 */ 0x41, 0x01, 0x01, 0x01, 0x41, 0x01, 0x41, 0x41,\
16234
+/* 40 */ 0x41, 0x41, 0x41, 0x26, 0x26, 0x41, 0x23, 0x0b,\
1621116235
/* 48 */ 0x01, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
16212
-/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
16236
+/* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x41,\
1621316237
/* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
1621416238
/* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
1621516239
/* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
16216
-/* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00,\
16217
-/* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x26, 0x26,\
16240
+/* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x40, 0x00,\
16241
+/* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x40, 0x26, 0x26,\
1621816242
/* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
16219
-/* 112 */ 0x00, 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00,\
16220
-/* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
16221
-/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
16222
-/* 136 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
16243
+/* 112 */ 0x40, 0x00, 0x12, 0x40, 0x40, 0x10, 0x40, 0x00,\
16244
+/* 120 */ 0x00, 0x00, 0x40, 0x00, 0x40, 0x40, 0x10, 0x10,\
16245
+/* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50,\
16246
+/* 136 */ 0x00, 0x40, 0x04, 0x04, 0x00, 0x40, 0x50, 0x40,\
1622316247
/* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
1622416248
/* 152 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
1622516249
/* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
16226
-/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
16250
+/* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x50, 0x40,\
1622716251
/* 176 */ 0x00, 0x10, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00,\
1622816252
/* 184 */ 0x00, 0x00, 0x00,}
1622916253
1623016254
/* The resolve3P2Values() routine is able to run faster if it knows
1623116255
** the value of the largest JUMP opcode. The smaller the maximum
@@ -16276,18 +16300,24 @@
1627616300
# define sqlite3VdbeVerifyAbortable(A,B)
1627716301
# define sqlite3VdbeNoJumpsOutsideSubrtn(A,B,C,D)
1627816302
#endif
1627916303
SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
1628016304
#ifndef SQLITE_OMIT_EXPLAIN
16281
-SQLITE_PRIVATE void sqlite3VdbeExplain(Parse*,u8,const char*,...);
16305
+SQLITE_PRIVATE int sqlite3VdbeExplain(Parse*,u8,const char*,...);
1628216306
SQLITE_PRIVATE void sqlite3VdbeExplainPop(Parse*);
1628316307
SQLITE_PRIVATE int sqlite3VdbeExplainParent(Parse*);
1628416308
# define ExplainQueryPlan(P) sqlite3VdbeExplain P
16309
+# ifdef SQLITE_ENABLE_STMT_SCANSTATUS
16310
+# define ExplainQueryPlan2(V,P) (V = sqlite3VdbeExplain P)
16311
+# else
16312
+# define ExplainQueryPlan2(V,P) ExplainQueryPlan(P)
16313
+# endif
1628516314
# define ExplainQueryPlanPop(P) sqlite3VdbeExplainPop(P)
1628616315
# define ExplainQueryPlanParent(P) sqlite3VdbeExplainParent(P)
1628716316
#else
1628816317
# define ExplainQueryPlan(P)
16318
+# define ExplainQueryPlan2(V,P)
1628916319
# define ExplainQueryPlanPop(P)
1629016320
# define ExplainQueryPlanParent(P) 0
1629116321
# define sqlite3ExplainBreakpoint(A,B) /*no-op*/
1629216322
#endif
1629316323
#if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_EXPLAIN)
@@ -16456,12 +16486,16 @@
1645616486
# define VDBE_OFFSET_LINENO(x) 0
1645716487
#endif
1645816488
1645916489
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
1646016490
SQLITE_PRIVATE void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
16491
+SQLITE_PRIVATE void sqlite3VdbeScanStatusRange(Vdbe*, int, int, int);
16492
+SQLITE_PRIVATE void sqlite3VdbeScanStatusCounters(Vdbe*, int, int, int);
1646116493
#else
16462
-# define sqlite3VdbeScanStatus(a,b,c,d,e)
16494
+# define sqlite3VdbeScanStatus(a,b,c,d,e,f)
16495
+# define sqlite3VdbeScanStatusRange(a,b,c,d)
16496
+# define sqlite3VdbeScanStatusCounters(a,b,c,d)
1646316497
#endif
1646416498
1646516499
#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
1646616500
SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, VdbeOp*);
1646716501
#endif
@@ -17254,10 +17288,11 @@
1725417288
#define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
1725517289
#define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
1725617290
#define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
1725717291
/* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
1725817292
#define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
17293
+#define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
1725917294
#define SQLITE_AllOpts 0xffffffff /* All optimizations */
1726017295
1726117296
/*
1726217297
** Macros for testing whether or not optimizations are enabled or disabled.
1726317298
*/
@@ -18875,10 +18910,11 @@
1887518910
#define SF_UFSrcCheck 0x0800000 /* Check pSrc as required by UPDATE...FROM */
1887618911
#define SF_PushDown 0x1000000 /* SELECT has be modified by push-down opt */
1887718912
#define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */
1887818913
#define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */
1887918914
#define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */
18915
+#define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */
1888018916
1888118917
/* True if S exists and has SF_NestedFrom */
1888218918
#define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0)
1888318919
1888418920
/*
@@ -18983,11 +19019,11 @@
1898319019
u8 eDest; /* How to dispose of the results. One of SRT_* above. */
1898419020
int iSDParm; /* A parameter used by the eDest disposal method */
1898519021
int iSDParm2; /* A second parameter for the eDest disposal method */
1898619022
int iSdst; /* Base register where results are written */
1898719023
int nSdst; /* Number of registers allocated */
18988
- char *zAffSdst; /* Affinity used for SRT_Set, SRT_Table, and similar */
19024
+ char *zAffSdst; /* Affinity used for SRT_Set */
1898919025
ExprList *pOrderBy; /* Key columns for SRT_Queue and SRT_DistQueue */
1899019026
};
1899119027
1899219028
/*
1899319029
** During code generation of statements that do inserts into AUTOINCREMENT
@@ -20088,11 +20124,11 @@
2008820124
SQLITE_PRIVATE void sqlite3ColumnSetColl(sqlite3*,Column*,const char*zColl);
2008920125
SQLITE_PRIVATE const char *sqlite3ColumnColl(Column*);
2009020126
SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
2009120127
SQLITE_PRIVATE void sqlite3GenerateColumnNames(Parse *pParse, Select *pSelect);
2009220128
SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
20093
-SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char);
20129
+SQLITE_PRIVATE void sqlite3SubqueryColumnTypes(Parse*,Table*,Select*,char);
2009420130
SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char);
2009520131
SQLITE_PRIVATE void sqlite3OpenSchemaTable(Parse *, int);
2009620132
SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
2009720133
SQLITE_PRIVATE i16 sqlite3TableColumnToIndex(Index*, i16);
2009820134
#ifdef SQLITE_OMIT_GENERATED_COLUMNS
@@ -20459,10 +20495,11 @@
2045920495
SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
2046020496
SQLITE_PRIVATE char sqlite3CompareAffinity(const Expr *pExpr, char aff2);
2046120497
SQLITE_PRIVATE int sqlite3IndexAffinityOk(const Expr *pExpr, char idx_affinity);
2046220498
SQLITE_PRIVATE char sqlite3TableColumnAffinity(const Table*,int);
2046320499
SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr);
20500
+SQLITE_PRIVATE int sqlite3ExprDataType(const Expr *pExpr);
2046420501
SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
2046520502
SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*);
2046620503
SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...);
2046720504
SQLITE_PRIVATE void sqlite3Error(sqlite3*,int);
2046820505
SQLITE_PRIVATE void sqlite3ErrorClear(sqlite3*);
@@ -20975,11 +21012,13 @@
2097521012
2097621013
#if SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL)
2097721014
SQLITE_PRIVATE int sqlite3KvvfsInit(void);
2097821015
#endif
2097921016
20980
-#if defined(VDBE_PROFILE) || defined(SQLITE_PERFORMANCE_TRACE)
21017
+#if defined(VDBE_PROFILE) \
21018
+ || defined(SQLITE_PERFORMANCE_TRACE) \
21019
+ || defined(SQLITE_ENABLE_STMT_SCANSTATUS)
2098121020
SQLITE_PRIVATE sqlite3_uint64 sqlite3Hwtime(void);
2098221021
#endif
2098321022
2098421023
#endif /* SQLITEINT_H */
2098521024
@@ -22464,11 +22503,10 @@
2246422503
typedef struct VdbeFrame VdbeFrame;
2246522504
struct VdbeFrame {
2246622505
Vdbe *v; /* VM this frame belongs to */
2246722506
VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
2246822507
Op *aOp; /* Program instructions for parent frame */
22469
- i64 *anExec; /* Event counters from parent frame */
2247022508
Mem *aMem; /* Array of memory cells for parent frame */
2247122509
VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
2247222510
u8 *aOnce; /* Bitmask used by OP_Once */
2247322511
void *token; /* Copy of SubProgram.token */
2247422512
i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
@@ -22680,14 +22718,23 @@
2268022718
*/
2268122719
typedef unsigned bft; /* Bit Field Type */
2268222720
2268322721
/* The ScanStatus object holds a single value for the
2268422722
** sqlite3_stmt_scanstatus() interface.
22723
+**
22724
+** aAddrRange[]:
22725
+** This array is used by ScanStatus elements associated with EQP
22726
+** notes that make an SQLITE_SCANSTAT_NCYCLE value available. It is
22727
+** an array of up to 3 ranges of VM addresses for which the Vdbe.anCycle[]
22728
+** values should be summed to calculate the NCYCLE value. Each pair of
22729
+** integer addresses is a start and end address (both inclusive) for a range
22730
+** instructions. A start value of 0 indicates an empty range.
2268522731
*/
2268622732
typedef struct ScanStatus ScanStatus;
2268722733
struct ScanStatus {
2268822734
int addrExplain; /* OP_Explain for loop */
22735
+ int aAddrRange[6];
2268922736
int addrLoop; /* Address of "loops" counter */
2269022737
int addrVisit; /* Address of "rows visited" counter */
2269122738
int iSelectID; /* The "Select-ID" for this loop */
2269222739
LogEst nEst; /* Estimated output rows per loop */
2269322740
char *zName; /* Name of table or index */
@@ -22776,11 +22823,10 @@
2277622823
int nFrame; /* Number of frames in pFrame list */
2277722824
u32 expmask; /* Binding to these vars invalidates VM */
2277822825
SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
2277922826
AuxData *pAuxData; /* Linked list of auxdata allocations */
2278022827
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
22781
- i64 *anExec; /* Number of times each op has been executed */
2278222828
int nScan; /* Entries in aScan[] */
2278322829
ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
2278422830
#endif
2278522831
};
2278622832
@@ -35198,11 +35244,13 @@
3519835244
}
3519935245
3520035246
/*
3520135247
** High-resolution hardware timer used for debugging and testing only.
3520235248
*/
35203
-#if defined(VDBE_PROFILE) || defined(SQLITE_PERFORMANCE_TRACE)
35249
+#if defined(VDBE_PROFILE) \
35250
+ || defined(SQLITE_PERFORMANCE_TRACE) \
35251
+ || defined(SQLITE_ENABLE_STMT_SCANSTATUS)
3520435252
/************** Include hwtime.h in the middle of util.c *********************/
3520535253
/************** Begin file hwtime.h ******************************************/
3520635254
/*
3520735255
** 2008 May 27
3520835256
**
@@ -35251,13 +35299,13 @@
3525135299
#endif
3525235300
3525335301
#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
3525435302
3525535303
__inline__ sqlite_uint64 sqlite3Hwtime(void){
35256
- unsigned long val;
35257
- __asm__ __volatile__ ("rdtsc" : "=A" (val));
35258
- return val;
35304
+ unsigned int lo, hi;
35305
+ __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
35306
+ return (sqlite_uint64)hi << 32 | lo;
3525935307
}
3526035308
3526135309
#elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
3526235310
3526335311
__inline__ sqlite_uint64 sqlite3Hwtime(void){
@@ -37442,10 +37490,13 @@
3744237490
if( fd<0 ){
3744337491
if( errno==EINTR ) continue;
3744437492
break;
3744537493
}
3744637494
if( fd>=SQLITE_MINIMUM_FILE_DESCRIPTOR ) break;
37495
+ if( (f & (O_EXCL|O_CREAT))==(O_EXCL|O_CREAT) ){
37496
+ (void)osUnlink(z);
37497
+ }
3744737498
osClose(fd);
3744837499
sqlite3_log(SQLITE_WARNING,
3744937500
"attempt to open \"%s\" as file descriptor %d", z, fd);
3745037501
fd = -1;
3745137502
if( osOpen("/dev/null", O_RDONLY, m)<0 ) break;
@@ -51436,14 +51487,39 @@
5143651487
MemFile *pThis = (MemFile*)pFile;
5143751488
MemStore *p = pThis->pStore;
5143851489
int rc = SQLITE_OK;
5143951490
if( eLock==pThis->eLock ) return SQLITE_OK;
5144051491
memdbEnter(p);
51492
+ assert( p->nWrLock==0 || p->nWrLock==1 ); /* No more than 1 write lock */
5144151493
if( eLock>SQLITE_LOCK_SHARED ){
51494
+ assert( pThis->eLock>=SQLITE_LOCK_SHARED );
5144251495
if( p->mFlags & SQLITE_DESERIALIZE_READONLY ){
5144351496
rc = SQLITE_READONLY;
51444
- }else if( pThis->eLock<=SQLITE_LOCK_SHARED ){
51497
+ }else if( eLock==SQLITE_LOCK_EXCLUSIVE ){
51498
+ /* We never go for an EXCLUSIVE lock unless we already hold SHARED or
51499
+ ** higher */
51500
+ assert( pThis->eLock>=SQLITE_LOCK_SHARED );
51501
+ testcase( pThis->eLock==SQLITE_LOCK_SHARED );
51502
+
51503
+ /* Because we are holding SHARED or more, there must be at least
51504
+ ** one read lock */
51505
+ assert( p->nRdLock>0 );
51506
+
51507
+ /* The only way that there can be an existing write lock is if we
51508
+ ** currently hold it. Otherwise, we would have never been able to
51509
+ ** promote from NONE to SHARED. */
51510
+ assert( p->nWrLock==0 || pThis->eLock>SQLITE_LOCK_SHARED );
51511
+
51512
+ if( p->nRdLock>1 ){
51513
+ /* Cannot take EXCLUSIVE if somebody else is holding SHARED */
51514
+ rc = SQLITE_BUSY;
51515
+ }else{
51516
+ p->nWrLock = 1;
51517
+ }
51518
+ }else if( ALWAYS(pThis->eLock<=SQLITE_LOCK_SHARED) ){
51519
+ /* Upgrading to RESERVED or PENDING from SHARED. Fail if any other
51520
+ ** client has a write-lock of any kind. */
5144551521
if( p->nWrLock ){
5144651522
rc = SQLITE_BUSY;
5144751523
}else{
5144851524
p->nWrLock = 1;
5144951525
}
@@ -82327,21 +82403,21 @@
8232782403
pOp->p3 = p3;
8232882404
pOp->p4.p = 0;
8232982405
pOp->p4type = P4_NOTUSED;
8233082406
#ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
8233182407
pOp->zComment = 0;
82408
+#endif
82409
+#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
82410
+ pOp->nExec = 0;
82411
+ pOp->nCycle = 0;
8233282412
#endif
8233382413
#ifdef SQLITE_DEBUG
8233482414
if( p->db->flags & SQLITE_VdbeAddopTrace ){
8233582415
sqlite3VdbePrintOp(0, i, &p->aOp[i]);
8233682416
test_addop_breakpoint(i, &p->aOp[i]);
8233782417
}
8233882418
#endif
82339
-#ifdef VDBE_PROFILE
82340
- pOp->cycles = 0;
82341
- pOp->cnt = 0;
82342
-#endif
8234382419
#ifdef SQLITE_VDBE_COVERAGE
8234482420
pOp->iSrcLine = 0;
8234582421
#endif
8234682422
return i;
8234782423
}
@@ -82505,12 +82581,13 @@
8250582581
** Add a new OP_Explain opcode.
8250682582
**
8250782583
** If the bPush flag is true, then make this opcode the parent for
8250882584
** subsequent Explains until sqlite3VdbeExplainPop() is called.
8250982585
*/
82510
-SQLITE_PRIVATE void sqlite3VdbeExplain(Parse *pParse, u8 bPush, const char *zFmt, ...){
82511
-#ifndef SQLITE_DEBUG
82586
+SQLITE_PRIVATE int sqlite3VdbeExplain(Parse *pParse, u8 bPush, const char *zFmt, ...){
82587
+ int addr = 0;
82588
+#if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
8251282589
/* Always include the OP_Explain opcodes if SQLITE_DEBUG is defined.
8251382590
** But omit them (for performance) during production builds */
8251482591
if( pParse->explain==2 )
8251582592
#endif
8251682593
{
@@ -82521,17 +82598,19 @@
8252182598
va_start(ap, zFmt);
8252282599
zMsg = sqlite3VMPrintf(pParse->db, zFmt, ap);
8252382600
va_end(ap);
8252482601
v = pParse->pVdbe;
8252582602
iThis = v->nOp;
82526
- sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
82603
+ addr = sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
8252782604
zMsg, P4_DYNAMIC);
8252882605
sqlite3ExplainBreakpoint(bPush?"PUSH":"", sqlite3VdbeGetLastOp(v)->p4.z);
8252982606
if( bPush){
8253082607
pParse->addrExplain = iThis;
8253182608
}
82609
+ sqlite3VdbeScanStatus(v, iThis, 0, 0, 0, 0);
8253282610
}
82611
+ return addr;
8253382612
}
8253482613
8253582614
/*
8253682615
** Pop the EXPLAIN QUERY PLAN stack one level.
8253782616
*/
@@ -83185,18 +83264,75 @@
8318583264
sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus);
8318683265
ScanStatus *aNew;
8318783266
aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
8318883267
if( aNew ){
8318983268
ScanStatus *pNew = &aNew[p->nScan++];
83269
+ memset(pNew, 0, sizeof(ScanStatus));
8319083270
pNew->addrExplain = addrExplain;
8319183271
pNew->addrLoop = addrLoop;
8319283272
pNew->addrVisit = addrVisit;
8319383273
pNew->nEst = nEst;
8319483274
pNew->zName = sqlite3DbStrDup(p->db, zName);
8319583275
p->aScan = aNew;
8319683276
}
8319783277
}
83278
+
83279
+/*
83280
+** Add the range of instructions from addrStart to addrEnd (inclusive) to
83281
+** the set of those corresponding to the sqlite3_stmt_scanstatus() counters
83282
+** associated with the OP_Explain instruction at addrExplain. The
83283
+** sum of the sqlite3Hwtime() values for each of these instructions
83284
+** will be returned for SQLITE_SCANSTAT_NCYCLE requests.
83285
+*/
83286
+SQLITE_PRIVATE void sqlite3VdbeScanStatusRange(
83287
+ Vdbe *p,
83288
+ int addrExplain,
83289
+ int addrStart,
83290
+ int addrEnd
83291
+){
83292
+ ScanStatus *pScan = 0;
83293
+ int ii;
83294
+ for(ii=p->nScan-1; ii>=0; ii--){
83295
+ pScan = &p->aScan[ii];
83296
+ if( pScan->addrExplain==addrExplain ) break;
83297
+ pScan = 0;
83298
+ }
83299
+ if( pScan ){
83300
+ if( addrEnd<0 ) addrEnd = sqlite3VdbeCurrentAddr(p)-1;
83301
+ for(ii=0; ii<ArraySize(pScan->aAddrRange); ii+=2){
83302
+ if( pScan->aAddrRange[ii]==0 ){
83303
+ pScan->aAddrRange[ii] = addrStart;
83304
+ pScan->aAddrRange[ii+1] = addrEnd;
83305
+ break;
83306
+ }
83307
+ }
83308
+ }
83309
+}
83310
+
83311
+/*
83312
+** Set the addresses for the SQLITE_SCANSTAT_NLOOP and SQLITE_SCANSTAT_NROW
83313
+** counters for the query element associated with the OP_Explain at
83314
+** addrExplain.
83315
+*/
83316
+SQLITE_PRIVATE void sqlite3VdbeScanStatusCounters(
83317
+ Vdbe *p,
83318
+ int addrExplain,
83319
+ int addrLoop,
83320
+ int addrVisit
83321
+){
83322
+ ScanStatus *pScan = 0;
83323
+ int ii;
83324
+ for(ii=p->nScan-1; ii>=0; ii--){
83325
+ pScan = &p->aScan[ii];
83326
+ if( pScan->addrExplain==addrExplain ) break;
83327
+ pScan = 0;
83328
+ }
83329
+ if( pScan ){
83330
+ pScan->addrLoop = addrLoop;
83331
+ pScan->addrVisit = addrVisit;
83332
+ }
83333
+}
8319883334
#endif
8319983335
8320083336
8320183337
/*
8320283338
** Change the value of the opcode, or P1, P2, P3, or P5 operands
@@ -84490,11 +84626,11 @@
8449084626
/*
8449184627
** Rewind the VDBE back to the beginning in preparation for
8449284628
** running it.
8449384629
*/
8449484630
SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){
84495
-#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
84631
+#if defined(SQLITE_DEBUG)
8449684632
int i;
8449784633
#endif
8449884634
assert( p!=0 );
8449984635
assert( p->eVdbeState==VDBE_INIT_STATE
8450084636
|| p->eVdbeState==VDBE_READY_STATE
@@ -84519,12 +84655,12 @@
8451984655
p->minWriteFileFormat = 255;
8452084656
p->iStatement = 0;
8452184657
p->nFkConstraint = 0;
8452284658
#ifdef VDBE_PROFILE
8452384659
for(i=0; i<p->nOp; i++){
84524
- p->aOp[i].cnt = 0;
84525
- p->aOp[i].cycles = 0;
84660
+ p->aOp[i].nExec = 0;
84661
+ p->aOp[i].nCycle = 0;
8452684662
}
8452784663
#endif
8452884664
}
8452984665
8453084666
/*
@@ -84629,24 +84765,18 @@
8462984765
x.nNeeded = 0;
8463084766
p->aMem = allocSpace(&x, 0, nMem*sizeof(Mem));
8463184767
p->aVar = allocSpace(&x, 0, nVar*sizeof(Mem));
8463284768
p->apArg = allocSpace(&x, 0, nArg*sizeof(Mem*));
8463384769
p->apCsr = allocSpace(&x, 0, nCursor*sizeof(VdbeCursor*));
84634
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
84635
- p->anExec = allocSpace(&x, 0, p->nOp*sizeof(i64));
84636
-#endif
8463784770
if( x.nNeeded ){
8463884771
x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
8463984772
x.nFree = x.nNeeded;
8464084773
if( !db->mallocFailed ){
8464184774
p->aMem = allocSpace(&x, p->aMem, nMem*sizeof(Mem));
8464284775
p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
8464384776
p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
8464484777
p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
84645
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
84646
- p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64));
84647
-#endif
8464884778
}
8464984779
}
8465084780
8465184781
if( db->mallocFailed ){
8465284782
p->nVar = 0;
@@ -84657,13 +84787,10 @@
8465784787
p->nVar = (ynVar)nVar;
8465884788
initMemArray(p->aVar, nVar, db, MEM_Null);
8465984789
p->nMem = nMem;
8466084790
initMemArray(p->aMem, nMem, db, MEM_Undefined);
8466184791
memset(p->apCsr, 0, nCursor*sizeof(VdbeCursor*));
84662
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
84663
- memset(p->anExec, 0, p->nOp*sizeof(i64));
84664
-#endif
8466584792
}
8466684793
sqlite3VdbeRewind(p);
8466784794
}
8466884795
8466984796
/*
@@ -84717,13 +84844,10 @@
8471784844
** control to the main program.
8471884845
*/
8471984846
SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
8472084847
Vdbe *v = pFrame->v;
8472184848
closeCursorsInFrame(v);
84722
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
84723
- v->anExec = pFrame->anExec;
84724
-#endif
8472584849
v->aOp = pFrame->aOp;
8472684850
v->nOp = pFrame->nOp;
8472784851
v->aMem = pFrame->aMem;
8472884852
v->nMem = pFrame->nMem;
8472984853
v->apCsr = pFrame->apCsr;
@@ -85551,14 +85675,16 @@
8555185675
}
8555285676
if( pc!='\n' ) fprintf(out, "\n");
8555385677
}
8555485678
for(i=0; i<p->nOp; i++){
8555585679
char zHdr[100];
85680
+ i64 cnt = p->aOp[i].nExec;
85681
+ i64 cycles = p->aOp[i].nCycle;
8555685682
sqlite3_snprintf(sizeof(zHdr), zHdr, "%6u %12llu %8llu ",
85557
- p->aOp[i].cnt,
85558
- p->aOp[i].cycles,
85559
- p->aOp[i].cnt>0 ? p->aOp[i].cycles/p->aOp[i].cnt : 0
85683
+ cnt,
85684
+ cycles,
85685
+ cnt>0 ? cycles/cnt : 0
8556085686
);
8556185687
fprintf(out, "%s", zHdr);
8556285688
sqlite3VdbePrintOp(out, i, &p->aOp[i]);
8556385689
}
8556485690
fclose(out);
@@ -87409,10 +87535,11 @@
8740987535
** This file contains code use to implement APIs that are part of the
8741087536
** VDBE.
8741187537
*/
8741287538
/* #include "sqliteInt.h" */
8741387539
/* #include "vdbeInt.h" */
87540
+/* #include "opcodes.h" */
8741487541
8741587542
#ifndef SQLITE_OMIT_DEPRECATED
8741687543
/*
8741787544
** Return TRUE (non-zero) of the statement supplied as an argument needs
8741887545
** to be recompiled. A statement needs to be recompiled whenever the
@@ -89505,27 +89632,64 @@
8950589632
8950689633
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
8950789634
/*
8950889635
** Return status data for a single loop within query pStmt.
8950989636
*/
89510
-SQLITE_API int sqlite3_stmt_scanstatus(
89637
+SQLITE_API int sqlite3_stmt_scanstatus_v2(
8951189638
sqlite3_stmt *pStmt, /* Prepared statement being queried */
89512
- int idx, /* Index of loop to report on */
89639
+ int iScan, /* Index of loop to report on */
8951389640
int iScanStatusOp, /* Which metric to return */
89641
+ int flags,
8951489642
void *pOut /* OUT: Write the answer here */
8951589643
){
8951689644
Vdbe *p = (Vdbe*)pStmt;
8951789645
ScanStatus *pScan;
89518
- if( idx<0 || idx>=p->nScan ) return 1;
89519
- pScan = &p->aScan[idx];
89646
+ int idx;
89647
+
89648
+ if( iScan<0 ){
89649
+ int ii;
89650
+ if( iScanStatusOp==SQLITE_SCANSTAT_NCYCLE ){
89651
+ i64 res = 0;
89652
+ for(ii=0; ii<p->nOp; ii++){
89653
+ res += p->aOp[ii].nCycle;
89654
+ }
89655
+ *(i64*)pOut = res;
89656
+ return 0;
89657
+ }
89658
+ return 1;
89659
+ }
89660
+ if( flags & SQLITE_SCANSTAT_COMPLEX ){
89661
+ idx = iScan;
89662
+ pScan = &p->aScan[idx];
89663
+ }else{
89664
+ /* If the COMPLEX flag is clear, then this function must ignore any
89665
+ ** ScanStatus structures with ScanStatus.addrLoop set to 0. */
89666
+ for(idx=0; idx<p->nScan; idx++){
89667
+ pScan = &p->aScan[idx];
89668
+ if( pScan->zName ){
89669
+ iScan--;
89670
+ if( iScan<0 ) break;
89671
+ }
89672
+ }
89673
+ }
89674
+ if( idx>=p->nScan ) return 1;
89675
+
8952089676
switch( iScanStatusOp ){
8952189677
case SQLITE_SCANSTAT_NLOOP: {
89522
- *(sqlite3_int64*)pOut = p->anExec[pScan->addrLoop];
89678
+ if( pScan->addrLoop>0 ){
89679
+ *(sqlite3_int64*)pOut = p->aOp[pScan->addrLoop].nExec;
89680
+ }else{
89681
+ *(sqlite3_int64*)pOut = -1;
89682
+ }
8952389683
break;
8952489684
}
8952589685
case SQLITE_SCANSTAT_NVISIT: {
89526
- *(sqlite3_int64*)pOut = p->anExec[pScan->addrVisit];
89686
+ if( pScan->addrVisit>0 ){
89687
+ *(sqlite3_int64*)pOut = p->aOp[pScan->addrVisit].nExec;
89688
+ }else{
89689
+ *(sqlite3_int64*)pOut = -1;
89690
+ }
8952789691
break;
8952889692
}
8952989693
case SQLITE_SCANSTAT_EST: {
8953089694
double r = 1.0;
8953189695
LogEst x = pScan->nEst;
@@ -89553,24 +89717,80 @@
8955389717
*(int*)pOut = p->aOp[ pScan->addrExplain ].p1;
8955489718
}else{
8955589719
*(int*)pOut = -1;
8955689720
}
8955789721
break;
89722
+ }
89723
+ case SQLITE_SCANSTAT_PARENTID: {
89724
+ if( pScan->addrExplain ){
89725
+ *(int*)pOut = p->aOp[ pScan->addrExplain ].p2;
89726
+ }else{
89727
+ *(int*)pOut = -1;
89728
+ }
89729
+ break;
89730
+ }
89731
+ case SQLITE_SCANSTAT_NCYCLE: {
89732
+ i64 res = 0;
89733
+ if( pScan->aAddrRange[0]==0 ){
89734
+ res = -1;
89735
+ }else{
89736
+ int ii;
89737
+ for(ii=0; ii<ArraySize(pScan->aAddrRange); ii+=2){
89738
+ int iIns = pScan->aAddrRange[ii];
89739
+ int iEnd = pScan->aAddrRange[ii+1];
89740
+ if( iIns==0 ) break;
89741
+ if( iIns>0 ){
89742
+ while( iIns<=iEnd ){
89743
+ res += p->aOp[iIns].nCycle;
89744
+ iIns++;
89745
+ }
89746
+ }else{
89747
+ int iOp;
89748
+ for(iOp=0; iOp<p->nOp; iOp++){
89749
+ Op *pOp = &p->aOp[iOp];
89750
+ if( pOp->p1!=iEnd ) continue;
89751
+ if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_NCYCLE)==0 ){
89752
+ continue;
89753
+ }
89754
+ res += p->aOp[iOp].nCycle;
89755
+ }
89756
+ }
89757
+ }
89758
+ }
89759
+ *(i64*)pOut = res;
89760
+ break;
8955889761
}
8955989762
default: {
8956089763
return 1;
8956189764
}
8956289765
}
8956389766
return 0;
8956489767
}
89768
+
89769
+/*
89770
+** Return status data for a single loop within query pStmt.
89771
+*/
89772
+SQLITE_API int sqlite3_stmt_scanstatus(
89773
+ sqlite3_stmt *pStmt, /* Prepared statement being queried */
89774
+ int iScan, /* Index of loop to report on */
89775
+ int iScanStatusOp, /* Which metric to return */
89776
+ void *pOut /* OUT: Write the answer here */
89777
+){
89778
+ return sqlite3_stmt_scanstatus_v2(pStmt, iScan, iScanStatusOp, 0, pOut);
89779
+}
8956589780
8956689781
/*
8956789782
** Zero all counters associated with the sqlite3_stmt_scanstatus() data.
8956889783
*/
8956989784
SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){
8957089785
Vdbe *p = (Vdbe*)pStmt;
89571
- memset(p->anExec, 0, p->nOp * sizeof(i64));
89786
+ int ii;
89787
+ for(ii=0; ii<p->nOp; ii++){
89788
+ Op *pOp = &p->aOp[ii];
89789
+ pOp->nExec = 0;
89790
+ pOp->nCycle = 0;
89791
+ }
8957289792
}
8957389793
#endif /* SQLITE_ENABLE_STMT_SCANSTATUS */
8957489794
8957589795
/************** End of vdbeapi.c *********************************************/
8957689796
/************** Begin file vdbetrace.c ***************************************/
@@ -90386,11 +90606,10 @@
9038690606
# define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
9038790607
#else
9038890608
# define REGISTER_TRACE(R,M)
9038990609
#endif
9039090610
90391
-
9039290611
#ifndef NDEBUG
9039390612
/*
9039490613
** This function is only called from within an assert() expression. It
9039590614
** checks that the sqlite3.nTransaction variable is correctly set to
9039690615
** the number of non-transaction savepoints currently in the
@@ -90476,14 +90695,12 @@
9047690695
SQLITE_PRIVATE int sqlite3VdbeExec(
9047790696
Vdbe *p /* The VDBE */
9047890697
){
9047990698
Op *aOp = p->aOp; /* Copy of p->aOp */
9048090699
Op *pOp = aOp; /* Current operation */
90481
-#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
90700
+#ifdef SQLITE_DEBUG
9048290701
Op *pOrigOp; /* Value of pOp at the top of the loop */
90483
-#endif
90484
-#ifdef SQLITE_DEBUG
9048590702
int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */
9048690703
#endif
9048790704
int rc = SQLITE_OK; /* Value to return */
9048890705
sqlite3 *db = p->db; /* The database */
9048990706
u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
@@ -90496,12 +90713,12 @@
9049690713
Mem *aMem = p->aMem; /* Copy of p->aMem */
9049790714
Mem *pIn1 = 0; /* 1st input operand */
9049890715
Mem *pIn2 = 0; /* 2nd input operand */
9049990716
Mem *pIn3 = 0; /* 3rd input operand */
9050090717
Mem *pOut = 0; /* Output operand */
90501
-#ifdef VDBE_PROFILE
90502
- u64 start; /* CPU clock count at start of opcode */
90718
+#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
90719
+ u64 *pnCycle = 0;
9050390720
#endif
9050490721
/*** INSERT STACK UNION HERE ***/
9050590722
9050690723
assert( p->eVdbeState==VDBE_RUN_STATE ); /* sqlite3_step() verifies this */
9050790724
sqlite3VdbeEnter(p);
@@ -90560,16 +90777,18 @@
9056090777
/* Errors are detected by individual opcodes, with an immediate
9056190778
** jumps to abort_due_to_error. */
9056290779
assert( rc==SQLITE_OK );
9056390780
9056490781
assert( pOp>=aOp && pOp<&aOp[p->nOp]);
90565
-#ifdef VDBE_PROFILE
90566
- start = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
90567
-#endif
9056890782
nVmStep++;
90569
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
90570
- if( p->anExec ) p->anExec[(int)(pOp-aOp)]++;
90783
+#if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
90784
+ pOp->nExec++;
90785
+ pnCycle = &pOp->nCycle;
90786
+# ifdef VDBE_PROFILE
90787
+ if( sqlite3NProfileCnt==0 )
90788
+# endif
90789
+ *pnCycle -= sqlite3Hwtime();
9057190790
#endif
9057290791
9057390792
/* Only allow tracing if SQLITE_DEBUG is defined.
9057490793
*/
9057590794
#ifdef SQLITE_DEBUG
@@ -90627,11 +90846,11 @@
9062790846
assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
9062890847
memAboutToChange(p, &aMem[pOp->p3]);
9062990848
}
9063090849
}
9063190850
#endif
90632
-#if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
90851
+#ifdef SQLITE_DEBUG
9063390852
pOrigOp = pOp;
9063490853
#endif
9063590854
9063690855
switch( pOp->opcode ){
9063790856
@@ -91885,11 +92104,10 @@
9188592104
pIn1 = &aMem[pOp->p1];
9188692105
pIn3 = &aMem[pOp->p3];
9188792106
flags1 = pIn1->flags;
9188892107
flags3 = pIn3->flags;
9188992108
if( (flags1 & flags3 & MEM_Int)!=0 ){
91890
- assert( (pOp->p5 & SQLITE_AFF_MASK)!=SQLITE_AFF_TEXT || CORRUPT_DB );
9189192109
/* Common case of comparison of two integers */
9189292110
if( pIn3->u.i > pIn1->u.i ){
9189392111
if( sqlite3aGTb[pOp->opcode] ){
9189492112
VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
9189592113
goto jump_to_p2;
@@ -91953,11 +92171,11 @@
9195392171
}
9195492172
if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
9195592173
applyNumericAffinity(pIn3,0);
9195692174
}
9195792175
}
91958
- }else if( affinity==SQLITE_AFF_TEXT ){
92176
+ }else if( affinity==SQLITE_AFF_TEXT && ((flags1 | flags3) & MEM_Str)!=0 ){
9195992177
if( (flags1 & MEM_Str)==0 && (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
9196092178
testcase( pIn1->flags & MEM_Int );
9196192179
testcase( pIn1->flags & MEM_Real );
9196292180
testcase( pIn1->flags & MEM_IntReal );
9196392181
sqlite3VdbeMemStringify(pIn1, encoding, 1);
@@ -92547,11 +92765,11 @@
9254792765
** of large blobs is not loaded, thus saving CPU cycles. If the
9254892766
** OPFLAG_TYPEOFARG bit is set then the result will only be used by the
9254992767
** typeof() function or the IS NULL or IS NOT NULL operators or the
9255092768
** equivalent. In this case, all content loading can be omitted.
9255192769
*/
92552
-case OP_Column: {
92770
+case OP_Column: { /* ncycle */
9255392771
u32 p2; /* column number to retrieve */
9255492772
VdbeCursor *pC; /* The VDBE cursor */
9255592773
BtCursor *pCrsr; /* The B-Tree cursor corresponding to pC */
9255692774
u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
9255792775
int len; /* The length of the serialized data for the column */
@@ -93899,11 +94117,11 @@
9389994117
** This instruction works like OpenRead except that it opens the cursor
9390094118
** in read/write mode.
9390194119
**
9390294120
** See also: OP_OpenRead, OP_ReopenIdx
9390394121
*/
93904
-case OP_ReopenIdx: {
94122
+case OP_ReopenIdx: { /* ncycle */
9390594123
int nField;
9390694124
KeyInfo *pKeyInfo;
9390794125
u32 p2;
9390894126
int iDb;
9390994127
int wrFlag;
@@ -93920,11 +94138,11 @@
9392094138
sqlite3BtreeClearCursor(pCur->uc.pCursor);
9392194139
goto open_cursor_set_hints;
9392294140
}
9392394141
/* If the cursor is not currently open or is open on a different
9392494142
** index, then fall through into OP_OpenRead to force a reopen */
93925
-case OP_OpenRead:
94143
+case OP_OpenRead: /* ncycle */
9392694144
case OP_OpenWrite:
9392794145
9392894146
assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
9392994147
assert( p->bIsReader );
9393094148
assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx
@@ -94014,11 +94232,11 @@
9401494232
** cursor P2. The P2 cursor must have been opened by a prior OP_OpenEphemeral
9401594233
** opcode. Only ephemeral cursors may be duplicated.
9401694234
**
9401794235
** Duplicate ephemeral cursors are used for self-joins of materialized views.
9401894236
*/
94019
-case OP_OpenDup: {
94237
+case OP_OpenDup: { /* ncycle */
9402094238
VdbeCursor *pOrig; /* The original cursor to be duplicated */
9402194239
VdbeCursor *pCx; /* The new cursor */
9402294240
9402394241
pOrig = p->apCsr[pOp->p2];
9402494242
assert( pOrig );
@@ -94076,12 +94294,12 @@
9407694294
** This opcode works the same as OP_OpenEphemeral. It has a
9407794295
** different name to distinguish its use. Tables created using
9407894296
** by this opcode will be used for automatically created transient
9407994297
** indices in joins.
9408094298
*/
94081
-case OP_OpenAutoindex:
94082
-case OP_OpenEphemeral: {
94299
+case OP_OpenAutoindex: /* ncycle */
94300
+case OP_OpenEphemeral: { /* ncycle */
9408394301
VdbeCursor *pCx;
9408494302
KeyInfo *pKeyInfo;
9408594303
9408694304
static const int vfsFlags =
9408794305
SQLITE_OPEN_READWRITE |
@@ -94235,11 +94453,11 @@
9423594453
/* Opcode: Close P1 * * * *
9423694454
**
9423794455
** Close a cursor previously opened as P1. If P1 is not
9423894456
** currently open, this instruction is a no-op.
9423994457
*/
94240
-case OP_Close: {
94458
+case OP_Close: { /* ncycle */
9424194459
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
9424294460
sqlite3VdbeFreeCursor(p, p->apCsr[pOp->p1]);
9424394461
p->apCsr[pOp->p1] = 0;
9424494462
break;
9424594463
}
@@ -94352,14 +94570,14 @@
9435294570
** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
9435394571
** is an equality search.
9435494572
**
9435594573
** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
9435694574
*/
94357
-case OP_SeekLT: /* jump, in3, group */
94358
-case OP_SeekLE: /* jump, in3, group */
94359
-case OP_SeekGE: /* jump, in3, group */
94360
-case OP_SeekGT: { /* jump, in3, group */
94575
+case OP_SeekLT: /* jump, in3, group, ncycle */
94576
+case OP_SeekLE: /* jump, in3, group, ncycle */
94577
+case OP_SeekGE: /* jump, in3, group, ncycle */
94578
+case OP_SeekGT: { /* jump, in3, group, ncycle */
9436194579
int res; /* Comparison result */
9436294580
int oc; /* Opcode */
9436394581
VdbeCursor *pC; /* The cursor to seek */
9436494582
UnpackedRecord r; /* The key to seek for */
9436594583
int nField; /* Number of columns or fields in the key */
@@ -94621,11 +94839,11 @@
9462194839
** <li> If the cursor ends up on a valid row that is past the target row
9462294840
** (indicating that the target row does not exist in the btree) then
9462394841
** jump to SeekOP.P2 if This.P5==0 or to This.P2 if This.P5>0.
9462494842
** </ol>
9462594843
*/
94626
-case OP_SeekScan: {
94844
+case OP_SeekScan: { /* ncycle */
9462794845
VdbeCursor *pC;
9462894846
int res;
9462994847
int nStep;
9463094848
UnpackedRecord r;
9463194849
@@ -94743,11 +94961,11 @@
9474394961
** OP_IfNoHope opcode might run to see if the IN loop can be abandoned
9474494962
** early, thus saving work. This is part of the IN-early-out optimization.
9474594963
**
9474694964
** P1 must be a valid b-tree cursor.
9474794965
*/
94748
-case OP_SeekHit: {
94966
+case OP_SeekHit: { /* ncycle */
9474994967
VdbeCursor *pC;
9475094968
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
9475194969
pC = p->apCsr[pOp->p1];
9475294970
assert( pC!=0 );
9475394971
assert( pOp->p3>=pOp->p2 );
@@ -94875,11 +95093,11 @@
9487595093
** advanced in either direction. In other words, the Next and Prev
9487695094
** opcodes do not work after this operation.
9487795095
**
9487895096
** See also: NotFound, Found, NotExists
9487995097
*/
94880
-case OP_IfNoHope: { /* jump, in3 */
95098
+case OP_IfNoHope: { /* jump, in3, ncycle */
9488195099
VdbeCursor *pC;
9488295100
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
9488395101
pC = p->apCsr[pOp->p1];
9488495102
assert( pC!=0 );
9488595103
#ifdef SQLITE_DEBUG
@@ -94889,13 +95107,13 @@
9488995107
#endif
9489095108
if( pC->seekHit>=pOp->p4.i ) break;
9489195109
/* Fall through into OP_NotFound */
9489295110
/* no break */ deliberate_fall_through
9489395111
}
94894
-case OP_NoConflict: /* jump, in3 */
94895
-case OP_NotFound: /* jump, in3 */
94896
-case OP_Found: { /* jump, in3 */
95112
+case OP_NoConflict: /* jump, in3, ncycle */
95113
+case OP_NotFound: /* jump, in3, ncycle */
95114
+case OP_Found: { /* jump, in3, ncycle */
9489795115
int alreadyExists;
9489895116
int ii;
9489995117
VdbeCursor *pC;
9490095118
UnpackedRecord *pIdxKey;
9490195119
UnpackedRecord r;
@@ -95021,11 +95239,11 @@
9502195239
** in either direction. In other words, the Next and Prev opcodes will
9502295240
** not work following this opcode.
9502395241
**
9502495242
** See also: Found, NotFound, NoConflict, SeekRowid
9502595243
*/
95026
-case OP_SeekRowid: { /* jump, in3 */
95244
+case OP_SeekRowid: { /* jump, in3, ncycle */
9502795245
VdbeCursor *pC;
9502895246
BtCursor *pCrsr;
9502995247
int res;
9503095248
u64 iKey;
9503195249
@@ -95046,11 +95264,11 @@
9504695264
iKey = x.u.i;
9504795265
goto notExistsWithKey;
9504895266
}
9504995267
/* Fall through into OP_NotExists */
9505095268
/* no break */ deliberate_fall_through
95051
-case OP_NotExists: /* jump, in3 */
95269
+case OP_NotExists: /* jump, in3, ncycle */
9505295270
pIn3 = &aMem[pOp->p3];
9505395271
assert( (pIn3->flags & MEM_Int)!=0 || pOp->opcode==OP_SeekRowid );
9505495272
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
9505595273
iKey = pIn3->u.i;
9505695274
notExistsWithKey:
@@ -95670,11 +95888,11 @@
9567095888
**
9567195889
** P1 can be either an ordinary table or a virtual table. There used to
9567295890
** be a separate OP_VRowid opcode for use with virtual tables, but this
9567395891
** one opcode now works for both table types.
9567495892
*/
95675
-case OP_Rowid: { /* out2 */
95893
+case OP_Rowid: { /* out2, ncycle */
9567695894
VdbeCursor *pC;
9567795895
i64 v;
9567895896
sqlite3_vtab *pVtab;
9567995897
const sqlite3_module *pModule;
9568095898
@@ -95769,12 +95987,12 @@
9576995987
**
9577095988
** This opcode leaves the cursor configured to move in reverse order,
9577195989
** from the end toward the beginning. In other words, the cursor is
9577295990
** configured to use Prev, not Next.
9577395991
*/
95774
-case OP_SeekEnd:
95775
-case OP_Last: { /* jump */
95992
+case OP_SeekEnd: /* ncycle */
95993
+case OP_Last: { /* jump, ncycle */
9577695994
VdbeCursor *pC;
9577795995
BtCursor *pCrsr;
9577895996
int res;
9577995997
9578095998
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -95875,11 +96093,11 @@
9587596093
**
9587696094
** This opcode leaves the cursor configured to move in forward order,
9587796095
** from the beginning toward the end. In other words, the cursor is
9587896096
** configured to use Next, not Prev.
9587996097
*/
95880
-case OP_Rewind: { /* jump */
96098
+case OP_Rewind: { /* jump, ncycle */
9588196099
VdbeCursor *pC;
9588296100
BtCursor *pCrsr;
9588396101
int res;
9588496102
9588596103
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -95969,11 +96187,11 @@
9596996187
pC = p->apCsr[pOp->p1];
9597096188
assert( isSorter(pC) );
9597196189
rc = sqlite3VdbeSorterNext(db, pC);
9597296190
goto next_tail;
9597396191
95974
-case OP_Prev: /* jump */
96192
+case OP_Prev: /* jump, ncycle */
9597596193
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
9597696194
assert( pOp->p5==0
9597796195
|| pOp->p5==SQLITE_STMTSTATUS_FULLSCAN_STEP
9597896196
|| pOp->p5==SQLITE_STMTSTATUS_AUTOINDEX);
9597996197
pC = p->apCsr[pOp->p1];
@@ -95984,11 +96202,11 @@
9598496202
|| pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope
9598596203
|| pC->seekOp==OP_NullRow);
9598696204
rc = sqlite3BtreePrevious(pC->uc.pCursor, pOp->p3);
9598796205
goto next_tail;
9598896206
95989
-case OP_Next: /* jump */
96207
+case OP_Next: /* jump, ncycle */
9599096208
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
9599196209
assert( pOp->p5==0
9599296210
|| pOp->p5==SQLITE_STMTSTATUS_FULLSCAN_STEP
9599396211
|| pOp->p5==SQLITE_STMTSTATUS_AUTOINDEX);
9599496212
pC = p->apCsr[pOp->p1];
@@ -96176,12 +96394,12 @@
9617696394
** the end of the index key pointed to by cursor P1. This integer should be
9617796395
** the rowid of the table entry to which this index entry points.
9617896396
**
9617996397
** See also: Rowid, MakeRecord.
9618096398
*/
96181
-case OP_DeferredSeek:
96182
-case OP_IdxRowid: { /* out2 */
96399
+case OP_DeferredSeek: /* ncycle */
96400
+case OP_IdxRowid: { /* out2, ncycle */
9618396401
VdbeCursor *pC; /* The P1 index cursor */
9618496402
VdbeCursor *pTabCur; /* The P2 table cursor (OP_DeferredSeek only) */
9618596403
i64 rowid; /* Rowid that P1 current points to */
9618696404
9618796405
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -96239,12 +96457,12 @@
9623996457
**
9624096458
** If cursor P1 was previously moved via OP_DeferredSeek, complete that
9624196459
** seek operation now, without further delay. If the cursor seek has
9624296460
** already occurred, this instruction is a no-op.
9624396461
*/
96244
-case OP_FinishSeek: {
96245
- VdbeCursor *pC; /* The P1 index cursor */
96462
+case OP_FinishSeek: { /* ncycle */
96463
+ VdbeCursor *pC; /* The P1 index cursor */
9624696464
9624796465
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
9624896466
pC = p->apCsr[pOp->p1];
9624996467
if( pC->deferredMoveto ){
9625096468
rc = sqlite3VdbeFinishMoveto(pC);
@@ -96295,14 +96513,14 @@
9629596513
** ROWID on the P1 index.
9629696514
**
9629796515
** If the P1 index entry is less than or equal to the key value then jump
9629896516
** to P2. Otherwise fall through to the next instruction.
9629996517
*/
96300
-case OP_IdxLE: /* jump */
96301
-case OP_IdxGT: /* jump */
96302
-case OP_IdxLT: /* jump */
96303
-case OP_IdxGE: { /* jump */
96518
+case OP_IdxLE: /* jump, ncycle */
96519
+case OP_IdxGT: /* jump, ncycle */
96520
+case OP_IdxLT: /* jump, ncycle */
96521
+case OP_IdxGE: { /* jump, ncycle */
9630496522
VdbeCursor *pC;
9630596523
int res;
9630696524
UnpackedRecord r;
9630796525
9630896526
assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -96919,13 +97137,10 @@
9691997137
pFrame->apCsr = p->apCsr;
9692097138
pFrame->nCursor = p->nCursor;
9692197139
pFrame->aOp = p->aOp;
9692297140
pFrame->nOp = p->nOp;
9692397141
pFrame->token = pProgram->token;
96924
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
96925
- pFrame->anExec = p->anExec;
96926
-#endif
9692797142
#ifdef SQLITE_DEBUG
9692897143
pFrame->iFrameMagic = SQLITE_FRAME_MAGIC;
9692997144
#endif
9693097145
9693197146
pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
@@ -96958,13 +97173,10 @@
9695897173
p->apCsr = (VdbeCursor **)&aMem[p->nMem];
9695997174
pFrame->aOnce = (u8*)&p->apCsr[pProgram->nCsr];
9696097175
memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
9696197176
p->aOp = aOp = pProgram->aOp;
9696297177
p->nOp = pProgram->nOp;
96963
-#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
96964
- p->anExec = 0;
96965
-#endif
9696697178
#ifdef SQLITE_DEBUG
9696797179
/* Verify that second and subsequent executions of the same trigger do not
9696897180
** try to reuse register values from the first use. */
9696997181
{
9697097182
int i;
@@ -97717,11 +97929,11 @@
9771797929
**
9771897930
** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
9771997931
** P1 is a cursor number. This opcode opens a cursor to the virtual
9772097932
** table and stores that cursor in P1.
9772197933
*/
97722
-case OP_VOpen: {
97934
+case OP_VOpen: { /* ncycle */
9772397935
VdbeCursor *pCur;
9772497936
sqlite3_vtab_cursor *pVCur;
9772597937
sqlite3_vtab *pVtab;
9772697938
const sqlite3_module *pModule;
9772797939
@@ -97764,11 +97976,11 @@
9776497976
** can be used as the first argument to sqlite3_vtab_in_first() and
9776597977
** sqlite3_vtab_in_next() to extract all of the values stored in the P1
9776697978
** cursor. Register P3 is used to hold the values returned by
9776797979
** sqlite3_vtab_in_first() and sqlite3_vtab_in_next().
9776897980
*/
97769
-case OP_VInitIn: { /* out2 */
97981
+case OP_VInitIn: { /* out2, ncycle */
9777097982
VdbeCursor *pC; /* The cursor containing the RHS values */
9777197983
ValueList *pRhs; /* New ValueList object to put in reg[P2] */
9777297984
9777397985
pC = p->apCsr[pOp->p1];
9777497986
pRhs = sqlite3_malloc64( sizeof(*pRhs) );
@@ -97801,11 +98013,11 @@
9780198013
** additional parameters which are passed to
9780298014
** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
9780398015
**
9780498016
** A jump is made to P2 if the result set after filtering would be empty.
9780598017
*/
97806
-case OP_VFilter: { /* jump */
98018
+case OP_VFilter: { /* jump, ncycle */
9780798019
int nArg;
9780898020
int iQuery;
9780998021
const sqlite3_module *pModule;
9781098022
Mem *pQuery;
9781198023
Mem *pArgc;
@@ -97861,11 +98073,11 @@
9786198073
** function to return true inside the xColumn method of the virtual
9786298074
** table implementation. The P5 column might also contain other
9786398075
** bits (OPFLAG_LENGTHARG or OPFLAG_TYPEOFARG) but those bits are
9786498076
** unused by OP_VColumn.
9786598077
*/
97866
-case OP_VColumn: {
98078
+case OP_VColumn: { /* ncycle */
9786798079
sqlite3_vtab *pVtab;
9786898080
const sqlite3_module *pModule;
9786998081
Mem *pDest;
9787098082
sqlite3_context sContext;
9787198083
@@ -97913,11 +98125,11 @@
9791398125
**
9791498126
** Advance virtual table P1 to the next row in its result set and
9791598127
** jump to instruction P2. Or, if the virtual table has reached
9791698128
** the end of its result set, then fall through to the next instruction.
9791798129
*/
97918
-case OP_VNext: { /* jump */
98130
+case OP_VNext: { /* jump, ncycle */
9791998131
sqlite3_vtab *pVtab;
9792098132
const sqlite3_module *pModule;
9792198133
int res;
9792298134
VdbeCursor *pCur;
9792398135
@@ -98496,16 +98708,16 @@
9849698708
** readability. From this point on down, the normal indentation rules are
9849798709
** restored.
9849898710
*****************************************************************************/
9849998711
}
9850098712
98501
-#ifdef VDBE_PROFILE
98502
- {
98503
- u64 endTime = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
98504
- if( endTime>start ) pOrigOp->cycles += endTime - start;
98505
- pOrigOp->cnt++;
98506
- }
98713
+#if defined(VDBE_PROFILE)
98714
+ *pnCycle += sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
98715
+ pnCycle = 0;
98716
+#elif defined(SQLITE_ENABLE_STMT_SCANSTATUS)
98717
+ *pnCycle += sqlite3Hwtime();
98718
+ pnCycle = 0;
9850798719
#endif
9850898720
9850998721
/* The following code adds nothing to the actual functionality
9851098722
** of the program. It is only here for testing and debugging.
9851198723
** On the other hand, it does burn CPU cycles every time through
@@ -98577,10 +98789,22 @@
9857798789
9857898790
/* This is the only way out of this procedure. We have to
9857998791
** release the mutexes on btrees that were acquired at the
9858098792
** top. */
9858198793
vdbe_return:
98794
+#if defined(VDBE_PROFILE)
98795
+ if( pnCycle ){
98796
+ *pnCycle += sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
98797
+ pnCycle = 0;
98798
+ }
98799
+#elif defined(SQLITE_ENABLE_STMT_SCANSTATUS)
98800
+ if( pnCycle ){
98801
+ *pnCycle += sqlite3Hwtime();
98802
+ pnCycle = 0;
98803
+ }
98804
+#endif
98805
+
9858298806
#ifndef SQLITE_OMIT_PROGRESS_CALLBACK
9858398807
while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
9858498808
nProgressLimit += db->nProgressOps;
9858598809
if( db->xProgress(db->pProgressArg) ){
9858698810
nProgressLimit = LARGEST_UINT64;
@@ -105224,51 +105448,124 @@
105224105448
** SELECT a AS b FROM t1 WHERE b;
105225105449
** SELECT * FROM t1 WHERE (select a from t1);
105226105450
*/
105227105451
SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr){
105228105452
int op;
105229
- while( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
105230
- assert( pExpr->op==TK_COLLATE
105231
- || pExpr->op==TK_IF_NULL_ROW
105232
- || (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW) );
105233
- pExpr = pExpr->pLeft;
105234
- assert( pExpr!=0 );
105235
- }
105236105453
op = pExpr->op;
105237
- if( op==TK_REGISTER ) op = pExpr->op2;
105238
- if( op==TK_COLUMN || (op==TK_AGG_COLUMN && pExpr->y.pTab!=0) ){
105239
- assert( ExprUseYTab(pExpr) );
105240
- assert( pExpr->y.pTab!=0 );
105241
- return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
105242
- }
105243
- if( op==TK_SELECT ){
105244
- assert( ExprUseXSelect(pExpr) );
105245
- assert( pExpr->x.pSelect!=0 );
105246
- assert( pExpr->x.pSelect->pEList!=0 );
105247
- assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
105248
- return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
105249
- }
105454
+ while( 1 /* exit-by-break */ ){
105455
+ if( op==TK_COLUMN || (op==TK_AGG_COLUMN && pExpr->y.pTab!=0) ){
105456
+ assert( ExprUseYTab(pExpr) );
105457
+ assert( pExpr->y.pTab!=0 );
105458
+ return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
105459
+ }
105460
+ if( op==TK_SELECT ){
105461
+ assert( ExprUseXSelect(pExpr) );
105462
+ assert( pExpr->x.pSelect!=0 );
105463
+ assert( pExpr->x.pSelect->pEList!=0 );
105464
+ assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
105465
+ return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
105466
+ }
105250105467
#ifndef SQLITE_OMIT_CAST
105251
- if( op==TK_CAST ){
105252
- assert( !ExprHasProperty(pExpr, EP_IntValue) );
105253
- return sqlite3AffinityType(pExpr->u.zToken, 0);
105254
- }
105468
+ if( op==TK_CAST ){
105469
+ assert( !ExprHasProperty(pExpr, EP_IntValue) );
105470
+ return sqlite3AffinityType(pExpr->u.zToken, 0);
105471
+ }
105255105472
#endif
105256
- if( op==TK_SELECT_COLUMN ){
105257
- assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
105258
- assert( pExpr->iColumn < pExpr->iTable );
105259
- assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
105260
- return sqlite3ExprAffinity(
105261
- pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
105262
- );
105263
- }
105264
- if( op==TK_VECTOR ){
105265
- assert( ExprUseXList(pExpr) );
105266
- return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
105473
+ if( op==TK_SELECT_COLUMN ){
105474
+ assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
105475
+ assert( pExpr->iColumn < pExpr->iTable );
105476
+ assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
105477
+ return sqlite3ExprAffinity(
105478
+ pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
105479
+ );
105480
+ }
105481
+ if( op==TK_VECTOR ){
105482
+ assert( ExprUseXList(pExpr) );
105483
+ return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
105484
+ }
105485
+ if( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
105486
+ assert( pExpr->op==TK_COLLATE
105487
+ || pExpr->op==TK_IF_NULL_ROW
105488
+ || (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW) );
105489
+ pExpr = pExpr->pLeft;
105490
+ op = pExpr->op;
105491
+ continue;
105492
+ }
105493
+ if( op!=TK_REGISTER || (op = pExpr->op2)==TK_REGISTER ) break;
105267105494
}
105268105495
return pExpr->affExpr;
105269105496
}
105497
+
105498
+/*
105499
+** Make a guess at all the possible datatypes of the result that could
105500
+** be returned by an expression. Return a bitmask indicating the answer:
105501
+**
105502
+** 0x01 Numeric
105503
+** 0x02 Text
105504
+** 0x04 Blob
105505
+**
105506
+** If the expression must return NULL, then 0x00 is returned.
105507
+*/
105508
+SQLITE_PRIVATE int sqlite3ExprDataType(const Expr *pExpr){
105509
+ while( pExpr ){
105510
+ switch( pExpr->op ){
105511
+ case TK_COLLATE:
105512
+ case TK_IF_NULL_ROW:
105513
+ case TK_UPLUS: {
105514
+ pExpr = pExpr->pLeft;
105515
+ break;
105516
+ }
105517
+ case TK_NULL: {
105518
+ pExpr = 0;
105519
+ break;
105520
+ }
105521
+ case TK_STRING: {
105522
+ return 0x02;
105523
+ }
105524
+ case TK_BLOB: {
105525
+ return 0x04;
105526
+ }
105527
+ case TK_CONCAT: {
105528
+ return 0x06;
105529
+ }
105530
+ case TK_VARIABLE:
105531
+ case TK_AGG_FUNCTION:
105532
+ case TK_FUNCTION: {
105533
+ return 0x07;
105534
+ }
105535
+ case TK_COLUMN:
105536
+ case TK_AGG_COLUMN:
105537
+ case TK_SELECT:
105538
+ case TK_CAST:
105539
+ case TK_SELECT_COLUMN:
105540
+ case TK_VECTOR: {
105541
+ int aff = sqlite3ExprAffinity(pExpr);
105542
+ if( aff>=SQLITE_AFF_NUMERIC ) return 0x05;
105543
+ if( aff==SQLITE_AFF_TEXT ) return 0x06;
105544
+ return 0x07;
105545
+ }
105546
+ case TK_CASE: {
105547
+ int res = 0;
105548
+ int ii;
105549
+ ExprList *pList = pExpr->x.pList;
105550
+ assert( ExprUseXList(pExpr) && pList!=0 );
105551
+ assert( pList->nExpr > 0);
105552
+ for(ii=1; ii<pList->nExpr; ii+=2){
105553
+ res |= sqlite3ExprDataType(pList->a[ii].pExpr);
105554
+ }
105555
+ if( pList->nExpr % 2 ){
105556
+ res |= sqlite3ExprDataType(pList->a[pList->nExpr-1].pExpr);
105557
+ }
105558
+ return res;
105559
+ }
105560
+ default: {
105561
+ return 0x01;
105562
+ }
105563
+ } /* End of switch(op) */
105564
+ } /* End of while(pExpr) */
105565
+ return 0x00;
105566
+}
105270105567
105271105568
/*
105272105569
** Set the collating sequence for expression pExpr to be the collating
105273105570
** sequence named by pToken. Return a pointer to a new Expr node that
105274105571
** implements the COLLATE operator.
@@ -108437,10 +108734,13 @@
108437108734
int rReg = 0; /* Register storing resulting */
108438108735
Select *pSel; /* SELECT statement to encode */
108439108736
SelectDest dest; /* How to deal with SELECT result */
108440108737
int nReg; /* Registers to allocate */
108441108738
Expr *pLimit; /* New limit expression */
108739
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
108740
+ int addrExplain; /* Address of OP_Explain instruction */
108741
+#endif
108442108742
108443108743
Vdbe *v = pParse->pVdbe;
108444108744
assert( v!=0 );
108445108745
if( pParse->nErr ) return 0;
108446108746
testcase( pExpr->op==TK_EXISTS );
@@ -108489,12 +108789,13 @@
108489108789
** into a register and return that register number.
108490108790
**
108491108791
** In both cases, the query is augmented with "LIMIT 1". Any
108492108792
** preexisting limit is discarded in place of the new LIMIT 1.
108493108793
*/
108494
- ExplainQueryPlan((pParse, 1, "%sSCALAR SUBQUERY %d",
108794
+ ExplainQueryPlan2(addrExplain, (pParse, 1, "%sSCALAR SUBQUERY %d",
108495108795
addrOnce?"":"CORRELATED ", pSel->selId));
108796
+ sqlite3VdbeScanStatusCounters(v, addrExplain, addrExplain, -1);
108496108797
nReg = pExpr->op==TK_SELECT ? pSel->pEList->nExpr : 1;
108497108798
sqlite3SelectDestInit(&dest, 0, pParse->nMem+1);
108498108799
pParse->nMem += nReg;
108499108800
if( pExpr->op==TK_SELECT ){
108500108801
dest.eDest = SRT_Mem;
@@ -108533,10 +108834,11 @@
108533108834
pExpr->iTable = rReg = dest.iSDParm;
108534108835
ExprSetVVAProperty(pExpr, EP_NoReduce);
108535108836
if( addrOnce ){
108536108837
sqlite3VdbeJumpHere(v, addrOnce);
108537108838
}
108839
+ sqlite3VdbeScanStatusRange(v, addrExplain, addrExplain, -1);
108538108840
108539108841
/* Subroutine return */
108540108842
assert( ExprUseYSub(pExpr) );
108541108843
assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn
108542108844
|| pParse->nErr );
@@ -119973,12 +120275,11 @@
119973120275
&pTable->nCol, &pTable->aCol);
119974120276
if( pParse->nErr==0
119975120277
&& pTable->nCol==pSel->pEList->nExpr
119976120278
){
119977120279
assert( db->mallocFailed==0 );
119978
- sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
119979
- SQLITE_AFF_NONE);
120280
+ sqlite3SubqueryColumnTypes(pParse, pTable, pSel, SQLITE_AFF_NONE);
119980120281
}
119981120282
}else{
119982120283
/* CREATE VIEW name AS... without an argument list. Construct
119983120284
** the column names from the SELECT statement that defines the view.
119984120285
*/
@@ -137508,10 +137809,14 @@
137508137809
int iCsr; /* Cursor number for table */
137509137810
int nKey; /* Number of PK columns for table pTab (>=1) */
137510137811
} aDefer[4];
137511137812
#endif
137512137813
struct RowLoadInfo *pDeferredRowLoad; /* Deferred row loading info or NULL */
137814
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
137815
+ int addrPush; /* First instruction to push data into sorter */
137816
+ int addrPushEnd; /* Last instruction that pushes data into sorter */
137817
+#endif
137513137818
};
137514137819
#define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
137515137820
137516137821
/*
137517137822
** Delete all the content of a Select structure. Deallocate the structure
@@ -138163,10 +138468,14 @@
138163138468
** SortCtx.pDeferredRowLoad optimiation. In any of these cases
138164138469
** regOrigData is 0 to prevent this routine from trying to copy
138165138470
** values that might not yet exist.
138166138471
*/
138167138472
assert( nData==1 || regData==regOrigData || regOrigData==0 );
138473
+
138474
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
138475
+ pSort->addrPush = sqlite3VdbeCurrentAddr(v);
138476
+#endif
138168138477
138169138478
if( nPrefixReg ){
138170138479
assert( nPrefixReg==nExpr+bSeq );
138171138480
regBase = regData - nPrefixReg;
138172138481
}else{
@@ -138264,10 +138573,13 @@
138264138573
regBase+nOBSat, nBase-nOBSat);
138265138574
if( iSkip ){
138266138575
sqlite3VdbeChangeP2(v, iSkip,
138267138576
pSort->labelOBLopt ? pSort->labelOBLopt : sqlite3VdbeCurrentAddr(v));
138268138577
}
138578
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
138579
+ pSort->addrPushEnd = sqlite3VdbeCurrentAddr(v)-1;
138580
+#endif
138269138581
}
138270138582
138271138583
/*
138272138584
** Add code to implement the OFFSET
138273138585
*/
@@ -138730,13 +139042,10 @@
138730139042
testcase( eDest==SRT_Table );
138731139043
testcase( eDest==SRT_EphemTab );
138732139044
testcase( eDest==SRT_Fifo );
138733139045
testcase( eDest==SRT_DistFifo );
138734139046
sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1+nPrefixReg);
138735
- if( pDest->zAffSdst ){
138736
- sqlite3VdbeChangeP4(v, -1, pDest->zAffSdst, nResultCol);
138737
- }
138738139047
#ifndef SQLITE_OMIT_CTE
138739139048
if( eDest==SRT_DistFifo ){
138740139049
/* If the destination is DistFifo, then cursor (iParm+1) is open
138741139050
** on an ephemeral index. If the current row is already present
138742139051
** in the index, do not write it to the output. If not, add the
@@ -139090,10 +139399,20 @@
139090139399
int iSortTab; /* Sorter cursor to read from */
139091139400
int i;
139092139401
int bSeq; /* True if sorter record includes seq. no. */
139093139402
int nRefKey = 0;
139094139403
struct ExprList_item *aOutEx = p->pEList->a;
139404
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
139405
+ int addrExplain; /* Address of OP_Explain instruction */
139406
+#endif
139407
+
139408
+ ExplainQueryPlan2(addrExplain, (pParse, 0,
139409
+ "USE TEMP B-TREE FOR %sORDER BY", pSort->nOBSat>0?"RIGHT PART OF ":"")
139410
+ );
139411
+ sqlite3VdbeScanStatusRange(v, addrExplain,pSort->addrPush,pSort->addrPushEnd);
139412
+ sqlite3VdbeScanStatusCounters(v, addrExplain, addrExplain, pSort->addrPush);
139413
+
139095139414
139096139415
assert( addrBreak<0 );
139097139416
if( pSort->labelBkOut ){
139098139417
sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
139099139418
sqlite3VdbeGoto(v, addrBreak);
@@ -139202,10 +139521,11 @@
139202139521
}
139203139522
sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i);
139204139523
VdbeComment((v, "%s", aOutEx[i].zEName));
139205139524
}
139206139525
}
139526
+ sqlite3VdbeScanStatusRange(v, addrExplain, addrExplain, -1);
139207139527
switch( eDest ){
139208139528
case SRT_Table:
139209139529
case SRT_EphemTab: {
139210139530
sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq, regRow);
139211139531
sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
@@ -139263,10 +139583,11 @@
139263139583
if( pSort->sortFlags & SORTFLAG_UseSorter ){
139264139584
sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr); VdbeCoverage(v);
139265139585
}else{
139266139586
sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); VdbeCoverage(v);
139267139587
}
139588
+ sqlite3VdbeScanStatusRange(v, addrExplain, sqlite3VdbeCurrentAddr(v)-1, -1);
139268139589
if( pSort->regReturn ) sqlite3VdbeAddOp1(v, OP_Return, pSort->regReturn);
139269139590
sqlite3VdbeResolveLabel(v, addrBreak);
139270139591
}
139271139592
139272139593
/*
@@ -139293,10 +139614,11 @@
139293139614
#ifdef SQLITE_ENABLE_COLUMN_METADATA
139294139615
# define columnType(A,B,C,D,E) columnTypeImpl(A,B,C,D,E)
139295139616
#else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */
139296139617
# define columnType(A,B,C,D,E) columnTypeImpl(A,B)
139297139618
#endif
139619
+#ifndef SQLITE_OMIT_DECLTYPE
139298139620
static const char *columnTypeImpl(
139299139621
NameContext *pNC,
139300139622
#ifndef SQLITE_ENABLE_COLUMN_METADATA
139301139623
Expr *pExpr
139302139624
#else
@@ -139439,10 +139761,11 @@
139439139761
*pzOrigCol = zOrigCol;
139440139762
}
139441139763
#endif
139442139764
return zType;
139443139765
}
139766
+#endif /* !defined(SQLITE_OMIT_DECLTYPE) */
139444139767
139445139768
/*
139446139769
** Generate code that will tell the VDBE the declaration types of columns
139447139770
** in the result set.
139448139771
*/
@@ -139710,51 +140033,94 @@
139710140033
}
139711140034
return SQLITE_OK;
139712140035
}
139713140036
139714140037
/*
139715
-** Add type and collation information to a column list based on
139716
-** a SELECT statement.
139717
-**
139718
-** The column list presumably came from selectColumnNamesFromExprList().
139719
-** The column list has only names, not types or collations. This
139720
-** routine goes through and adds the types and collations.
139721
-**
139722
-** This routine requires that all identifiers in the SELECT
139723
-** statement be resolved.
139724
-*/
139725
-SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(
139726
- Parse *pParse, /* Parsing contexts */
139727
- Table *pTab, /* Add column type information to this table */
139728
- Select *pSelect, /* SELECT used to determine types and collations */
139729
- char aff /* Default affinity for columns */
140038
+** This bit, when added to the "aff" parameter of
140039
+** sqlite3ColumnTypeOfSubquery() means that result set
140040
+** expressions of the form "CAST(expr AS NUMERIC)" should result in
140041
+** NONE affinity rather than NUMERIC affinity.
140042
+*/
140043
+#define SQLITE_AFF_FLAG1 0x10
140044
+
140045
+/*
140046
+** pTab is a transient Table object that represents a subquery of some
140047
+** kind (maybe a parenthesized subquery in the FROM clause of a larger
140048
+** query, or a VIEW, or a CTE). This routine computes type information
140049
+** for that Table object based on the Select object that implements the
140050
+** subquery. For the purposes of this routine, "type infomation" means:
140051
+**
140052
+** * The datatype name, as it might appear in a CREATE TABLE statement
140053
+** * Which collating sequence to use for the column
140054
+** * The affinity of the column
140055
+**
140056
+** The SQLITE_AFF_FLAG1 bit added to parameter aff means that a
140057
+** result set column of the form "CAST(expr AS NUMERIC)" should use
140058
+** NONE affinity rather than NUMERIC affinity. See the
140059
+** 2022-12-10 "reopen" of ticket https://sqlite.org/src/tktview/57c47526c3.
140060
+*/
140061
+SQLITE_PRIVATE void sqlite3SubqueryColumnTypes(
140062
+ Parse *pParse, /* Parsing contexts */
140063
+ Table *pTab, /* Add column type information to this table */
140064
+ Select *pSelect, /* SELECT used to determine types and collations */
140065
+ char aff /* Default affinity. Maybe with SQLITE_AFF_FLAG1 too */
139730140066
){
139731140067
sqlite3 *db = pParse->db;
139732
- NameContext sNC;
139733140068
Column *pCol;
139734140069
CollSeq *pColl;
139735
- int i;
140070
+ int i,j;
139736140071
Expr *p;
139737140072
struct ExprList_item *a;
139738140073
139739140074
assert( pSelect!=0 );
139740140075
assert( (pSelect->selFlags & SF_Resolved)!=0 );
139741140076
assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
139742140077
if( db->mallocFailed ) return;
139743
- memset(&sNC, 0, sizeof(sNC));
139744
- sNC.pSrcList = pSelect->pSrc;
140078
+ while( pSelect->pPrior ) pSelect = pSelect->pPrior;
139745140079
a = pSelect->pEList->a;
139746140080
for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
139747140081
const char *zType;
139748
- i64 n, m;
140082
+ i64 n;
139749140083
pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT);
139750140084
p = a[i].pExpr;
139751
- zType = columnType(&sNC, p, 0, 0, 0);
139752140085
/* pCol->szEst = ... // Column size est for SELECT tables never used */
139753140086
pCol->affinity = sqlite3ExprAffinity(p);
140087
+ if( pCol->affinity<=SQLITE_AFF_NONE ){
140088
+ assert( (SQLITE_AFF_FLAG1 & SQLITE_AFF_MASK)==0 );
140089
+ pCol->affinity = aff & SQLITE_AFF_MASK;
140090
+ }
140091
+ if( aff & SQLITE_AFF_FLAG1 ){
140092
+ if( pCol->affinity==SQLITE_AFF_NUMERIC && p->op==TK_CAST ){
140093
+ pCol->affinity = SQLITE_AFF_NONE;
140094
+ }
140095
+ }
140096
+ if( pCol->affinity>=SQLITE_AFF_TEXT && pSelect->pNext ){
140097
+ int m = 0;
140098
+ Select *pS2;
140099
+ for(m=0, pS2=pSelect->pNext; pS2; pS2=pS2->pNext){
140100
+ m |= sqlite3ExprDataType(pS2->pEList->a[i].pExpr);
140101
+ }
140102
+ if( pCol->affinity==SQLITE_AFF_TEXT && (m&0x01)!=0 ){
140103
+ pCol->affinity = SQLITE_AFF_BLOB;
140104
+ }else
140105
+ if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){
140106
+ pCol->affinity = SQLITE_AFF_BLOB;
140107
+ }
140108
+ }
140109
+ if( pCol->affinity==SQLITE_AFF_NUMERIC ){
140110
+ zType = "NUM";
140111
+ }else{
140112
+ zType = 0;
140113
+ for(j=1; j<SQLITE_N_STDTYPE; j++){
140114
+ if( sqlite3StdTypeAffinity[j]==pCol->affinity ){
140115
+ zType = sqlite3StdType[j];
140116
+ break;
140117
+ }
140118
+ }
140119
+ }
139754140120
if( zType ){
139755
- m = sqlite3Strlen30(zType);
140121
+ i64 m = sqlite3Strlen30(zType);
139756140122
n = sqlite3Strlen30(pCol->zCnName);
139757140123
pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2);
139758140124
if( pCol->zCnName ){
139759140125
memcpy(&pCol->zCnName[n+1], zType, m+1);
139760140126
pCol->colFlags |= COLFLAG_HASTYPE;
@@ -139761,11 +140127,10 @@
139761140127
}else{
139762140128
testcase( pCol->colFlags & COLFLAG_HASTYPE );
139763140129
pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL);
139764140130
}
139765140131
}
139766
- if( pCol->affinity<=SQLITE_AFF_NONE ) pCol->affinity = aff;
139767140132
pColl = sqlite3ExprCollSeq(pParse, p);
139768140133
if( pColl ){
139769140134
assert( pTab->pIndex==0 );
139770140135
sqlite3ColumnSetColl(db, pCol, pColl->zName);
139771140136
}
@@ -139795,11 +140160,11 @@
139795140160
}
139796140161
pTab->nTabRef = 1;
139797140162
pTab->zName = 0;
139798140163
pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
139799140164
sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
139800
- sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSelect, aff);
140165
+ sqlite3SubqueryColumnTypes(pParse, pTab, pSelect, aff);
139801140166
pTab->iPKey = -1;
139802140167
if( db->mallocFailed ){
139803140168
sqlite3DeleteTable(db, pTab);
139804140169
return 0;
139805140170
}
@@ -143606,18 +143971,18 @@
143606143971
#ifndef SQLITE_OMIT_SUBQUERY
143607143972
/*
143608143973
** This is a Walker.xSelectCallback callback for the sqlite3SelectTypeInfo()
143609143974
** interface.
143610143975
**
143611
-** For each FROM-clause subquery, add Column.zType and Column.zColl
143612
-** information to the Table structure that represents the result set
143613
-** of that subquery.
143976
+** For each FROM-clause subquery, add Column.zType, Column.zColl, and
143977
+** Column.affinity information to the Table structure that represents
143978
+** the result set of that subquery.
143614143979
**
143615143980
** The Table structure that represents the result set was constructed
143616
-** by selectExpander() but the type and collation information was omitted
143617
-** at that point because identifiers had not yet been resolved. This
143618
-** routine is called after identifier resolution.
143981
+** by selectExpander() but the type and collation and affinity information
143982
+** was omitted at that point because identifiers had not yet been resolved.
143983
+** This routine is called after identifier resolution.
143619143984
*/
143620143985
static void selectAddSubqueryTypeInfo(Walker *pWalker, Select *p){
143621143986
Parse *pParse;
143622143987
int i;
143623143988
SrcList *pTabList;
@@ -143633,13 +143998,12 @@
143633143998
assert( pTab!=0 );
143634143999
if( (pTab->tabFlags & TF_Ephemeral)!=0 ){
143635144000
/* A sub-query in the FROM clause of a SELECT */
143636144001
Select *pSel = pFrom->pSelect;
143637144002
if( pSel ){
143638
- while( pSel->pPrior ) pSel = pSel->pPrior;
143639
- sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSel,
143640
- SQLITE_AFF_NONE);
144003
+ sqlite3SubqueryColumnTypes(pParse, pTab, pSel,
144004
+ SQLITE_AFF_NONE|SQLITE_AFF_FLAG1);
143641144005
}
143642144006
}
143643144007
}
143644144008
}
143645144009
#endif
@@ -144117,23 +144481,28 @@
144117144481
}
144118144482
#endif
144119144483
}
144120144484
144121144485
/*
144122
-** Check to see if the pThis entry of pTabList is a self-join of a prior view.
144123
-** If it is, then return the SrcItem for the prior view. If it is not,
144124
-** then return 0.
144486
+** Check to see if the pThis entry of pTabList is a self-join of another view.
144487
+** Search FROM-clause entries in the range of iFirst..iEnd, including iFirst
144488
+** but stopping before iEnd.
144489
+**
144490
+** If pThis is a self-join, then return the SrcItem for the first other
144491
+** instance of that view found. If pThis is not a self-join then return 0.
144125144492
*/
144126144493
static SrcItem *isSelfJoinView(
144127144494
SrcList *pTabList, /* Search for self-joins in this FROM clause */
144128
- SrcItem *pThis /* Search for prior reference to this subquery */
144495
+ SrcItem *pThis, /* Search for prior reference to this subquery */
144496
+ int iFirst, int iEnd /* Range of FROM-clause entries to search. */
144129144497
){
144130144498
SrcItem *pItem;
144131144499
assert( pThis->pSelect!=0 );
144132144500
if( pThis->pSelect->selFlags & SF_PushDown ) return 0;
144133
- for(pItem = pTabList->a; pItem<pThis; pItem++){
144501
+ while( iFirst<iEnd ){
144134144502
Select *pS1;
144503
+ pItem = &pTabList->a[iFirst++];
144135144504
if( pItem->pSelect==0 ) continue;
144136144505
if( pItem->fg.viaCoroutine ) continue;
144137144506
if( pItem->zName==0 ) continue;
144138144507
assert( pItem->pTab!=0 );
144139144508
assert( pThis->pTab!=0 );
@@ -144273,10 +144642,66 @@
144273144642
return 1;
144274144643
}
144275144644
}
144276144645
return 0;
144277144646
}
144647
+
144648
+/*
144649
+** Return TRUE (non-zero) if the i-th entry in the pTabList SrcList can
144650
+** be implemented as a co-routine. The i-th entry is guaranteed to be
144651
+** a subquery.
144652
+**
144653
+** The subquery is implemented as a co-routine if all of the following are
144654
+** true:
144655
+**
144656
+** (1) The subquery will likely be implemented in the outer loop of
144657
+** the query. This will be the case if any one of the following
144658
+** conditions hold:
144659
+** (a) The subquery is the only term in the FROM clause
144660
+** (b) The subquery is the left-most term and a CROSS JOIN or similar
144661
+** requires it to be the outer loop
144662
+** (c) All of the following are true:
144663
+** (i) The subquery is the left-most subquery in the FROM clause
144664
+** (ii) There is nothing that would prevent the subquery from
144665
+** being used as the outer loop if the sqlite3WhereBegin()
144666
+** routine nominates it to that position.
144667
+** (iii) The query is not a UPDATE ... FROM
144668
+** (2) The subquery is not a CTE that should be materialized because of
144669
+** the AS MATERIALIZED keywords
144670
+** (3) The subquery is not part of a left operand for a RIGHT JOIN
144671
+** (4) The SQLITE_Coroutine optimization disable flag is not set
144672
+** (5) The subquery is not self-joined
144673
+*/
144674
+static int fromClauseTermCanBeCoroutine(
144675
+ Parse *pParse, /* Parsing context */
144676
+ SrcList *pTabList, /* FROM clause */
144677
+ int i, /* Which term of the FROM clause holds the subquery */
144678
+ int selFlags /* Flags on the SELECT statement */
144679
+){
144680
+ SrcItem *pItem = &pTabList->a[i];
144681
+ if( pItem->fg.isCte && pItem->u2.pCteUse->eM10d==M10d_Yes ) return 0;/* (2) */
144682
+ if( pTabList->a[0].fg.jointype & JT_LTORJ ) return 0; /* (3) */
144683
+ if( OptimizationDisabled(pParse->db, SQLITE_Coroutines) ) return 0; /* (4) */
144684
+ if( isSelfJoinView(pTabList, pItem, i+1, pTabList->nSrc)!=0 ){
144685
+ return 0; /* (5) */
144686
+ }
144687
+ if( i==0 ){
144688
+ if( pTabList->nSrc==1 ) return 1; /* (1a) */
144689
+ if( pTabList->a[1].fg.jointype & JT_CROSS ) return 1; /* (1b) */
144690
+ if( selFlags & SF_UpdateFrom ) return 0; /* (1c-iii) */
144691
+ return 1;
144692
+ }
144693
+ if( selFlags & SF_UpdateFrom ) return 0; /* (1c-iii) */
144694
+ while( 1 /*exit-by-break*/ ){
144695
+ if( pItem->fg.jointype & (JT_OUTER|JT_CROSS) ) return 0; /* (1c-ii) */
144696
+ if( i==0 ) break;
144697
+ i--;
144698
+ pItem--;
144699
+ if( pItem->pSelect!=0 ) return 0; /* (1c-i) */
144700
+ }
144701
+ return 1;
144702
+}
144278144703
144279144704
/*
144280144705
** Generate code for the SELECT statement given in the p argument.
144281144706
**
144282144707
** The results are returned according to the SelectDest structure.
@@ -144661,25 +145086,12 @@
144661145086
144662145087
zSavedAuthContext = pParse->zAuthContext;
144663145088
pParse->zAuthContext = pItem->zName;
144664145089
144665145090
/* Generate code to implement the subquery
144666
- **
144667
- ** The subquery is implemented as a co-routine if all of the following are
144668
- ** true:
144669
- **
144670
- ** (1) the subquery is guaranteed to be the outer loop (so that
144671
- ** it does not need to be computed more than once), and
144672
- ** (2) the subquery is not a CTE that should be materialized
144673
- ** (3) the subquery is not part of a left operand for a RIGHT JOIN
144674145091
*/
144675
- if( i==0
144676
- && (pTabList->nSrc==1
144677
- || (pTabList->a[1].fg.jointype&(JT_OUTER|JT_CROSS))!=0) /* (1) */
144678
- && (pItem->fg.isCte==0 || pItem->u2.pCteUse->eM10d!=M10d_Yes) /* (2) */
144679
- && (pTabList->a[0].fg.jointype & JT_LTORJ)==0 /* (3) */
144680
- ){
145092
+ if( fromClauseTermCanBeCoroutine(pParse, pTabList, i, p->selFlags) ){
144681145093
/* Implement a co-routine that will return a single row of the result
144682145094
** set on each invocation.
144683145095
*/
144684145096
int addrTop = sqlite3VdbeCurrentAddr(v)+1;
144685145097
@@ -144706,11 +145118,11 @@
144706145118
if( pItem->iCursor!=pCteUse->iCur ){
144707145119
sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pCteUse->iCur);
144708145120
VdbeComment((v, "%!S", pItem));
144709145121
}
144710145122
pSub->nSelectRow = pCteUse->nRowEst;
144711
- }else if( (pPrior = isSelfJoinView(pTabList, pItem))!=0 ){
145123
+ }else if( (pPrior = isSelfJoinView(pTabList, pItem, 0, i))!=0 ){
144712145124
/* This view has already been materialized by a prior entry in
144713145125
** this same FROM clause. Reuse it. */
144714145126
if( pPrior->addrFillSub ){
144715145127
sqlite3VdbeAddOp2(v, OP_Gosub, pPrior->regReturn, pPrior->addrFillSub);
144716145128
}
@@ -144720,10 +145132,13 @@
144720145132
/* Materialize the view. If the view is not correlated, generate a
144721145133
** subroutine to do the materialization so that subsequent uses of
144722145134
** the same view can reuse the materialization. */
144723145135
int topAddr;
144724145136
int onceAddr = 0;
145137
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
145138
+ int addrExplain;
145139
+#endif
144725145140
144726145141
pItem->regReturn = ++pParse->nMem;
144727145142
topAddr = sqlite3VdbeAddOp0(v, OP_Goto);
144728145143
pItem->addrFillSub = topAddr+1;
144729145144
pItem->fg.isMaterialized = 1;
@@ -144735,19 +145150,18 @@
144735145150
VdbeComment((v, "materialize %!S", pItem));
144736145151
}else{
144737145152
VdbeNoopComment((v, "materialize %!S", pItem));
144738145153
}
144739145154
sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
144740
- ExplainQueryPlan((pParse, 1, "MATERIALIZE %!S", pItem));
144741
- dest.zAffSdst = sqlite3TableAffinityStr(db, pItem->pTab);
145155
+
145156
+ ExplainQueryPlan2(addrExplain, (pParse, 1, "MATERIALIZE %!S", pItem));
144742145157
sqlite3Select(pParse, pSub, &dest);
144743
- sqlite3DbFree(db, dest.zAffSdst);
144744
- dest.zAffSdst = 0;
144745145158
pItem->pTab->nRowLogEst = pSub->nSelectRow;
144746145159
if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
144747145160
sqlite3VdbeAddOp2(v, OP_Return, pItem->regReturn, topAddr+1);
144748145161
VdbeComment((v, "end %!S", pItem));
145162
+ sqlite3VdbeScanStatusRange(v, addrExplain, addrExplain, -1);
144749145163
sqlite3VdbeJumpHere(v, topAddr);
144750145164
sqlite3ClearTempRegCache(pParse);
144751145165
if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
144752145166
CteUse *pCteUse = pItem->u2.pCteUse;
144753145167
pCteUse->addrM9e = pItem->addrFillSub;
@@ -145498,12 +145912,10 @@
145498145912
145499145913
/* If there is an ORDER BY clause, then we need to sort the results
145500145914
** and send them to the callback one by one.
145501145915
*/
145502145916
if( sSort.pOrderBy ){
145503
- explainTempTable(pParse,
145504
- sSort.nOBSat>0 ? "RIGHT PART OF ORDER BY":"ORDER BY");
145505145917
assert( p->pEList==pEList );
145506145918
generateSortTail(pParse, p, &sSort, pEList->nExpr, pDest);
145507145919
}
145508145920
145509145921
/* Jump here to skip this query
@@ -147492,11 +147904,12 @@
147492147904
sqlite3ExprDup(db, pChanges->a[i].pExpr, 0)
147493147905
);
147494147906
}
147495147907
}
147496147908
pSelect = sqlite3SelectNew(pParse, pList,
147497
- pSrc, pWhere2, pGrp, 0, pOrderBy2, SF_UFSrcCheck|SF_IncludeHidden, pLimit2
147909
+ pSrc, pWhere2, pGrp, 0, pOrderBy2,
147910
+ SF_UFSrcCheck|SF_IncludeHidden|SF_UpdateFrom, pLimit2
147498147911
);
147499147912
if( pSelect ) pSelect->selFlags |= SF_OrderByReqd;
147500147913
sqlite3SelectDestInit(&dest, eDest, iEph);
147501147914
dest.iSDParm2 = (pPk ? pPk->nKeyCol : -1);
147502147915
sqlite3Select(pParse, pSelect, &dest);
@@ -151576,10 +151989,12 @@
151576151989
}
151577151990
sqlite3_str_append(&str, ")", 1);
151578151991
zMsg = sqlite3StrAccumFinish(&str);
151579151992
ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v),
151580151993
pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
151994
+
151995
+ sqlite3VdbeScanStatus(v, sqlite3VdbeCurrentAddr(v)-1, 0, 0, 0, 0);
151581151996
return ret;
151582151997
}
151583151998
#endif /* SQLITE_OMIT_EXPLAIN */
151584151999
151585152000
#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
@@ -151598,18 +152013,31 @@
151598152013
WhereLevel *pLvl, /* Level to add scanstatus() entry for */
151599152014
int addrExplain /* Address of OP_Explain (or 0) */
151600152015
){
151601152016
const char *zObj = 0;
151602152017
WhereLoop *pLoop = pLvl->pWLoop;
151603
- if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 && pLoop->u.btree.pIndex!=0 ){
152018
+ int wsFlags = pLoop->wsFlags;
152019
+ int viaCoroutine = 0;
152020
+
152021
+ if( (wsFlags & WHERE_VIRTUALTABLE)==0 && pLoop->u.btree.pIndex!=0 ){
151604152022
zObj = pLoop->u.btree.pIndex->zName;
151605152023
}else{
151606152024
zObj = pSrclist->a[pLvl->iFrom].zName;
152025
+ viaCoroutine = pSrclist->a[pLvl->iFrom].fg.viaCoroutine;
151607152026
}
151608152027
sqlite3VdbeScanStatus(
151609152028
v, addrExplain, pLvl->addrBody, pLvl->addrVisit, pLoop->nOut, zObj
151610152029
);
152030
+
152031
+ if( viaCoroutine==0 ){
152032
+ if( (wsFlags & (WHERE_MULTI_OR|WHERE_AUTO_INDEX))==0 ){
152033
+ sqlite3VdbeScanStatusRange(v, addrExplain, -1, pLvl->iTabCur);
152034
+ }
152035
+ if( wsFlags & WHERE_INDEXED ){
152036
+ sqlite3VdbeScanStatusRange(v, addrExplain, -1, pLvl->iIdxCur);
152037
+ }
152038
+ }
151611152039
}
151612152040
#endif
151613152041
151614152042
151615152043
/*
@@ -155999,11 +156427,11 @@
155999156427
** terms means that no sorting is needed at all. A return that
156000156428
** is positive but less than the number of ORDER BY terms means that
156001156429
** block sorting is required.
156002156430
*/
156003156431
SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo *pWInfo){
156004
- return pWInfo->nOBSat;
156432
+ return pWInfo->nOBSat<0 ? 0 : pWInfo->nOBSat;
156005156433
}
156006156434
156007156435
/*
156008156436
** In the ORDER BY LIMIT optimization, if the inner-most loop is known
156009156437
** to emit rows in increasing order, and if the last row emitted by the
@@ -156744,10 +157172,61 @@
156744157172
}
156745157173
#endif
156746157174
156747157175
156748157176
#ifndef SQLITE_OMIT_AUTOMATIC_INDEX
157177
+
157178
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
157179
+/*
157180
+** Argument pIdx represents an automatic index that the current statement
157181
+** will create and populate. Add an OP_Explain with text of the form:
157182
+**
157183
+** CREATE AUTOMATIC INDEX ON <table>(<cols>) [WHERE <expr>]
157184
+**
157185
+** This is only required if sqlite3_stmt_scanstatus() is enabled, to
157186
+** associate an SQLITE_SCANSTAT_NCYCLE and SQLITE_SCANSTAT_NLOOP
157187
+** values with. In order to avoid breaking legacy code and test cases,
157188
+** the OP_Explain is not added if this is an EXPLAIN QUERY PLAN command.
157189
+*/
157190
+static void explainAutomaticIndex(
157191
+ Parse *pParse,
157192
+ Index *pIdx, /* Automatic index to explain */
157193
+ int bPartial, /* True if pIdx is a partial index */
157194
+ int *pAddrExplain /* OUT: Address of OP_Explain */
157195
+){
157196
+ if( pParse->explain!=2 ){
157197
+ Table *pTab = pIdx->pTable;
157198
+ const char *zSep = "";
157199
+ char *zText = 0;
157200
+ int ii = 0;
157201
+ sqlite3_str *pStr = sqlite3_str_new(pParse->db);
157202
+ sqlite3_str_appendf(pStr,"CREATE AUTOMATIC INDEX ON %s(", pTab->zName);
157203
+ assert( pIdx->nColumn>1 );
157204
+ assert( pIdx->aiColumn[pIdx->nColumn-1]==XN_ROWID );
157205
+ for(ii=0; ii<(pIdx->nColumn-1); ii++){
157206
+ const char *zName = 0;
157207
+ int iCol = pIdx->aiColumn[ii];
157208
+
157209
+ zName = pTab->aCol[iCol].zCnName;
157210
+ sqlite3_str_appendf(pStr, "%s%s", zSep, zName);
157211
+ zSep = ", ";
157212
+ }
157213
+ zText = sqlite3_str_finish(pStr);
157214
+ if( zText==0 ){
157215
+ sqlite3OomFault(pParse->db);
157216
+ }else{
157217
+ *pAddrExplain = sqlite3VdbeExplain(
157218
+ pParse, 0, "%s)%s", zText, (bPartial ? " WHERE <expr>" : "")
157219
+ );
157220
+ sqlite3_free(zText);
157221
+ }
157222
+ }
157223
+}
157224
+#else
157225
+# define explainAutomaticIndex(a,b,c,d)
157226
+#endif
157227
+
156749157228
/*
156750157229
** Generate code to construct the Index object for an automatic index
156751157230
** and to set up the WhereLevel object pLevel so that the code generator
156752157231
** makes use of the automatic index.
156753157232
*/
@@ -156779,10 +157258,13 @@
156779157258
Expr *pPartial = 0; /* Partial Index Expression */
156780157259
int iContinue = 0; /* Jump here to skip excluded rows */
156781157260
SrcItem *pTabItem; /* FROM clause term being indexed */
156782157261
int addrCounter = 0; /* Address where integer counter is initialized */
156783157262
int regBase; /* Array of registers where record is assembled */
157263
+#ifdef SQLITE_ENABLE_STMT_SCANSTATUS
157264
+ int addrExp = 0; /* Address of OP_Explain */
157265
+#endif
156784157266
156785157267
/* Generate code to skip over the creation and initialization of the
156786157268
** transient index on 2nd and subsequent iterations of the loop. */
156787157269
v = pParse->pVdbe;
156788157270
assert( v!=0 );
@@ -156902,10 +157384,11 @@
156902157384
assert( n==nKeyCol );
156903157385
pIdx->aiColumn[n] = XN_ROWID;
156904157386
pIdx->azColl[n] = sqlite3StrBINARY;
156905157387
156906157388
/* Create the automatic index */
157389
+ explainAutomaticIndex(pParse, pIdx, pPartial!=0, &addrExp);
156907157390
assert( pLevel->iIdxCur>=0 );
156908157391
pLevel->iIdxCur = pParse->nTab++;
156909157392
sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
156910157393
sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
156911157394
VdbeComment((v, "for %s", pTable->zName));
@@ -156937,10 +157420,11 @@
156937157420
);
156938157421
if( pLevel->regFilter ){
156939157422
sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0,
156940157423
regBase, pLoop->u.btree.nEq);
156941157424
}
157425
+ sqlite3VdbeScanStatusCounters(v, addrExp, addrExp, sqlite3VdbeCurrentAddr(v));
156942157426
sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
156943157427
sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
156944157428
if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
156945157429
if( pTabItem->fg.viaCoroutine ){
156946157430
sqlite3VdbeChangeP2(v, addrCounter, regBase+n);
@@ -156957,10 +157441,11 @@
156957157441
sqlite3VdbeJumpHere(v, addrTop);
156958157442
sqlite3ReleaseTempReg(pParse, regRecord);
156959157443
156960157444
/* Jump here when skipping the initialization */
156961157445
sqlite3VdbeJumpHere(v, addrInit);
157446
+ sqlite3VdbeScanStatusRange(v, addrExp, addrExp, -1);
156962157447
156963157448
end_auto_index_create:
156964157449
sqlite3ExprDelete(pParse->db, pPartial);
156965157450
}
156966157451
#endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
@@ -174461,10 +174946,11 @@
174461174946
case SQLITE_ROW: zName = "SQLITE_ROW"; break;
174462174947
case SQLITE_NOTICE: zName = "SQLITE_NOTICE"; break;
174463174948
case SQLITE_NOTICE_RECOVER_WAL: zName = "SQLITE_NOTICE_RECOVER_WAL";break;
174464174949
case SQLITE_NOTICE_RECOVER_ROLLBACK:
174465174950
zName = "SQLITE_NOTICE_RECOVER_ROLLBACK"; break;
174951
+ case SQLITE_NOTICE_RBU: zName = "SQLITE_NOTICE_RBU"; break;
174466174952
case SQLITE_WARNING: zName = "SQLITE_WARNING"; break;
174467174953
case SQLITE_WARNING_AUTOINDEX: zName = "SQLITE_WARNING_AUTOINDEX"; break;
174468174954
case SQLITE_DONE: zName = "SQLITE_DONE"; break;
174469174955
}
174470174956
}
@@ -175013,11 +175499,11 @@
175013175499
#endif
175014175500
sqlite3_mutex_enter(db->mutex);
175015175501
rc = sqlite3FindFunction(db, zName, nArg, SQLITE_UTF8, 0)!=0;
175016175502
sqlite3_mutex_leave(db->mutex);
175017175503
if( rc ) return SQLITE_OK;
175018
- zCopy = sqlite3_mprintf(zName);
175504
+ zCopy = sqlite3_mprintf("%s", zName);
175019175505
if( zCopy==0 ) return SQLITE_NOMEM;
175020175506
return sqlite3_create_function_v2(db, zName, nArg, SQLITE_UTF8,
175021175507
zCopy, sqlite3InvalidFunction, 0, 0, sqlite3_free);
175022175508
}
175023175509
@@ -211261,25 +211747,25 @@
211261211747
** * Calls to xShmLock(UNLOCK) to release the exclusive shm WRITER,
211262211748
** READ0 and CHECKPOINT locks taken as part of the checkpoint are
211263211749
** no-ops. These locks will not be released until the connection
211264211750
** is closed.
211265211751
**
211266
- ** * Attempting to xSync() the database file causes an SQLITE_INTERNAL
211752
+ ** * Attempting to xSync() the database file causes an SQLITE_NOTICE
211267211753
** error.
211268211754
**
211269211755
** As a result, unless an error (i.e. OOM or SQLITE_BUSY) occurs, the
211270
- ** checkpoint below fails with SQLITE_INTERNAL, and leaves the aFrame[]
211756
+ ** checkpoint below fails with SQLITE_NOTICE, and leaves the aFrame[]
211271211757
** array populated with a set of (frame -> page) mappings. Because the
211272211758
** WRITER, CHECKPOINT and READ0 locks are still held, it is safe to copy
211273211759
** data from the wal file into the database file according to the
211274211760
** contents of aFrame[].
211275211761
*/
211276211762
if( p->rc==SQLITE_OK ){
211277211763
int rc2;
211278211764
p->eStage = RBU_STAGE_CAPTURE;
211279211765
rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0);
211280
- if( rc2!=SQLITE_INTERNAL ) p->rc = rc2;
211766
+ if( rc2!=SQLITE_NOTICE ) p->rc = rc2;
211281211767
}
211282211768
211283211769
if( p->rc==SQLITE_OK && p->nFrame>0 ){
211284211770
p->eStage = RBU_STAGE_CKPT;
211285211771
p->nStep = (pState ? pState->nRow : 0);
@@ -211321,11 +211807,11 @@
211321211807
const u32 mReq = (1<<WAL_LOCK_WRITE)|(1<<WAL_LOCK_CKPT)|(1<<WAL_LOCK_READ0);
211322211808
u32 iFrame;
211323211809
211324211810
if( pRbu->mLock!=mReq ){
211325211811
pRbu->rc = SQLITE_BUSY;
211326
- return SQLITE_INTERNAL;
211812
+ return SQLITE_NOTICE_RBU;
211327211813
}
211328211814
211329211815
pRbu->pgsz = iAmt;
211330211816
if( pRbu->nFrame==pRbu->nFrameAlloc ){
211331211817
int nNew = (pRbu->nFrameAlloc ? pRbu->nFrameAlloc : 64) * 2;
@@ -212708,11 +213194,11 @@
212708213194
** are recorded. Additionally, successful attempts to obtain exclusive
212709213195
** xShmLock() WRITER, CHECKPOINTER and READ0 locks on the target
212710213196
** database file are recorded. xShmLock() calls to unlock the same
212711213197
** locks are no-ops (so that once obtained, these locks are never
212712213198
** relinquished). Finally, calls to xSync() on the target database
212713
-** file fail with SQLITE_INTERNAL errors.
213199
+** file fail with SQLITE_NOTICE errors.
212714213200
*/
212715213201
212716213202
static void rbuUnlockShm(rbu_file *p){
212717213203
assert( p->openFlags & SQLITE_OPEN_MAIN_DB );
212718213204
if( p->pRbu ){
@@ -212987,11 +213473,11 @@
212987213473
*/
212988213474
static int rbuVfsSync(sqlite3_file *pFile, int flags){
212989213475
rbu_file *p = (rbu_file *)pFile;
212990213476
if( p->pRbu && p->pRbu->eStage==RBU_STAGE_CAPTURE ){
212991213477
if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
212992
- return SQLITE_INTERNAL;
213478
+ return SQLITE_NOTICE_RBU;
212993213479
}
212994213480
return SQLITE_OK;
212995213481
}
212996213482
return p->pReal->pMethods->xSync(p->pReal, flags);
212997213483
}
@@ -218263,10 +218749,26 @@
218263218749
}
218264218750
}else if( p->bInvert ){
218265218751
if( p->op==SQLITE_INSERT ) p->op = SQLITE_DELETE;
218266218752
else if( p->op==SQLITE_DELETE ) p->op = SQLITE_INSERT;
218267218753
}
218754
+
218755
+ /* If this is an UPDATE that is part of a changeset, then check that
218756
+ ** there are no fields in the old.* record that are not (a) PK fields,
218757
+ ** or (b) also present in the new.* record.
218758
+ **
218759
+ ** Such records are technically corrupt, but the rebaser was at one
218760
+ ** point generating them. Under most circumstances this is benign, but
218761
+ ** can cause spurious SQLITE_RANGE errors when applying the changeset. */
218762
+ if( p->bPatchset==0 && p->op==SQLITE_UPDATE){
218763
+ for(i=0; i<p->nCol; i++){
218764
+ if( p->abPK[i]==0 && p->apValue[i+p->nCol]==0 ){
218765
+ sqlite3ValueFree(p->apValue[i]);
218766
+ p->apValue[i] = 0;
218767
+ }
218768
+ }
218769
+ }
218268218770
}
218269218771
218270218772
return SQLITE_ROW;
218271218773
}
218272218774
@@ -220459,11 +220961,11 @@
220459220961
int n2 = sessionSerialLen(a2);
220460220962
if( pIter->abPK[i] || a2[0]==0 ){
220461220963
if( !pIter->abPK[i] && a1[0] ) bData = 1;
220462220964
memcpy(pOut, a1, n1);
220463220965
pOut += n1;
220464
- }else if( a2[0]!=0xFF ){
220966
+ }else if( a2[0]!=0xFF && a1[0] ){
220465220967
bData = 1;
220466220968
memcpy(pOut, a2, n2);
220467220969
pOut += n2;
220468220970
}else{
220469220971
*pOut++ = '\0';
@@ -239022,11 +239524,11 @@
239022239524
int nArg, /* Number of args */
239023239525
sqlite3_value **apUnused /* Function arguments */
239024239526
){
239025239527
assert( nArg==0 );
239026239528
UNUSED_PARAM2(nArg, apUnused);
239027
- sqlite3_result_text(pCtx, "fts5: 2022-12-03 19:04:09 1a61c500add4a2bfe80c0c691d559cfca166dc5f8262651a58da7ec16a51d430", -1, SQLITE_TRANSIENT);
239529
+ sqlite3_result_text(pCtx, "fts5: 2022-12-15 15:37:52 751e344f4cd2045caf97920cc9f4571caf0de1ba83b94ded902a03b36c10a389", -1, SQLITE_TRANSIENT);
239028239530
}
239029239531
239030239532
/*
239031239533
** Return true if zName is the extension on one of the shadow tables used
239032239534
** by this module.
239033239535
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.41.0"
456 #define SQLITE_VERSION_NUMBER 3041000
457 #define SQLITE_SOURCE_ID "2022-12-05 02:52:37 1b779afa3ed2f35a110e460fc6ed13cba744db85b9924149ab028b100d1e1e12"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -867,10 +867,11 @@
867 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
868 #define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
869 #define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))
870 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
871 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
 
872 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
873 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
874 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
875 #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
876
@@ -2488,11 +2489,11 @@
2488 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
2489 ** rounded down to the next smaller multiple of 8. ^(The lookaside memory
2490 ** configuration for a database connection can only be changed when that
2491 ** connection is not currently using lookaside memory, or in other words
2492 ** when the "current value" returned by
2493 ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
2494 ** Any attempt to change the lookaside memory configuration when lookaside
2495 ** memory is in use leaves the configuration unchanged and returns
2496 ** [SQLITE_BUSY].)^</dd>
2497 **
2498 ** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
@@ -2638,12 +2639,16 @@
2638 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
2639 ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
2640 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
2641 ** </ol>
2642 ** Because resetting a database is destructive and irreversible, the
2643 ** process requires the use of this obscure API and multiple steps to help
2644 ** ensure that it does not happen by accident.
 
 
 
 
2645 **
2646 ** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
2647 ** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
2648 ** "defensive" flag for a database connection. When the defensive
2649 ** flag is enabled, language features that allow ordinary SQL to
@@ -7318,19 +7323,10 @@
7318 ** ^This interface disables all automatic extensions previously
7319 ** registered using [sqlite3_auto_extension()].
7320 */
7321 SQLITE_API void sqlite3_reset_auto_extension(void);
7322
7323 /*
7324 ** The interface to the virtual-table mechanism is currently considered
7325 ** to be experimental. The interface might change in incompatible ways.
7326 ** If this is a problem for you, do not use the interface at this time.
7327 **
7328 ** When the virtual-table mechanism stabilizes, we will declare the
7329 ** interface fixed, support it indefinitely, and remove this comment.
7330 */
7331
7332 /*
7333 ** Structures used by the virtual table interface
7334 */
7335 typedef struct sqlite3_vtab sqlite3_vtab;
7336 typedef struct sqlite3_index_info sqlite3_index_info;
@@ -7568,11 +7564,11 @@
7568 **
7569 ** The collating sequence to be used for comparison can be found using
7570 ** the [sqlite3_vtab_collation()] interface. For most real-world virtual
7571 ** tables, the collating sequence of constraints does not matter (for example
7572 ** because the constraints are numeric) and so the sqlite3_vtab_collation()
7573 ** interface is no commonly needed.
7574 */
7575 #define SQLITE_INDEX_CONSTRAINT_EQ 2
7576 #define SQLITE_INDEX_CONSTRAINT_GT 4
7577 #define SQLITE_INDEX_CONSTRAINT_LE 8
7578 #define SQLITE_INDEX_CONSTRAINT_LT 16
@@ -7727,20 +7723,10 @@
7727 ** purpose is to be a placeholder function that can be overloaded
7728 ** by a [virtual table].
7729 */
7730 SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
7731
7732 /*
7733 ** The interface to the virtual-table mechanism defined above (back up
7734 ** to a comment remarkably similar to this one) is currently considered
7735 ** to be experimental. The interface might change in incompatible ways.
7736 ** If this is a problem for you, do not use the interface at this time.
7737 **
7738 ** When the virtual-table mechanism stabilizes, we will declare the
7739 ** interface fixed, support it indefinitely, and remove this comment.
7740 */
7741
7742 /*
7743 ** CAPI3REF: A Handle To An Open BLOB
7744 ** KEYWORDS: {BLOB handle} {BLOB handles}
7745 **
7746 ** An instance of this object represents an open BLOB on which
@@ -9940,11 +9926,11 @@
9940 ** statement that was passed into [sqlite3_declare_vtab()], then the
9941 ** name of that alternative collating sequence is returned.
9942 ** <li><p> Otherwise, "BINARY" is returned.
9943 ** </ol>
9944 */
9945 SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9946
9947 /*
9948 ** CAPI3REF: Determine if a virtual table query is DISTINCT
9949 ** METHOD: sqlite3_index_info
9950 **
@@ -10209,10 +10195,14 @@
10209 **
10210 ** When the value returned to V is a string, space to hold that string is
10211 ** managed by the prepared statement S and will be automatically freed when
10212 ** S is finalized.
10213 **
 
 
 
 
10214 ** <dl>
10215 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
10216 ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
10217 ** set to the total number of times that the X-th loop has run.</dd>
10218 **
@@ -10236,30 +10226,44 @@
10236 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
10237 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10238 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
10239 ** description for the X-th loop.
10240 **
10241 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
10242 ** <dd>^The "int" variable pointed to by the V parameter will be set to the
10243 ** "select-id" for the X-th loop. The select-id identifies which query or
10244 ** subquery the loop is part of. The main query has a select-id of zero.
10245 ** The select-id is the same value as is output in the first column
10246 ** of an [EXPLAIN QUERY PLAN] query.
10247 ** </dl>
 
 
 
 
 
 
 
 
 
 
 
 
 
10248 */
10249 #define SQLITE_SCANSTAT_NLOOP 0
10250 #define SQLITE_SCANSTAT_NVISIT 1
10251 #define SQLITE_SCANSTAT_EST 2
10252 #define SQLITE_SCANSTAT_NAME 3
10253 #define SQLITE_SCANSTAT_EXPLAIN 4
10254 #define SQLITE_SCANSTAT_SELECTID 5
 
 
10255
10256 /*
10257 ** CAPI3REF: Prepared Statement Scan Status
10258 ** METHOD: sqlite3_stmt
10259 **
10260 ** This interface returns information about the predicted and measured
10261 ** performance for pStmt. Advanced applications can use this
10262 ** interface to compare the predicted and the measured performance and
10263 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
10264 **
10265 ** Since this interface is expected to be rarely used, it is only
@@ -10266,32 +10270,51 @@
10266 ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
10267 ** compile-time option.
10268 **
10269 ** The "iScanStatusOp" parameter determines which status information to return.
10270 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
10271 ** of this interface is undefined.
10272 ** ^The requested measurement is written into a variable pointed to by
10273 ** the "pOut" parameter.
10274 ** Parameter "idx" identifies the specific loop to retrieve statistics for.
10275 ** Loops are numbered starting from zero. ^If idx is out of range - less than
10276 ** zero or greater than or equal to the total number of loops used to implement
10277 ** the statement - a non-zero value is returned and the variable that pOut
10278 ** points to is unchanged.
10279 **
10280 ** ^Statistics might not be available for all loops in all statements. ^In cases
10281 ** where there exist loops with no available statistics, this function behaves
10282 ** as if the loop did not exist - it returns non-zero and leave the variable
10283 ** that pOut points to unchanged.
 
 
 
 
 
 
 
 
 
 
 
 
10284 **
10285 ** See also: [sqlite3_stmt_scanstatus_reset()]
10286 */
10287 SQLITE_API int sqlite3_stmt_scanstatus(
10288 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
10289 int idx, /* Index of loop to report on */
10290 int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
10291 void *pOut /* Result written here */
10292 );
 
 
 
 
 
 
 
 
 
 
 
 
 
10293
10294 /*
10295 ** CAPI3REF: Zero Scan-Status Counters
10296 ** METHOD: sqlite3_stmt
10297 **
@@ -15901,17 +15924,17 @@
15901 #endif
15902 } p4;
15903 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
15904 char *zComment; /* Comment to improve readability */
15905 #endif
15906 #ifdef VDBE_PROFILE
15907 u32 cnt; /* Number of times this instruction was executed */
15908 u64 cycles; /* Total time spent executing this instruction */
15909 #endif
15910 #ifdef SQLITE_VDBE_COVERAGE
15911 u32 iSrcLine; /* Source-code line that generated this opcode
15912 ** with flags in the upper 8 bits */
 
 
 
 
15913 #endif
15914 };
15915 typedef struct VdbeOp VdbeOp;
15916
15917
@@ -16199,33 +16222,34 @@
16199 #define OPFLG_IN1 0x02 /* in1: P1 is an input */
16200 #define OPFLG_IN2 0x04 /* in2: P2 is an input */
16201 #define OPFLG_IN3 0x08 /* in3: P3 is an input */
16202 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
16203 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
 
16204 #define OPFLG_INITIALIZER {\
16205 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00,\
16206 /* 8 */ 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01,\
16207 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x09, 0x09, 0x09,\
16208 /* 24 */ 0x09, 0x01, 0x09, 0x09, 0x09, 0x09, 0x09, 0x09,\
16209 /* 32 */ 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,\
16210 /* 40 */ 0x01, 0x01, 0x01, 0x26, 0x26, 0x01, 0x23, 0x0b,\
16211 /* 48 */ 0x01, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
16212 /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x01,\
16213 /* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
16214 /* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
16215 /* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
16216 /* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x00, 0x00,\
16217 /* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x00, 0x26, 0x26,\
16218 /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
16219 /* 112 */ 0x00, 0x00, 0x12, 0x00, 0x00, 0x10, 0x00, 0x00,\
16220 /* 120 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10,\
16221 /* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10,\
16222 /* 136 */ 0x00, 0x00, 0x04, 0x04, 0x00, 0x00, 0x10, 0x00,\
16223 /* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
16224 /* 152 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
16225 /* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
16226 /* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00,\
16227 /* 176 */ 0x00, 0x10, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00,\
16228 /* 184 */ 0x00, 0x00, 0x00,}
16229
16230 /* The resolve3P2Values() routine is able to run faster if it knows
16231 ** the value of the largest JUMP opcode. The smaller the maximum
@@ -16276,18 +16300,24 @@
16276 # define sqlite3VdbeVerifyAbortable(A,B)
16277 # define sqlite3VdbeNoJumpsOutsideSubrtn(A,B,C,D)
16278 #endif
16279 SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
16280 #ifndef SQLITE_OMIT_EXPLAIN
16281 SQLITE_PRIVATE void sqlite3VdbeExplain(Parse*,u8,const char*,...);
16282 SQLITE_PRIVATE void sqlite3VdbeExplainPop(Parse*);
16283 SQLITE_PRIVATE int sqlite3VdbeExplainParent(Parse*);
16284 # define ExplainQueryPlan(P) sqlite3VdbeExplain P
 
 
 
 
 
16285 # define ExplainQueryPlanPop(P) sqlite3VdbeExplainPop(P)
16286 # define ExplainQueryPlanParent(P) sqlite3VdbeExplainParent(P)
16287 #else
16288 # define ExplainQueryPlan(P)
 
16289 # define ExplainQueryPlanPop(P)
16290 # define ExplainQueryPlanParent(P) 0
16291 # define sqlite3ExplainBreakpoint(A,B) /*no-op*/
16292 #endif
16293 #if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_EXPLAIN)
@@ -16456,12 +16486,16 @@
16456 # define VDBE_OFFSET_LINENO(x) 0
16457 #endif
16458
16459 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
16460 SQLITE_PRIVATE void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
 
 
16461 #else
16462 # define sqlite3VdbeScanStatus(a,b,c,d,e)
 
 
16463 #endif
16464
16465 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
16466 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, VdbeOp*);
16467 #endif
@@ -17254,10 +17288,11 @@
17254 #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
17255 #define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
17256 #define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
17257 /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
17258 #define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
 
17259 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17260
17261 /*
17262 ** Macros for testing whether or not optimizations are enabled or disabled.
17263 */
@@ -18875,10 +18910,11 @@
18875 #define SF_UFSrcCheck 0x0800000 /* Check pSrc as required by UPDATE...FROM */
18876 #define SF_PushDown 0x1000000 /* SELECT has be modified by push-down opt */
18877 #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */
18878 #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */
18879 #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */
 
18880
18881 /* True if S exists and has SF_NestedFrom */
18882 #define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0)
18883
18884 /*
@@ -18983,11 +19019,11 @@
18983 u8 eDest; /* How to dispose of the results. One of SRT_* above. */
18984 int iSDParm; /* A parameter used by the eDest disposal method */
18985 int iSDParm2; /* A second parameter for the eDest disposal method */
18986 int iSdst; /* Base register where results are written */
18987 int nSdst; /* Number of registers allocated */
18988 char *zAffSdst; /* Affinity used for SRT_Set, SRT_Table, and similar */
18989 ExprList *pOrderBy; /* Key columns for SRT_Queue and SRT_DistQueue */
18990 };
18991
18992 /*
18993 ** During code generation of statements that do inserts into AUTOINCREMENT
@@ -20088,11 +20124,11 @@
20088 SQLITE_PRIVATE void sqlite3ColumnSetColl(sqlite3*,Column*,const char*zColl);
20089 SQLITE_PRIVATE const char *sqlite3ColumnColl(Column*);
20090 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
20091 SQLITE_PRIVATE void sqlite3GenerateColumnNames(Parse *pParse, Select *pSelect);
20092 SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
20093 SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(Parse*,Table*,Select*,char);
20094 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char);
20095 SQLITE_PRIVATE void sqlite3OpenSchemaTable(Parse *, int);
20096 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
20097 SQLITE_PRIVATE i16 sqlite3TableColumnToIndex(Index*, i16);
20098 #ifdef SQLITE_OMIT_GENERATED_COLUMNS
@@ -20459,10 +20495,11 @@
20459 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
20460 SQLITE_PRIVATE char sqlite3CompareAffinity(const Expr *pExpr, char aff2);
20461 SQLITE_PRIVATE int sqlite3IndexAffinityOk(const Expr *pExpr, char idx_affinity);
20462 SQLITE_PRIVATE char sqlite3TableColumnAffinity(const Table*,int);
20463 SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr);
 
20464 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
20465 SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*);
20466 SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...);
20467 SQLITE_PRIVATE void sqlite3Error(sqlite3*,int);
20468 SQLITE_PRIVATE void sqlite3ErrorClear(sqlite3*);
@@ -20975,11 +21012,13 @@
20975
20976 #if SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL)
20977 SQLITE_PRIVATE int sqlite3KvvfsInit(void);
20978 #endif
20979
20980 #if defined(VDBE_PROFILE) || defined(SQLITE_PERFORMANCE_TRACE)
 
 
20981 SQLITE_PRIVATE sqlite3_uint64 sqlite3Hwtime(void);
20982 #endif
20983
20984 #endif /* SQLITEINT_H */
20985
@@ -22464,11 +22503,10 @@
22464 typedef struct VdbeFrame VdbeFrame;
22465 struct VdbeFrame {
22466 Vdbe *v; /* VM this frame belongs to */
22467 VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
22468 Op *aOp; /* Program instructions for parent frame */
22469 i64 *anExec; /* Event counters from parent frame */
22470 Mem *aMem; /* Array of memory cells for parent frame */
22471 VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
22472 u8 *aOnce; /* Bitmask used by OP_Once */
22473 void *token; /* Copy of SubProgram.token */
22474 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
@@ -22680,14 +22718,23 @@
22680 */
22681 typedef unsigned bft; /* Bit Field Type */
22682
22683 /* The ScanStatus object holds a single value for the
22684 ** sqlite3_stmt_scanstatus() interface.
 
 
 
 
 
 
 
 
22685 */
22686 typedef struct ScanStatus ScanStatus;
22687 struct ScanStatus {
22688 int addrExplain; /* OP_Explain for loop */
 
22689 int addrLoop; /* Address of "loops" counter */
22690 int addrVisit; /* Address of "rows visited" counter */
22691 int iSelectID; /* The "Select-ID" for this loop */
22692 LogEst nEst; /* Estimated output rows per loop */
22693 char *zName; /* Name of table or index */
@@ -22776,11 +22823,10 @@
22776 int nFrame; /* Number of frames in pFrame list */
22777 u32 expmask; /* Binding to these vars invalidates VM */
22778 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
22779 AuxData *pAuxData; /* Linked list of auxdata allocations */
22780 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
22781 i64 *anExec; /* Number of times each op has been executed */
22782 int nScan; /* Entries in aScan[] */
22783 ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
22784 #endif
22785 };
22786
@@ -35198,11 +35244,13 @@
35198 }
35199
35200 /*
35201 ** High-resolution hardware timer used for debugging and testing only.
35202 */
35203 #if defined(VDBE_PROFILE) || defined(SQLITE_PERFORMANCE_TRACE)
 
 
35204 /************** Include hwtime.h in the middle of util.c *********************/
35205 /************** Begin file hwtime.h ******************************************/
35206 /*
35207 ** 2008 May 27
35208 **
@@ -35251,13 +35299,13 @@
35251 #endif
35252
35253 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
35254
35255 __inline__ sqlite_uint64 sqlite3Hwtime(void){
35256 unsigned long val;
35257 __asm__ __volatile__ ("rdtsc" : "=A" (val));
35258 return val;
35259 }
35260
35261 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
35262
35263 __inline__ sqlite_uint64 sqlite3Hwtime(void){
@@ -37442,10 +37490,13 @@
37442 if( fd<0 ){
37443 if( errno==EINTR ) continue;
37444 break;
37445 }
37446 if( fd>=SQLITE_MINIMUM_FILE_DESCRIPTOR ) break;
 
 
 
37447 osClose(fd);
37448 sqlite3_log(SQLITE_WARNING,
37449 "attempt to open \"%s\" as file descriptor %d", z, fd);
37450 fd = -1;
37451 if( osOpen("/dev/null", O_RDONLY, m)<0 ) break;
@@ -51436,14 +51487,39 @@
51436 MemFile *pThis = (MemFile*)pFile;
51437 MemStore *p = pThis->pStore;
51438 int rc = SQLITE_OK;
51439 if( eLock==pThis->eLock ) return SQLITE_OK;
51440 memdbEnter(p);
 
51441 if( eLock>SQLITE_LOCK_SHARED ){
 
51442 if( p->mFlags & SQLITE_DESERIALIZE_READONLY ){
51443 rc = SQLITE_READONLY;
51444 }else if( pThis->eLock<=SQLITE_LOCK_SHARED ){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
51445 if( p->nWrLock ){
51446 rc = SQLITE_BUSY;
51447 }else{
51448 p->nWrLock = 1;
51449 }
@@ -82327,21 +82403,21 @@
82327 pOp->p3 = p3;
82328 pOp->p4.p = 0;
82329 pOp->p4type = P4_NOTUSED;
82330 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
82331 pOp->zComment = 0;
 
 
 
 
82332 #endif
82333 #ifdef SQLITE_DEBUG
82334 if( p->db->flags & SQLITE_VdbeAddopTrace ){
82335 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
82336 test_addop_breakpoint(i, &p->aOp[i]);
82337 }
82338 #endif
82339 #ifdef VDBE_PROFILE
82340 pOp->cycles = 0;
82341 pOp->cnt = 0;
82342 #endif
82343 #ifdef SQLITE_VDBE_COVERAGE
82344 pOp->iSrcLine = 0;
82345 #endif
82346 return i;
82347 }
@@ -82505,12 +82581,13 @@
82505 ** Add a new OP_Explain opcode.
82506 **
82507 ** If the bPush flag is true, then make this opcode the parent for
82508 ** subsequent Explains until sqlite3VdbeExplainPop() is called.
82509 */
82510 SQLITE_PRIVATE void sqlite3VdbeExplain(Parse *pParse, u8 bPush, const char *zFmt, ...){
82511 #ifndef SQLITE_DEBUG
 
82512 /* Always include the OP_Explain opcodes if SQLITE_DEBUG is defined.
82513 ** But omit them (for performance) during production builds */
82514 if( pParse->explain==2 )
82515 #endif
82516 {
@@ -82521,17 +82598,19 @@
82521 va_start(ap, zFmt);
82522 zMsg = sqlite3VMPrintf(pParse->db, zFmt, ap);
82523 va_end(ap);
82524 v = pParse->pVdbe;
82525 iThis = v->nOp;
82526 sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
82527 zMsg, P4_DYNAMIC);
82528 sqlite3ExplainBreakpoint(bPush?"PUSH":"", sqlite3VdbeGetLastOp(v)->p4.z);
82529 if( bPush){
82530 pParse->addrExplain = iThis;
82531 }
 
82532 }
 
82533 }
82534
82535 /*
82536 ** Pop the EXPLAIN QUERY PLAN stack one level.
82537 */
@@ -83185,18 +83264,75 @@
83185 sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus);
83186 ScanStatus *aNew;
83187 aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
83188 if( aNew ){
83189 ScanStatus *pNew = &aNew[p->nScan++];
 
83190 pNew->addrExplain = addrExplain;
83191 pNew->addrLoop = addrLoop;
83192 pNew->addrVisit = addrVisit;
83193 pNew->nEst = nEst;
83194 pNew->zName = sqlite3DbStrDup(p->db, zName);
83195 p->aScan = aNew;
83196 }
83197 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83198 #endif
83199
83200
83201 /*
83202 ** Change the value of the opcode, or P1, P2, P3, or P5 operands
@@ -84490,11 +84626,11 @@
84490 /*
84491 ** Rewind the VDBE back to the beginning in preparation for
84492 ** running it.
84493 */
84494 SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){
84495 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
84496 int i;
84497 #endif
84498 assert( p!=0 );
84499 assert( p->eVdbeState==VDBE_INIT_STATE
84500 || p->eVdbeState==VDBE_READY_STATE
@@ -84519,12 +84655,12 @@
84519 p->minWriteFileFormat = 255;
84520 p->iStatement = 0;
84521 p->nFkConstraint = 0;
84522 #ifdef VDBE_PROFILE
84523 for(i=0; i<p->nOp; i++){
84524 p->aOp[i].cnt = 0;
84525 p->aOp[i].cycles = 0;
84526 }
84527 #endif
84528 }
84529
84530 /*
@@ -84629,24 +84765,18 @@
84629 x.nNeeded = 0;
84630 p->aMem = allocSpace(&x, 0, nMem*sizeof(Mem));
84631 p->aVar = allocSpace(&x, 0, nVar*sizeof(Mem));
84632 p->apArg = allocSpace(&x, 0, nArg*sizeof(Mem*));
84633 p->apCsr = allocSpace(&x, 0, nCursor*sizeof(VdbeCursor*));
84634 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
84635 p->anExec = allocSpace(&x, 0, p->nOp*sizeof(i64));
84636 #endif
84637 if( x.nNeeded ){
84638 x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
84639 x.nFree = x.nNeeded;
84640 if( !db->mallocFailed ){
84641 p->aMem = allocSpace(&x, p->aMem, nMem*sizeof(Mem));
84642 p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
84643 p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
84644 p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
84645 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
84646 p->anExec = allocSpace(&x, p->anExec, p->nOp*sizeof(i64));
84647 #endif
84648 }
84649 }
84650
84651 if( db->mallocFailed ){
84652 p->nVar = 0;
@@ -84657,13 +84787,10 @@
84657 p->nVar = (ynVar)nVar;
84658 initMemArray(p->aVar, nVar, db, MEM_Null);
84659 p->nMem = nMem;
84660 initMemArray(p->aMem, nMem, db, MEM_Undefined);
84661 memset(p->apCsr, 0, nCursor*sizeof(VdbeCursor*));
84662 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
84663 memset(p->anExec, 0, p->nOp*sizeof(i64));
84664 #endif
84665 }
84666 sqlite3VdbeRewind(p);
84667 }
84668
84669 /*
@@ -84717,13 +84844,10 @@
84717 ** control to the main program.
84718 */
84719 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
84720 Vdbe *v = pFrame->v;
84721 closeCursorsInFrame(v);
84722 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
84723 v->anExec = pFrame->anExec;
84724 #endif
84725 v->aOp = pFrame->aOp;
84726 v->nOp = pFrame->nOp;
84727 v->aMem = pFrame->aMem;
84728 v->nMem = pFrame->nMem;
84729 v->apCsr = pFrame->apCsr;
@@ -85551,14 +85675,16 @@
85551 }
85552 if( pc!='\n' ) fprintf(out, "\n");
85553 }
85554 for(i=0; i<p->nOp; i++){
85555 char zHdr[100];
 
 
85556 sqlite3_snprintf(sizeof(zHdr), zHdr, "%6u %12llu %8llu ",
85557 p->aOp[i].cnt,
85558 p->aOp[i].cycles,
85559 p->aOp[i].cnt>0 ? p->aOp[i].cycles/p->aOp[i].cnt : 0
85560 );
85561 fprintf(out, "%s", zHdr);
85562 sqlite3VdbePrintOp(out, i, &p->aOp[i]);
85563 }
85564 fclose(out);
@@ -87409,10 +87535,11 @@
87409 ** This file contains code use to implement APIs that are part of the
87410 ** VDBE.
87411 */
87412 /* #include "sqliteInt.h" */
87413 /* #include "vdbeInt.h" */
 
87414
87415 #ifndef SQLITE_OMIT_DEPRECATED
87416 /*
87417 ** Return TRUE (non-zero) of the statement supplied as an argument needs
87418 ** to be recompiled. A statement needs to be recompiled whenever the
@@ -89505,27 +89632,64 @@
89505
89506 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
89507 /*
89508 ** Return status data for a single loop within query pStmt.
89509 */
89510 SQLITE_API int sqlite3_stmt_scanstatus(
89511 sqlite3_stmt *pStmt, /* Prepared statement being queried */
89512 int idx, /* Index of loop to report on */
89513 int iScanStatusOp, /* Which metric to return */
 
89514 void *pOut /* OUT: Write the answer here */
89515 ){
89516 Vdbe *p = (Vdbe*)pStmt;
89517 ScanStatus *pScan;
89518 if( idx<0 || idx>=p->nScan ) return 1;
89519 pScan = &p->aScan[idx];
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89520 switch( iScanStatusOp ){
89521 case SQLITE_SCANSTAT_NLOOP: {
89522 *(sqlite3_int64*)pOut = p->anExec[pScan->addrLoop];
 
 
 
 
89523 break;
89524 }
89525 case SQLITE_SCANSTAT_NVISIT: {
89526 *(sqlite3_int64*)pOut = p->anExec[pScan->addrVisit];
 
 
 
 
89527 break;
89528 }
89529 case SQLITE_SCANSTAT_EST: {
89530 double r = 1.0;
89531 LogEst x = pScan->nEst;
@@ -89553,24 +89717,80 @@
89553 *(int*)pOut = p->aOp[ pScan->addrExplain ].p1;
89554 }else{
89555 *(int*)pOut = -1;
89556 }
89557 break;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
89558 }
89559 default: {
89560 return 1;
89561 }
89562 }
89563 return 0;
89564 }
 
 
 
 
 
 
 
 
 
 
 
 
89565
89566 /*
89567 ** Zero all counters associated with the sqlite3_stmt_scanstatus() data.
89568 */
89569 SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){
89570 Vdbe *p = (Vdbe*)pStmt;
89571 memset(p->anExec, 0, p->nOp * sizeof(i64));
 
 
 
 
 
89572 }
89573 #endif /* SQLITE_ENABLE_STMT_SCANSTATUS */
89574
89575 /************** End of vdbeapi.c *********************************************/
89576 /************** Begin file vdbetrace.c ***************************************/
@@ -90386,11 +90606,10 @@
90386 # define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
90387 #else
90388 # define REGISTER_TRACE(R,M)
90389 #endif
90390
90391
90392 #ifndef NDEBUG
90393 /*
90394 ** This function is only called from within an assert() expression. It
90395 ** checks that the sqlite3.nTransaction variable is correctly set to
90396 ** the number of non-transaction savepoints currently in the
@@ -90476,14 +90695,12 @@
90476 SQLITE_PRIVATE int sqlite3VdbeExec(
90477 Vdbe *p /* The VDBE */
90478 ){
90479 Op *aOp = p->aOp; /* Copy of p->aOp */
90480 Op *pOp = aOp; /* Current operation */
90481 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
90482 Op *pOrigOp; /* Value of pOp at the top of the loop */
90483 #endif
90484 #ifdef SQLITE_DEBUG
90485 int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */
90486 #endif
90487 int rc = SQLITE_OK; /* Value to return */
90488 sqlite3 *db = p->db; /* The database */
90489 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
@@ -90496,12 +90713,12 @@
90496 Mem *aMem = p->aMem; /* Copy of p->aMem */
90497 Mem *pIn1 = 0; /* 1st input operand */
90498 Mem *pIn2 = 0; /* 2nd input operand */
90499 Mem *pIn3 = 0; /* 3rd input operand */
90500 Mem *pOut = 0; /* Output operand */
90501 #ifdef VDBE_PROFILE
90502 u64 start; /* CPU clock count at start of opcode */
90503 #endif
90504 /*** INSERT STACK UNION HERE ***/
90505
90506 assert( p->eVdbeState==VDBE_RUN_STATE ); /* sqlite3_step() verifies this */
90507 sqlite3VdbeEnter(p);
@@ -90560,16 +90777,18 @@
90560 /* Errors are detected by individual opcodes, with an immediate
90561 ** jumps to abort_due_to_error. */
90562 assert( rc==SQLITE_OK );
90563
90564 assert( pOp>=aOp && pOp<&aOp[p->nOp]);
90565 #ifdef VDBE_PROFILE
90566 start = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
90567 #endif
90568 nVmStep++;
90569 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
90570 if( p->anExec ) p->anExec[(int)(pOp-aOp)]++;
 
 
 
 
 
90571 #endif
90572
90573 /* Only allow tracing if SQLITE_DEBUG is defined.
90574 */
90575 #ifdef SQLITE_DEBUG
@@ -90627,11 +90846,11 @@
90627 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
90628 memAboutToChange(p, &aMem[pOp->p3]);
90629 }
90630 }
90631 #endif
90632 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
90633 pOrigOp = pOp;
90634 #endif
90635
90636 switch( pOp->opcode ){
90637
@@ -91885,11 +92104,10 @@
91885 pIn1 = &aMem[pOp->p1];
91886 pIn3 = &aMem[pOp->p3];
91887 flags1 = pIn1->flags;
91888 flags3 = pIn3->flags;
91889 if( (flags1 & flags3 & MEM_Int)!=0 ){
91890 assert( (pOp->p5 & SQLITE_AFF_MASK)!=SQLITE_AFF_TEXT || CORRUPT_DB );
91891 /* Common case of comparison of two integers */
91892 if( pIn3->u.i > pIn1->u.i ){
91893 if( sqlite3aGTb[pOp->opcode] ){
91894 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
91895 goto jump_to_p2;
@@ -91953,11 +92171,11 @@
91953 }
91954 if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
91955 applyNumericAffinity(pIn3,0);
91956 }
91957 }
91958 }else if( affinity==SQLITE_AFF_TEXT ){
91959 if( (flags1 & MEM_Str)==0 && (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
91960 testcase( pIn1->flags & MEM_Int );
91961 testcase( pIn1->flags & MEM_Real );
91962 testcase( pIn1->flags & MEM_IntReal );
91963 sqlite3VdbeMemStringify(pIn1, encoding, 1);
@@ -92547,11 +92765,11 @@
92547 ** of large blobs is not loaded, thus saving CPU cycles. If the
92548 ** OPFLAG_TYPEOFARG bit is set then the result will only be used by the
92549 ** typeof() function or the IS NULL or IS NOT NULL operators or the
92550 ** equivalent. In this case, all content loading can be omitted.
92551 */
92552 case OP_Column: {
92553 u32 p2; /* column number to retrieve */
92554 VdbeCursor *pC; /* The VDBE cursor */
92555 BtCursor *pCrsr; /* The B-Tree cursor corresponding to pC */
92556 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
92557 int len; /* The length of the serialized data for the column */
@@ -93899,11 +94117,11 @@
93899 ** This instruction works like OpenRead except that it opens the cursor
93900 ** in read/write mode.
93901 **
93902 ** See also: OP_OpenRead, OP_ReopenIdx
93903 */
93904 case OP_ReopenIdx: {
93905 int nField;
93906 KeyInfo *pKeyInfo;
93907 u32 p2;
93908 int iDb;
93909 int wrFlag;
@@ -93920,11 +94138,11 @@
93920 sqlite3BtreeClearCursor(pCur->uc.pCursor);
93921 goto open_cursor_set_hints;
93922 }
93923 /* If the cursor is not currently open or is open on a different
93924 ** index, then fall through into OP_OpenRead to force a reopen */
93925 case OP_OpenRead:
93926 case OP_OpenWrite:
93927
93928 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
93929 assert( p->bIsReader );
93930 assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx
@@ -94014,11 +94232,11 @@
94014 ** cursor P2. The P2 cursor must have been opened by a prior OP_OpenEphemeral
94015 ** opcode. Only ephemeral cursors may be duplicated.
94016 **
94017 ** Duplicate ephemeral cursors are used for self-joins of materialized views.
94018 */
94019 case OP_OpenDup: {
94020 VdbeCursor *pOrig; /* The original cursor to be duplicated */
94021 VdbeCursor *pCx; /* The new cursor */
94022
94023 pOrig = p->apCsr[pOp->p2];
94024 assert( pOrig );
@@ -94076,12 +94294,12 @@
94076 ** This opcode works the same as OP_OpenEphemeral. It has a
94077 ** different name to distinguish its use. Tables created using
94078 ** by this opcode will be used for automatically created transient
94079 ** indices in joins.
94080 */
94081 case OP_OpenAutoindex:
94082 case OP_OpenEphemeral: {
94083 VdbeCursor *pCx;
94084 KeyInfo *pKeyInfo;
94085
94086 static const int vfsFlags =
94087 SQLITE_OPEN_READWRITE |
@@ -94235,11 +94453,11 @@
94235 /* Opcode: Close P1 * * * *
94236 **
94237 ** Close a cursor previously opened as P1. If P1 is not
94238 ** currently open, this instruction is a no-op.
94239 */
94240 case OP_Close: {
94241 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
94242 sqlite3VdbeFreeCursor(p, p->apCsr[pOp->p1]);
94243 p->apCsr[pOp->p1] = 0;
94244 break;
94245 }
@@ -94352,14 +94570,14 @@
94352 ** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
94353 ** is an equality search.
94354 **
94355 ** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
94356 */
94357 case OP_SeekLT: /* jump, in3, group */
94358 case OP_SeekLE: /* jump, in3, group */
94359 case OP_SeekGE: /* jump, in3, group */
94360 case OP_SeekGT: { /* jump, in3, group */
94361 int res; /* Comparison result */
94362 int oc; /* Opcode */
94363 VdbeCursor *pC; /* The cursor to seek */
94364 UnpackedRecord r; /* The key to seek for */
94365 int nField; /* Number of columns or fields in the key */
@@ -94621,11 +94839,11 @@
94621 ** <li> If the cursor ends up on a valid row that is past the target row
94622 ** (indicating that the target row does not exist in the btree) then
94623 ** jump to SeekOP.P2 if This.P5==0 or to This.P2 if This.P5>0.
94624 ** </ol>
94625 */
94626 case OP_SeekScan: {
94627 VdbeCursor *pC;
94628 int res;
94629 int nStep;
94630 UnpackedRecord r;
94631
@@ -94743,11 +94961,11 @@
94743 ** OP_IfNoHope opcode might run to see if the IN loop can be abandoned
94744 ** early, thus saving work. This is part of the IN-early-out optimization.
94745 **
94746 ** P1 must be a valid b-tree cursor.
94747 */
94748 case OP_SeekHit: {
94749 VdbeCursor *pC;
94750 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
94751 pC = p->apCsr[pOp->p1];
94752 assert( pC!=0 );
94753 assert( pOp->p3>=pOp->p2 );
@@ -94875,11 +95093,11 @@
94875 ** advanced in either direction. In other words, the Next and Prev
94876 ** opcodes do not work after this operation.
94877 **
94878 ** See also: NotFound, Found, NotExists
94879 */
94880 case OP_IfNoHope: { /* jump, in3 */
94881 VdbeCursor *pC;
94882 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
94883 pC = p->apCsr[pOp->p1];
94884 assert( pC!=0 );
94885 #ifdef SQLITE_DEBUG
@@ -94889,13 +95107,13 @@
94889 #endif
94890 if( pC->seekHit>=pOp->p4.i ) break;
94891 /* Fall through into OP_NotFound */
94892 /* no break */ deliberate_fall_through
94893 }
94894 case OP_NoConflict: /* jump, in3 */
94895 case OP_NotFound: /* jump, in3 */
94896 case OP_Found: { /* jump, in3 */
94897 int alreadyExists;
94898 int ii;
94899 VdbeCursor *pC;
94900 UnpackedRecord *pIdxKey;
94901 UnpackedRecord r;
@@ -95021,11 +95239,11 @@
95021 ** in either direction. In other words, the Next and Prev opcodes will
95022 ** not work following this opcode.
95023 **
95024 ** See also: Found, NotFound, NoConflict, SeekRowid
95025 */
95026 case OP_SeekRowid: { /* jump, in3 */
95027 VdbeCursor *pC;
95028 BtCursor *pCrsr;
95029 int res;
95030 u64 iKey;
95031
@@ -95046,11 +95264,11 @@
95046 iKey = x.u.i;
95047 goto notExistsWithKey;
95048 }
95049 /* Fall through into OP_NotExists */
95050 /* no break */ deliberate_fall_through
95051 case OP_NotExists: /* jump, in3 */
95052 pIn3 = &aMem[pOp->p3];
95053 assert( (pIn3->flags & MEM_Int)!=0 || pOp->opcode==OP_SeekRowid );
95054 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
95055 iKey = pIn3->u.i;
95056 notExistsWithKey:
@@ -95670,11 +95888,11 @@
95670 **
95671 ** P1 can be either an ordinary table or a virtual table. There used to
95672 ** be a separate OP_VRowid opcode for use with virtual tables, but this
95673 ** one opcode now works for both table types.
95674 */
95675 case OP_Rowid: { /* out2 */
95676 VdbeCursor *pC;
95677 i64 v;
95678 sqlite3_vtab *pVtab;
95679 const sqlite3_module *pModule;
95680
@@ -95769,12 +95987,12 @@
95769 **
95770 ** This opcode leaves the cursor configured to move in reverse order,
95771 ** from the end toward the beginning. In other words, the cursor is
95772 ** configured to use Prev, not Next.
95773 */
95774 case OP_SeekEnd:
95775 case OP_Last: { /* jump */
95776 VdbeCursor *pC;
95777 BtCursor *pCrsr;
95778 int res;
95779
95780 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -95875,11 +96093,11 @@
95875 **
95876 ** This opcode leaves the cursor configured to move in forward order,
95877 ** from the beginning toward the end. In other words, the cursor is
95878 ** configured to use Next, not Prev.
95879 */
95880 case OP_Rewind: { /* jump */
95881 VdbeCursor *pC;
95882 BtCursor *pCrsr;
95883 int res;
95884
95885 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -95969,11 +96187,11 @@
95969 pC = p->apCsr[pOp->p1];
95970 assert( isSorter(pC) );
95971 rc = sqlite3VdbeSorterNext(db, pC);
95972 goto next_tail;
95973
95974 case OP_Prev: /* jump */
95975 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
95976 assert( pOp->p5==0
95977 || pOp->p5==SQLITE_STMTSTATUS_FULLSCAN_STEP
95978 || pOp->p5==SQLITE_STMTSTATUS_AUTOINDEX);
95979 pC = p->apCsr[pOp->p1];
@@ -95984,11 +96202,11 @@
95984 || pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope
95985 || pC->seekOp==OP_NullRow);
95986 rc = sqlite3BtreePrevious(pC->uc.pCursor, pOp->p3);
95987 goto next_tail;
95988
95989 case OP_Next: /* jump */
95990 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
95991 assert( pOp->p5==0
95992 || pOp->p5==SQLITE_STMTSTATUS_FULLSCAN_STEP
95993 || pOp->p5==SQLITE_STMTSTATUS_AUTOINDEX);
95994 pC = p->apCsr[pOp->p1];
@@ -96176,12 +96394,12 @@
96176 ** the end of the index key pointed to by cursor P1. This integer should be
96177 ** the rowid of the table entry to which this index entry points.
96178 **
96179 ** See also: Rowid, MakeRecord.
96180 */
96181 case OP_DeferredSeek:
96182 case OP_IdxRowid: { /* out2 */
96183 VdbeCursor *pC; /* The P1 index cursor */
96184 VdbeCursor *pTabCur; /* The P2 table cursor (OP_DeferredSeek only) */
96185 i64 rowid; /* Rowid that P1 current points to */
96186
96187 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -96239,12 +96457,12 @@
96239 **
96240 ** If cursor P1 was previously moved via OP_DeferredSeek, complete that
96241 ** seek operation now, without further delay. If the cursor seek has
96242 ** already occurred, this instruction is a no-op.
96243 */
96244 case OP_FinishSeek: {
96245 VdbeCursor *pC; /* The P1 index cursor */
96246
96247 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
96248 pC = p->apCsr[pOp->p1];
96249 if( pC->deferredMoveto ){
96250 rc = sqlite3VdbeFinishMoveto(pC);
@@ -96295,14 +96513,14 @@
96295 ** ROWID on the P1 index.
96296 **
96297 ** If the P1 index entry is less than or equal to the key value then jump
96298 ** to P2. Otherwise fall through to the next instruction.
96299 */
96300 case OP_IdxLE: /* jump */
96301 case OP_IdxGT: /* jump */
96302 case OP_IdxLT: /* jump */
96303 case OP_IdxGE: { /* jump */
96304 VdbeCursor *pC;
96305 int res;
96306 UnpackedRecord r;
96307
96308 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -96919,13 +97137,10 @@
96919 pFrame->apCsr = p->apCsr;
96920 pFrame->nCursor = p->nCursor;
96921 pFrame->aOp = p->aOp;
96922 pFrame->nOp = p->nOp;
96923 pFrame->token = pProgram->token;
96924 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
96925 pFrame->anExec = p->anExec;
96926 #endif
96927 #ifdef SQLITE_DEBUG
96928 pFrame->iFrameMagic = SQLITE_FRAME_MAGIC;
96929 #endif
96930
96931 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
@@ -96958,13 +97173,10 @@
96958 p->apCsr = (VdbeCursor **)&aMem[p->nMem];
96959 pFrame->aOnce = (u8*)&p->apCsr[pProgram->nCsr];
96960 memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
96961 p->aOp = aOp = pProgram->aOp;
96962 p->nOp = pProgram->nOp;
96963 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
96964 p->anExec = 0;
96965 #endif
96966 #ifdef SQLITE_DEBUG
96967 /* Verify that second and subsequent executions of the same trigger do not
96968 ** try to reuse register values from the first use. */
96969 {
96970 int i;
@@ -97717,11 +97929,11 @@
97717 **
97718 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
97719 ** P1 is a cursor number. This opcode opens a cursor to the virtual
97720 ** table and stores that cursor in P1.
97721 */
97722 case OP_VOpen: {
97723 VdbeCursor *pCur;
97724 sqlite3_vtab_cursor *pVCur;
97725 sqlite3_vtab *pVtab;
97726 const sqlite3_module *pModule;
97727
@@ -97764,11 +97976,11 @@
97764 ** can be used as the first argument to sqlite3_vtab_in_first() and
97765 ** sqlite3_vtab_in_next() to extract all of the values stored in the P1
97766 ** cursor. Register P3 is used to hold the values returned by
97767 ** sqlite3_vtab_in_first() and sqlite3_vtab_in_next().
97768 */
97769 case OP_VInitIn: { /* out2 */
97770 VdbeCursor *pC; /* The cursor containing the RHS values */
97771 ValueList *pRhs; /* New ValueList object to put in reg[P2] */
97772
97773 pC = p->apCsr[pOp->p1];
97774 pRhs = sqlite3_malloc64( sizeof(*pRhs) );
@@ -97801,11 +98013,11 @@
97801 ** additional parameters which are passed to
97802 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
97803 **
97804 ** A jump is made to P2 if the result set after filtering would be empty.
97805 */
97806 case OP_VFilter: { /* jump */
97807 int nArg;
97808 int iQuery;
97809 const sqlite3_module *pModule;
97810 Mem *pQuery;
97811 Mem *pArgc;
@@ -97861,11 +98073,11 @@
97861 ** function to return true inside the xColumn method of the virtual
97862 ** table implementation. The P5 column might also contain other
97863 ** bits (OPFLAG_LENGTHARG or OPFLAG_TYPEOFARG) but those bits are
97864 ** unused by OP_VColumn.
97865 */
97866 case OP_VColumn: {
97867 sqlite3_vtab *pVtab;
97868 const sqlite3_module *pModule;
97869 Mem *pDest;
97870 sqlite3_context sContext;
97871
@@ -97913,11 +98125,11 @@
97913 **
97914 ** Advance virtual table P1 to the next row in its result set and
97915 ** jump to instruction P2. Or, if the virtual table has reached
97916 ** the end of its result set, then fall through to the next instruction.
97917 */
97918 case OP_VNext: { /* jump */
97919 sqlite3_vtab *pVtab;
97920 const sqlite3_module *pModule;
97921 int res;
97922 VdbeCursor *pCur;
97923
@@ -98496,16 +98708,16 @@
98496 ** readability. From this point on down, the normal indentation rules are
98497 ** restored.
98498 *****************************************************************************/
98499 }
98500
98501 #ifdef VDBE_PROFILE
98502 {
98503 u64 endTime = sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
98504 if( endTime>start ) pOrigOp->cycles += endTime - start;
98505 pOrigOp->cnt++;
98506 }
98507 #endif
98508
98509 /* The following code adds nothing to the actual functionality
98510 ** of the program. It is only here for testing and debugging.
98511 ** On the other hand, it does burn CPU cycles every time through
@@ -98577,10 +98789,22 @@
98577
98578 /* This is the only way out of this procedure. We have to
98579 ** release the mutexes on btrees that were acquired at the
98580 ** top. */
98581 vdbe_return:
 
 
 
 
 
 
 
 
 
 
 
 
98582 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
98583 while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
98584 nProgressLimit += db->nProgressOps;
98585 if( db->xProgress(db->pProgressArg) ){
98586 nProgressLimit = LARGEST_UINT64;
@@ -105224,51 +105448,124 @@
105224 ** SELECT a AS b FROM t1 WHERE b;
105225 ** SELECT * FROM t1 WHERE (select a from t1);
105226 */
105227 SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr){
105228 int op;
105229 while( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
105230 assert( pExpr->op==TK_COLLATE
105231 || pExpr->op==TK_IF_NULL_ROW
105232 || (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW) );
105233 pExpr = pExpr->pLeft;
105234 assert( pExpr!=0 );
105235 }
105236 op = pExpr->op;
105237 if( op==TK_REGISTER ) op = pExpr->op2;
105238 if( op==TK_COLUMN || (op==TK_AGG_COLUMN && pExpr->y.pTab!=0) ){
105239 assert( ExprUseYTab(pExpr) );
105240 assert( pExpr->y.pTab!=0 );
105241 return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
105242 }
105243 if( op==TK_SELECT ){
105244 assert( ExprUseXSelect(pExpr) );
105245 assert( pExpr->x.pSelect!=0 );
105246 assert( pExpr->x.pSelect->pEList!=0 );
105247 assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
105248 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
105249 }
105250 #ifndef SQLITE_OMIT_CAST
105251 if( op==TK_CAST ){
105252 assert( !ExprHasProperty(pExpr, EP_IntValue) );
105253 return sqlite3AffinityType(pExpr->u.zToken, 0);
105254 }
105255 #endif
105256 if( op==TK_SELECT_COLUMN ){
105257 assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
105258 assert( pExpr->iColumn < pExpr->iTable );
105259 assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
105260 return sqlite3ExprAffinity(
105261 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
105262 );
105263 }
105264 if( op==TK_VECTOR ){
105265 assert( ExprUseXList(pExpr) );
105266 return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
 
 
 
 
 
 
 
 
 
 
105267 }
105268 return pExpr->affExpr;
105269 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105270
105271 /*
105272 ** Set the collating sequence for expression pExpr to be the collating
105273 ** sequence named by pToken. Return a pointer to a new Expr node that
105274 ** implements the COLLATE operator.
@@ -108437,10 +108734,13 @@
108437 int rReg = 0; /* Register storing resulting */
108438 Select *pSel; /* SELECT statement to encode */
108439 SelectDest dest; /* How to deal with SELECT result */
108440 int nReg; /* Registers to allocate */
108441 Expr *pLimit; /* New limit expression */
 
 
 
108442
108443 Vdbe *v = pParse->pVdbe;
108444 assert( v!=0 );
108445 if( pParse->nErr ) return 0;
108446 testcase( pExpr->op==TK_EXISTS );
@@ -108489,12 +108789,13 @@
108489 ** into a register and return that register number.
108490 **
108491 ** In both cases, the query is augmented with "LIMIT 1". Any
108492 ** preexisting limit is discarded in place of the new LIMIT 1.
108493 */
108494 ExplainQueryPlan((pParse, 1, "%sSCALAR SUBQUERY %d",
108495 addrOnce?"":"CORRELATED ", pSel->selId));
 
108496 nReg = pExpr->op==TK_SELECT ? pSel->pEList->nExpr : 1;
108497 sqlite3SelectDestInit(&dest, 0, pParse->nMem+1);
108498 pParse->nMem += nReg;
108499 if( pExpr->op==TK_SELECT ){
108500 dest.eDest = SRT_Mem;
@@ -108533,10 +108834,11 @@
108533 pExpr->iTable = rReg = dest.iSDParm;
108534 ExprSetVVAProperty(pExpr, EP_NoReduce);
108535 if( addrOnce ){
108536 sqlite3VdbeJumpHere(v, addrOnce);
108537 }
 
108538
108539 /* Subroutine return */
108540 assert( ExprUseYSub(pExpr) );
108541 assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn
108542 || pParse->nErr );
@@ -119973,12 +120275,11 @@
119973 &pTable->nCol, &pTable->aCol);
119974 if( pParse->nErr==0
119975 && pTable->nCol==pSel->pEList->nExpr
119976 ){
119977 assert( db->mallocFailed==0 );
119978 sqlite3SelectAddColumnTypeAndCollation(pParse, pTable, pSel,
119979 SQLITE_AFF_NONE);
119980 }
119981 }else{
119982 /* CREATE VIEW name AS... without an argument list. Construct
119983 ** the column names from the SELECT statement that defines the view.
119984 */
@@ -137508,10 +137809,14 @@
137508 int iCsr; /* Cursor number for table */
137509 int nKey; /* Number of PK columns for table pTab (>=1) */
137510 } aDefer[4];
137511 #endif
137512 struct RowLoadInfo *pDeferredRowLoad; /* Deferred row loading info or NULL */
 
 
 
 
137513 };
137514 #define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
137515
137516 /*
137517 ** Delete all the content of a Select structure. Deallocate the structure
@@ -138163,10 +138468,14 @@
138163 ** SortCtx.pDeferredRowLoad optimiation. In any of these cases
138164 ** regOrigData is 0 to prevent this routine from trying to copy
138165 ** values that might not yet exist.
138166 */
138167 assert( nData==1 || regData==regOrigData || regOrigData==0 );
 
 
 
 
138168
138169 if( nPrefixReg ){
138170 assert( nPrefixReg==nExpr+bSeq );
138171 regBase = regData - nPrefixReg;
138172 }else{
@@ -138264,10 +138573,13 @@
138264 regBase+nOBSat, nBase-nOBSat);
138265 if( iSkip ){
138266 sqlite3VdbeChangeP2(v, iSkip,
138267 pSort->labelOBLopt ? pSort->labelOBLopt : sqlite3VdbeCurrentAddr(v));
138268 }
 
 
 
138269 }
138270
138271 /*
138272 ** Add code to implement the OFFSET
138273 */
@@ -138730,13 +139042,10 @@
138730 testcase( eDest==SRT_Table );
138731 testcase( eDest==SRT_EphemTab );
138732 testcase( eDest==SRT_Fifo );
138733 testcase( eDest==SRT_DistFifo );
138734 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1+nPrefixReg);
138735 if( pDest->zAffSdst ){
138736 sqlite3VdbeChangeP4(v, -1, pDest->zAffSdst, nResultCol);
138737 }
138738 #ifndef SQLITE_OMIT_CTE
138739 if( eDest==SRT_DistFifo ){
138740 /* If the destination is DistFifo, then cursor (iParm+1) is open
138741 ** on an ephemeral index. If the current row is already present
138742 ** in the index, do not write it to the output. If not, add the
@@ -139090,10 +139399,20 @@
139090 int iSortTab; /* Sorter cursor to read from */
139091 int i;
139092 int bSeq; /* True if sorter record includes seq. no. */
139093 int nRefKey = 0;
139094 struct ExprList_item *aOutEx = p->pEList->a;
 
 
 
 
 
 
 
 
 
 
139095
139096 assert( addrBreak<0 );
139097 if( pSort->labelBkOut ){
139098 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
139099 sqlite3VdbeGoto(v, addrBreak);
@@ -139202,10 +139521,11 @@
139202 }
139203 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i);
139204 VdbeComment((v, "%s", aOutEx[i].zEName));
139205 }
139206 }
 
139207 switch( eDest ){
139208 case SRT_Table:
139209 case SRT_EphemTab: {
139210 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq, regRow);
139211 sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
@@ -139263,10 +139583,11 @@
139263 if( pSort->sortFlags & SORTFLAG_UseSorter ){
139264 sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr); VdbeCoverage(v);
139265 }else{
139266 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); VdbeCoverage(v);
139267 }
 
139268 if( pSort->regReturn ) sqlite3VdbeAddOp1(v, OP_Return, pSort->regReturn);
139269 sqlite3VdbeResolveLabel(v, addrBreak);
139270 }
139271
139272 /*
@@ -139293,10 +139614,11 @@
139293 #ifdef SQLITE_ENABLE_COLUMN_METADATA
139294 # define columnType(A,B,C,D,E) columnTypeImpl(A,B,C,D,E)
139295 #else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */
139296 # define columnType(A,B,C,D,E) columnTypeImpl(A,B)
139297 #endif
 
139298 static const char *columnTypeImpl(
139299 NameContext *pNC,
139300 #ifndef SQLITE_ENABLE_COLUMN_METADATA
139301 Expr *pExpr
139302 #else
@@ -139439,10 +139761,11 @@
139439 *pzOrigCol = zOrigCol;
139440 }
139441 #endif
139442 return zType;
139443 }
 
139444
139445 /*
139446 ** Generate code that will tell the VDBE the declaration types of columns
139447 ** in the result set.
139448 */
@@ -139710,51 +140033,94 @@
139710 }
139711 return SQLITE_OK;
139712 }
139713
139714 /*
139715 ** Add type and collation information to a column list based on
139716 ** a SELECT statement.
139717 **
139718 ** The column list presumably came from selectColumnNamesFromExprList().
139719 ** The column list has only names, not types or collations. This
139720 ** routine goes through and adds the types and collations.
139721 **
139722 ** This routine requires that all identifiers in the SELECT
139723 ** statement be resolved.
139724 */
139725 SQLITE_PRIVATE void sqlite3SelectAddColumnTypeAndCollation(
139726 Parse *pParse, /* Parsing contexts */
139727 Table *pTab, /* Add column type information to this table */
139728 Select *pSelect, /* SELECT used to determine types and collations */
139729 char aff /* Default affinity for columns */
 
 
 
 
 
 
 
 
 
 
 
 
 
139730 ){
139731 sqlite3 *db = pParse->db;
139732 NameContext sNC;
139733 Column *pCol;
139734 CollSeq *pColl;
139735 int i;
139736 Expr *p;
139737 struct ExprList_item *a;
139738
139739 assert( pSelect!=0 );
139740 assert( (pSelect->selFlags & SF_Resolved)!=0 );
139741 assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
139742 if( db->mallocFailed ) return;
139743 memset(&sNC, 0, sizeof(sNC));
139744 sNC.pSrcList = pSelect->pSrc;
139745 a = pSelect->pEList->a;
139746 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
139747 const char *zType;
139748 i64 n, m;
139749 pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT);
139750 p = a[i].pExpr;
139751 zType = columnType(&sNC, p, 0, 0, 0);
139752 /* pCol->szEst = ... // Column size est for SELECT tables never used */
139753 pCol->affinity = sqlite3ExprAffinity(p);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
139754 if( zType ){
139755 m = sqlite3Strlen30(zType);
139756 n = sqlite3Strlen30(pCol->zCnName);
139757 pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2);
139758 if( pCol->zCnName ){
139759 memcpy(&pCol->zCnName[n+1], zType, m+1);
139760 pCol->colFlags |= COLFLAG_HASTYPE;
@@ -139761,11 +140127,10 @@
139761 }else{
139762 testcase( pCol->colFlags & COLFLAG_HASTYPE );
139763 pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL);
139764 }
139765 }
139766 if( pCol->affinity<=SQLITE_AFF_NONE ) pCol->affinity = aff;
139767 pColl = sqlite3ExprCollSeq(pParse, p);
139768 if( pColl ){
139769 assert( pTab->pIndex==0 );
139770 sqlite3ColumnSetColl(db, pCol, pColl->zName);
139771 }
@@ -139795,11 +140160,11 @@
139795 }
139796 pTab->nTabRef = 1;
139797 pTab->zName = 0;
139798 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
139799 sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
139800 sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSelect, aff);
139801 pTab->iPKey = -1;
139802 if( db->mallocFailed ){
139803 sqlite3DeleteTable(db, pTab);
139804 return 0;
139805 }
@@ -143606,18 +143971,18 @@
143606 #ifndef SQLITE_OMIT_SUBQUERY
143607 /*
143608 ** This is a Walker.xSelectCallback callback for the sqlite3SelectTypeInfo()
143609 ** interface.
143610 **
143611 ** For each FROM-clause subquery, add Column.zType and Column.zColl
143612 ** information to the Table structure that represents the result set
143613 ** of that subquery.
143614 **
143615 ** The Table structure that represents the result set was constructed
143616 ** by selectExpander() but the type and collation information was omitted
143617 ** at that point because identifiers had not yet been resolved. This
143618 ** routine is called after identifier resolution.
143619 */
143620 static void selectAddSubqueryTypeInfo(Walker *pWalker, Select *p){
143621 Parse *pParse;
143622 int i;
143623 SrcList *pTabList;
@@ -143633,13 +143998,12 @@
143633 assert( pTab!=0 );
143634 if( (pTab->tabFlags & TF_Ephemeral)!=0 ){
143635 /* A sub-query in the FROM clause of a SELECT */
143636 Select *pSel = pFrom->pSelect;
143637 if( pSel ){
143638 while( pSel->pPrior ) pSel = pSel->pPrior;
143639 sqlite3SelectAddColumnTypeAndCollation(pParse, pTab, pSel,
143640 SQLITE_AFF_NONE);
143641 }
143642 }
143643 }
143644 }
143645 #endif
@@ -144117,23 +144481,28 @@
144117 }
144118 #endif
144119 }
144120
144121 /*
144122 ** Check to see if the pThis entry of pTabList is a self-join of a prior view.
144123 ** If it is, then return the SrcItem for the prior view. If it is not,
144124 ** then return 0.
 
 
 
144125 */
144126 static SrcItem *isSelfJoinView(
144127 SrcList *pTabList, /* Search for self-joins in this FROM clause */
144128 SrcItem *pThis /* Search for prior reference to this subquery */
 
144129 ){
144130 SrcItem *pItem;
144131 assert( pThis->pSelect!=0 );
144132 if( pThis->pSelect->selFlags & SF_PushDown ) return 0;
144133 for(pItem = pTabList->a; pItem<pThis; pItem++){
144134 Select *pS1;
 
144135 if( pItem->pSelect==0 ) continue;
144136 if( pItem->fg.viaCoroutine ) continue;
144137 if( pItem->zName==0 ) continue;
144138 assert( pItem->pTab!=0 );
144139 assert( pThis->pTab!=0 );
@@ -144273,10 +144642,66 @@
144273 return 1;
144274 }
144275 }
144276 return 0;
144277 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
144278
144279 /*
144280 ** Generate code for the SELECT statement given in the p argument.
144281 **
144282 ** The results are returned according to the SelectDest structure.
@@ -144661,25 +145086,12 @@
144661
144662 zSavedAuthContext = pParse->zAuthContext;
144663 pParse->zAuthContext = pItem->zName;
144664
144665 /* Generate code to implement the subquery
144666 **
144667 ** The subquery is implemented as a co-routine if all of the following are
144668 ** true:
144669 **
144670 ** (1) the subquery is guaranteed to be the outer loop (so that
144671 ** it does not need to be computed more than once), and
144672 ** (2) the subquery is not a CTE that should be materialized
144673 ** (3) the subquery is not part of a left operand for a RIGHT JOIN
144674 */
144675 if( i==0
144676 && (pTabList->nSrc==1
144677 || (pTabList->a[1].fg.jointype&(JT_OUTER|JT_CROSS))!=0) /* (1) */
144678 && (pItem->fg.isCte==0 || pItem->u2.pCteUse->eM10d!=M10d_Yes) /* (2) */
144679 && (pTabList->a[0].fg.jointype & JT_LTORJ)==0 /* (3) */
144680 ){
144681 /* Implement a co-routine that will return a single row of the result
144682 ** set on each invocation.
144683 */
144684 int addrTop = sqlite3VdbeCurrentAddr(v)+1;
144685
@@ -144706,11 +145118,11 @@
144706 if( pItem->iCursor!=pCteUse->iCur ){
144707 sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pCteUse->iCur);
144708 VdbeComment((v, "%!S", pItem));
144709 }
144710 pSub->nSelectRow = pCteUse->nRowEst;
144711 }else if( (pPrior = isSelfJoinView(pTabList, pItem))!=0 ){
144712 /* This view has already been materialized by a prior entry in
144713 ** this same FROM clause. Reuse it. */
144714 if( pPrior->addrFillSub ){
144715 sqlite3VdbeAddOp2(v, OP_Gosub, pPrior->regReturn, pPrior->addrFillSub);
144716 }
@@ -144720,10 +145132,13 @@
144720 /* Materialize the view. If the view is not correlated, generate a
144721 ** subroutine to do the materialization so that subsequent uses of
144722 ** the same view can reuse the materialization. */
144723 int topAddr;
144724 int onceAddr = 0;
 
 
 
144725
144726 pItem->regReturn = ++pParse->nMem;
144727 topAddr = sqlite3VdbeAddOp0(v, OP_Goto);
144728 pItem->addrFillSub = topAddr+1;
144729 pItem->fg.isMaterialized = 1;
@@ -144735,19 +145150,18 @@
144735 VdbeComment((v, "materialize %!S", pItem));
144736 }else{
144737 VdbeNoopComment((v, "materialize %!S", pItem));
144738 }
144739 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
144740 ExplainQueryPlan((pParse, 1, "MATERIALIZE %!S", pItem));
144741 dest.zAffSdst = sqlite3TableAffinityStr(db, pItem->pTab);
144742 sqlite3Select(pParse, pSub, &dest);
144743 sqlite3DbFree(db, dest.zAffSdst);
144744 dest.zAffSdst = 0;
144745 pItem->pTab->nRowLogEst = pSub->nSelectRow;
144746 if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
144747 sqlite3VdbeAddOp2(v, OP_Return, pItem->regReturn, topAddr+1);
144748 VdbeComment((v, "end %!S", pItem));
 
144749 sqlite3VdbeJumpHere(v, topAddr);
144750 sqlite3ClearTempRegCache(pParse);
144751 if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
144752 CteUse *pCteUse = pItem->u2.pCteUse;
144753 pCteUse->addrM9e = pItem->addrFillSub;
@@ -145498,12 +145912,10 @@
145498
145499 /* If there is an ORDER BY clause, then we need to sort the results
145500 ** and send them to the callback one by one.
145501 */
145502 if( sSort.pOrderBy ){
145503 explainTempTable(pParse,
145504 sSort.nOBSat>0 ? "RIGHT PART OF ORDER BY":"ORDER BY");
145505 assert( p->pEList==pEList );
145506 generateSortTail(pParse, p, &sSort, pEList->nExpr, pDest);
145507 }
145508
145509 /* Jump here to skip this query
@@ -147492,11 +147904,12 @@
147492 sqlite3ExprDup(db, pChanges->a[i].pExpr, 0)
147493 );
147494 }
147495 }
147496 pSelect = sqlite3SelectNew(pParse, pList,
147497 pSrc, pWhere2, pGrp, 0, pOrderBy2, SF_UFSrcCheck|SF_IncludeHidden, pLimit2
 
147498 );
147499 if( pSelect ) pSelect->selFlags |= SF_OrderByReqd;
147500 sqlite3SelectDestInit(&dest, eDest, iEph);
147501 dest.iSDParm2 = (pPk ? pPk->nKeyCol : -1);
147502 sqlite3Select(pParse, pSelect, &dest);
@@ -151576,10 +151989,12 @@
151576 }
151577 sqlite3_str_append(&str, ")", 1);
151578 zMsg = sqlite3StrAccumFinish(&str);
151579 ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v),
151580 pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
 
 
151581 return ret;
151582 }
151583 #endif /* SQLITE_OMIT_EXPLAIN */
151584
151585 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
@@ -151598,18 +152013,31 @@
151598 WhereLevel *pLvl, /* Level to add scanstatus() entry for */
151599 int addrExplain /* Address of OP_Explain (or 0) */
151600 ){
151601 const char *zObj = 0;
151602 WhereLoop *pLoop = pLvl->pWLoop;
151603 if( (pLoop->wsFlags & WHERE_VIRTUALTABLE)==0 && pLoop->u.btree.pIndex!=0 ){
 
 
 
151604 zObj = pLoop->u.btree.pIndex->zName;
151605 }else{
151606 zObj = pSrclist->a[pLvl->iFrom].zName;
 
151607 }
151608 sqlite3VdbeScanStatus(
151609 v, addrExplain, pLvl->addrBody, pLvl->addrVisit, pLoop->nOut, zObj
151610 );
 
 
 
 
 
 
 
 
 
151611 }
151612 #endif
151613
151614
151615 /*
@@ -155999,11 +156427,11 @@
155999 ** terms means that no sorting is needed at all. A return that
156000 ** is positive but less than the number of ORDER BY terms means that
156001 ** block sorting is required.
156002 */
156003 SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo *pWInfo){
156004 return pWInfo->nOBSat;
156005 }
156006
156007 /*
156008 ** In the ORDER BY LIMIT optimization, if the inner-most loop is known
156009 ** to emit rows in increasing order, and if the last row emitted by the
@@ -156744,10 +157172,61 @@
156744 }
156745 #endif
156746
156747
156748 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
156749 /*
156750 ** Generate code to construct the Index object for an automatic index
156751 ** and to set up the WhereLevel object pLevel so that the code generator
156752 ** makes use of the automatic index.
156753 */
@@ -156779,10 +157258,13 @@
156779 Expr *pPartial = 0; /* Partial Index Expression */
156780 int iContinue = 0; /* Jump here to skip excluded rows */
156781 SrcItem *pTabItem; /* FROM clause term being indexed */
156782 int addrCounter = 0; /* Address where integer counter is initialized */
156783 int regBase; /* Array of registers where record is assembled */
 
 
 
156784
156785 /* Generate code to skip over the creation and initialization of the
156786 ** transient index on 2nd and subsequent iterations of the loop. */
156787 v = pParse->pVdbe;
156788 assert( v!=0 );
@@ -156902,10 +157384,11 @@
156902 assert( n==nKeyCol );
156903 pIdx->aiColumn[n] = XN_ROWID;
156904 pIdx->azColl[n] = sqlite3StrBINARY;
156905
156906 /* Create the automatic index */
 
156907 assert( pLevel->iIdxCur>=0 );
156908 pLevel->iIdxCur = pParse->nTab++;
156909 sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
156910 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
156911 VdbeComment((v, "for %s", pTable->zName));
@@ -156937,10 +157420,11 @@
156937 );
156938 if( pLevel->regFilter ){
156939 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0,
156940 regBase, pLoop->u.btree.nEq);
156941 }
 
156942 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
156943 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
156944 if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
156945 if( pTabItem->fg.viaCoroutine ){
156946 sqlite3VdbeChangeP2(v, addrCounter, regBase+n);
@@ -156957,10 +157441,11 @@
156957 sqlite3VdbeJumpHere(v, addrTop);
156958 sqlite3ReleaseTempReg(pParse, regRecord);
156959
156960 /* Jump here when skipping the initialization */
156961 sqlite3VdbeJumpHere(v, addrInit);
 
156962
156963 end_auto_index_create:
156964 sqlite3ExprDelete(pParse->db, pPartial);
156965 }
156966 #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
@@ -174461,10 +174946,11 @@
174461 case SQLITE_ROW: zName = "SQLITE_ROW"; break;
174462 case SQLITE_NOTICE: zName = "SQLITE_NOTICE"; break;
174463 case SQLITE_NOTICE_RECOVER_WAL: zName = "SQLITE_NOTICE_RECOVER_WAL";break;
174464 case SQLITE_NOTICE_RECOVER_ROLLBACK:
174465 zName = "SQLITE_NOTICE_RECOVER_ROLLBACK"; break;
 
174466 case SQLITE_WARNING: zName = "SQLITE_WARNING"; break;
174467 case SQLITE_WARNING_AUTOINDEX: zName = "SQLITE_WARNING_AUTOINDEX"; break;
174468 case SQLITE_DONE: zName = "SQLITE_DONE"; break;
174469 }
174470 }
@@ -175013,11 +175499,11 @@
175013 #endif
175014 sqlite3_mutex_enter(db->mutex);
175015 rc = sqlite3FindFunction(db, zName, nArg, SQLITE_UTF8, 0)!=0;
175016 sqlite3_mutex_leave(db->mutex);
175017 if( rc ) return SQLITE_OK;
175018 zCopy = sqlite3_mprintf(zName);
175019 if( zCopy==0 ) return SQLITE_NOMEM;
175020 return sqlite3_create_function_v2(db, zName, nArg, SQLITE_UTF8,
175021 zCopy, sqlite3InvalidFunction, 0, 0, sqlite3_free);
175022 }
175023
@@ -211261,25 +211747,25 @@
211261 ** * Calls to xShmLock(UNLOCK) to release the exclusive shm WRITER,
211262 ** READ0 and CHECKPOINT locks taken as part of the checkpoint are
211263 ** no-ops. These locks will not be released until the connection
211264 ** is closed.
211265 **
211266 ** * Attempting to xSync() the database file causes an SQLITE_INTERNAL
211267 ** error.
211268 **
211269 ** As a result, unless an error (i.e. OOM or SQLITE_BUSY) occurs, the
211270 ** checkpoint below fails with SQLITE_INTERNAL, and leaves the aFrame[]
211271 ** array populated with a set of (frame -> page) mappings. Because the
211272 ** WRITER, CHECKPOINT and READ0 locks are still held, it is safe to copy
211273 ** data from the wal file into the database file according to the
211274 ** contents of aFrame[].
211275 */
211276 if( p->rc==SQLITE_OK ){
211277 int rc2;
211278 p->eStage = RBU_STAGE_CAPTURE;
211279 rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0);
211280 if( rc2!=SQLITE_INTERNAL ) p->rc = rc2;
211281 }
211282
211283 if( p->rc==SQLITE_OK && p->nFrame>0 ){
211284 p->eStage = RBU_STAGE_CKPT;
211285 p->nStep = (pState ? pState->nRow : 0);
@@ -211321,11 +211807,11 @@
211321 const u32 mReq = (1<<WAL_LOCK_WRITE)|(1<<WAL_LOCK_CKPT)|(1<<WAL_LOCK_READ0);
211322 u32 iFrame;
211323
211324 if( pRbu->mLock!=mReq ){
211325 pRbu->rc = SQLITE_BUSY;
211326 return SQLITE_INTERNAL;
211327 }
211328
211329 pRbu->pgsz = iAmt;
211330 if( pRbu->nFrame==pRbu->nFrameAlloc ){
211331 int nNew = (pRbu->nFrameAlloc ? pRbu->nFrameAlloc : 64) * 2;
@@ -212708,11 +213194,11 @@
212708 ** are recorded. Additionally, successful attempts to obtain exclusive
212709 ** xShmLock() WRITER, CHECKPOINTER and READ0 locks on the target
212710 ** database file are recorded. xShmLock() calls to unlock the same
212711 ** locks are no-ops (so that once obtained, these locks are never
212712 ** relinquished). Finally, calls to xSync() on the target database
212713 ** file fail with SQLITE_INTERNAL errors.
212714 */
212715
212716 static void rbuUnlockShm(rbu_file *p){
212717 assert( p->openFlags & SQLITE_OPEN_MAIN_DB );
212718 if( p->pRbu ){
@@ -212987,11 +213473,11 @@
212987 */
212988 static int rbuVfsSync(sqlite3_file *pFile, int flags){
212989 rbu_file *p = (rbu_file *)pFile;
212990 if( p->pRbu && p->pRbu->eStage==RBU_STAGE_CAPTURE ){
212991 if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
212992 return SQLITE_INTERNAL;
212993 }
212994 return SQLITE_OK;
212995 }
212996 return p->pReal->pMethods->xSync(p->pReal, flags);
212997 }
@@ -218263,10 +218749,26 @@
218263 }
218264 }else if( p->bInvert ){
218265 if( p->op==SQLITE_INSERT ) p->op = SQLITE_DELETE;
218266 else if( p->op==SQLITE_DELETE ) p->op = SQLITE_INSERT;
218267 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218268 }
218269
218270 return SQLITE_ROW;
218271 }
218272
@@ -220459,11 +220961,11 @@
220459 int n2 = sessionSerialLen(a2);
220460 if( pIter->abPK[i] || a2[0]==0 ){
220461 if( !pIter->abPK[i] && a1[0] ) bData = 1;
220462 memcpy(pOut, a1, n1);
220463 pOut += n1;
220464 }else if( a2[0]!=0xFF ){
220465 bData = 1;
220466 memcpy(pOut, a2, n2);
220467 pOut += n2;
220468 }else{
220469 *pOut++ = '\0';
@@ -239022,11 +239524,11 @@
239022 int nArg, /* Number of args */
239023 sqlite3_value **apUnused /* Function arguments */
239024 ){
239025 assert( nArg==0 );
239026 UNUSED_PARAM2(nArg, apUnused);
239027 sqlite3_result_text(pCtx, "fts5: 2022-12-03 19:04:09 1a61c500add4a2bfe80c0c691d559cfca166dc5f8262651a58da7ec16a51d430", -1, SQLITE_TRANSIENT);
239028 }
239029
239030 /*
239031 ** Return true if zName is the extension on one of the shadow tables used
239032 ** by this module.
239033
--- extsrc/sqlite3.c
+++ extsrc/sqlite3.c
@@ -452,11 +452,11 @@
452 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
453 ** [sqlite_version()] and [sqlite_source_id()].
454 */
455 #define SQLITE_VERSION "3.41.0"
456 #define SQLITE_VERSION_NUMBER 3041000
457 #define SQLITE_SOURCE_ID "2022-12-15 15:37:52 751e344f4cd2045caf97920cc9f4571caf0de1ba83b94ded902a03b36c10a389"
458
459 /*
460 ** CAPI3REF: Run-Time Library Version Numbers
461 ** KEYWORDS: sqlite3_version sqlite3_sourceid
462 **
@@ -867,10 +867,11 @@
867 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
868 #define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
869 #define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))
870 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
871 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
872 #define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8))
873 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
874 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
875 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
876 #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
877
@@ -2488,11 +2489,11 @@
2489 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
2490 ** rounded down to the next smaller multiple of 8. ^(The lookaside memory
2491 ** configuration for a database connection can only be changed when that
2492 ** connection is not currently using lookaside memory, or in other words
2493 ** when the "current value" returned by
2494 ** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero.
2495 ** Any attempt to change the lookaside memory configuration when lookaside
2496 ** memory is in use leaves the configuration unchanged and returns
2497 ** [SQLITE_BUSY].)^</dd>
2498 **
2499 ** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
@@ -2638,12 +2639,16 @@
2639 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
2640 ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
2641 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
2642 ** </ol>
2643 ** Because resetting a database is destructive and irreversible, the
2644 ** process requires the use of this obscure API and multiple steps to
2645 ** help ensure that it does not happen by accident. Because this
2646 ** feature must be capable of resetting corrupt databases, and
2647 ** shutting down virtual tables may require access to that corrupt
2648 ** storage, the library must abandon any installed virtual tables
2649 ** without calling their xDestroy() methods.
2650 **
2651 ** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
2652 ** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
2653 ** "defensive" flag for a database connection. When the defensive
2654 ** flag is enabled, language features that allow ordinary SQL to
@@ -7318,19 +7323,10 @@
7323 ** ^This interface disables all automatic extensions previously
7324 ** registered using [sqlite3_auto_extension()].
7325 */
7326 SQLITE_API void sqlite3_reset_auto_extension(void);
7327
 
 
 
 
 
 
 
 
 
7328 /*
7329 ** Structures used by the virtual table interface
7330 */
7331 typedef struct sqlite3_vtab sqlite3_vtab;
7332 typedef struct sqlite3_index_info sqlite3_index_info;
@@ -7568,11 +7564,11 @@
7564 **
7565 ** The collating sequence to be used for comparison can be found using
7566 ** the [sqlite3_vtab_collation()] interface. For most real-world virtual
7567 ** tables, the collating sequence of constraints does not matter (for example
7568 ** because the constraints are numeric) and so the sqlite3_vtab_collation()
7569 ** interface is not commonly needed.
7570 */
7571 #define SQLITE_INDEX_CONSTRAINT_EQ 2
7572 #define SQLITE_INDEX_CONSTRAINT_GT 4
7573 #define SQLITE_INDEX_CONSTRAINT_LE 8
7574 #define SQLITE_INDEX_CONSTRAINT_LT 16
@@ -7727,20 +7723,10 @@
7723 ** purpose is to be a placeholder function that can be overloaded
7724 ** by a [virtual table].
7725 */
7726 SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
7727
 
 
 
 
 
 
 
 
 
 
7728 /*
7729 ** CAPI3REF: A Handle To An Open BLOB
7730 ** KEYWORDS: {BLOB handle} {BLOB handles}
7731 **
7732 ** An instance of this object represents an open BLOB on which
@@ -9940,11 +9926,11 @@
9926 ** statement that was passed into [sqlite3_declare_vtab()], then the
9927 ** name of that alternative collating sequence is returned.
9928 ** <li><p> Otherwise, "BINARY" is returned.
9929 ** </ol>
9930 */
9931 SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9932
9933 /*
9934 ** CAPI3REF: Determine if a virtual table query is DISTINCT
9935 ** METHOD: sqlite3_index_info
9936 **
@@ -10209,10 +10195,14 @@
10195 **
10196 ** When the value returned to V is a string, space to hold that string is
10197 ** managed by the prepared statement S and will be automatically freed when
10198 ** S is finalized.
10199 **
10200 ** Not all values are available for all query elements. When a value is
10201 ** not available, the output variable is set to -1 if the value is numeric,
10202 ** or to NULL if it is a string (SQLITE_SCANSTAT_NAME).
10203 **
10204 ** <dl>
10205 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
10206 ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
10207 ** set to the total number of times that the X-th loop has run.</dd>
10208 **
@@ -10236,30 +10226,44 @@
10226 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
10227 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
10228 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
10229 ** description for the X-th loop.
10230 **
10231 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
10232 ** <dd>^The "int" variable pointed to by the V parameter will be set to the
10233 ** id for the X-th query plan element. The id value is unique within the
10234 ** statement. The select-id is the same value as is output in the first
10235 ** column of an [EXPLAIN QUERY PLAN] query.
 
10236 ** </dl>
10237 **
10238 ** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
10239 ** <dd>The "int" variable pointed to by the V parameter will be set to the
10240 ** the id of the parent of the current query element, if applicable, or
10241 ** to zero if the query element has no parent. This is the same value as
10242 ** returned in the second column of an [EXPLAIN QUERY PLAN] query.
10243 **
10244 ** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
10245 ** <dd>The sqlite3_int64 output value is set to the number of cycles,
10246 ** according to the processor time-stamp counter, that elapsed while the
10247 ** query element was being processed. This value is not available for
10248 ** all query elements - if it is unavailable the output variable is
10249 ** set to -1.
10250 */
10251 #define SQLITE_SCANSTAT_NLOOP 0
10252 #define SQLITE_SCANSTAT_NVISIT 1
10253 #define SQLITE_SCANSTAT_EST 2
10254 #define SQLITE_SCANSTAT_NAME 3
10255 #define SQLITE_SCANSTAT_EXPLAIN 4
10256 #define SQLITE_SCANSTAT_SELECTID 5
10257 #define SQLITE_SCANSTAT_PARENTID 6
10258 #define SQLITE_SCANSTAT_NCYCLE 7
10259
10260 /*
10261 ** CAPI3REF: Prepared Statement Scan Status
10262 ** METHOD: sqlite3_stmt
10263 **
10264 ** These interfaces return information about the predicted and measured
10265 ** performance for pStmt. Advanced applications can use this
10266 ** interface to compare the predicted and the measured performance and
10267 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
10268 **
10269 ** Since this interface is expected to be rarely used, it is only
@@ -10266,32 +10270,51 @@
10270 ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
10271 ** compile-time option.
10272 **
10273 ** The "iScanStatusOp" parameter determines which status information to return.
10274 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
10275 ** of this interface is undefined. ^The requested measurement is written into
10276 ** a variable pointed to by the "pOut" parameter.
 
 
 
 
 
 
10277 **
10278 ** The "flags" parameter must be passed a mask of flags. At present only
10279 ** one flag is defined - SQLITE_SCANSTAT_COMPLEX. If SQLITE_SCANSTAT_COMPLEX
10280 ** is specified, then status information is available for all elements
10281 ** of a query plan that are reported by "EXPLAIN QUERY PLAN" output. If
10282 ** SQLITE_SCANSTAT_COMPLEX is not specified, then only query plan elements
10283 ** that correspond to query loops (the "SCAN..." and "SEARCH..." elements of
10284 ** the EXPLAIN QUERY PLAN output) are available. Invoking API
10285 ** sqlite3_stmt_scanstatus() is equivalent to calling
10286 ** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
10287 **
10288 ** Parameter "idx" identifies the specific query element to retrieve statistics
10289 ** for. Query elements are numbered starting from zero. A value of -1 may be
10290 ** to query for statistics regarding the entire query. ^If idx is out of range
10291 ** - less than -1 or greater than or equal to the total number of query
10292 ** elements used to implement the statement - a non-zero value is returned and
10293 ** the variable that pOut points to is unchanged.
10294 **
10295 ** See also: [sqlite3_stmt_scanstatus_reset()]
10296 */
10297 SQLITE_API int sqlite3_stmt_scanstatus(
10298 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
10299 int idx, /* Index of loop to report on */
10300 int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
10301 void *pOut /* Result written here */
10302 );
10303 SQLITE_API int sqlite3_stmt_scanstatus_v2(
10304 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
10305 int idx, /* Index of loop to report on */
10306 int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
10307 int flags, /* Mask of flags defined below */
10308 void *pOut /* Result written here */
10309 );
10310
10311 /*
10312 ** CAPI3REF: Prepared Statement Scan Status
10313 ** KEYWORDS: {scan status flags}
10314 */
10315 #define SQLITE_SCANSTAT_COMPLEX 0x0001
10316
10317 /*
10318 ** CAPI3REF: Zero Scan-Status Counters
10319 ** METHOD: sqlite3_stmt
10320 **
@@ -15901,17 +15924,17 @@
15924 #endif
15925 } p4;
15926 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
15927 char *zComment; /* Comment to improve readability */
15928 #endif
 
 
 
 
15929 #ifdef SQLITE_VDBE_COVERAGE
15930 u32 iSrcLine; /* Source-code line that generated this opcode
15931 ** with flags in the upper 8 bits */
15932 #endif
15933 #if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
15934 u64 nExec;
15935 u64 nCycle;
15936 #endif
15937 };
15938 typedef struct VdbeOp VdbeOp;
15939
15940
@@ -16199,33 +16222,34 @@
16222 #define OPFLG_IN1 0x02 /* in1: P1 is an input */
16223 #define OPFLG_IN2 0x04 /* in2: P2 is an input */
16224 #define OPFLG_IN3 0x08 /* in3: P3 is an input */
16225 #define OPFLG_OUT2 0x10 /* out2: P2 is an output */
16226 #define OPFLG_OUT3 0x20 /* out3: P3 is an output */
16227 #define OPFLG_NCYCLE 0x40 /* ncycle:Cycles count against P1 */
16228 #define OPFLG_INITIALIZER {\
16229 /* 0 */ 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x41, 0x00,\
16230 /* 8 */ 0x01, 0x01, 0x01, 0x01, 0x03, 0x03, 0x01, 0x01,\
16231 /* 16 */ 0x03, 0x03, 0x01, 0x12, 0x01, 0x49, 0x49, 0x49,\
16232 /* 24 */ 0x49, 0x01, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49,\
16233 /* 32 */ 0x41, 0x01, 0x01, 0x01, 0x41, 0x01, 0x41, 0x41,\
16234 /* 40 */ 0x41, 0x41, 0x41, 0x26, 0x26, 0x41, 0x23, 0x0b,\
16235 /* 48 */ 0x01, 0x01, 0x03, 0x03, 0x0b, 0x0b, 0x0b, 0x0b,\
16236 /* 56 */ 0x0b, 0x0b, 0x01, 0x03, 0x03, 0x03, 0x01, 0x41,\
16237 /* 64 */ 0x01, 0x00, 0x00, 0x02, 0x02, 0x08, 0x00, 0x10,\
16238 /* 72 */ 0x10, 0x10, 0x00, 0x10, 0x00, 0x10, 0x10, 0x00,\
16239 /* 80 */ 0x00, 0x10, 0x10, 0x00, 0x00, 0x00, 0x02, 0x02,\
16240 /* 88 */ 0x02, 0x00, 0x00, 0x12, 0x1e, 0x20, 0x40, 0x00,\
16241 /* 96 */ 0x00, 0x00, 0x10, 0x10, 0x00, 0x40, 0x26, 0x26,\
16242 /* 104 */ 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26, 0x26,\
16243 /* 112 */ 0x40, 0x00, 0x12, 0x40, 0x40, 0x10, 0x40, 0x00,\
16244 /* 120 */ 0x00, 0x00, 0x40, 0x00, 0x40, 0x40, 0x10, 0x10,\
16245 /* 128 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50,\
16246 /* 136 */ 0x00, 0x40, 0x04, 0x04, 0x00, 0x40, 0x50, 0x40,\
16247 /* 144 */ 0x10, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00, 0x00,\
16248 /* 152 */ 0x00, 0x10, 0x00, 0x00, 0x06, 0x10, 0x00, 0x04,\
16249 /* 160 */ 0x1a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
16250 /* 168 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x50, 0x40,\
16251 /* 176 */ 0x00, 0x10, 0x10, 0x02, 0x00, 0x00, 0x00, 0x00,\
16252 /* 184 */ 0x00, 0x00, 0x00,}
16253
16254 /* The resolve3P2Values() routine is able to run faster if it knows
16255 ** the value of the largest JUMP opcode. The smaller the maximum
@@ -16276,18 +16300,24 @@
16300 # define sqlite3VdbeVerifyAbortable(A,B)
16301 # define sqlite3VdbeNoJumpsOutsideSubrtn(A,B,C,D)
16302 #endif
16303 SQLITE_PRIVATE VdbeOp *sqlite3VdbeAddOpList(Vdbe*, int nOp, VdbeOpList const *aOp,int iLineno);
16304 #ifndef SQLITE_OMIT_EXPLAIN
16305 SQLITE_PRIVATE int sqlite3VdbeExplain(Parse*,u8,const char*,...);
16306 SQLITE_PRIVATE void sqlite3VdbeExplainPop(Parse*);
16307 SQLITE_PRIVATE int sqlite3VdbeExplainParent(Parse*);
16308 # define ExplainQueryPlan(P) sqlite3VdbeExplain P
16309 # ifdef SQLITE_ENABLE_STMT_SCANSTATUS
16310 # define ExplainQueryPlan2(V,P) (V = sqlite3VdbeExplain P)
16311 # else
16312 # define ExplainQueryPlan2(V,P) ExplainQueryPlan(P)
16313 # endif
16314 # define ExplainQueryPlanPop(P) sqlite3VdbeExplainPop(P)
16315 # define ExplainQueryPlanParent(P) sqlite3VdbeExplainParent(P)
16316 #else
16317 # define ExplainQueryPlan(P)
16318 # define ExplainQueryPlan2(V,P)
16319 # define ExplainQueryPlanPop(P)
16320 # define ExplainQueryPlanParent(P) 0
16321 # define sqlite3ExplainBreakpoint(A,B) /*no-op*/
16322 #endif
16323 #if defined(SQLITE_DEBUG) && !defined(SQLITE_OMIT_EXPLAIN)
@@ -16456,12 +16486,16 @@
16486 # define VDBE_OFFSET_LINENO(x) 0
16487 #endif
16488
16489 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
16490 SQLITE_PRIVATE void sqlite3VdbeScanStatus(Vdbe*, int, int, int, LogEst, const char*);
16491 SQLITE_PRIVATE void sqlite3VdbeScanStatusRange(Vdbe*, int, int, int);
16492 SQLITE_PRIVATE void sqlite3VdbeScanStatusCounters(Vdbe*, int, int, int);
16493 #else
16494 # define sqlite3VdbeScanStatus(a,b,c,d,e,f)
16495 # define sqlite3VdbeScanStatusRange(a,b,c,d)
16496 # define sqlite3VdbeScanStatusCounters(a,b,c,d)
16497 #endif
16498
16499 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
16500 SQLITE_PRIVATE void sqlite3VdbePrintOp(FILE*, int, VdbeOp*);
16501 #endif
@@ -17254,10 +17288,11 @@
17288 #define SQLITE_BalancedMerge 0x00200000 /* Balance multi-way merges */
17289 #define SQLITE_ReleaseReg 0x00400000 /* Use OP_ReleaseReg for testing */
17290 #define SQLITE_FlttnUnionAll 0x00800000 /* Disable the UNION ALL flattener */
17291 /* TH3 expects this value ^^^^^^^^^^ See flatten04.test */
17292 #define SQLITE_IndexedExpr 0x01000000 /* Pull exprs from index when able */
17293 #define SQLITE_Coroutines 0x02000000 /* Co-routines for subqueries */
17294 #define SQLITE_AllOpts 0xffffffff /* All optimizations */
17295
17296 /*
17297 ** Macros for testing whether or not optimizations are enabled or disabled.
17298 */
@@ -18875,10 +18910,11 @@
18910 #define SF_UFSrcCheck 0x0800000 /* Check pSrc as required by UPDATE...FROM */
18911 #define SF_PushDown 0x1000000 /* SELECT has be modified by push-down opt */
18912 #define SF_MultiPart 0x2000000 /* Has multiple incompatible PARTITIONs */
18913 #define SF_CopyCte 0x4000000 /* SELECT statement is a copy of a CTE */
18914 #define SF_OrderByReqd 0x8000000 /* The ORDER BY clause may not be omitted */
18915 #define SF_UpdateFrom 0x10000000 /* Query originates with UPDATE FROM */
18916
18917 /* True if S exists and has SF_NestedFrom */
18918 #define IsNestedFrom(S) ((S)!=0 && ((S)->selFlags&SF_NestedFrom)!=0)
18919
18920 /*
@@ -18983,11 +19019,11 @@
19019 u8 eDest; /* How to dispose of the results. One of SRT_* above. */
19020 int iSDParm; /* A parameter used by the eDest disposal method */
19021 int iSDParm2; /* A second parameter for the eDest disposal method */
19022 int iSdst; /* Base register where results are written */
19023 int nSdst; /* Number of registers allocated */
19024 char *zAffSdst; /* Affinity used for SRT_Set */
19025 ExprList *pOrderBy; /* Key columns for SRT_Queue and SRT_DistQueue */
19026 };
19027
19028 /*
19029 ** During code generation of statements that do inserts into AUTOINCREMENT
@@ -20088,11 +20124,11 @@
20124 SQLITE_PRIVATE void sqlite3ColumnSetColl(sqlite3*,Column*,const char*zColl);
20125 SQLITE_PRIVATE const char *sqlite3ColumnColl(Column*);
20126 SQLITE_PRIVATE void sqlite3DeleteColumnNames(sqlite3*,Table*);
20127 SQLITE_PRIVATE void sqlite3GenerateColumnNames(Parse *pParse, Select *pSelect);
20128 SQLITE_PRIVATE int sqlite3ColumnsFromExprList(Parse*,ExprList*,i16*,Column**);
20129 SQLITE_PRIVATE void sqlite3SubqueryColumnTypes(Parse*,Table*,Select*,char);
20130 SQLITE_PRIVATE Table *sqlite3ResultSetOfSelect(Parse*,Select*,char);
20131 SQLITE_PRIVATE void sqlite3OpenSchemaTable(Parse *, int);
20132 SQLITE_PRIVATE Index *sqlite3PrimaryKeyIndex(Table*);
20133 SQLITE_PRIVATE i16 sqlite3TableColumnToIndex(Index*, i16);
20134 #ifdef SQLITE_OMIT_GENERATED_COLUMNS
@@ -20459,10 +20495,11 @@
20495 SQLITE_PRIVATE void sqlite3TableAffinity(Vdbe*, Table*, int);
20496 SQLITE_PRIVATE char sqlite3CompareAffinity(const Expr *pExpr, char aff2);
20497 SQLITE_PRIVATE int sqlite3IndexAffinityOk(const Expr *pExpr, char idx_affinity);
20498 SQLITE_PRIVATE char sqlite3TableColumnAffinity(const Table*,int);
20499 SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr);
20500 SQLITE_PRIVATE int sqlite3ExprDataType(const Expr *pExpr);
20501 SQLITE_PRIVATE int sqlite3Atoi64(const char*, i64*, int, u8);
20502 SQLITE_PRIVATE int sqlite3DecOrHexToI64(const char*, i64*);
20503 SQLITE_PRIVATE void sqlite3ErrorWithMsg(sqlite3*, int, const char*,...);
20504 SQLITE_PRIVATE void sqlite3Error(sqlite3*,int);
20505 SQLITE_PRIVATE void sqlite3ErrorClear(sqlite3*);
@@ -20975,11 +21012,13 @@
21012
21013 #if SQLITE_OS_UNIX && defined(SQLITE_OS_KV_OPTIONAL)
21014 SQLITE_PRIVATE int sqlite3KvvfsInit(void);
21015 #endif
21016
21017 #if defined(VDBE_PROFILE) \
21018 || defined(SQLITE_PERFORMANCE_TRACE) \
21019 || defined(SQLITE_ENABLE_STMT_SCANSTATUS)
21020 SQLITE_PRIVATE sqlite3_uint64 sqlite3Hwtime(void);
21021 #endif
21022
21023 #endif /* SQLITEINT_H */
21024
@@ -22464,11 +22503,10 @@
22503 typedef struct VdbeFrame VdbeFrame;
22504 struct VdbeFrame {
22505 Vdbe *v; /* VM this frame belongs to */
22506 VdbeFrame *pParent; /* Parent of this frame, or NULL if parent is main */
22507 Op *aOp; /* Program instructions for parent frame */
 
22508 Mem *aMem; /* Array of memory cells for parent frame */
22509 VdbeCursor **apCsr; /* Array of Vdbe cursors for parent frame */
22510 u8 *aOnce; /* Bitmask used by OP_Once */
22511 void *token; /* Copy of SubProgram.token */
22512 i64 lastRowid; /* Last insert rowid (sqlite3.lastRowid) */
@@ -22680,14 +22718,23 @@
22718 */
22719 typedef unsigned bft; /* Bit Field Type */
22720
22721 /* The ScanStatus object holds a single value for the
22722 ** sqlite3_stmt_scanstatus() interface.
22723 **
22724 ** aAddrRange[]:
22725 ** This array is used by ScanStatus elements associated with EQP
22726 ** notes that make an SQLITE_SCANSTAT_NCYCLE value available. It is
22727 ** an array of up to 3 ranges of VM addresses for which the Vdbe.anCycle[]
22728 ** values should be summed to calculate the NCYCLE value. Each pair of
22729 ** integer addresses is a start and end address (both inclusive) for a range
22730 ** instructions. A start value of 0 indicates an empty range.
22731 */
22732 typedef struct ScanStatus ScanStatus;
22733 struct ScanStatus {
22734 int addrExplain; /* OP_Explain for loop */
22735 int aAddrRange[6];
22736 int addrLoop; /* Address of "loops" counter */
22737 int addrVisit; /* Address of "rows visited" counter */
22738 int iSelectID; /* The "Select-ID" for this loop */
22739 LogEst nEst; /* Estimated output rows per loop */
22740 char *zName; /* Name of table or index */
@@ -22776,11 +22823,10 @@
22823 int nFrame; /* Number of frames in pFrame list */
22824 u32 expmask; /* Binding to these vars invalidates VM */
22825 SubProgram *pProgram; /* Linked list of all sub-programs used by VM */
22826 AuxData *pAuxData; /* Linked list of auxdata allocations */
22827 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
 
22828 int nScan; /* Entries in aScan[] */
22829 ScanStatus *aScan; /* Scan definitions for sqlite3_stmt_scanstatus() */
22830 #endif
22831 };
22832
@@ -35198,11 +35244,13 @@
35244 }
35245
35246 /*
35247 ** High-resolution hardware timer used for debugging and testing only.
35248 */
35249 #if defined(VDBE_PROFILE) \
35250 || defined(SQLITE_PERFORMANCE_TRACE) \
35251 || defined(SQLITE_ENABLE_STMT_SCANSTATUS)
35252 /************** Include hwtime.h in the middle of util.c *********************/
35253 /************** Begin file hwtime.h ******************************************/
35254 /*
35255 ** 2008 May 27
35256 **
@@ -35251,13 +35299,13 @@
35299 #endif
35300
35301 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__x86_64__))
35302
35303 __inline__ sqlite_uint64 sqlite3Hwtime(void){
35304 unsigned int lo, hi;
35305 __asm__ __volatile__ ("rdtsc" : "=a" (lo), "=d" (hi));
35306 return (sqlite_uint64)hi << 32 | lo;
35307 }
35308
35309 #elif !defined(__STRICT_ANSI__) && (defined(__GNUC__) && defined(__ppc__))
35310
35311 __inline__ sqlite_uint64 sqlite3Hwtime(void){
@@ -37442,10 +37490,13 @@
37490 if( fd<0 ){
37491 if( errno==EINTR ) continue;
37492 break;
37493 }
37494 if( fd>=SQLITE_MINIMUM_FILE_DESCRIPTOR ) break;
37495 if( (f & (O_EXCL|O_CREAT))==(O_EXCL|O_CREAT) ){
37496 (void)osUnlink(z);
37497 }
37498 osClose(fd);
37499 sqlite3_log(SQLITE_WARNING,
37500 "attempt to open \"%s\" as file descriptor %d", z, fd);
37501 fd = -1;
37502 if( osOpen("/dev/null", O_RDONLY, m)<0 ) break;
@@ -51436,14 +51487,39 @@
51487 MemFile *pThis = (MemFile*)pFile;
51488 MemStore *p = pThis->pStore;
51489 int rc = SQLITE_OK;
51490 if( eLock==pThis->eLock ) return SQLITE_OK;
51491 memdbEnter(p);
51492 assert( p->nWrLock==0 || p->nWrLock==1 ); /* No more than 1 write lock */
51493 if( eLock>SQLITE_LOCK_SHARED ){
51494 assert( pThis->eLock>=SQLITE_LOCK_SHARED );
51495 if( p->mFlags & SQLITE_DESERIALIZE_READONLY ){
51496 rc = SQLITE_READONLY;
51497 }else if( eLock==SQLITE_LOCK_EXCLUSIVE ){
51498 /* We never go for an EXCLUSIVE lock unless we already hold SHARED or
51499 ** higher */
51500 assert( pThis->eLock>=SQLITE_LOCK_SHARED );
51501 testcase( pThis->eLock==SQLITE_LOCK_SHARED );
51502
51503 /* Because we are holding SHARED or more, there must be at least
51504 ** one read lock */
51505 assert( p->nRdLock>0 );
51506
51507 /* The only way that there can be an existing write lock is if we
51508 ** currently hold it. Otherwise, we would have never been able to
51509 ** promote from NONE to SHARED. */
51510 assert( p->nWrLock==0 || pThis->eLock>SQLITE_LOCK_SHARED );
51511
51512 if( p->nRdLock>1 ){
51513 /* Cannot take EXCLUSIVE if somebody else is holding SHARED */
51514 rc = SQLITE_BUSY;
51515 }else{
51516 p->nWrLock = 1;
51517 }
51518 }else if( ALWAYS(pThis->eLock<=SQLITE_LOCK_SHARED) ){
51519 /* Upgrading to RESERVED or PENDING from SHARED. Fail if any other
51520 ** client has a write-lock of any kind. */
51521 if( p->nWrLock ){
51522 rc = SQLITE_BUSY;
51523 }else{
51524 p->nWrLock = 1;
51525 }
@@ -82327,21 +82403,21 @@
82403 pOp->p3 = p3;
82404 pOp->p4.p = 0;
82405 pOp->p4type = P4_NOTUSED;
82406 #ifdef SQLITE_ENABLE_EXPLAIN_COMMENTS
82407 pOp->zComment = 0;
82408 #endif
82409 #if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
82410 pOp->nExec = 0;
82411 pOp->nCycle = 0;
82412 #endif
82413 #ifdef SQLITE_DEBUG
82414 if( p->db->flags & SQLITE_VdbeAddopTrace ){
82415 sqlite3VdbePrintOp(0, i, &p->aOp[i]);
82416 test_addop_breakpoint(i, &p->aOp[i]);
82417 }
82418 #endif
 
 
 
 
82419 #ifdef SQLITE_VDBE_COVERAGE
82420 pOp->iSrcLine = 0;
82421 #endif
82422 return i;
82423 }
@@ -82505,12 +82581,13 @@
82581 ** Add a new OP_Explain opcode.
82582 **
82583 ** If the bPush flag is true, then make this opcode the parent for
82584 ** subsequent Explains until sqlite3VdbeExplainPop() is called.
82585 */
82586 SQLITE_PRIVATE int sqlite3VdbeExplain(Parse *pParse, u8 bPush, const char *zFmt, ...){
82587 int addr = 0;
82588 #if !defined(SQLITE_DEBUG) && !defined(SQLITE_ENABLE_STMT_SCANSTATUS)
82589 /* Always include the OP_Explain opcodes if SQLITE_DEBUG is defined.
82590 ** But omit them (for performance) during production builds */
82591 if( pParse->explain==2 )
82592 #endif
82593 {
@@ -82521,17 +82598,19 @@
82598 va_start(ap, zFmt);
82599 zMsg = sqlite3VMPrintf(pParse->db, zFmt, ap);
82600 va_end(ap);
82601 v = pParse->pVdbe;
82602 iThis = v->nOp;
82603 addr = sqlite3VdbeAddOp4(v, OP_Explain, iThis, pParse->addrExplain, 0,
82604 zMsg, P4_DYNAMIC);
82605 sqlite3ExplainBreakpoint(bPush?"PUSH":"", sqlite3VdbeGetLastOp(v)->p4.z);
82606 if( bPush){
82607 pParse->addrExplain = iThis;
82608 }
82609 sqlite3VdbeScanStatus(v, iThis, 0, 0, 0, 0);
82610 }
82611 return addr;
82612 }
82613
82614 /*
82615 ** Pop the EXPLAIN QUERY PLAN stack one level.
82616 */
@@ -83185,18 +83264,75 @@
83264 sqlite3_int64 nByte = (p->nScan+1) * sizeof(ScanStatus);
83265 ScanStatus *aNew;
83266 aNew = (ScanStatus*)sqlite3DbRealloc(p->db, p->aScan, nByte);
83267 if( aNew ){
83268 ScanStatus *pNew = &aNew[p->nScan++];
83269 memset(pNew, 0, sizeof(ScanStatus));
83270 pNew->addrExplain = addrExplain;
83271 pNew->addrLoop = addrLoop;
83272 pNew->addrVisit = addrVisit;
83273 pNew->nEst = nEst;
83274 pNew->zName = sqlite3DbStrDup(p->db, zName);
83275 p->aScan = aNew;
83276 }
83277 }
83278
83279 /*
83280 ** Add the range of instructions from addrStart to addrEnd (inclusive) to
83281 ** the set of those corresponding to the sqlite3_stmt_scanstatus() counters
83282 ** associated with the OP_Explain instruction at addrExplain. The
83283 ** sum of the sqlite3Hwtime() values for each of these instructions
83284 ** will be returned for SQLITE_SCANSTAT_NCYCLE requests.
83285 */
83286 SQLITE_PRIVATE void sqlite3VdbeScanStatusRange(
83287 Vdbe *p,
83288 int addrExplain,
83289 int addrStart,
83290 int addrEnd
83291 ){
83292 ScanStatus *pScan = 0;
83293 int ii;
83294 for(ii=p->nScan-1; ii>=0; ii--){
83295 pScan = &p->aScan[ii];
83296 if( pScan->addrExplain==addrExplain ) break;
83297 pScan = 0;
83298 }
83299 if( pScan ){
83300 if( addrEnd<0 ) addrEnd = sqlite3VdbeCurrentAddr(p)-1;
83301 for(ii=0; ii<ArraySize(pScan->aAddrRange); ii+=2){
83302 if( pScan->aAddrRange[ii]==0 ){
83303 pScan->aAddrRange[ii] = addrStart;
83304 pScan->aAddrRange[ii+1] = addrEnd;
83305 break;
83306 }
83307 }
83308 }
83309 }
83310
83311 /*
83312 ** Set the addresses for the SQLITE_SCANSTAT_NLOOP and SQLITE_SCANSTAT_NROW
83313 ** counters for the query element associated with the OP_Explain at
83314 ** addrExplain.
83315 */
83316 SQLITE_PRIVATE void sqlite3VdbeScanStatusCounters(
83317 Vdbe *p,
83318 int addrExplain,
83319 int addrLoop,
83320 int addrVisit
83321 ){
83322 ScanStatus *pScan = 0;
83323 int ii;
83324 for(ii=p->nScan-1; ii>=0; ii--){
83325 pScan = &p->aScan[ii];
83326 if( pScan->addrExplain==addrExplain ) break;
83327 pScan = 0;
83328 }
83329 if( pScan ){
83330 pScan->addrLoop = addrLoop;
83331 pScan->addrVisit = addrVisit;
83332 }
83333 }
83334 #endif
83335
83336
83337 /*
83338 ** Change the value of the opcode, or P1, P2, P3, or P5 operands
@@ -84490,11 +84626,11 @@
84626 /*
84627 ** Rewind the VDBE back to the beginning in preparation for
84628 ** running it.
84629 */
84630 SQLITE_PRIVATE void sqlite3VdbeRewind(Vdbe *p){
84631 #if defined(SQLITE_DEBUG)
84632 int i;
84633 #endif
84634 assert( p!=0 );
84635 assert( p->eVdbeState==VDBE_INIT_STATE
84636 || p->eVdbeState==VDBE_READY_STATE
@@ -84519,12 +84655,12 @@
84655 p->minWriteFileFormat = 255;
84656 p->iStatement = 0;
84657 p->nFkConstraint = 0;
84658 #ifdef VDBE_PROFILE
84659 for(i=0; i<p->nOp; i++){
84660 p->aOp[i].nExec = 0;
84661 p->aOp[i].nCycle = 0;
84662 }
84663 #endif
84664 }
84665
84666 /*
@@ -84629,24 +84765,18 @@
84765 x.nNeeded = 0;
84766 p->aMem = allocSpace(&x, 0, nMem*sizeof(Mem));
84767 p->aVar = allocSpace(&x, 0, nVar*sizeof(Mem));
84768 p->apArg = allocSpace(&x, 0, nArg*sizeof(Mem*));
84769 p->apCsr = allocSpace(&x, 0, nCursor*sizeof(VdbeCursor*));
 
 
 
84770 if( x.nNeeded ){
84771 x.pSpace = p->pFree = sqlite3DbMallocRawNN(db, x.nNeeded);
84772 x.nFree = x.nNeeded;
84773 if( !db->mallocFailed ){
84774 p->aMem = allocSpace(&x, p->aMem, nMem*sizeof(Mem));
84775 p->aVar = allocSpace(&x, p->aVar, nVar*sizeof(Mem));
84776 p->apArg = allocSpace(&x, p->apArg, nArg*sizeof(Mem*));
84777 p->apCsr = allocSpace(&x, p->apCsr, nCursor*sizeof(VdbeCursor*));
 
 
 
84778 }
84779 }
84780
84781 if( db->mallocFailed ){
84782 p->nVar = 0;
@@ -84657,13 +84787,10 @@
84787 p->nVar = (ynVar)nVar;
84788 initMemArray(p->aVar, nVar, db, MEM_Null);
84789 p->nMem = nMem;
84790 initMemArray(p->aMem, nMem, db, MEM_Undefined);
84791 memset(p->apCsr, 0, nCursor*sizeof(VdbeCursor*));
 
 
 
84792 }
84793 sqlite3VdbeRewind(p);
84794 }
84795
84796 /*
@@ -84717,13 +84844,10 @@
84844 ** control to the main program.
84845 */
84846 SQLITE_PRIVATE int sqlite3VdbeFrameRestore(VdbeFrame *pFrame){
84847 Vdbe *v = pFrame->v;
84848 closeCursorsInFrame(v);
 
 
 
84849 v->aOp = pFrame->aOp;
84850 v->nOp = pFrame->nOp;
84851 v->aMem = pFrame->aMem;
84852 v->nMem = pFrame->nMem;
84853 v->apCsr = pFrame->apCsr;
@@ -85551,14 +85675,16 @@
85675 }
85676 if( pc!='\n' ) fprintf(out, "\n");
85677 }
85678 for(i=0; i<p->nOp; i++){
85679 char zHdr[100];
85680 i64 cnt = p->aOp[i].nExec;
85681 i64 cycles = p->aOp[i].nCycle;
85682 sqlite3_snprintf(sizeof(zHdr), zHdr, "%6u %12llu %8llu ",
85683 cnt,
85684 cycles,
85685 cnt>0 ? cycles/cnt : 0
85686 );
85687 fprintf(out, "%s", zHdr);
85688 sqlite3VdbePrintOp(out, i, &p->aOp[i]);
85689 }
85690 fclose(out);
@@ -87409,10 +87535,11 @@
87535 ** This file contains code use to implement APIs that are part of the
87536 ** VDBE.
87537 */
87538 /* #include "sqliteInt.h" */
87539 /* #include "vdbeInt.h" */
87540 /* #include "opcodes.h" */
87541
87542 #ifndef SQLITE_OMIT_DEPRECATED
87543 /*
87544 ** Return TRUE (non-zero) of the statement supplied as an argument needs
87545 ** to be recompiled. A statement needs to be recompiled whenever the
@@ -89505,27 +89632,64 @@
89632
89633 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
89634 /*
89635 ** Return status data for a single loop within query pStmt.
89636 */
89637 SQLITE_API int sqlite3_stmt_scanstatus_v2(
89638 sqlite3_stmt *pStmt, /* Prepared statement being queried */
89639 int iScan, /* Index of loop to report on */
89640 int iScanStatusOp, /* Which metric to return */
89641 int flags,
89642 void *pOut /* OUT: Write the answer here */
89643 ){
89644 Vdbe *p = (Vdbe*)pStmt;
89645 ScanStatus *pScan;
89646 int idx;
89647
89648 if( iScan<0 ){
89649 int ii;
89650 if( iScanStatusOp==SQLITE_SCANSTAT_NCYCLE ){
89651 i64 res = 0;
89652 for(ii=0; ii<p->nOp; ii++){
89653 res += p->aOp[ii].nCycle;
89654 }
89655 *(i64*)pOut = res;
89656 return 0;
89657 }
89658 return 1;
89659 }
89660 if( flags & SQLITE_SCANSTAT_COMPLEX ){
89661 idx = iScan;
89662 pScan = &p->aScan[idx];
89663 }else{
89664 /* If the COMPLEX flag is clear, then this function must ignore any
89665 ** ScanStatus structures with ScanStatus.addrLoop set to 0. */
89666 for(idx=0; idx<p->nScan; idx++){
89667 pScan = &p->aScan[idx];
89668 if( pScan->zName ){
89669 iScan--;
89670 if( iScan<0 ) break;
89671 }
89672 }
89673 }
89674 if( idx>=p->nScan ) return 1;
89675
89676 switch( iScanStatusOp ){
89677 case SQLITE_SCANSTAT_NLOOP: {
89678 if( pScan->addrLoop>0 ){
89679 *(sqlite3_int64*)pOut = p->aOp[pScan->addrLoop].nExec;
89680 }else{
89681 *(sqlite3_int64*)pOut = -1;
89682 }
89683 break;
89684 }
89685 case SQLITE_SCANSTAT_NVISIT: {
89686 if( pScan->addrVisit>0 ){
89687 *(sqlite3_int64*)pOut = p->aOp[pScan->addrVisit].nExec;
89688 }else{
89689 *(sqlite3_int64*)pOut = -1;
89690 }
89691 break;
89692 }
89693 case SQLITE_SCANSTAT_EST: {
89694 double r = 1.0;
89695 LogEst x = pScan->nEst;
@@ -89553,24 +89717,80 @@
89717 *(int*)pOut = p->aOp[ pScan->addrExplain ].p1;
89718 }else{
89719 *(int*)pOut = -1;
89720 }
89721 break;
89722 }
89723 case SQLITE_SCANSTAT_PARENTID: {
89724 if( pScan->addrExplain ){
89725 *(int*)pOut = p->aOp[ pScan->addrExplain ].p2;
89726 }else{
89727 *(int*)pOut = -1;
89728 }
89729 break;
89730 }
89731 case SQLITE_SCANSTAT_NCYCLE: {
89732 i64 res = 0;
89733 if( pScan->aAddrRange[0]==0 ){
89734 res = -1;
89735 }else{
89736 int ii;
89737 for(ii=0; ii<ArraySize(pScan->aAddrRange); ii+=2){
89738 int iIns = pScan->aAddrRange[ii];
89739 int iEnd = pScan->aAddrRange[ii+1];
89740 if( iIns==0 ) break;
89741 if( iIns>0 ){
89742 while( iIns<=iEnd ){
89743 res += p->aOp[iIns].nCycle;
89744 iIns++;
89745 }
89746 }else{
89747 int iOp;
89748 for(iOp=0; iOp<p->nOp; iOp++){
89749 Op *pOp = &p->aOp[iOp];
89750 if( pOp->p1!=iEnd ) continue;
89751 if( (sqlite3OpcodeProperty[pOp->opcode] & OPFLG_NCYCLE)==0 ){
89752 continue;
89753 }
89754 res += p->aOp[iOp].nCycle;
89755 }
89756 }
89757 }
89758 }
89759 *(i64*)pOut = res;
89760 break;
89761 }
89762 default: {
89763 return 1;
89764 }
89765 }
89766 return 0;
89767 }
89768
89769 /*
89770 ** Return status data for a single loop within query pStmt.
89771 */
89772 SQLITE_API int sqlite3_stmt_scanstatus(
89773 sqlite3_stmt *pStmt, /* Prepared statement being queried */
89774 int iScan, /* Index of loop to report on */
89775 int iScanStatusOp, /* Which metric to return */
89776 void *pOut /* OUT: Write the answer here */
89777 ){
89778 return sqlite3_stmt_scanstatus_v2(pStmt, iScan, iScanStatusOp, 0, pOut);
89779 }
89780
89781 /*
89782 ** Zero all counters associated with the sqlite3_stmt_scanstatus() data.
89783 */
89784 SQLITE_API void sqlite3_stmt_scanstatus_reset(sqlite3_stmt *pStmt){
89785 Vdbe *p = (Vdbe*)pStmt;
89786 int ii;
89787 for(ii=0; ii<p->nOp; ii++){
89788 Op *pOp = &p->aOp[ii];
89789 pOp->nExec = 0;
89790 pOp->nCycle = 0;
89791 }
89792 }
89793 #endif /* SQLITE_ENABLE_STMT_SCANSTATUS */
89794
89795 /************** End of vdbeapi.c *********************************************/
89796 /************** Begin file vdbetrace.c ***************************************/
@@ -90386,11 +90606,10 @@
90606 # define REGISTER_TRACE(R,M) if(db->flags&SQLITE_VdbeTrace)registerTrace(R,M)
90607 #else
90608 # define REGISTER_TRACE(R,M)
90609 #endif
90610
 
90611 #ifndef NDEBUG
90612 /*
90613 ** This function is only called from within an assert() expression. It
90614 ** checks that the sqlite3.nTransaction variable is correctly set to
90615 ** the number of non-transaction savepoints currently in the
@@ -90476,14 +90695,12 @@
90695 SQLITE_PRIVATE int sqlite3VdbeExec(
90696 Vdbe *p /* The VDBE */
90697 ){
90698 Op *aOp = p->aOp; /* Copy of p->aOp */
90699 Op *pOp = aOp; /* Current operation */
90700 #ifdef SQLITE_DEBUG
90701 Op *pOrigOp; /* Value of pOp at the top of the loop */
 
 
90702 int nExtraDelete = 0; /* Verifies FORDELETE and AUXDELETE flags */
90703 #endif
90704 int rc = SQLITE_OK; /* Value to return */
90705 sqlite3 *db = p->db; /* The database */
90706 u8 resetSchemaOnFault = 0; /* Reset schema after an error if positive */
@@ -90496,12 +90713,12 @@
90713 Mem *aMem = p->aMem; /* Copy of p->aMem */
90714 Mem *pIn1 = 0; /* 1st input operand */
90715 Mem *pIn2 = 0; /* 2nd input operand */
90716 Mem *pIn3 = 0; /* 3rd input operand */
90717 Mem *pOut = 0; /* Output operand */
90718 #if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
90719 u64 *pnCycle = 0;
90720 #endif
90721 /*** INSERT STACK UNION HERE ***/
90722
90723 assert( p->eVdbeState==VDBE_RUN_STATE ); /* sqlite3_step() verifies this */
90724 sqlite3VdbeEnter(p);
@@ -90560,16 +90777,18 @@
90777 /* Errors are detected by individual opcodes, with an immediate
90778 ** jumps to abort_due_to_error. */
90779 assert( rc==SQLITE_OK );
90780
90781 assert( pOp>=aOp && pOp<&aOp[p->nOp]);
 
 
 
90782 nVmStep++;
90783 #if defined(SQLITE_ENABLE_STMT_SCANSTATUS) || defined(VDBE_PROFILE)
90784 pOp->nExec++;
90785 pnCycle = &pOp->nCycle;
90786 # ifdef VDBE_PROFILE
90787 if( sqlite3NProfileCnt==0 )
90788 # endif
90789 *pnCycle -= sqlite3Hwtime();
90790 #endif
90791
90792 /* Only allow tracing if SQLITE_DEBUG is defined.
90793 */
90794 #ifdef SQLITE_DEBUG
@@ -90627,11 +90846,11 @@
90846 assert( pOp->p3<=(p->nMem+1 - p->nCursor) );
90847 memAboutToChange(p, &aMem[pOp->p3]);
90848 }
90849 }
90850 #endif
90851 #ifdef SQLITE_DEBUG
90852 pOrigOp = pOp;
90853 #endif
90854
90855 switch( pOp->opcode ){
90856
@@ -91885,11 +92104,10 @@
92104 pIn1 = &aMem[pOp->p1];
92105 pIn3 = &aMem[pOp->p3];
92106 flags1 = pIn1->flags;
92107 flags3 = pIn3->flags;
92108 if( (flags1 & flags3 & MEM_Int)!=0 ){
 
92109 /* Common case of comparison of two integers */
92110 if( pIn3->u.i > pIn1->u.i ){
92111 if( sqlite3aGTb[pOp->opcode] ){
92112 VdbeBranchTaken(1, (pOp->p5 & SQLITE_NULLEQ)?2:3);
92113 goto jump_to_p2;
@@ -91953,11 +92171,11 @@
92171 }
92172 if( (flags3 & (MEM_Int|MEM_IntReal|MEM_Real|MEM_Str))==MEM_Str ){
92173 applyNumericAffinity(pIn3,0);
92174 }
92175 }
92176 }else if( affinity==SQLITE_AFF_TEXT && ((flags1 | flags3) & MEM_Str)!=0 ){
92177 if( (flags1 & MEM_Str)==0 && (flags1&(MEM_Int|MEM_Real|MEM_IntReal))!=0 ){
92178 testcase( pIn1->flags & MEM_Int );
92179 testcase( pIn1->flags & MEM_Real );
92180 testcase( pIn1->flags & MEM_IntReal );
92181 sqlite3VdbeMemStringify(pIn1, encoding, 1);
@@ -92547,11 +92765,11 @@
92765 ** of large blobs is not loaded, thus saving CPU cycles. If the
92766 ** OPFLAG_TYPEOFARG bit is set then the result will only be used by the
92767 ** typeof() function or the IS NULL or IS NOT NULL operators or the
92768 ** equivalent. In this case, all content loading can be omitted.
92769 */
92770 case OP_Column: { /* ncycle */
92771 u32 p2; /* column number to retrieve */
92772 VdbeCursor *pC; /* The VDBE cursor */
92773 BtCursor *pCrsr; /* The B-Tree cursor corresponding to pC */
92774 u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
92775 int len; /* The length of the serialized data for the column */
@@ -93899,11 +94117,11 @@
94117 ** This instruction works like OpenRead except that it opens the cursor
94118 ** in read/write mode.
94119 **
94120 ** See also: OP_OpenRead, OP_ReopenIdx
94121 */
94122 case OP_ReopenIdx: { /* ncycle */
94123 int nField;
94124 KeyInfo *pKeyInfo;
94125 u32 p2;
94126 int iDb;
94127 int wrFlag;
@@ -93920,11 +94138,11 @@
94138 sqlite3BtreeClearCursor(pCur->uc.pCursor);
94139 goto open_cursor_set_hints;
94140 }
94141 /* If the cursor is not currently open or is open on a different
94142 ** index, then fall through into OP_OpenRead to force a reopen */
94143 case OP_OpenRead: /* ncycle */
94144 case OP_OpenWrite:
94145
94146 assert( pOp->opcode==OP_OpenWrite || pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ );
94147 assert( p->bIsReader );
94148 assert( pOp->opcode==OP_OpenRead || pOp->opcode==OP_ReopenIdx
@@ -94014,11 +94232,11 @@
94232 ** cursor P2. The P2 cursor must have been opened by a prior OP_OpenEphemeral
94233 ** opcode. Only ephemeral cursors may be duplicated.
94234 **
94235 ** Duplicate ephemeral cursors are used for self-joins of materialized views.
94236 */
94237 case OP_OpenDup: { /* ncycle */
94238 VdbeCursor *pOrig; /* The original cursor to be duplicated */
94239 VdbeCursor *pCx; /* The new cursor */
94240
94241 pOrig = p->apCsr[pOp->p2];
94242 assert( pOrig );
@@ -94076,12 +94294,12 @@
94294 ** This opcode works the same as OP_OpenEphemeral. It has a
94295 ** different name to distinguish its use. Tables created using
94296 ** by this opcode will be used for automatically created transient
94297 ** indices in joins.
94298 */
94299 case OP_OpenAutoindex: /* ncycle */
94300 case OP_OpenEphemeral: { /* ncycle */
94301 VdbeCursor *pCx;
94302 KeyInfo *pKeyInfo;
94303
94304 static const int vfsFlags =
94305 SQLITE_OPEN_READWRITE |
@@ -94235,11 +94453,11 @@
94453 /* Opcode: Close P1 * * * *
94454 **
94455 ** Close a cursor previously opened as P1. If P1 is not
94456 ** currently open, this instruction is a no-op.
94457 */
94458 case OP_Close: { /* ncycle */
94459 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
94460 sqlite3VdbeFreeCursor(p, p->apCsr[pOp->p1]);
94461 p->apCsr[pOp->p1] = 0;
94462 break;
94463 }
@@ -94352,14 +94570,14 @@
94570 ** OPFLAG_SEEKEQ flags is a hint to the btree layer to say that this
94571 ** is an equality search.
94572 **
94573 ** See also: Found, NotFound, SeekGt, SeekGe, SeekLt
94574 */
94575 case OP_SeekLT: /* jump, in3, group, ncycle */
94576 case OP_SeekLE: /* jump, in3, group, ncycle */
94577 case OP_SeekGE: /* jump, in3, group, ncycle */
94578 case OP_SeekGT: { /* jump, in3, group, ncycle */
94579 int res; /* Comparison result */
94580 int oc; /* Opcode */
94581 VdbeCursor *pC; /* The cursor to seek */
94582 UnpackedRecord r; /* The key to seek for */
94583 int nField; /* Number of columns or fields in the key */
@@ -94621,11 +94839,11 @@
94839 ** <li> If the cursor ends up on a valid row that is past the target row
94840 ** (indicating that the target row does not exist in the btree) then
94841 ** jump to SeekOP.P2 if This.P5==0 or to This.P2 if This.P5>0.
94842 ** </ol>
94843 */
94844 case OP_SeekScan: { /* ncycle */
94845 VdbeCursor *pC;
94846 int res;
94847 int nStep;
94848 UnpackedRecord r;
94849
@@ -94743,11 +94961,11 @@
94961 ** OP_IfNoHope opcode might run to see if the IN loop can be abandoned
94962 ** early, thus saving work. This is part of the IN-early-out optimization.
94963 **
94964 ** P1 must be a valid b-tree cursor.
94965 */
94966 case OP_SeekHit: { /* ncycle */
94967 VdbeCursor *pC;
94968 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
94969 pC = p->apCsr[pOp->p1];
94970 assert( pC!=0 );
94971 assert( pOp->p3>=pOp->p2 );
@@ -94875,11 +95093,11 @@
95093 ** advanced in either direction. In other words, the Next and Prev
95094 ** opcodes do not work after this operation.
95095 **
95096 ** See also: NotFound, Found, NotExists
95097 */
95098 case OP_IfNoHope: { /* jump, in3, ncycle */
95099 VdbeCursor *pC;
95100 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
95101 pC = p->apCsr[pOp->p1];
95102 assert( pC!=0 );
95103 #ifdef SQLITE_DEBUG
@@ -94889,13 +95107,13 @@
95107 #endif
95108 if( pC->seekHit>=pOp->p4.i ) break;
95109 /* Fall through into OP_NotFound */
95110 /* no break */ deliberate_fall_through
95111 }
95112 case OP_NoConflict: /* jump, in3, ncycle */
95113 case OP_NotFound: /* jump, in3, ncycle */
95114 case OP_Found: { /* jump, in3, ncycle */
95115 int alreadyExists;
95116 int ii;
95117 VdbeCursor *pC;
95118 UnpackedRecord *pIdxKey;
95119 UnpackedRecord r;
@@ -95021,11 +95239,11 @@
95239 ** in either direction. In other words, the Next and Prev opcodes will
95240 ** not work following this opcode.
95241 **
95242 ** See also: Found, NotFound, NoConflict, SeekRowid
95243 */
95244 case OP_SeekRowid: { /* jump, in3, ncycle */
95245 VdbeCursor *pC;
95246 BtCursor *pCrsr;
95247 int res;
95248 u64 iKey;
95249
@@ -95046,11 +95264,11 @@
95264 iKey = x.u.i;
95265 goto notExistsWithKey;
95266 }
95267 /* Fall through into OP_NotExists */
95268 /* no break */ deliberate_fall_through
95269 case OP_NotExists: /* jump, in3, ncycle */
95270 pIn3 = &aMem[pOp->p3];
95271 assert( (pIn3->flags & MEM_Int)!=0 || pOp->opcode==OP_SeekRowid );
95272 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
95273 iKey = pIn3->u.i;
95274 notExistsWithKey:
@@ -95670,11 +95888,11 @@
95888 **
95889 ** P1 can be either an ordinary table or a virtual table. There used to
95890 ** be a separate OP_VRowid opcode for use with virtual tables, but this
95891 ** one opcode now works for both table types.
95892 */
95893 case OP_Rowid: { /* out2, ncycle */
95894 VdbeCursor *pC;
95895 i64 v;
95896 sqlite3_vtab *pVtab;
95897 const sqlite3_module *pModule;
95898
@@ -95769,12 +95987,12 @@
95987 **
95988 ** This opcode leaves the cursor configured to move in reverse order,
95989 ** from the end toward the beginning. In other words, the cursor is
95990 ** configured to use Prev, not Next.
95991 */
95992 case OP_SeekEnd: /* ncycle */
95993 case OP_Last: { /* jump, ncycle */
95994 VdbeCursor *pC;
95995 BtCursor *pCrsr;
95996 int res;
95997
95998 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -95875,11 +96093,11 @@
96093 **
96094 ** This opcode leaves the cursor configured to move in forward order,
96095 ** from the beginning toward the end. In other words, the cursor is
96096 ** configured to use Next, not Prev.
96097 */
96098 case OP_Rewind: { /* jump, ncycle */
96099 VdbeCursor *pC;
96100 BtCursor *pCrsr;
96101 int res;
96102
96103 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -95969,11 +96187,11 @@
96187 pC = p->apCsr[pOp->p1];
96188 assert( isSorter(pC) );
96189 rc = sqlite3VdbeSorterNext(db, pC);
96190 goto next_tail;
96191
96192 case OP_Prev: /* jump, ncycle */
96193 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
96194 assert( pOp->p5==0
96195 || pOp->p5==SQLITE_STMTSTATUS_FULLSCAN_STEP
96196 || pOp->p5==SQLITE_STMTSTATUS_AUTOINDEX);
96197 pC = p->apCsr[pOp->p1];
@@ -95984,11 +96202,11 @@
96202 || pC->seekOp==OP_Last || pC->seekOp==OP_IfNoHope
96203 || pC->seekOp==OP_NullRow);
96204 rc = sqlite3BtreePrevious(pC->uc.pCursor, pOp->p3);
96205 goto next_tail;
96206
96207 case OP_Next: /* jump, ncycle */
96208 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
96209 assert( pOp->p5==0
96210 || pOp->p5==SQLITE_STMTSTATUS_FULLSCAN_STEP
96211 || pOp->p5==SQLITE_STMTSTATUS_AUTOINDEX);
96212 pC = p->apCsr[pOp->p1];
@@ -96176,12 +96394,12 @@
96394 ** the end of the index key pointed to by cursor P1. This integer should be
96395 ** the rowid of the table entry to which this index entry points.
96396 **
96397 ** See also: Rowid, MakeRecord.
96398 */
96399 case OP_DeferredSeek: /* ncycle */
96400 case OP_IdxRowid: { /* out2, ncycle */
96401 VdbeCursor *pC; /* The P1 index cursor */
96402 VdbeCursor *pTabCur; /* The P2 table cursor (OP_DeferredSeek only) */
96403 i64 rowid; /* Rowid that P1 current points to */
96404
96405 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -96239,12 +96457,12 @@
96457 **
96458 ** If cursor P1 was previously moved via OP_DeferredSeek, complete that
96459 ** seek operation now, without further delay. If the cursor seek has
96460 ** already occurred, this instruction is a no-op.
96461 */
96462 case OP_FinishSeek: { /* ncycle */
96463 VdbeCursor *pC; /* The P1 index cursor */
96464
96465 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
96466 pC = p->apCsr[pOp->p1];
96467 if( pC->deferredMoveto ){
96468 rc = sqlite3VdbeFinishMoveto(pC);
@@ -96295,14 +96513,14 @@
96513 ** ROWID on the P1 index.
96514 **
96515 ** If the P1 index entry is less than or equal to the key value then jump
96516 ** to P2. Otherwise fall through to the next instruction.
96517 */
96518 case OP_IdxLE: /* jump, ncycle */
96519 case OP_IdxGT: /* jump, ncycle */
96520 case OP_IdxLT: /* jump, ncycle */
96521 case OP_IdxGE: { /* jump, ncycle */
96522 VdbeCursor *pC;
96523 int res;
96524 UnpackedRecord r;
96525
96526 assert( pOp->p1>=0 && pOp->p1<p->nCursor );
@@ -96919,13 +97137,10 @@
97137 pFrame->apCsr = p->apCsr;
97138 pFrame->nCursor = p->nCursor;
97139 pFrame->aOp = p->aOp;
97140 pFrame->nOp = p->nOp;
97141 pFrame->token = pProgram->token;
 
 
 
97142 #ifdef SQLITE_DEBUG
97143 pFrame->iFrameMagic = SQLITE_FRAME_MAGIC;
97144 #endif
97145
97146 pEnd = &VdbeFrameMem(pFrame)[pFrame->nChildMem];
@@ -96958,13 +97173,10 @@
97173 p->apCsr = (VdbeCursor **)&aMem[p->nMem];
97174 pFrame->aOnce = (u8*)&p->apCsr[pProgram->nCsr];
97175 memset(pFrame->aOnce, 0, (pProgram->nOp + 7)/8);
97176 p->aOp = aOp = pProgram->aOp;
97177 p->nOp = pProgram->nOp;
 
 
 
97178 #ifdef SQLITE_DEBUG
97179 /* Verify that second and subsequent executions of the same trigger do not
97180 ** try to reuse register values from the first use. */
97181 {
97182 int i;
@@ -97717,11 +97929,11 @@
97929 **
97930 ** P4 is a pointer to a virtual table object, an sqlite3_vtab structure.
97931 ** P1 is a cursor number. This opcode opens a cursor to the virtual
97932 ** table and stores that cursor in P1.
97933 */
97934 case OP_VOpen: { /* ncycle */
97935 VdbeCursor *pCur;
97936 sqlite3_vtab_cursor *pVCur;
97937 sqlite3_vtab *pVtab;
97938 const sqlite3_module *pModule;
97939
@@ -97764,11 +97976,11 @@
97976 ** can be used as the first argument to sqlite3_vtab_in_first() and
97977 ** sqlite3_vtab_in_next() to extract all of the values stored in the P1
97978 ** cursor. Register P3 is used to hold the values returned by
97979 ** sqlite3_vtab_in_first() and sqlite3_vtab_in_next().
97980 */
97981 case OP_VInitIn: { /* out2, ncycle */
97982 VdbeCursor *pC; /* The cursor containing the RHS values */
97983 ValueList *pRhs; /* New ValueList object to put in reg[P2] */
97984
97985 pC = p->apCsr[pOp->p1];
97986 pRhs = sqlite3_malloc64( sizeof(*pRhs) );
@@ -97801,11 +98013,11 @@
98013 ** additional parameters which are passed to
98014 ** xFilter as argv. Register P3+2 becomes argv[0] when passed to xFilter.
98015 **
98016 ** A jump is made to P2 if the result set after filtering would be empty.
98017 */
98018 case OP_VFilter: { /* jump, ncycle */
98019 int nArg;
98020 int iQuery;
98021 const sqlite3_module *pModule;
98022 Mem *pQuery;
98023 Mem *pArgc;
@@ -97861,11 +98073,11 @@
98073 ** function to return true inside the xColumn method of the virtual
98074 ** table implementation. The P5 column might also contain other
98075 ** bits (OPFLAG_LENGTHARG or OPFLAG_TYPEOFARG) but those bits are
98076 ** unused by OP_VColumn.
98077 */
98078 case OP_VColumn: { /* ncycle */
98079 sqlite3_vtab *pVtab;
98080 const sqlite3_module *pModule;
98081 Mem *pDest;
98082 sqlite3_context sContext;
98083
@@ -97913,11 +98125,11 @@
98125 **
98126 ** Advance virtual table P1 to the next row in its result set and
98127 ** jump to instruction P2. Or, if the virtual table has reached
98128 ** the end of its result set, then fall through to the next instruction.
98129 */
98130 case OP_VNext: { /* jump, ncycle */
98131 sqlite3_vtab *pVtab;
98132 const sqlite3_module *pModule;
98133 int res;
98134 VdbeCursor *pCur;
98135
@@ -98496,16 +98708,16 @@
98708 ** readability. From this point on down, the normal indentation rules are
98709 ** restored.
98710 *****************************************************************************/
98711 }
98712
98713 #if defined(VDBE_PROFILE)
98714 *pnCycle += sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
98715 pnCycle = 0;
98716 #elif defined(SQLITE_ENABLE_STMT_SCANSTATUS)
98717 *pnCycle += sqlite3Hwtime();
98718 pnCycle = 0;
98719 #endif
98720
98721 /* The following code adds nothing to the actual functionality
98722 ** of the program. It is only here for testing and debugging.
98723 ** On the other hand, it does burn CPU cycles every time through
@@ -98577,10 +98789,22 @@
98789
98790 /* This is the only way out of this procedure. We have to
98791 ** release the mutexes on btrees that were acquired at the
98792 ** top. */
98793 vdbe_return:
98794 #if defined(VDBE_PROFILE)
98795 if( pnCycle ){
98796 *pnCycle += sqlite3NProfileCnt ? sqlite3NProfileCnt : sqlite3Hwtime();
98797 pnCycle = 0;
98798 }
98799 #elif defined(SQLITE_ENABLE_STMT_SCANSTATUS)
98800 if( pnCycle ){
98801 *pnCycle += sqlite3Hwtime();
98802 pnCycle = 0;
98803 }
98804 #endif
98805
98806 #ifndef SQLITE_OMIT_PROGRESS_CALLBACK
98807 while( nVmStep>=nProgressLimit && db->xProgress!=0 ){
98808 nProgressLimit += db->nProgressOps;
98809 if( db->xProgress(db->pProgressArg) ){
98810 nProgressLimit = LARGEST_UINT64;
@@ -105224,51 +105448,124 @@
105448 ** SELECT a AS b FROM t1 WHERE b;
105449 ** SELECT * FROM t1 WHERE (select a from t1);
105450 */
105451 SQLITE_PRIVATE char sqlite3ExprAffinity(const Expr *pExpr){
105452 int op;
 
 
 
 
 
 
 
105453 op = pExpr->op;
105454 while( 1 /* exit-by-break */ ){
105455 if( op==TK_COLUMN || (op==TK_AGG_COLUMN && pExpr->y.pTab!=0) ){
105456 assert( ExprUseYTab(pExpr) );
105457 assert( pExpr->y.pTab!=0 );
105458 return sqlite3TableColumnAffinity(pExpr->y.pTab, pExpr->iColumn);
105459 }
105460 if( op==TK_SELECT ){
105461 assert( ExprUseXSelect(pExpr) );
105462 assert( pExpr->x.pSelect!=0 );
105463 assert( pExpr->x.pSelect->pEList!=0 );
105464 assert( pExpr->x.pSelect->pEList->a[0].pExpr!=0 );
105465 return sqlite3ExprAffinity(pExpr->x.pSelect->pEList->a[0].pExpr);
105466 }
105467 #ifndef SQLITE_OMIT_CAST
105468 if( op==TK_CAST ){
105469 assert( !ExprHasProperty(pExpr, EP_IntValue) );
105470 return sqlite3AffinityType(pExpr->u.zToken, 0);
105471 }
105472 #endif
105473 if( op==TK_SELECT_COLUMN ){
105474 assert( pExpr->pLeft!=0 && ExprUseXSelect(pExpr->pLeft) );
105475 assert( pExpr->iColumn < pExpr->iTable );
105476 assert( pExpr->iTable==pExpr->pLeft->x.pSelect->pEList->nExpr );
105477 return sqlite3ExprAffinity(
105478 pExpr->pLeft->x.pSelect->pEList->a[pExpr->iColumn].pExpr
105479 );
105480 }
105481 if( op==TK_VECTOR ){
105482 assert( ExprUseXList(pExpr) );
105483 return sqlite3ExprAffinity(pExpr->x.pList->a[0].pExpr);
105484 }
105485 if( ExprHasProperty(pExpr, EP_Skip|EP_IfNullRow) ){
105486 assert( pExpr->op==TK_COLLATE
105487 || pExpr->op==TK_IF_NULL_ROW
105488 || (pExpr->op==TK_REGISTER && pExpr->op2==TK_IF_NULL_ROW) );
105489 pExpr = pExpr->pLeft;
105490 op = pExpr->op;
105491 continue;
105492 }
105493 if( op!=TK_REGISTER || (op = pExpr->op2)==TK_REGISTER ) break;
105494 }
105495 return pExpr->affExpr;
105496 }
105497
105498 /*
105499 ** Make a guess at all the possible datatypes of the result that could
105500 ** be returned by an expression. Return a bitmask indicating the answer:
105501 **
105502 ** 0x01 Numeric
105503 ** 0x02 Text
105504 ** 0x04 Blob
105505 **
105506 ** If the expression must return NULL, then 0x00 is returned.
105507 */
105508 SQLITE_PRIVATE int sqlite3ExprDataType(const Expr *pExpr){
105509 while( pExpr ){
105510 switch( pExpr->op ){
105511 case TK_COLLATE:
105512 case TK_IF_NULL_ROW:
105513 case TK_UPLUS: {
105514 pExpr = pExpr->pLeft;
105515 break;
105516 }
105517 case TK_NULL: {
105518 pExpr = 0;
105519 break;
105520 }
105521 case TK_STRING: {
105522 return 0x02;
105523 }
105524 case TK_BLOB: {
105525 return 0x04;
105526 }
105527 case TK_CONCAT: {
105528 return 0x06;
105529 }
105530 case TK_VARIABLE:
105531 case TK_AGG_FUNCTION:
105532 case TK_FUNCTION: {
105533 return 0x07;
105534 }
105535 case TK_COLUMN:
105536 case TK_AGG_COLUMN:
105537 case TK_SELECT:
105538 case TK_CAST:
105539 case TK_SELECT_COLUMN:
105540 case TK_VECTOR: {
105541 int aff = sqlite3ExprAffinity(pExpr);
105542 if( aff>=SQLITE_AFF_NUMERIC ) return 0x05;
105543 if( aff==SQLITE_AFF_TEXT ) return 0x06;
105544 return 0x07;
105545 }
105546 case TK_CASE: {
105547 int res = 0;
105548 int ii;
105549 ExprList *pList = pExpr->x.pList;
105550 assert( ExprUseXList(pExpr) && pList!=0 );
105551 assert( pList->nExpr > 0);
105552 for(ii=1; ii<pList->nExpr; ii+=2){
105553 res |= sqlite3ExprDataType(pList->a[ii].pExpr);
105554 }
105555 if( pList->nExpr % 2 ){
105556 res |= sqlite3ExprDataType(pList->a[pList->nExpr-1].pExpr);
105557 }
105558 return res;
105559 }
105560 default: {
105561 return 0x01;
105562 }
105563 } /* End of switch(op) */
105564 } /* End of while(pExpr) */
105565 return 0x00;
105566 }
105567
105568 /*
105569 ** Set the collating sequence for expression pExpr to be the collating
105570 ** sequence named by pToken. Return a pointer to a new Expr node that
105571 ** implements the COLLATE operator.
@@ -108437,10 +108734,13 @@
108734 int rReg = 0; /* Register storing resulting */
108735 Select *pSel; /* SELECT statement to encode */
108736 SelectDest dest; /* How to deal with SELECT result */
108737 int nReg; /* Registers to allocate */
108738 Expr *pLimit; /* New limit expression */
108739 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
108740 int addrExplain; /* Address of OP_Explain instruction */
108741 #endif
108742
108743 Vdbe *v = pParse->pVdbe;
108744 assert( v!=0 );
108745 if( pParse->nErr ) return 0;
108746 testcase( pExpr->op==TK_EXISTS );
@@ -108489,12 +108789,13 @@
108789 ** into a register and return that register number.
108790 **
108791 ** In both cases, the query is augmented with "LIMIT 1". Any
108792 ** preexisting limit is discarded in place of the new LIMIT 1.
108793 */
108794 ExplainQueryPlan2(addrExplain, (pParse, 1, "%sSCALAR SUBQUERY %d",
108795 addrOnce?"":"CORRELATED ", pSel->selId));
108796 sqlite3VdbeScanStatusCounters(v, addrExplain, addrExplain, -1);
108797 nReg = pExpr->op==TK_SELECT ? pSel->pEList->nExpr : 1;
108798 sqlite3SelectDestInit(&dest, 0, pParse->nMem+1);
108799 pParse->nMem += nReg;
108800 if( pExpr->op==TK_SELECT ){
108801 dest.eDest = SRT_Mem;
@@ -108533,10 +108834,11 @@
108834 pExpr->iTable = rReg = dest.iSDParm;
108835 ExprSetVVAProperty(pExpr, EP_NoReduce);
108836 if( addrOnce ){
108837 sqlite3VdbeJumpHere(v, addrOnce);
108838 }
108839 sqlite3VdbeScanStatusRange(v, addrExplain, addrExplain, -1);
108840
108841 /* Subroutine return */
108842 assert( ExprUseYSub(pExpr) );
108843 assert( sqlite3VdbeGetOp(v,pExpr->y.sub.iAddr-1)->opcode==OP_BeginSubrtn
108844 || pParse->nErr );
@@ -119973,12 +120275,11 @@
120275 &pTable->nCol, &pTable->aCol);
120276 if( pParse->nErr==0
120277 && pTable->nCol==pSel->pEList->nExpr
120278 ){
120279 assert( db->mallocFailed==0 );
120280 sqlite3SubqueryColumnTypes(pParse, pTable, pSel, SQLITE_AFF_NONE);
 
120281 }
120282 }else{
120283 /* CREATE VIEW name AS... without an argument list. Construct
120284 ** the column names from the SELECT statement that defines the view.
120285 */
@@ -137508,10 +137809,14 @@
137809 int iCsr; /* Cursor number for table */
137810 int nKey; /* Number of PK columns for table pTab (>=1) */
137811 } aDefer[4];
137812 #endif
137813 struct RowLoadInfo *pDeferredRowLoad; /* Deferred row loading info or NULL */
137814 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
137815 int addrPush; /* First instruction to push data into sorter */
137816 int addrPushEnd; /* Last instruction that pushes data into sorter */
137817 #endif
137818 };
137819 #define SORTFLAG_UseSorter 0x01 /* Use SorterOpen instead of OpenEphemeral */
137820
137821 /*
137822 ** Delete all the content of a Select structure. Deallocate the structure
@@ -138163,10 +138468,14 @@
138468 ** SortCtx.pDeferredRowLoad optimiation. In any of these cases
138469 ** regOrigData is 0 to prevent this routine from trying to copy
138470 ** values that might not yet exist.
138471 */
138472 assert( nData==1 || regData==regOrigData || regOrigData==0 );
138473
138474 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
138475 pSort->addrPush = sqlite3VdbeCurrentAddr(v);
138476 #endif
138477
138478 if( nPrefixReg ){
138479 assert( nPrefixReg==nExpr+bSeq );
138480 regBase = regData - nPrefixReg;
138481 }else{
@@ -138264,10 +138573,13 @@
138573 regBase+nOBSat, nBase-nOBSat);
138574 if( iSkip ){
138575 sqlite3VdbeChangeP2(v, iSkip,
138576 pSort->labelOBLopt ? pSort->labelOBLopt : sqlite3VdbeCurrentAddr(v));
138577 }
138578 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
138579 pSort->addrPushEnd = sqlite3VdbeCurrentAddr(v)-1;
138580 #endif
138581 }
138582
138583 /*
138584 ** Add code to implement the OFFSET
138585 */
@@ -138730,13 +139042,10 @@
139042 testcase( eDest==SRT_Table );
139043 testcase( eDest==SRT_EphemTab );
139044 testcase( eDest==SRT_Fifo );
139045 testcase( eDest==SRT_DistFifo );
139046 sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult, nResultCol, r1+nPrefixReg);
 
 
 
139047 #ifndef SQLITE_OMIT_CTE
139048 if( eDest==SRT_DistFifo ){
139049 /* If the destination is DistFifo, then cursor (iParm+1) is open
139050 ** on an ephemeral index. If the current row is already present
139051 ** in the index, do not write it to the output. If not, add the
@@ -139090,10 +139399,20 @@
139399 int iSortTab; /* Sorter cursor to read from */
139400 int i;
139401 int bSeq; /* True if sorter record includes seq. no. */
139402 int nRefKey = 0;
139403 struct ExprList_item *aOutEx = p->pEList->a;
139404 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
139405 int addrExplain; /* Address of OP_Explain instruction */
139406 #endif
139407
139408 ExplainQueryPlan2(addrExplain, (pParse, 0,
139409 "USE TEMP B-TREE FOR %sORDER BY", pSort->nOBSat>0?"RIGHT PART OF ":"")
139410 );
139411 sqlite3VdbeScanStatusRange(v, addrExplain,pSort->addrPush,pSort->addrPushEnd);
139412 sqlite3VdbeScanStatusCounters(v, addrExplain, addrExplain, pSort->addrPush);
139413
139414
139415 assert( addrBreak<0 );
139416 if( pSort->labelBkOut ){
139417 sqlite3VdbeAddOp2(v, OP_Gosub, pSort->regReturn, pSort->labelBkOut);
139418 sqlite3VdbeGoto(v, addrBreak);
@@ -139202,10 +139521,11 @@
139521 }
139522 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, iRead, regRow+i);
139523 VdbeComment((v, "%s", aOutEx[i].zEName));
139524 }
139525 }
139526 sqlite3VdbeScanStatusRange(v, addrExplain, addrExplain, -1);
139527 switch( eDest ){
139528 case SRT_Table:
139529 case SRT_EphemTab: {
139530 sqlite3VdbeAddOp3(v, OP_Column, iSortTab, nKey+bSeq, regRow);
139531 sqlite3VdbeAddOp2(v, OP_NewRowid, iParm, regRowid);
@@ -139263,10 +139583,11 @@
139583 if( pSort->sortFlags & SORTFLAG_UseSorter ){
139584 sqlite3VdbeAddOp2(v, OP_SorterNext, iTab, addr); VdbeCoverage(v);
139585 }else{
139586 sqlite3VdbeAddOp2(v, OP_Next, iTab, addr); VdbeCoverage(v);
139587 }
139588 sqlite3VdbeScanStatusRange(v, addrExplain, sqlite3VdbeCurrentAddr(v)-1, -1);
139589 if( pSort->regReturn ) sqlite3VdbeAddOp1(v, OP_Return, pSort->regReturn);
139590 sqlite3VdbeResolveLabel(v, addrBreak);
139591 }
139592
139593 /*
@@ -139293,10 +139614,11 @@
139614 #ifdef SQLITE_ENABLE_COLUMN_METADATA
139615 # define columnType(A,B,C,D,E) columnTypeImpl(A,B,C,D,E)
139616 #else /* if !defined(SQLITE_ENABLE_COLUMN_METADATA) */
139617 # define columnType(A,B,C,D,E) columnTypeImpl(A,B)
139618 #endif
139619 #ifndef SQLITE_OMIT_DECLTYPE
139620 static const char *columnTypeImpl(
139621 NameContext *pNC,
139622 #ifndef SQLITE_ENABLE_COLUMN_METADATA
139623 Expr *pExpr
139624 #else
@@ -139439,10 +139761,11 @@
139761 *pzOrigCol = zOrigCol;
139762 }
139763 #endif
139764 return zType;
139765 }
139766 #endif /* !defined(SQLITE_OMIT_DECLTYPE) */
139767
139768 /*
139769 ** Generate code that will tell the VDBE the declaration types of columns
139770 ** in the result set.
139771 */
@@ -139710,51 +140033,94 @@
140033 }
140034 return SQLITE_OK;
140035 }
140036
140037 /*
140038 ** This bit, when added to the "aff" parameter of
140039 ** sqlite3ColumnTypeOfSubquery() means that result set
140040 ** expressions of the form "CAST(expr AS NUMERIC)" should result in
140041 ** NONE affinity rather than NUMERIC affinity.
140042 */
140043 #define SQLITE_AFF_FLAG1 0x10
140044
140045 /*
140046 ** pTab is a transient Table object that represents a subquery of some
140047 ** kind (maybe a parenthesized subquery in the FROM clause of a larger
140048 ** query, or a VIEW, or a CTE). This routine computes type information
140049 ** for that Table object based on the Select object that implements the
140050 ** subquery. For the purposes of this routine, "type infomation" means:
140051 **
140052 ** * The datatype name, as it might appear in a CREATE TABLE statement
140053 ** * Which collating sequence to use for the column
140054 ** * The affinity of the column
140055 **
140056 ** The SQLITE_AFF_FLAG1 bit added to parameter aff means that a
140057 ** result set column of the form "CAST(expr AS NUMERIC)" should use
140058 ** NONE affinity rather than NUMERIC affinity. See the
140059 ** 2022-12-10 "reopen" of ticket https://sqlite.org/src/tktview/57c47526c3.
140060 */
140061 SQLITE_PRIVATE void sqlite3SubqueryColumnTypes(
140062 Parse *pParse, /* Parsing contexts */
140063 Table *pTab, /* Add column type information to this table */
140064 Select *pSelect, /* SELECT used to determine types and collations */
140065 char aff /* Default affinity. Maybe with SQLITE_AFF_FLAG1 too */
140066 ){
140067 sqlite3 *db = pParse->db;
 
140068 Column *pCol;
140069 CollSeq *pColl;
140070 int i,j;
140071 Expr *p;
140072 struct ExprList_item *a;
140073
140074 assert( pSelect!=0 );
140075 assert( (pSelect->selFlags & SF_Resolved)!=0 );
140076 assert( pTab->nCol==pSelect->pEList->nExpr || db->mallocFailed );
140077 if( db->mallocFailed ) return;
140078 while( pSelect->pPrior ) pSelect = pSelect->pPrior;
 
140079 a = pSelect->pEList->a;
140080 for(i=0, pCol=pTab->aCol; i<pTab->nCol; i++, pCol++){
140081 const char *zType;
140082 i64 n;
140083 pTab->tabFlags |= (pCol->colFlags & COLFLAG_NOINSERT);
140084 p = a[i].pExpr;
 
140085 /* pCol->szEst = ... // Column size est for SELECT tables never used */
140086 pCol->affinity = sqlite3ExprAffinity(p);
140087 if( pCol->affinity<=SQLITE_AFF_NONE ){
140088 assert( (SQLITE_AFF_FLAG1 & SQLITE_AFF_MASK)==0 );
140089 pCol->affinity = aff & SQLITE_AFF_MASK;
140090 }
140091 if( aff & SQLITE_AFF_FLAG1 ){
140092 if( pCol->affinity==SQLITE_AFF_NUMERIC && p->op==TK_CAST ){
140093 pCol->affinity = SQLITE_AFF_NONE;
140094 }
140095 }
140096 if( pCol->affinity>=SQLITE_AFF_TEXT && pSelect->pNext ){
140097 int m = 0;
140098 Select *pS2;
140099 for(m=0, pS2=pSelect->pNext; pS2; pS2=pS2->pNext){
140100 m |= sqlite3ExprDataType(pS2->pEList->a[i].pExpr);
140101 }
140102 if( pCol->affinity==SQLITE_AFF_TEXT && (m&0x01)!=0 ){
140103 pCol->affinity = SQLITE_AFF_BLOB;
140104 }else
140105 if( pCol->affinity>=SQLITE_AFF_NUMERIC && (m&0x02)!=0 ){
140106 pCol->affinity = SQLITE_AFF_BLOB;
140107 }
140108 }
140109 if( pCol->affinity==SQLITE_AFF_NUMERIC ){
140110 zType = "NUM";
140111 }else{
140112 zType = 0;
140113 for(j=1; j<SQLITE_N_STDTYPE; j++){
140114 if( sqlite3StdTypeAffinity[j]==pCol->affinity ){
140115 zType = sqlite3StdType[j];
140116 break;
140117 }
140118 }
140119 }
140120 if( zType ){
140121 i64 m = sqlite3Strlen30(zType);
140122 n = sqlite3Strlen30(pCol->zCnName);
140123 pCol->zCnName = sqlite3DbReallocOrFree(db, pCol->zCnName, n+m+2);
140124 if( pCol->zCnName ){
140125 memcpy(&pCol->zCnName[n+1], zType, m+1);
140126 pCol->colFlags |= COLFLAG_HASTYPE;
@@ -139761,11 +140127,10 @@
140127 }else{
140128 testcase( pCol->colFlags & COLFLAG_HASTYPE );
140129 pCol->colFlags &= ~(COLFLAG_HASTYPE|COLFLAG_HASCOLL);
140130 }
140131 }
 
140132 pColl = sqlite3ExprCollSeq(pParse, p);
140133 if( pColl ){
140134 assert( pTab->pIndex==0 );
140135 sqlite3ColumnSetColl(db, pCol, pColl->zName);
140136 }
@@ -139795,11 +140160,11 @@
140160 }
140161 pTab->nTabRef = 1;
140162 pTab->zName = 0;
140163 pTab->nRowLogEst = 200; assert( 200==sqlite3LogEst(1048576) );
140164 sqlite3ColumnsFromExprList(pParse, pSelect->pEList, &pTab->nCol, &pTab->aCol);
140165 sqlite3SubqueryColumnTypes(pParse, pTab, pSelect, aff);
140166 pTab->iPKey = -1;
140167 if( db->mallocFailed ){
140168 sqlite3DeleteTable(db, pTab);
140169 return 0;
140170 }
@@ -143606,18 +143971,18 @@
143971 #ifndef SQLITE_OMIT_SUBQUERY
143972 /*
143973 ** This is a Walker.xSelectCallback callback for the sqlite3SelectTypeInfo()
143974 ** interface.
143975 **
143976 ** For each FROM-clause subquery, add Column.zType, Column.zColl, and
143977 ** Column.affinity information to the Table structure that represents
143978 ** the result set of that subquery.
143979 **
143980 ** The Table structure that represents the result set was constructed
143981 ** by selectExpander() but the type and collation and affinity information
143982 ** was omitted at that point because identifiers had not yet been resolved.
143983 ** This routine is called after identifier resolution.
143984 */
143985 static void selectAddSubqueryTypeInfo(Walker *pWalker, Select *p){
143986 Parse *pParse;
143987 int i;
143988 SrcList *pTabList;
@@ -143633,13 +143998,12 @@
143998 assert( pTab!=0 );
143999 if( (pTab->tabFlags & TF_Ephemeral)!=0 ){
144000 /* A sub-query in the FROM clause of a SELECT */
144001 Select *pSel = pFrom->pSelect;
144002 if( pSel ){
144003 sqlite3SubqueryColumnTypes(pParse, pTab, pSel,
144004 SQLITE_AFF_NONE|SQLITE_AFF_FLAG1);
 
144005 }
144006 }
144007 }
144008 }
144009 #endif
@@ -144117,23 +144481,28 @@
144481 }
144482 #endif
144483 }
144484
144485 /*
144486 ** Check to see if the pThis entry of pTabList is a self-join of another view.
144487 ** Search FROM-clause entries in the range of iFirst..iEnd, including iFirst
144488 ** but stopping before iEnd.
144489 **
144490 ** If pThis is a self-join, then return the SrcItem for the first other
144491 ** instance of that view found. If pThis is not a self-join then return 0.
144492 */
144493 static SrcItem *isSelfJoinView(
144494 SrcList *pTabList, /* Search for self-joins in this FROM clause */
144495 SrcItem *pThis, /* Search for prior reference to this subquery */
144496 int iFirst, int iEnd /* Range of FROM-clause entries to search. */
144497 ){
144498 SrcItem *pItem;
144499 assert( pThis->pSelect!=0 );
144500 if( pThis->pSelect->selFlags & SF_PushDown ) return 0;
144501 while( iFirst<iEnd ){
144502 Select *pS1;
144503 pItem = &pTabList->a[iFirst++];
144504 if( pItem->pSelect==0 ) continue;
144505 if( pItem->fg.viaCoroutine ) continue;
144506 if( pItem->zName==0 ) continue;
144507 assert( pItem->pTab!=0 );
144508 assert( pThis->pTab!=0 );
@@ -144273,10 +144642,66 @@
144642 return 1;
144643 }
144644 }
144645 return 0;
144646 }
144647
144648 /*
144649 ** Return TRUE (non-zero) if the i-th entry in the pTabList SrcList can
144650 ** be implemented as a co-routine. The i-th entry is guaranteed to be
144651 ** a subquery.
144652 **
144653 ** The subquery is implemented as a co-routine if all of the following are
144654 ** true:
144655 **
144656 ** (1) The subquery will likely be implemented in the outer loop of
144657 ** the query. This will be the case if any one of the following
144658 ** conditions hold:
144659 ** (a) The subquery is the only term in the FROM clause
144660 ** (b) The subquery is the left-most term and a CROSS JOIN or similar
144661 ** requires it to be the outer loop
144662 ** (c) All of the following are true:
144663 ** (i) The subquery is the left-most subquery in the FROM clause
144664 ** (ii) There is nothing that would prevent the subquery from
144665 ** being used as the outer loop if the sqlite3WhereBegin()
144666 ** routine nominates it to that position.
144667 ** (iii) The query is not a UPDATE ... FROM
144668 ** (2) The subquery is not a CTE that should be materialized because of
144669 ** the AS MATERIALIZED keywords
144670 ** (3) The subquery is not part of a left operand for a RIGHT JOIN
144671 ** (4) The SQLITE_Coroutine optimization disable flag is not set
144672 ** (5) The subquery is not self-joined
144673 */
144674 static int fromClauseTermCanBeCoroutine(
144675 Parse *pParse, /* Parsing context */
144676 SrcList *pTabList, /* FROM clause */
144677 int i, /* Which term of the FROM clause holds the subquery */
144678 int selFlags /* Flags on the SELECT statement */
144679 ){
144680 SrcItem *pItem = &pTabList->a[i];
144681 if( pItem->fg.isCte && pItem->u2.pCteUse->eM10d==M10d_Yes ) return 0;/* (2) */
144682 if( pTabList->a[0].fg.jointype & JT_LTORJ ) return 0; /* (3) */
144683 if( OptimizationDisabled(pParse->db, SQLITE_Coroutines) ) return 0; /* (4) */
144684 if( isSelfJoinView(pTabList, pItem, i+1, pTabList->nSrc)!=0 ){
144685 return 0; /* (5) */
144686 }
144687 if( i==0 ){
144688 if( pTabList->nSrc==1 ) return 1; /* (1a) */
144689 if( pTabList->a[1].fg.jointype & JT_CROSS ) return 1; /* (1b) */
144690 if( selFlags & SF_UpdateFrom ) return 0; /* (1c-iii) */
144691 return 1;
144692 }
144693 if( selFlags & SF_UpdateFrom ) return 0; /* (1c-iii) */
144694 while( 1 /*exit-by-break*/ ){
144695 if( pItem->fg.jointype & (JT_OUTER|JT_CROSS) ) return 0; /* (1c-ii) */
144696 if( i==0 ) break;
144697 i--;
144698 pItem--;
144699 if( pItem->pSelect!=0 ) return 0; /* (1c-i) */
144700 }
144701 return 1;
144702 }
144703
144704 /*
144705 ** Generate code for the SELECT statement given in the p argument.
144706 **
144707 ** The results are returned according to the SelectDest structure.
@@ -144661,25 +145086,12 @@
145086
145087 zSavedAuthContext = pParse->zAuthContext;
145088 pParse->zAuthContext = pItem->zName;
145089
145090 /* Generate code to implement the subquery
 
 
 
 
 
 
 
 
145091 */
145092 if( fromClauseTermCanBeCoroutine(pParse, pTabList, i, p->selFlags) ){
 
 
 
 
 
145093 /* Implement a co-routine that will return a single row of the result
145094 ** set on each invocation.
145095 */
145096 int addrTop = sqlite3VdbeCurrentAddr(v)+1;
145097
@@ -144706,11 +145118,11 @@
145118 if( pItem->iCursor!=pCteUse->iCur ){
145119 sqlite3VdbeAddOp2(v, OP_OpenDup, pItem->iCursor, pCteUse->iCur);
145120 VdbeComment((v, "%!S", pItem));
145121 }
145122 pSub->nSelectRow = pCteUse->nRowEst;
145123 }else if( (pPrior = isSelfJoinView(pTabList, pItem, 0, i))!=0 ){
145124 /* This view has already been materialized by a prior entry in
145125 ** this same FROM clause. Reuse it. */
145126 if( pPrior->addrFillSub ){
145127 sqlite3VdbeAddOp2(v, OP_Gosub, pPrior->regReturn, pPrior->addrFillSub);
145128 }
@@ -144720,10 +145132,13 @@
145132 /* Materialize the view. If the view is not correlated, generate a
145133 ** subroutine to do the materialization so that subsequent uses of
145134 ** the same view can reuse the materialization. */
145135 int topAddr;
145136 int onceAddr = 0;
145137 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
145138 int addrExplain;
145139 #endif
145140
145141 pItem->regReturn = ++pParse->nMem;
145142 topAddr = sqlite3VdbeAddOp0(v, OP_Goto);
145143 pItem->addrFillSub = topAddr+1;
145144 pItem->fg.isMaterialized = 1;
@@ -144735,19 +145150,18 @@
145150 VdbeComment((v, "materialize %!S", pItem));
145151 }else{
145152 VdbeNoopComment((v, "materialize %!S", pItem));
145153 }
145154 sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
145155
145156 ExplainQueryPlan2(addrExplain, (pParse, 1, "MATERIALIZE %!S", pItem));
145157 sqlite3Select(pParse, pSub, &dest);
 
 
145158 pItem->pTab->nRowLogEst = pSub->nSelectRow;
145159 if( onceAddr ) sqlite3VdbeJumpHere(v, onceAddr);
145160 sqlite3VdbeAddOp2(v, OP_Return, pItem->regReturn, topAddr+1);
145161 VdbeComment((v, "end %!S", pItem));
145162 sqlite3VdbeScanStatusRange(v, addrExplain, addrExplain, -1);
145163 sqlite3VdbeJumpHere(v, topAddr);
145164 sqlite3ClearTempRegCache(pParse);
145165 if( pItem->fg.isCte && pItem->fg.isCorrelated==0 ){
145166 CteUse *pCteUse = pItem->u2.pCteUse;
145167 pCteUse->addrM9e = pItem->addrFillSub;
@@ -145498,12 +145912,10 @@
145912
145913 /* If there is an ORDER BY clause, then we need to sort the results
145914 ** and send them to the callback one by one.
145915 */
145916 if( sSort.pOrderBy ){
 
 
145917 assert( p->pEList==pEList );
145918 generateSortTail(pParse, p, &sSort, pEList->nExpr, pDest);
145919 }
145920
145921 /* Jump here to skip this query
@@ -147492,11 +147904,12 @@
147904 sqlite3ExprDup(db, pChanges->a[i].pExpr, 0)
147905 );
147906 }
147907 }
147908 pSelect = sqlite3SelectNew(pParse, pList,
147909 pSrc, pWhere2, pGrp, 0, pOrderBy2,
147910 SF_UFSrcCheck|SF_IncludeHidden|SF_UpdateFrom, pLimit2
147911 );
147912 if( pSelect ) pSelect->selFlags |= SF_OrderByReqd;
147913 sqlite3SelectDestInit(&dest, eDest, iEph);
147914 dest.iSDParm2 = (pPk ? pPk->nKeyCol : -1);
147915 sqlite3Select(pParse, pSelect, &dest);
@@ -151576,10 +151989,12 @@
151989 }
151990 sqlite3_str_append(&str, ")", 1);
151991 zMsg = sqlite3StrAccumFinish(&str);
151992 ret = sqlite3VdbeAddOp4(v, OP_Explain, sqlite3VdbeCurrentAddr(v),
151993 pParse->addrExplain, 0, zMsg,P4_DYNAMIC);
151994
151995 sqlite3VdbeScanStatus(v, sqlite3VdbeCurrentAddr(v)-1, 0, 0, 0, 0);
151996 return ret;
151997 }
151998 #endif /* SQLITE_OMIT_EXPLAIN */
151999
152000 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
@@ -151598,18 +152013,31 @@
152013 WhereLevel *pLvl, /* Level to add scanstatus() entry for */
152014 int addrExplain /* Address of OP_Explain (or 0) */
152015 ){
152016 const char *zObj = 0;
152017 WhereLoop *pLoop = pLvl->pWLoop;
152018 int wsFlags = pLoop->wsFlags;
152019 int viaCoroutine = 0;
152020
152021 if( (wsFlags & WHERE_VIRTUALTABLE)==0 && pLoop->u.btree.pIndex!=0 ){
152022 zObj = pLoop->u.btree.pIndex->zName;
152023 }else{
152024 zObj = pSrclist->a[pLvl->iFrom].zName;
152025 viaCoroutine = pSrclist->a[pLvl->iFrom].fg.viaCoroutine;
152026 }
152027 sqlite3VdbeScanStatus(
152028 v, addrExplain, pLvl->addrBody, pLvl->addrVisit, pLoop->nOut, zObj
152029 );
152030
152031 if( viaCoroutine==0 ){
152032 if( (wsFlags & (WHERE_MULTI_OR|WHERE_AUTO_INDEX))==0 ){
152033 sqlite3VdbeScanStatusRange(v, addrExplain, -1, pLvl->iTabCur);
152034 }
152035 if( wsFlags & WHERE_INDEXED ){
152036 sqlite3VdbeScanStatusRange(v, addrExplain, -1, pLvl->iIdxCur);
152037 }
152038 }
152039 }
152040 #endif
152041
152042
152043 /*
@@ -155999,11 +156427,11 @@
156427 ** terms means that no sorting is needed at all. A return that
156428 ** is positive but less than the number of ORDER BY terms means that
156429 ** block sorting is required.
156430 */
156431 SQLITE_PRIVATE int sqlite3WhereIsOrdered(WhereInfo *pWInfo){
156432 return pWInfo->nOBSat<0 ? 0 : pWInfo->nOBSat;
156433 }
156434
156435 /*
156436 ** In the ORDER BY LIMIT optimization, if the inner-most loop is known
156437 ** to emit rows in increasing order, and if the last row emitted by the
@@ -156744,10 +157172,61 @@
157172 }
157173 #endif
157174
157175
157176 #ifndef SQLITE_OMIT_AUTOMATIC_INDEX
157177
157178 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
157179 /*
157180 ** Argument pIdx represents an automatic index that the current statement
157181 ** will create and populate. Add an OP_Explain with text of the form:
157182 **
157183 ** CREATE AUTOMATIC INDEX ON <table>(<cols>) [WHERE <expr>]
157184 **
157185 ** This is only required if sqlite3_stmt_scanstatus() is enabled, to
157186 ** associate an SQLITE_SCANSTAT_NCYCLE and SQLITE_SCANSTAT_NLOOP
157187 ** values with. In order to avoid breaking legacy code and test cases,
157188 ** the OP_Explain is not added if this is an EXPLAIN QUERY PLAN command.
157189 */
157190 static void explainAutomaticIndex(
157191 Parse *pParse,
157192 Index *pIdx, /* Automatic index to explain */
157193 int bPartial, /* True if pIdx is a partial index */
157194 int *pAddrExplain /* OUT: Address of OP_Explain */
157195 ){
157196 if( pParse->explain!=2 ){
157197 Table *pTab = pIdx->pTable;
157198 const char *zSep = "";
157199 char *zText = 0;
157200 int ii = 0;
157201 sqlite3_str *pStr = sqlite3_str_new(pParse->db);
157202 sqlite3_str_appendf(pStr,"CREATE AUTOMATIC INDEX ON %s(", pTab->zName);
157203 assert( pIdx->nColumn>1 );
157204 assert( pIdx->aiColumn[pIdx->nColumn-1]==XN_ROWID );
157205 for(ii=0; ii<(pIdx->nColumn-1); ii++){
157206 const char *zName = 0;
157207 int iCol = pIdx->aiColumn[ii];
157208
157209 zName = pTab->aCol[iCol].zCnName;
157210 sqlite3_str_appendf(pStr, "%s%s", zSep, zName);
157211 zSep = ", ";
157212 }
157213 zText = sqlite3_str_finish(pStr);
157214 if( zText==0 ){
157215 sqlite3OomFault(pParse->db);
157216 }else{
157217 *pAddrExplain = sqlite3VdbeExplain(
157218 pParse, 0, "%s)%s", zText, (bPartial ? " WHERE <expr>" : "")
157219 );
157220 sqlite3_free(zText);
157221 }
157222 }
157223 }
157224 #else
157225 # define explainAutomaticIndex(a,b,c,d)
157226 #endif
157227
157228 /*
157229 ** Generate code to construct the Index object for an automatic index
157230 ** and to set up the WhereLevel object pLevel so that the code generator
157231 ** makes use of the automatic index.
157232 */
@@ -156779,10 +157258,13 @@
157258 Expr *pPartial = 0; /* Partial Index Expression */
157259 int iContinue = 0; /* Jump here to skip excluded rows */
157260 SrcItem *pTabItem; /* FROM clause term being indexed */
157261 int addrCounter = 0; /* Address where integer counter is initialized */
157262 int regBase; /* Array of registers where record is assembled */
157263 #ifdef SQLITE_ENABLE_STMT_SCANSTATUS
157264 int addrExp = 0; /* Address of OP_Explain */
157265 #endif
157266
157267 /* Generate code to skip over the creation and initialization of the
157268 ** transient index on 2nd and subsequent iterations of the loop. */
157269 v = pParse->pVdbe;
157270 assert( v!=0 );
@@ -156902,10 +157384,11 @@
157384 assert( n==nKeyCol );
157385 pIdx->aiColumn[n] = XN_ROWID;
157386 pIdx->azColl[n] = sqlite3StrBINARY;
157387
157388 /* Create the automatic index */
157389 explainAutomaticIndex(pParse, pIdx, pPartial!=0, &addrExp);
157390 assert( pLevel->iIdxCur>=0 );
157391 pLevel->iIdxCur = pParse->nTab++;
157392 sqlite3VdbeAddOp2(v, OP_OpenAutoindex, pLevel->iIdxCur, nKeyCol+1);
157393 sqlite3VdbeSetP4KeyInfo(pParse, pIdx);
157394 VdbeComment((v, "for %s", pTable->zName));
@@ -156937,10 +157420,11 @@
157420 );
157421 if( pLevel->regFilter ){
157422 sqlite3VdbeAddOp4Int(v, OP_FilterAdd, pLevel->regFilter, 0,
157423 regBase, pLoop->u.btree.nEq);
157424 }
157425 sqlite3VdbeScanStatusCounters(v, addrExp, addrExp, sqlite3VdbeCurrentAddr(v));
157426 sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
157427 sqlite3VdbeChangeP5(v, OPFLAG_USESEEKRESULT);
157428 if( pPartial ) sqlite3VdbeResolveLabel(v, iContinue);
157429 if( pTabItem->fg.viaCoroutine ){
157430 sqlite3VdbeChangeP2(v, addrCounter, regBase+n);
@@ -156957,10 +157441,11 @@
157441 sqlite3VdbeJumpHere(v, addrTop);
157442 sqlite3ReleaseTempReg(pParse, regRecord);
157443
157444 /* Jump here when skipping the initialization */
157445 sqlite3VdbeJumpHere(v, addrInit);
157446 sqlite3VdbeScanStatusRange(v, addrExp, addrExp, -1);
157447
157448 end_auto_index_create:
157449 sqlite3ExprDelete(pParse->db, pPartial);
157450 }
157451 #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
@@ -174461,10 +174946,11 @@
174946 case SQLITE_ROW: zName = "SQLITE_ROW"; break;
174947 case SQLITE_NOTICE: zName = "SQLITE_NOTICE"; break;
174948 case SQLITE_NOTICE_RECOVER_WAL: zName = "SQLITE_NOTICE_RECOVER_WAL";break;
174949 case SQLITE_NOTICE_RECOVER_ROLLBACK:
174950 zName = "SQLITE_NOTICE_RECOVER_ROLLBACK"; break;
174951 case SQLITE_NOTICE_RBU: zName = "SQLITE_NOTICE_RBU"; break;
174952 case SQLITE_WARNING: zName = "SQLITE_WARNING"; break;
174953 case SQLITE_WARNING_AUTOINDEX: zName = "SQLITE_WARNING_AUTOINDEX"; break;
174954 case SQLITE_DONE: zName = "SQLITE_DONE"; break;
174955 }
174956 }
@@ -175013,11 +175499,11 @@
175499 #endif
175500 sqlite3_mutex_enter(db->mutex);
175501 rc = sqlite3FindFunction(db, zName, nArg, SQLITE_UTF8, 0)!=0;
175502 sqlite3_mutex_leave(db->mutex);
175503 if( rc ) return SQLITE_OK;
175504 zCopy = sqlite3_mprintf("%s", zName);
175505 if( zCopy==0 ) return SQLITE_NOMEM;
175506 return sqlite3_create_function_v2(db, zName, nArg, SQLITE_UTF8,
175507 zCopy, sqlite3InvalidFunction, 0, 0, sqlite3_free);
175508 }
175509
@@ -211261,25 +211747,25 @@
211747 ** * Calls to xShmLock(UNLOCK) to release the exclusive shm WRITER,
211748 ** READ0 and CHECKPOINT locks taken as part of the checkpoint are
211749 ** no-ops. These locks will not be released until the connection
211750 ** is closed.
211751 **
211752 ** * Attempting to xSync() the database file causes an SQLITE_NOTICE
211753 ** error.
211754 **
211755 ** As a result, unless an error (i.e. OOM or SQLITE_BUSY) occurs, the
211756 ** checkpoint below fails with SQLITE_NOTICE, and leaves the aFrame[]
211757 ** array populated with a set of (frame -> page) mappings. Because the
211758 ** WRITER, CHECKPOINT and READ0 locks are still held, it is safe to copy
211759 ** data from the wal file into the database file according to the
211760 ** contents of aFrame[].
211761 */
211762 if( p->rc==SQLITE_OK ){
211763 int rc2;
211764 p->eStage = RBU_STAGE_CAPTURE;
211765 rc2 = sqlite3_exec(p->dbMain, "PRAGMA main.wal_checkpoint=restart", 0, 0,0);
211766 if( rc2!=SQLITE_NOTICE ) p->rc = rc2;
211767 }
211768
211769 if( p->rc==SQLITE_OK && p->nFrame>0 ){
211770 p->eStage = RBU_STAGE_CKPT;
211771 p->nStep = (pState ? pState->nRow : 0);
@@ -211321,11 +211807,11 @@
211807 const u32 mReq = (1<<WAL_LOCK_WRITE)|(1<<WAL_LOCK_CKPT)|(1<<WAL_LOCK_READ0);
211808 u32 iFrame;
211809
211810 if( pRbu->mLock!=mReq ){
211811 pRbu->rc = SQLITE_BUSY;
211812 return SQLITE_NOTICE_RBU;
211813 }
211814
211815 pRbu->pgsz = iAmt;
211816 if( pRbu->nFrame==pRbu->nFrameAlloc ){
211817 int nNew = (pRbu->nFrameAlloc ? pRbu->nFrameAlloc : 64) * 2;
@@ -212708,11 +213194,11 @@
213194 ** are recorded. Additionally, successful attempts to obtain exclusive
213195 ** xShmLock() WRITER, CHECKPOINTER and READ0 locks on the target
213196 ** database file are recorded. xShmLock() calls to unlock the same
213197 ** locks are no-ops (so that once obtained, these locks are never
213198 ** relinquished). Finally, calls to xSync() on the target database
213199 ** file fail with SQLITE_NOTICE errors.
213200 */
213201
213202 static void rbuUnlockShm(rbu_file *p){
213203 assert( p->openFlags & SQLITE_OPEN_MAIN_DB );
213204 if( p->pRbu ){
@@ -212987,11 +213473,11 @@
213473 */
213474 static int rbuVfsSync(sqlite3_file *pFile, int flags){
213475 rbu_file *p = (rbu_file *)pFile;
213476 if( p->pRbu && p->pRbu->eStage==RBU_STAGE_CAPTURE ){
213477 if( p->openFlags & SQLITE_OPEN_MAIN_DB ){
213478 return SQLITE_NOTICE_RBU;
213479 }
213480 return SQLITE_OK;
213481 }
213482 return p->pReal->pMethods->xSync(p->pReal, flags);
213483 }
@@ -218263,10 +218749,26 @@
218749 }
218750 }else if( p->bInvert ){
218751 if( p->op==SQLITE_INSERT ) p->op = SQLITE_DELETE;
218752 else if( p->op==SQLITE_DELETE ) p->op = SQLITE_INSERT;
218753 }
218754
218755 /* If this is an UPDATE that is part of a changeset, then check that
218756 ** there are no fields in the old.* record that are not (a) PK fields,
218757 ** or (b) also present in the new.* record.
218758 **
218759 ** Such records are technically corrupt, but the rebaser was at one
218760 ** point generating them. Under most circumstances this is benign, but
218761 ** can cause spurious SQLITE_RANGE errors when applying the changeset. */
218762 if( p->bPatchset==0 && p->op==SQLITE_UPDATE){
218763 for(i=0; i<p->nCol; i++){
218764 if( p->abPK[i]==0 && p->apValue[i+p->nCol]==0 ){
218765 sqlite3ValueFree(p->apValue[i]);
218766 p->apValue[i] = 0;
218767 }
218768 }
218769 }
218770 }
218771
218772 return SQLITE_ROW;
218773 }
218774
@@ -220459,11 +220961,11 @@
220961 int n2 = sessionSerialLen(a2);
220962 if( pIter->abPK[i] || a2[0]==0 ){
220963 if( !pIter->abPK[i] && a1[0] ) bData = 1;
220964 memcpy(pOut, a1, n1);
220965 pOut += n1;
220966 }else if( a2[0]!=0xFF && a1[0] ){
220967 bData = 1;
220968 memcpy(pOut, a2, n2);
220969 pOut += n2;
220970 }else{
220971 *pOut++ = '\0';
@@ -239022,11 +239524,11 @@
239524 int nArg, /* Number of args */
239525 sqlite3_value **apUnused /* Function arguments */
239526 ){
239527 assert( nArg==0 );
239528 UNUSED_PARAM2(nArg, apUnused);
239529 sqlite3_result_text(pCtx, "fts5: 2022-12-15 15:37:52 751e344f4cd2045caf97920cc9f4571caf0de1ba83b94ded902a03b36c10a389", -1, SQLITE_TRANSIENT);
239530 }
239531
239532 /*
239533 ** Return true if zName is the extension on one of the shadow tables used
239534 ** by this module.
239535
+66 -43
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146146
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147147
** [sqlite_version()] and [sqlite_source_id()].
148148
*/
149149
#define SQLITE_VERSION "3.41.0"
150150
#define SQLITE_VERSION_NUMBER 3041000
151
-#define SQLITE_SOURCE_ID "2022-12-05 02:52:37 1b779afa3ed2f35a110e460fc6ed13cba744db85b9924149ab028b100d1e1e12"
151
+#define SQLITE_SOURCE_ID "2022-12-15 15:37:52 751e344f4cd2045caf97920cc9f4571caf0de1ba83b94ded902a03b36c10a389"
152152
153153
/*
154154
** CAPI3REF: Run-Time Library Version Numbers
155155
** KEYWORDS: sqlite3_version sqlite3_sourceid
156156
**
@@ -561,10 +561,11 @@
561561
#define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
562562
#define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
563563
#define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))
564564
#define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
565565
#define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
566
+#define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8))
566567
#define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
567568
#define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
568569
#define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
569570
#define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
570571
@@ -2182,11 +2183,11 @@
21822183
** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
21832184
** rounded down to the next smaller multiple of 8. ^(The lookaside memory
21842185
** configuration for a database connection can only be changed when that
21852186
** connection is not currently using lookaside memory, or in other words
21862187
** when the "current value" returned by
2187
-** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
2188
+** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero.
21882189
** Any attempt to change the lookaside memory configuration when lookaside
21892190
** memory is in use leaves the configuration unchanged and returns
21902191
** [SQLITE_BUSY].)^</dd>
21912192
**
21922193
** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
@@ -2332,12 +2333,16 @@
23322333
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
23332334
** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
23342335
** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
23352336
** </ol>
23362337
** Because resetting a database is destructive and irreversible, the
2337
-** process requires the use of this obscure API and multiple steps to help
2338
-** ensure that it does not happen by accident.
2338
+** process requires the use of this obscure API and multiple steps to
2339
+** help ensure that it does not happen by accident. Because this
2340
+** feature must be capable of resetting corrupt databases, and
2341
+** shutting down virtual tables may require access to that corrupt
2342
+** storage, the library must abandon any installed virtual tables
2343
+** without calling their xDestroy() methods.
23392344
**
23402345
** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
23412346
** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
23422347
** "defensive" flag for a database connection. When the defensive
23432348
** flag is enabled, language features that allow ordinary SQL to
@@ -7012,19 +7017,10 @@
70127017
** ^This interface disables all automatic extensions previously
70137018
** registered using [sqlite3_auto_extension()].
70147019
*/
70157020
SQLITE_API void sqlite3_reset_auto_extension(void);
70167021
7017
-/*
7018
-** The interface to the virtual-table mechanism is currently considered
7019
-** to be experimental. The interface might change in incompatible ways.
7020
-** If this is a problem for you, do not use the interface at this time.
7021
-**
7022
-** When the virtual-table mechanism stabilizes, we will declare the
7023
-** interface fixed, support it indefinitely, and remove this comment.
7024
-*/
7025
-
70267022
/*
70277023
** Structures used by the virtual table interface
70287024
*/
70297025
typedef struct sqlite3_vtab sqlite3_vtab;
70307026
typedef struct sqlite3_index_info sqlite3_index_info;
@@ -7262,11 +7258,11 @@
72627258
**
72637259
** The collating sequence to be used for comparison can be found using
72647260
** the [sqlite3_vtab_collation()] interface. For most real-world virtual
72657261
** tables, the collating sequence of constraints does not matter (for example
72667262
** because the constraints are numeric) and so the sqlite3_vtab_collation()
7267
-** interface is no commonly needed.
7263
+** interface is not commonly needed.
72687264
*/
72697265
#define SQLITE_INDEX_CONSTRAINT_EQ 2
72707266
#define SQLITE_INDEX_CONSTRAINT_GT 4
72717267
#define SQLITE_INDEX_CONSTRAINT_LE 8
72727268
#define SQLITE_INDEX_CONSTRAINT_LT 16
@@ -7421,20 +7417,10 @@
74217417
** purpose is to be a placeholder function that can be overloaded
74227418
** by a [virtual table].
74237419
*/
74247420
SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
74257421
7426
-/*
7427
-** The interface to the virtual-table mechanism defined above (back up
7428
-** to a comment remarkably similar to this one) is currently considered
7429
-** to be experimental. The interface might change in incompatible ways.
7430
-** If this is a problem for you, do not use the interface at this time.
7431
-**
7432
-** When the virtual-table mechanism stabilizes, we will declare the
7433
-** interface fixed, support it indefinitely, and remove this comment.
7434
-*/
7435
-
74367422
/*
74377423
** CAPI3REF: A Handle To An Open BLOB
74387424
** KEYWORDS: {BLOB handle} {BLOB handles}
74397425
**
74407426
** An instance of this object represents an open BLOB on which
@@ -9634,11 +9620,11 @@
96349620
** statement that was passed into [sqlite3_declare_vtab()], then the
96359621
** name of that alternative collating sequence is returned.
96369622
** <li><p> Otherwise, "BINARY" is returned.
96379623
** </ol>
96389624
*/
9639
-SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9625
+SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
96409626
96419627
/*
96429628
** CAPI3REF: Determine if a virtual table query is DISTINCT
96439629
** METHOD: sqlite3_index_info
96449630
**
@@ -9903,10 +9889,14 @@
99039889
**
99049890
** When the value returned to V is a string, space to hold that string is
99059891
** managed by the prepared statement S and will be automatically freed when
99069892
** S is finalized.
99079893
**
9894
+** Not all values are available for all query elements. When a value is
9895
+** not available, the output variable is set to -1 if the value is numeric,
9896
+** or to NULL if it is a string (SQLITE_SCANSTAT_NAME).
9897
+**
99089898
** <dl>
99099899
** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
99109900
** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
99119901
** set to the total number of times that the X-th loop has run.</dd>
99129902
**
@@ -9930,30 +9920,44 @@
99309920
** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
99319921
** <dd>^The "const char *" variable pointed to by the V parameter will be set
99329922
** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
99339923
** description for the X-th loop.
99349924
**
9935
-** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
9925
+** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
99369926
** <dd>^The "int" variable pointed to by the V parameter will be set to the
9937
-** "select-id" for the X-th loop. The select-id identifies which query or
9938
-** subquery the loop is part of. The main query has a select-id of zero.
9939
-** The select-id is the same value as is output in the first column
9940
-** of an [EXPLAIN QUERY PLAN] query.
9927
+** id for the X-th query plan element. The id value is unique within the
9928
+** statement. The select-id is the same value as is output in the first
9929
+** column of an [EXPLAIN QUERY PLAN] query.
99419930
** </dl>
9931
+**
9932
+** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
9933
+** <dd>The "int" variable pointed to by the V parameter will be set to the
9934
+** the id of the parent of the current query element, if applicable, or
9935
+** to zero if the query element has no parent. This is the same value as
9936
+** returned in the second column of an [EXPLAIN QUERY PLAN] query.
9937
+**
9938
+** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
9939
+** <dd>The sqlite3_int64 output value is set to the number of cycles,
9940
+** according to the processor time-stamp counter, that elapsed while the
9941
+** query element was being processed. This value is not available for
9942
+** all query elements - if it is unavailable the output variable is
9943
+** set to -1.
99429944
*/
99439945
#define SQLITE_SCANSTAT_NLOOP 0
99449946
#define SQLITE_SCANSTAT_NVISIT 1
99459947
#define SQLITE_SCANSTAT_EST 2
99469948
#define SQLITE_SCANSTAT_NAME 3
99479949
#define SQLITE_SCANSTAT_EXPLAIN 4
99489950
#define SQLITE_SCANSTAT_SELECTID 5
9951
+#define SQLITE_SCANSTAT_PARENTID 6
9952
+#define SQLITE_SCANSTAT_NCYCLE 7
99499953
99509954
/*
99519955
** CAPI3REF: Prepared Statement Scan Status
99529956
** METHOD: sqlite3_stmt
99539957
**
9954
-** This interface returns information about the predicted and measured
9958
+** These interfaces return information about the predicted and measured
99559959
** performance for pStmt. Advanced applications can use this
99569960
** interface to compare the predicted and the measured performance and
99579961
** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
99589962
**
99599963
** Since this interface is expected to be rarely used, it is only
@@ -9960,32 +9964,51 @@
99609964
** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
99619965
** compile-time option.
99629966
**
99639967
** The "iScanStatusOp" parameter determines which status information to return.
99649968
** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
9965
-** of this interface is undefined.
9966
-** ^The requested measurement is written into a variable pointed to by
9967
-** the "pOut" parameter.
9968
-** Parameter "idx" identifies the specific loop to retrieve statistics for.
9969
-** Loops are numbered starting from zero. ^If idx is out of range - less than
9970
-** zero or greater than or equal to the total number of loops used to implement
9971
-** the statement - a non-zero value is returned and the variable that pOut
9972
-** points to is unchanged.
9969
+** of this interface is undefined. ^The requested measurement is written into
9970
+** a variable pointed to by the "pOut" parameter.
99739971
**
9974
-** ^Statistics might not be available for all loops in all statements. ^In cases
9975
-** where there exist loops with no available statistics, this function behaves
9976
-** as if the loop did not exist - it returns non-zero and leave the variable
9977
-** that pOut points to unchanged.
9972
+** The "flags" parameter must be passed a mask of flags. At present only
9973
+** one flag is defined - SQLITE_SCANSTAT_COMPLEX. If SQLITE_SCANSTAT_COMPLEX
9974
+** is specified, then status information is available for all elements
9975
+** of a query plan that are reported by "EXPLAIN QUERY PLAN" output. If
9976
+** SQLITE_SCANSTAT_COMPLEX is not specified, then only query plan elements
9977
+** that correspond to query loops (the "SCAN..." and "SEARCH..." elements of
9978
+** the EXPLAIN QUERY PLAN output) are available. Invoking API
9979
+** sqlite3_stmt_scanstatus() is equivalent to calling
9980
+** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
9981
+**
9982
+** Parameter "idx" identifies the specific query element to retrieve statistics
9983
+** for. Query elements are numbered starting from zero. A value of -1 may be
9984
+** to query for statistics regarding the entire query. ^If idx is out of range
9985
+** - less than -1 or greater than or equal to the total number of query
9986
+** elements used to implement the statement - a non-zero value is returned and
9987
+** the variable that pOut points to is unchanged.
99789988
**
99799989
** See also: [sqlite3_stmt_scanstatus_reset()]
99809990
*/
99819991
SQLITE_API int sqlite3_stmt_scanstatus(
99829992
sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
99839993
int idx, /* Index of loop to report on */
99849994
int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
99859995
void *pOut /* Result written here */
99869996
);
9997
+SQLITE_API int sqlite3_stmt_scanstatus_v2(
9998
+ sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
9999
+ int idx, /* Index of loop to report on */
10000
+ int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
10001
+ int flags, /* Mask of flags defined below */
10002
+ void *pOut /* Result written here */
10003
+);
10004
+
10005
+/*
10006
+** CAPI3REF: Prepared Statement Scan Status
10007
+** KEYWORDS: {scan status flags}
10008
+*/
10009
+#define SQLITE_SCANSTAT_COMPLEX 0x0001
998710010
998810011
/*
998910012
** CAPI3REF: Zero Scan-Status Counters
999010013
** METHOD: sqlite3_stmt
999110014
**
999210015
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.41.0"
150 #define SQLITE_VERSION_NUMBER 3041000
151 #define SQLITE_SOURCE_ID "2022-12-05 02:52:37 1b779afa3ed2f35a110e460fc6ed13cba744db85b9924149ab028b100d1e1e12"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -561,10 +561,11 @@
561 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
562 #define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
563 #define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))
564 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
565 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
 
566 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
567 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
568 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
569 #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
570
@@ -2182,11 +2183,11 @@
2182 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
2183 ** rounded down to the next smaller multiple of 8. ^(The lookaside memory
2184 ** configuration for a database connection can only be changed when that
2185 ** connection is not currently using lookaside memory, or in other words
2186 ** when the "current value" returned by
2187 ** [sqlite3_db_status](D,[SQLITE_CONFIG_LOOKASIDE],...) is zero.
2188 ** Any attempt to change the lookaside memory configuration when lookaside
2189 ** memory is in use leaves the configuration unchanged and returns
2190 ** [SQLITE_BUSY].)^</dd>
2191 **
2192 ** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
@@ -2332,12 +2333,16 @@
2332 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
2333 ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
2334 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
2335 ** </ol>
2336 ** Because resetting a database is destructive and irreversible, the
2337 ** process requires the use of this obscure API and multiple steps to help
2338 ** ensure that it does not happen by accident.
 
 
 
 
2339 **
2340 ** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
2341 ** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
2342 ** "defensive" flag for a database connection. When the defensive
2343 ** flag is enabled, language features that allow ordinary SQL to
@@ -7012,19 +7017,10 @@
7012 ** ^This interface disables all automatic extensions previously
7013 ** registered using [sqlite3_auto_extension()].
7014 */
7015 SQLITE_API void sqlite3_reset_auto_extension(void);
7016
7017 /*
7018 ** The interface to the virtual-table mechanism is currently considered
7019 ** to be experimental. The interface might change in incompatible ways.
7020 ** If this is a problem for you, do not use the interface at this time.
7021 **
7022 ** When the virtual-table mechanism stabilizes, we will declare the
7023 ** interface fixed, support it indefinitely, and remove this comment.
7024 */
7025
7026 /*
7027 ** Structures used by the virtual table interface
7028 */
7029 typedef struct sqlite3_vtab sqlite3_vtab;
7030 typedef struct sqlite3_index_info sqlite3_index_info;
@@ -7262,11 +7258,11 @@
7262 **
7263 ** The collating sequence to be used for comparison can be found using
7264 ** the [sqlite3_vtab_collation()] interface. For most real-world virtual
7265 ** tables, the collating sequence of constraints does not matter (for example
7266 ** because the constraints are numeric) and so the sqlite3_vtab_collation()
7267 ** interface is no commonly needed.
7268 */
7269 #define SQLITE_INDEX_CONSTRAINT_EQ 2
7270 #define SQLITE_INDEX_CONSTRAINT_GT 4
7271 #define SQLITE_INDEX_CONSTRAINT_LE 8
7272 #define SQLITE_INDEX_CONSTRAINT_LT 16
@@ -7421,20 +7417,10 @@
7421 ** purpose is to be a placeholder function that can be overloaded
7422 ** by a [virtual table].
7423 */
7424 SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
7425
7426 /*
7427 ** The interface to the virtual-table mechanism defined above (back up
7428 ** to a comment remarkably similar to this one) is currently considered
7429 ** to be experimental. The interface might change in incompatible ways.
7430 ** If this is a problem for you, do not use the interface at this time.
7431 **
7432 ** When the virtual-table mechanism stabilizes, we will declare the
7433 ** interface fixed, support it indefinitely, and remove this comment.
7434 */
7435
7436 /*
7437 ** CAPI3REF: A Handle To An Open BLOB
7438 ** KEYWORDS: {BLOB handle} {BLOB handles}
7439 **
7440 ** An instance of this object represents an open BLOB on which
@@ -9634,11 +9620,11 @@
9634 ** statement that was passed into [sqlite3_declare_vtab()], then the
9635 ** name of that alternative collating sequence is returned.
9636 ** <li><p> Otherwise, "BINARY" is returned.
9637 ** </ol>
9638 */
9639 SQLITE_API SQLITE_EXPERIMENTAL const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9640
9641 /*
9642 ** CAPI3REF: Determine if a virtual table query is DISTINCT
9643 ** METHOD: sqlite3_index_info
9644 **
@@ -9903,10 +9889,14 @@
9903 **
9904 ** When the value returned to V is a string, space to hold that string is
9905 ** managed by the prepared statement S and will be automatically freed when
9906 ** S is finalized.
9907 **
 
 
 
 
9908 ** <dl>
9909 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
9910 ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
9911 ** set to the total number of times that the X-th loop has run.</dd>
9912 **
@@ -9930,30 +9920,44 @@
9930 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
9931 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
9932 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
9933 ** description for the X-th loop.
9934 **
9935 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECT</dt>
9936 ** <dd>^The "int" variable pointed to by the V parameter will be set to the
9937 ** "select-id" for the X-th loop. The select-id identifies which query or
9938 ** subquery the loop is part of. The main query has a select-id of zero.
9939 ** The select-id is the same value as is output in the first column
9940 ** of an [EXPLAIN QUERY PLAN] query.
9941 ** </dl>
 
 
 
 
 
 
 
 
 
 
 
 
 
9942 */
9943 #define SQLITE_SCANSTAT_NLOOP 0
9944 #define SQLITE_SCANSTAT_NVISIT 1
9945 #define SQLITE_SCANSTAT_EST 2
9946 #define SQLITE_SCANSTAT_NAME 3
9947 #define SQLITE_SCANSTAT_EXPLAIN 4
9948 #define SQLITE_SCANSTAT_SELECTID 5
 
 
9949
9950 /*
9951 ** CAPI3REF: Prepared Statement Scan Status
9952 ** METHOD: sqlite3_stmt
9953 **
9954 ** This interface returns information about the predicted and measured
9955 ** performance for pStmt. Advanced applications can use this
9956 ** interface to compare the predicted and the measured performance and
9957 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
9958 **
9959 ** Since this interface is expected to be rarely used, it is only
@@ -9960,32 +9964,51 @@
9960 ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
9961 ** compile-time option.
9962 **
9963 ** The "iScanStatusOp" parameter determines which status information to return.
9964 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
9965 ** of this interface is undefined.
9966 ** ^The requested measurement is written into a variable pointed to by
9967 ** the "pOut" parameter.
9968 ** Parameter "idx" identifies the specific loop to retrieve statistics for.
9969 ** Loops are numbered starting from zero. ^If idx is out of range - less than
9970 ** zero or greater than or equal to the total number of loops used to implement
9971 ** the statement - a non-zero value is returned and the variable that pOut
9972 ** points to is unchanged.
9973 **
9974 ** ^Statistics might not be available for all loops in all statements. ^In cases
9975 ** where there exist loops with no available statistics, this function behaves
9976 ** as if the loop did not exist - it returns non-zero and leave the variable
9977 ** that pOut points to unchanged.
 
 
 
 
 
 
 
 
 
 
 
 
9978 **
9979 ** See also: [sqlite3_stmt_scanstatus_reset()]
9980 */
9981 SQLITE_API int sqlite3_stmt_scanstatus(
9982 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
9983 int idx, /* Index of loop to report on */
9984 int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
9985 void *pOut /* Result written here */
9986 );
 
 
 
 
 
 
 
 
 
 
 
 
 
9987
9988 /*
9989 ** CAPI3REF: Zero Scan-Status Counters
9990 ** METHOD: sqlite3_stmt
9991 **
9992
--- extsrc/sqlite3.h
+++ extsrc/sqlite3.h
@@ -146,11 +146,11 @@
146 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
147 ** [sqlite_version()] and [sqlite_source_id()].
148 */
149 #define SQLITE_VERSION "3.41.0"
150 #define SQLITE_VERSION_NUMBER 3041000
151 #define SQLITE_SOURCE_ID "2022-12-15 15:37:52 751e344f4cd2045caf97920cc9f4571caf0de1ba83b94ded902a03b36c10a389"
152
153 /*
154 ** CAPI3REF: Run-Time Library Version Numbers
155 ** KEYWORDS: sqlite3_version sqlite3_sourceid
156 **
@@ -561,10 +561,11 @@
561 #define SQLITE_CONSTRAINT_ROWID (SQLITE_CONSTRAINT |(10<<8))
562 #define SQLITE_CONSTRAINT_PINNED (SQLITE_CONSTRAINT |(11<<8))
563 #define SQLITE_CONSTRAINT_DATATYPE (SQLITE_CONSTRAINT |(12<<8))
564 #define SQLITE_NOTICE_RECOVER_WAL (SQLITE_NOTICE | (1<<8))
565 #define SQLITE_NOTICE_RECOVER_ROLLBACK (SQLITE_NOTICE | (2<<8))
566 #define SQLITE_NOTICE_RBU (SQLITE_NOTICE | (3<<8))
567 #define SQLITE_WARNING_AUTOINDEX (SQLITE_WARNING | (1<<8))
568 #define SQLITE_AUTH_USER (SQLITE_AUTH | (1<<8))
569 #define SQLITE_OK_LOAD_PERMANENTLY (SQLITE_OK | (1<<8))
570 #define SQLITE_OK_SYMLINK (SQLITE_OK | (2<<8)) /* internal use only */
571
@@ -2182,11 +2183,11 @@
2183 ** SQLITE_DBCONFIG_LOOKASIDE is not a multiple of 8, it is internally
2184 ** rounded down to the next smaller multiple of 8. ^(The lookaside memory
2185 ** configuration for a database connection can only be changed when that
2186 ** connection is not currently using lookaside memory, or in other words
2187 ** when the "current value" returned by
2188 ** [sqlite3_db_status](D,[SQLITE_DBSTATUS_LOOKASIDE_USED],...) is zero.
2189 ** Any attempt to change the lookaside memory configuration when lookaside
2190 ** memory is in use leaves the configuration unchanged and returns
2191 ** [SQLITE_BUSY].)^</dd>
2192 **
2193 ** [[SQLITE_DBCONFIG_ENABLE_FKEY]]
@@ -2332,12 +2333,16 @@
2333 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 1, 0);
2334 ** <li> [sqlite3_exec](db, "[VACUUM]", 0, 0, 0);
2335 ** <li> sqlite3_db_config(db, SQLITE_DBCONFIG_RESET_DATABASE, 0, 0);
2336 ** </ol>
2337 ** Because resetting a database is destructive and irreversible, the
2338 ** process requires the use of this obscure API and multiple steps to
2339 ** help ensure that it does not happen by accident. Because this
2340 ** feature must be capable of resetting corrupt databases, and
2341 ** shutting down virtual tables may require access to that corrupt
2342 ** storage, the library must abandon any installed virtual tables
2343 ** without calling their xDestroy() methods.
2344 **
2345 ** [[SQLITE_DBCONFIG_DEFENSIVE]] <dt>SQLITE_DBCONFIG_DEFENSIVE</dt>
2346 ** <dd>The SQLITE_DBCONFIG_DEFENSIVE option activates or deactivates the
2347 ** "defensive" flag for a database connection. When the defensive
2348 ** flag is enabled, language features that allow ordinary SQL to
@@ -7012,19 +7017,10 @@
7017 ** ^This interface disables all automatic extensions previously
7018 ** registered using [sqlite3_auto_extension()].
7019 */
7020 SQLITE_API void sqlite3_reset_auto_extension(void);
7021
 
 
 
 
 
 
 
 
 
7022 /*
7023 ** Structures used by the virtual table interface
7024 */
7025 typedef struct sqlite3_vtab sqlite3_vtab;
7026 typedef struct sqlite3_index_info sqlite3_index_info;
@@ -7262,11 +7258,11 @@
7258 **
7259 ** The collating sequence to be used for comparison can be found using
7260 ** the [sqlite3_vtab_collation()] interface. For most real-world virtual
7261 ** tables, the collating sequence of constraints does not matter (for example
7262 ** because the constraints are numeric) and so the sqlite3_vtab_collation()
7263 ** interface is not commonly needed.
7264 */
7265 #define SQLITE_INDEX_CONSTRAINT_EQ 2
7266 #define SQLITE_INDEX_CONSTRAINT_GT 4
7267 #define SQLITE_INDEX_CONSTRAINT_LE 8
7268 #define SQLITE_INDEX_CONSTRAINT_LT 16
@@ -7421,20 +7417,10 @@
7417 ** purpose is to be a placeholder function that can be overloaded
7418 ** by a [virtual table].
7419 */
7420 SQLITE_API int sqlite3_overload_function(sqlite3*, const char *zFuncName, int nArg);
7421
 
 
 
 
 
 
 
 
 
 
7422 /*
7423 ** CAPI3REF: A Handle To An Open BLOB
7424 ** KEYWORDS: {BLOB handle} {BLOB handles}
7425 **
7426 ** An instance of this object represents an open BLOB on which
@@ -9634,11 +9620,11 @@
9620 ** statement that was passed into [sqlite3_declare_vtab()], then the
9621 ** name of that alternative collating sequence is returned.
9622 ** <li><p> Otherwise, "BINARY" is returned.
9623 ** </ol>
9624 */
9625 SQLITE_API const char *sqlite3_vtab_collation(sqlite3_index_info*,int);
9626
9627 /*
9628 ** CAPI3REF: Determine if a virtual table query is DISTINCT
9629 ** METHOD: sqlite3_index_info
9630 **
@@ -9903,10 +9889,14 @@
9889 **
9890 ** When the value returned to V is a string, space to hold that string is
9891 ** managed by the prepared statement S and will be automatically freed when
9892 ** S is finalized.
9893 **
9894 ** Not all values are available for all query elements. When a value is
9895 ** not available, the output variable is set to -1 if the value is numeric,
9896 ** or to NULL if it is a string (SQLITE_SCANSTAT_NAME).
9897 **
9898 ** <dl>
9899 ** [[SQLITE_SCANSTAT_NLOOP]] <dt>SQLITE_SCANSTAT_NLOOP</dt>
9900 ** <dd>^The [sqlite3_int64] variable pointed to by the V parameter will be
9901 ** set to the total number of times that the X-th loop has run.</dd>
9902 **
@@ -9930,30 +9920,44 @@
9920 ** [[SQLITE_SCANSTAT_EXPLAIN]] <dt>SQLITE_SCANSTAT_EXPLAIN</dt>
9921 ** <dd>^The "const char *" variable pointed to by the V parameter will be set
9922 ** to a zero-terminated UTF-8 string containing the [EXPLAIN QUERY PLAN]
9923 ** description for the X-th loop.
9924 **
9925 ** [[SQLITE_SCANSTAT_SELECTID]] <dt>SQLITE_SCANSTAT_SELECTID</dt>
9926 ** <dd>^The "int" variable pointed to by the V parameter will be set to the
9927 ** id for the X-th query plan element. The id value is unique within the
9928 ** statement. The select-id is the same value as is output in the first
9929 ** column of an [EXPLAIN QUERY PLAN] query.
 
9930 ** </dl>
9931 **
9932 ** [[SQLITE_SCANSTAT_PARENTID]] <dt>SQLITE_SCANSTAT_PARENTID</dt>
9933 ** <dd>The "int" variable pointed to by the V parameter will be set to the
9934 ** the id of the parent of the current query element, if applicable, or
9935 ** to zero if the query element has no parent. This is the same value as
9936 ** returned in the second column of an [EXPLAIN QUERY PLAN] query.
9937 **
9938 ** [[SQLITE_SCANSTAT_NCYCLE]] <dt>SQLITE_SCANSTAT_NCYCLE</dt>
9939 ** <dd>The sqlite3_int64 output value is set to the number of cycles,
9940 ** according to the processor time-stamp counter, that elapsed while the
9941 ** query element was being processed. This value is not available for
9942 ** all query elements - if it is unavailable the output variable is
9943 ** set to -1.
9944 */
9945 #define SQLITE_SCANSTAT_NLOOP 0
9946 #define SQLITE_SCANSTAT_NVISIT 1
9947 #define SQLITE_SCANSTAT_EST 2
9948 #define SQLITE_SCANSTAT_NAME 3
9949 #define SQLITE_SCANSTAT_EXPLAIN 4
9950 #define SQLITE_SCANSTAT_SELECTID 5
9951 #define SQLITE_SCANSTAT_PARENTID 6
9952 #define SQLITE_SCANSTAT_NCYCLE 7
9953
9954 /*
9955 ** CAPI3REF: Prepared Statement Scan Status
9956 ** METHOD: sqlite3_stmt
9957 **
9958 ** These interfaces return information about the predicted and measured
9959 ** performance for pStmt. Advanced applications can use this
9960 ** interface to compare the predicted and the measured performance and
9961 ** issue warnings and/or rerun [ANALYZE] if discrepancies are found.
9962 **
9963 ** Since this interface is expected to be rarely used, it is only
@@ -9960,32 +9964,51 @@
9964 ** available if SQLite is compiled using the [SQLITE_ENABLE_STMT_SCANSTATUS]
9965 ** compile-time option.
9966 **
9967 ** The "iScanStatusOp" parameter determines which status information to return.
9968 ** The "iScanStatusOp" must be one of the [scanstatus options] or the behavior
9969 ** of this interface is undefined. ^The requested measurement is written into
9970 ** a variable pointed to by the "pOut" parameter.
 
 
 
 
 
 
9971 **
9972 ** The "flags" parameter must be passed a mask of flags. At present only
9973 ** one flag is defined - SQLITE_SCANSTAT_COMPLEX. If SQLITE_SCANSTAT_COMPLEX
9974 ** is specified, then status information is available for all elements
9975 ** of a query plan that are reported by "EXPLAIN QUERY PLAN" output. If
9976 ** SQLITE_SCANSTAT_COMPLEX is not specified, then only query plan elements
9977 ** that correspond to query loops (the "SCAN..." and "SEARCH..." elements of
9978 ** the EXPLAIN QUERY PLAN output) are available. Invoking API
9979 ** sqlite3_stmt_scanstatus() is equivalent to calling
9980 ** sqlite3_stmt_scanstatus_v2() with a zeroed flags parameter.
9981 **
9982 ** Parameter "idx" identifies the specific query element to retrieve statistics
9983 ** for. Query elements are numbered starting from zero. A value of -1 may be
9984 ** to query for statistics regarding the entire query. ^If idx is out of range
9985 ** - less than -1 or greater than or equal to the total number of query
9986 ** elements used to implement the statement - a non-zero value is returned and
9987 ** the variable that pOut points to is unchanged.
9988 **
9989 ** See also: [sqlite3_stmt_scanstatus_reset()]
9990 */
9991 SQLITE_API int sqlite3_stmt_scanstatus(
9992 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
9993 int idx, /* Index of loop to report on */
9994 int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
9995 void *pOut /* Result written here */
9996 );
9997 SQLITE_API int sqlite3_stmt_scanstatus_v2(
9998 sqlite3_stmt *pStmt, /* Prepared statement for which info desired */
9999 int idx, /* Index of loop to report on */
10000 int iScanStatusOp, /* Information desired. SQLITE_SCANSTAT_* */
10001 int flags, /* Mask of flags defined below */
10002 void *pOut /* Result written here */
10003 );
10004
10005 /*
10006 ** CAPI3REF: Prepared Statement Scan Status
10007 ** KEYWORDS: {scan status flags}
10008 */
10009 #define SQLITE_SCANSTAT_COMPLEX 0x0001
10010
10011 /*
10012 ** CAPI3REF: Zero Scan-Status Counters
10013 ** METHOD: sqlite3_stmt
10014 **
10015

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button