Fossil SCM

Update the built-in SQLite to the latest pre-release snapshot for beta testing.

drh 2018-03-22 19:43 trunk
Commit 1849c6e205c9ede7c9d2f64e55f700bfad156b9efe165d2a3dcc5b1209c7a949
3 files changed +138 -19 +189 -66 +13 -4
+138 -19
--- src/shell.c
+++ src/shell.c
@@ -2205,10 +2205,101 @@
22052205
zMsg = sqlite3_vmprintf(zFmt, ap);
22062206
sqlite3_result_error(ctx, zMsg, -1);
22072207
sqlite3_free(zMsg);
22082208
va_end(ap);
22092209
}
2210
+
2211
+#if defined(_WIN32)
2212
+/*
2213
+** This function is designed to convert a Win32 FILETIME structure into the
2214
+** number of seconds since the Unix Epoch (1970-01-01 00:00:00 UTC).
2215
+*/
2216
+static sqlite3_uint64 fileTimeToUnixTime(
2217
+ LPFILETIME pFileTime
2218
+){
2219
+ SYSTEMTIME epochSystemTime;
2220
+ ULARGE_INTEGER epochIntervals;
2221
+ FILETIME epochFileTime;
2222
+ ULARGE_INTEGER fileIntervals;
2223
+
2224
+ memset(&epochSystemTime, 0, sizeof(SYSTEMTIME));
2225
+ epochSystemTime.wYear = 1970;
2226
+ epochSystemTime.wMonth = 1;
2227
+ epochSystemTime.wDay = 1;
2228
+ SystemTimeToFileTime(&epochSystemTime, &epochFileTime);
2229
+ epochIntervals.LowPart = epochFileTime.dwLowDateTime;
2230
+ epochIntervals.HighPart = epochFileTime.dwHighDateTime;
2231
+
2232
+ fileIntervals.LowPart = pFileTime->dwLowDateTime;
2233
+ fileIntervals.HighPart = pFileTime->dwHighDateTime;
2234
+
2235
+ return (fileIntervals.QuadPart - epochIntervals.QuadPart) / 10000000;
2236
+}
2237
+
2238
+/*
2239
+** This function attempts to normalize the time values found in the stat()
2240
+** buffer to UTC. This is necessary on Win32, where the runtime library
2241
+** appears to return these values as local times.
2242
+*/
2243
+static void statTimesToUtc(
2244
+ const char *zPath,
2245
+ struct stat *pStatBuf
2246
+){
2247
+ HANDLE hFindFile;
2248
+ WIN32_FIND_DATAW fd;
2249
+ LPWSTR zUnicodeName;
2250
+ extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
2251
+ zUnicodeName = sqlite3_win32_utf8_to_unicode(zPath);
2252
+ if( zUnicodeName ){
2253
+ memset(&fd, 0, sizeof(WIN32_FIND_DATA));
2254
+ hFindFile = FindFirstFileW(zUnicodeName, &fd);
2255
+ if( hFindFile!=NULL ){
2256
+ pStatBuf->st_ctime = (time_t)fileTimeToUnixTime(&fd.ftCreationTime);
2257
+ pStatBuf->st_atime = (time_t)fileTimeToUnixTime(&fd.ftLastAccessTime);
2258
+ pStatBuf->st_mtime = (time_t)fileTimeToUnixTime(&fd.ftLastWriteTime);
2259
+ FindClose(hFindFile);
2260
+ }
2261
+ sqlite3_free(zUnicodeName);
2262
+ }
2263
+}
2264
+#endif
2265
+
2266
+/*
2267
+** This function is used in place of stat(). On Windows, special handling
2268
+** is required in order for the included time to be returned as UTC. On all
2269
+** other systems, this function simply calls stat().
2270
+*/
2271
+static int fileStat(
2272
+ const char *zPath,
2273
+ struct stat *pStatBuf
2274
+){
2275
+#if defined(_WIN32)
2276
+ int rc = stat(zPath, pStatBuf);
2277
+ if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
2278
+ return rc;
2279
+#else
2280
+ return stat(zPath, pStatBuf);
2281
+#endif
2282
+}
2283
+
2284
+/*
2285
+** This function is used in place of lstat(). On Windows, special handling
2286
+** is required in order for the included time to be returned as UTC. On all
2287
+** other systems, this function simply calls lstat().
2288
+*/
2289
+static int fileLinkStat(
2290
+ const char *zPath,
2291
+ struct stat *pStatBuf
2292
+){
2293
+#if defined(_WIN32)
2294
+ int rc = lstat(zPath, pStatBuf);
2295
+ if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
2296
+ return rc;
2297
+#else
2298
+ return lstat(zPath, pStatBuf);
2299
+#endif
2300
+}
22102301
22112302
/*
22122303
** Argument zFile is the name of a file that will be created and/or written
22132304
** by SQL function writefile(). This function ensures that the directory
22142305
** zFile will be written to exists, creating it if required. The permissions
@@ -2237,11 +2328,11 @@
22372328
22382329
for(; zCopy[i]!='/' && i<nCopy; i++);
22392330
if( i==nCopy ) break;
22402331
zCopy[i] = '\0';
22412332
2242
- rc2 = stat(zCopy, &sStat);
2333
+ rc2 = fileStat(zCopy, &sStat);
22432334
if( rc2!=0 ){
22442335
if( mkdir(zCopy, mode & 0777) ) rc = SQLITE_ERROR;
22452336
}else{
22462337
if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
22472338
}
@@ -2279,11 +2370,11 @@
22792370
** be an error though - if there is already a directory at the same
22802371
** path and either the permissions already match or can be changed
22812372
** to do so using chmod(), it is not an error. */
22822373
struct stat sStat;
22832374
if( errno!=EEXIST
2284
- || 0!=stat(zFile, &sStat)
2375
+ || 0!=fileStat(zFile, &sStat)
22852376
|| !S_ISDIR(sStat.st_mode)
22862377
|| ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
22872378
){
22882379
return 1;
22892380
}
@@ -2326,10 +2417,13 @@
23262417
SystemTimeToFileTime(&currentTime, &lastAccess);
23272418
intervals = Int32x32To64(mtime, 10000000) + 116444736000000000;
23282419
lastWrite.dwLowDateTime = (DWORD)intervals;
23292420
lastWrite.dwHighDateTime = intervals >> 32;
23302421
zUnicodeName = sqlite3_win32_utf8_to_unicode(zFile);
2422
+ if( zUnicodeName==0 ){
2423
+ return 1;
2424
+ }
23312425
hFile = CreateFileW(
23322426
zUnicodeName, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
23332427
FILE_FLAG_BACKUP_SEMANTICS, NULL
23342428
);
23352429
sqlite3_free(zUnicodeName);
@@ -2338,11 +2432,11 @@
23382432
CloseHandle(hFile);
23392433
return !bResult;
23402434
}else{
23412435
return 1;
23422436
}
2343
-#elif defined(AT_FDCWD) && 0 /* utimensat() is not univerally available */
2437
+#elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */
23442438
/* Recent unix */
23452439
struct timespec times[2];
23462440
times[0].tv_nsec = times[1].tv_nsec = 0;
23472441
times[0].tv_sec = time(0);
23482442
times[1].tv_sec = mtime;
@@ -2615,11 +2709,11 @@
26152709
if( pEntry->d_name[1]=='\0' ) continue;
26162710
}
26172711
sqlite3_free(pCur->zPath);
26182712
pCur->zPath = sqlite3_mprintf("%s/%s", pLvl->zDir, pEntry->d_name);
26192713
if( pCur->zPath==0 ) return SQLITE_NOMEM;
2620
- if( lstat(pCur->zPath, &pCur->sStat) ){
2714
+ if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
26212715
fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
26222716
return SQLITE_ERROR;
26232717
}
26242718
return SQLITE_OK;
26252719
}
@@ -2749,11 +2843,11 @@
27492843
}
27502844
27512845
if( pCur->zPath==0 ){
27522846
return SQLITE_NOMEM;
27532847
}
2754
- if( lstat(pCur->zPath, &pCur->sStat) ){
2848
+ if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
27552849
fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
27562850
return SQLITE_ERROR;
27572851
}
27582852
27592853
return SQLITE_OK;
@@ -2956,11 +3050,11 @@
29563050
#define COMPLETION_FUNCTIONS 3
29573051
#define COMPLETION_COLLATIONS 4
29583052
#define COMPLETION_INDEXES 5
29593053
#define COMPLETION_TRIGGERS 6
29603054
#define COMPLETION_DATABASES 7
2961
-#define COMPLETION_TABLES 8
3055
+#define COMPLETION_TABLES 8 /* Also VIEWs and TRIGGERs */
29623056
#define COMPLETION_COLUMNS 9
29633057
#define COMPLETION_MODULES 10
29643058
#define COMPLETION_EOF 11
29653059
29663060
/*
@@ -3128,12 +3222,11 @@
31283222
sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
31293223
while( sqlite3_step(pS2)==SQLITE_ROW ){
31303224
const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
31313225
zSql = sqlite3_mprintf(
31323226
"%z%s"
3133
- "SELECT name FROM \"%w\".sqlite_master"
3134
- " WHERE type='table'",
3227
+ "SELECT name FROM \"%w\".sqlite_master",
31353228
zSql, zSep, zDb
31363229
);
31373230
if( zSql==0 ) return SQLITE_NOMEM;
31383231
zSep = " UNION ";
31393232
}
@@ -5470,10 +5563,23 @@
54705563
if( pVal==0 || sqlite3_value_type(pVal)==SQLITE_NULL ){
54715564
return zipfileTime();
54725565
}
54735566
return (u32)sqlite3_value_int64(pVal);
54745567
}
5568
+
5569
+/*
5570
+** Unless it is NULL, entry pOld is currently part of the pTab->pFirstEntry
5571
+** linked list. Remove it from the list and free the object.
5572
+*/
5573
+static void zipfileRemoveEntryFromList(ZipfileTab *pTab, ZipfileEntry *pOld){
5574
+ if( pOld ){
5575
+ ZipfileEntry **pp;
5576
+ for(pp=&pTab->pFirstEntry; (*pp)!=pOld; pp=&((*pp)->pNext));
5577
+ *pp = (*pp)->pNext;
5578
+ zipfileEntryFree(pOld);
5579
+ }
5580
+}
54755581
54765582
/*
54775583
** xUpdate method.
54785584
*/
54795585
static int zipfileUpdate(
@@ -5495,10 +5601,12 @@
54955601
int nData = 0; /* Size of pData buffer in bytes */
54965602
int iMethod = 0; /* Compression method for new entry */
54975603
u8 *pFree = 0; /* Free this */
54985604
char *zFree = 0; /* Also free this */
54995605
ZipfileEntry *pOld = 0;
5606
+ ZipfileEntry *pOld2 = 0;
5607
+ int bUpdate = 0; /* True for an update that modifies "name" */
55005608
int bIsDir = 0;
55015609
u32 iCrc32 = 0;
55025610
55035611
if( pTab->pWriteFd==0 ){
55045612
rc = zipfileBegin(pVtab);
@@ -5507,10 +5615,16 @@
55075615
55085616
/* If this is a DELETE or UPDATE, find the archive entry to delete. */
55095617
if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
55105618
const char *zDelete = (const char*)sqlite3_value_text(apVal[0]);
55115619
int nDelete = (int)strlen(zDelete);
5620
+ if( nVal>1 ){
5621
+ const char *zUpdate = (const char*)sqlite3_value_text(apVal[1]);
5622
+ if( zUpdate && zipfileComparePath(zUpdate, zDelete, nDelete)!=0 ){
5623
+ bUpdate = 1;
5624
+ }
5625
+ }
55125626
for(pOld=pTab->pFirstEntry; 1; pOld=pOld->pNext){
55135627
if( zipfileComparePath(pOld->cds.zFile, zDelete, nDelete)==0 ){
55145628
break;
55155629
}
55165630
assert( pOld->pNext );
@@ -5584,21 +5698,22 @@
55845698
zPath = (const char*)zFree;
55855699
nPath++;
55865700
}
55875701
}
55885702
5589
- /* Check that we're not inserting a duplicate entry */
5590
- if( pOld==0 && rc==SQLITE_OK ){
5703
+ /* Check that we're not inserting a duplicate entry -OR- updating an
5704
+ ** entry with a path, thereby making it into a duplicate. */
5705
+ if( (pOld==0 || bUpdate) && rc==SQLITE_OK ){
55915706
ZipfileEntry *p;
55925707
for(p=pTab->pFirstEntry; p; p=p->pNext){
55935708
if( zipfileComparePath(p->cds.zFile, zPath, nPath)==0 ){
55945709
switch( sqlite3_vtab_on_conflict(pTab->db) ){
55955710
case SQLITE_IGNORE: {
55965711
goto zipfile_update_done;
55975712
}
55985713
case SQLITE_REPLACE: {
5599
- pOld = p;
5714
+ pOld2 = p;
56005715
break;
56015716
}
56025717
default: {
56035718
zipfileTableErr(pTab, "duplicate name: \"%s\"", zPath);
56045719
rc = SQLITE_CONSTRAINT;
@@ -5632,22 +5747,21 @@
56325747
zipfileAddEntry(pTab, pOld, pNew);
56335748
}
56345749
}
56355750
}
56365751
5637
- if( rc==SQLITE_OK && pOld ){
5638
- ZipfileEntry **pp;
5752
+ if( rc==SQLITE_OK && (pOld || pOld2) ){
56395753
ZipfileCsr *pCsr;
56405754
for(pCsr=pTab->pCsrList; pCsr; pCsr=pCsr->pCsrNext){
5641
- if( pCsr->pCurrent==pOld ){
5642
- pCsr->pCurrent = pOld->pNext;
5755
+ if( pCsr->pCurrent && (pCsr->pCurrent==pOld || pCsr->pCurrent==pOld2) ){
5756
+ pCsr->pCurrent = pCsr->pCurrent->pNext;
56435757
pCsr->bNoop = 1;
56445758
}
56455759
}
5646
- for(pp=&pTab->pFirstEntry; (*pp)!=pOld; pp=&((*pp)->pNext));
5647
- *pp = (*pp)->pNext;
5648
- zipfileEntryFree(pOld);
5760
+
5761
+ zipfileRemoveEntryFromList(pTab, pOld);
5762
+ zipfileRemoveEntryFromList(pTab, pOld2);
56495763
}
56505764
56515765
zipfile_update_done:
56525766
sqlite3_free(pFree);
56535767
sqlite3_free(zFree);
@@ -10282,11 +10396,16 @@
1028210396
explain_data_delete(pArg);
1028310397
}
1028410398
sqlite3_finalize(pExplain);
1028510399
sqlite3_free(zEQP);
1028610400
}
10287
- sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, triggerEQP, 0);
10401
+ if( pArg->autoEQP>=AUTOEQP_trigger && triggerEQP==0 ){
10402
+ sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 0, 0);
10403
+ /* Reprepare pStmt before reactiving trace modes */
10404
+ sqlite3_finalize(pStmt);
10405
+ sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
10406
+ }
1028810407
restore_debug_trace_modes();
1028910408
}
1029010409
1029110410
if( pArg ){
1029210411
pArg->cMode = pArg->mode;
1029310412
--- src/shell.c
+++ src/shell.c
@@ -2205,10 +2205,101 @@
2205 zMsg = sqlite3_vmprintf(zFmt, ap);
2206 sqlite3_result_error(ctx, zMsg, -1);
2207 sqlite3_free(zMsg);
2208 va_end(ap);
2209 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2210
2211 /*
2212 ** Argument zFile is the name of a file that will be created and/or written
2213 ** by SQL function writefile(). This function ensures that the directory
2214 ** zFile will be written to exists, creating it if required. The permissions
@@ -2237,11 +2328,11 @@
2237
2238 for(; zCopy[i]!='/' && i<nCopy; i++);
2239 if( i==nCopy ) break;
2240 zCopy[i] = '\0';
2241
2242 rc2 = stat(zCopy, &sStat);
2243 if( rc2!=0 ){
2244 if( mkdir(zCopy, mode & 0777) ) rc = SQLITE_ERROR;
2245 }else{
2246 if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
2247 }
@@ -2279,11 +2370,11 @@
2279 ** be an error though - if there is already a directory at the same
2280 ** path and either the permissions already match or can be changed
2281 ** to do so using chmod(), it is not an error. */
2282 struct stat sStat;
2283 if( errno!=EEXIST
2284 || 0!=stat(zFile, &sStat)
2285 || !S_ISDIR(sStat.st_mode)
2286 || ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
2287 ){
2288 return 1;
2289 }
@@ -2326,10 +2417,13 @@
2326 SystemTimeToFileTime(&currentTime, &lastAccess);
2327 intervals = Int32x32To64(mtime, 10000000) + 116444736000000000;
2328 lastWrite.dwLowDateTime = (DWORD)intervals;
2329 lastWrite.dwHighDateTime = intervals >> 32;
2330 zUnicodeName = sqlite3_win32_utf8_to_unicode(zFile);
 
 
 
2331 hFile = CreateFileW(
2332 zUnicodeName, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
2333 FILE_FLAG_BACKUP_SEMANTICS, NULL
2334 );
2335 sqlite3_free(zUnicodeName);
@@ -2338,11 +2432,11 @@
2338 CloseHandle(hFile);
2339 return !bResult;
2340 }else{
2341 return 1;
2342 }
2343 #elif defined(AT_FDCWD) && 0 /* utimensat() is not univerally available */
2344 /* Recent unix */
2345 struct timespec times[2];
2346 times[0].tv_nsec = times[1].tv_nsec = 0;
2347 times[0].tv_sec = time(0);
2348 times[1].tv_sec = mtime;
@@ -2615,11 +2709,11 @@
2615 if( pEntry->d_name[1]=='\0' ) continue;
2616 }
2617 sqlite3_free(pCur->zPath);
2618 pCur->zPath = sqlite3_mprintf("%s/%s", pLvl->zDir, pEntry->d_name);
2619 if( pCur->zPath==0 ) return SQLITE_NOMEM;
2620 if( lstat(pCur->zPath, &pCur->sStat) ){
2621 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
2622 return SQLITE_ERROR;
2623 }
2624 return SQLITE_OK;
2625 }
@@ -2749,11 +2843,11 @@
2749 }
2750
2751 if( pCur->zPath==0 ){
2752 return SQLITE_NOMEM;
2753 }
2754 if( lstat(pCur->zPath, &pCur->sStat) ){
2755 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
2756 return SQLITE_ERROR;
2757 }
2758
2759 return SQLITE_OK;
@@ -2956,11 +3050,11 @@
2956 #define COMPLETION_FUNCTIONS 3
2957 #define COMPLETION_COLLATIONS 4
2958 #define COMPLETION_INDEXES 5
2959 #define COMPLETION_TRIGGERS 6
2960 #define COMPLETION_DATABASES 7
2961 #define COMPLETION_TABLES 8
2962 #define COMPLETION_COLUMNS 9
2963 #define COMPLETION_MODULES 10
2964 #define COMPLETION_EOF 11
2965
2966 /*
@@ -3128,12 +3222,11 @@
3128 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
3129 while( sqlite3_step(pS2)==SQLITE_ROW ){
3130 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
3131 zSql = sqlite3_mprintf(
3132 "%z%s"
3133 "SELECT name FROM \"%w\".sqlite_master"
3134 " WHERE type='table'",
3135 zSql, zSep, zDb
3136 );
3137 if( zSql==0 ) return SQLITE_NOMEM;
3138 zSep = " UNION ";
3139 }
@@ -5470,10 +5563,23 @@
5470 if( pVal==0 || sqlite3_value_type(pVal)==SQLITE_NULL ){
5471 return zipfileTime();
5472 }
5473 return (u32)sqlite3_value_int64(pVal);
5474 }
 
 
 
 
 
 
 
 
 
 
 
 
 
5475
5476 /*
5477 ** xUpdate method.
5478 */
5479 static int zipfileUpdate(
@@ -5495,10 +5601,12 @@
5495 int nData = 0; /* Size of pData buffer in bytes */
5496 int iMethod = 0; /* Compression method for new entry */
5497 u8 *pFree = 0; /* Free this */
5498 char *zFree = 0; /* Also free this */
5499 ZipfileEntry *pOld = 0;
 
 
5500 int bIsDir = 0;
5501 u32 iCrc32 = 0;
5502
5503 if( pTab->pWriteFd==0 ){
5504 rc = zipfileBegin(pVtab);
@@ -5507,10 +5615,16 @@
5507
5508 /* If this is a DELETE or UPDATE, find the archive entry to delete. */
5509 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
5510 const char *zDelete = (const char*)sqlite3_value_text(apVal[0]);
5511 int nDelete = (int)strlen(zDelete);
 
 
 
 
 
 
5512 for(pOld=pTab->pFirstEntry; 1; pOld=pOld->pNext){
5513 if( zipfileComparePath(pOld->cds.zFile, zDelete, nDelete)==0 ){
5514 break;
5515 }
5516 assert( pOld->pNext );
@@ -5584,21 +5698,22 @@
5584 zPath = (const char*)zFree;
5585 nPath++;
5586 }
5587 }
5588
5589 /* Check that we're not inserting a duplicate entry */
5590 if( pOld==0 && rc==SQLITE_OK ){
 
5591 ZipfileEntry *p;
5592 for(p=pTab->pFirstEntry; p; p=p->pNext){
5593 if( zipfileComparePath(p->cds.zFile, zPath, nPath)==0 ){
5594 switch( sqlite3_vtab_on_conflict(pTab->db) ){
5595 case SQLITE_IGNORE: {
5596 goto zipfile_update_done;
5597 }
5598 case SQLITE_REPLACE: {
5599 pOld = p;
5600 break;
5601 }
5602 default: {
5603 zipfileTableErr(pTab, "duplicate name: \"%s\"", zPath);
5604 rc = SQLITE_CONSTRAINT;
@@ -5632,22 +5747,21 @@
5632 zipfileAddEntry(pTab, pOld, pNew);
5633 }
5634 }
5635 }
5636
5637 if( rc==SQLITE_OK && pOld ){
5638 ZipfileEntry **pp;
5639 ZipfileCsr *pCsr;
5640 for(pCsr=pTab->pCsrList; pCsr; pCsr=pCsr->pCsrNext){
5641 if( pCsr->pCurrent==pOld ){
5642 pCsr->pCurrent = pOld->pNext;
5643 pCsr->bNoop = 1;
5644 }
5645 }
5646 for(pp=&pTab->pFirstEntry; (*pp)!=pOld; pp=&((*pp)->pNext));
5647 *pp = (*pp)->pNext;
5648 zipfileEntryFree(pOld);
5649 }
5650
5651 zipfile_update_done:
5652 sqlite3_free(pFree);
5653 sqlite3_free(zFree);
@@ -10282,11 +10396,16 @@
10282 explain_data_delete(pArg);
10283 }
10284 sqlite3_finalize(pExplain);
10285 sqlite3_free(zEQP);
10286 }
10287 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, triggerEQP, 0);
 
 
 
 
 
10288 restore_debug_trace_modes();
10289 }
10290
10291 if( pArg ){
10292 pArg->cMode = pArg->mode;
10293
--- src/shell.c
+++ src/shell.c
@@ -2205,10 +2205,101 @@
2205 zMsg = sqlite3_vmprintf(zFmt, ap);
2206 sqlite3_result_error(ctx, zMsg, -1);
2207 sqlite3_free(zMsg);
2208 va_end(ap);
2209 }
2210
2211 #if defined(_WIN32)
2212 /*
2213 ** This function is designed to convert a Win32 FILETIME structure into the
2214 ** number of seconds since the Unix Epoch (1970-01-01 00:00:00 UTC).
2215 */
2216 static sqlite3_uint64 fileTimeToUnixTime(
2217 LPFILETIME pFileTime
2218 ){
2219 SYSTEMTIME epochSystemTime;
2220 ULARGE_INTEGER epochIntervals;
2221 FILETIME epochFileTime;
2222 ULARGE_INTEGER fileIntervals;
2223
2224 memset(&epochSystemTime, 0, sizeof(SYSTEMTIME));
2225 epochSystemTime.wYear = 1970;
2226 epochSystemTime.wMonth = 1;
2227 epochSystemTime.wDay = 1;
2228 SystemTimeToFileTime(&epochSystemTime, &epochFileTime);
2229 epochIntervals.LowPart = epochFileTime.dwLowDateTime;
2230 epochIntervals.HighPart = epochFileTime.dwHighDateTime;
2231
2232 fileIntervals.LowPart = pFileTime->dwLowDateTime;
2233 fileIntervals.HighPart = pFileTime->dwHighDateTime;
2234
2235 return (fileIntervals.QuadPart - epochIntervals.QuadPart) / 10000000;
2236 }
2237
2238 /*
2239 ** This function attempts to normalize the time values found in the stat()
2240 ** buffer to UTC. This is necessary on Win32, where the runtime library
2241 ** appears to return these values as local times.
2242 */
2243 static void statTimesToUtc(
2244 const char *zPath,
2245 struct stat *pStatBuf
2246 ){
2247 HANDLE hFindFile;
2248 WIN32_FIND_DATAW fd;
2249 LPWSTR zUnicodeName;
2250 extern LPWSTR sqlite3_win32_utf8_to_unicode(const char*);
2251 zUnicodeName = sqlite3_win32_utf8_to_unicode(zPath);
2252 if( zUnicodeName ){
2253 memset(&fd, 0, sizeof(WIN32_FIND_DATA));
2254 hFindFile = FindFirstFileW(zUnicodeName, &fd);
2255 if( hFindFile!=NULL ){
2256 pStatBuf->st_ctime = (time_t)fileTimeToUnixTime(&fd.ftCreationTime);
2257 pStatBuf->st_atime = (time_t)fileTimeToUnixTime(&fd.ftLastAccessTime);
2258 pStatBuf->st_mtime = (time_t)fileTimeToUnixTime(&fd.ftLastWriteTime);
2259 FindClose(hFindFile);
2260 }
2261 sqlite3_free(zUnicodeName);
2262 }
2263 }
2264 #endif
2265
2266 /*
2267 ** This function is used in place of stat(). On Windows, special handling
2268 ** is required in order for the included time to be returned as UTC. On all
2269 ** other systems, this function simply calls stat().
2270 */
2271 static int fileStat(
2272 const char *zPath,
2273 struct stat *pStatBuf
2274 ){
2275 #if defined(_WIN32)
2276 int rc = stat(zPath, pStatBuf);
2277 if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
2278 return rc;
2279 #else
2280 return stat(zPath, pStatBuf);
2281 #endif
2282 }
2283
2284 /*
2285 ** This function is used in place of lstat(). On Windows, special handling
2286 ** is required in order for the included time to be returned as UTC. On all
2287 ** other systems, this function simply calls lstat().
2288 */
2289 static int fileLinkStat(
2290 const char *zPath,
2291 struct stat *pStatBuf
2292 ){
2293 #if defined(_WIN32)
2294 int rc = lstat(zPath, pStatBuf);
2295 if( rc==0 ) statTimesToUtc(zPath, pStatBuf);
2296 return rc;
2297 #else
2298 return lstat(zPath, pStatBuf);
2299 #endif
2300 }
2301
2302 /*
2303 ** Argument zFile is the name of a file that will be created and/or written
2304 ** by SQL function writefile(). This function ensures that the directory
2305 ** zFile will be written to exists, creating it if required. The permissions
@@ -2237,11 +2328,11 @@
2328
2329 for(; zCopy[i]!='/' && i<nCopy; i++);
2330 if( i==nCopy ) break;
2331 zCopy[i] = '\0';
2332
2333 rc2 = fileStat(zCopy, &sStat);
2334 if( rc2!=0 ){
2335 if( mkdir(zCopy, mode & 0777) ) rc = SQLITE_ERROR;
2336 }else{
2337 if( !S_ISDIR(sStat.st_mode) ) rc = SQLITE_ERROR;
2338 }
@@ -2279,11 +2370,11 @@
2370 ** be an error though - if there is already a directory at the same
2371 ** path and either the permissions already match or can be changed
2372 ** to do so using chmod(), it is not an error. */
2373 struct stat sStat;
2374 if( errno!=EEXIST
2375 || 0!=fileStat(zFile, &sStat)
2376 || !S_ISDIR(sStat.st_mode)
2377 || ((sStat.st_mode&0777)!=(mode&0777) && 0!=chmod(zFile, mode&0777))
2378 ){
2379 return 1;
2380 }
@@ -2326,10 +2417,13 @@
2417 SystemTimeToFileTime(&currentTime, &lastAccess);
2418 intervals = Int32x32To64(mtime, 10000000) + 116444736000000000;
2419 lastWrite.dwLowDateTime = (DWORD)intervals;
2420 lastWrite.dwHighDateTime = intervals >> 32;
2421 zUnicodeName = sqlite3_win32_utf8_to_unicode(zFile);
2422 if( zUnicodeName==0 ){
2423 return 1;
2424 }
2425 hFile = CreateFileW(
2426 zUnicodeName, FILE_WRITE_ATTRIBUTES, 0, NULL, OPEN_EXISTING,
2427 FILE_FLAG_BACKUP_SEMANTICS, NULL
2428 );
2429 sqlite3_free(zUnicodeName);
@@ -2338,11 +2432,11 @@
2432 CloseHandle(hFile);
2433 return !bResult;
2434 }else{
2435 return 1;
2436 }
2437 #elif defined(AT_FDCWD) && 0 /* utimensat() is not universally available */
2438 /* Recent unix */
2439 struct timespec times[2];
2440 times[0].tv_nsec = times[1].tv_nsec = 0;
2441 times[0].tv_sec = time(0);
2442 times[1].tv_sec = mtime;
@@ -2615,11 +2709,11 @@
2709 if( pEntry->d_name[1]=='\0' ) continue;
2710 }
2711 sqlite3_free(pCur->zPath);
2712 pCur->zPath = sqlite3_mprintf("%s/%s", pLvl->zDir, pEntry->d_name);
2713 if( pCur->zPath==0 ) return SQLITE_NOMEM;
2714 if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
2715 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
2716 return SQLITE_ERROR;
2717 }
2718 return SQLITE_OK;
2719 }
@@ -2749,11 +2843,11 @@
2843 }
2844
2845 if( pCur->zPath==0 ){
2846 return SQLITE_NOMEM;
2847 }
2848 if( fileLinkStat(pCur->zPath, &pCur->sStat) ){
2849 fsdirSetErrmsg(pCur, "cannot stat file: %s", pCur->zPath);
2850 return SQLITE_ERROR;
2851 }
2852
2853 return SQLITE_OK;
@@ -2956,11 +3050,11 @@
3050 #define COMPLETION_FUNCTIONS 3
3051 #define COMPLETION_COLLATIONS 4
3052 #define COMPLETION_INDEXES 5
3053 #define COMPLETION_TRIGGERS 6
3054 #define COMPLETION_DATABASES 7
3055 #define COMPLETION_TABLES 8 /* Also VIEWs and TRIGGERs */
3056 #define COMPLETION_COLUMNS 9
3057 #define COMPLETION_MODULES 10
3058 #define COMPLETION_EOF 11
3059
3060 /*
@@ -3128,12 +3222,11 @@
3222 sqlite3_prepare_v2(pCur->db, "PRAGMA database_list", -1, &pS2, 0);
3223 while( sqlite3_step(pS2)==SQLITE_ROW ){
3224 const char *zDb = (const char*)sqlite3_column_text(pS2, 1);
3225 zSql = sqlite3_mprintf(
3226 "%z%s"
3227 "SELECT name FROM \"%w\".sqlite_master",
 
3228 zSql, zSep, zDb
3229 );
3230 if( zSql==0 ) return SQLITE_NOMEM;
3231 zSep = " UNION ";
3232 }
@@ -5470,10 +5563,23 @@
5563 if( pVal==0 || sqlite3_value_type(pVal)==SQLITE_NULL ){
5564 return zipfileTime();
5565 }
5566 return (u32)sqlite3_value_int64(pVal);
5567 }
5568
5569 /*
5570 ** Unless it is NULL, entry pOld is currently part of the pTab->pFirstEntry
5571 ** linked list. Remove it from the list and free the object.
5572 */
5573 static void zipfileRemoveEntryFromList(ZipfileTab *pTab, ZipfileEntry *pOld){
5574 if( pOld ){
5575 ZipfileEntry **pp;
5576 for(pp=&pTab->pFirstEntry; (*pp)!=pOld; pp=&((*pp)->pNext));
5577 *pp = (*pp)->pNext;
5578 zipfileEntryFree(pOld);
5579 }
5580 }
5581
5582 /*
5583 ** xUpdate method.
5584 */
5585 static int zipfileUpdate(
@@ -5495,10 +5601,12 @@
5601 int nData = 0; /* Size of pData buffer in bytes */
5602 int iMethod = 0; /* Compression method for new entry */
5603 u8 *pFree = 0; /* Free this */
5604 char *zFree = 0; /* Also free this */
5605 ZipfileEntry *pOld = 0;
5606 ZipfileEntry *pOld2 = 0;
5607 int bUpdate = 0; /* True for an update that modifies "name" */
5608 int bIsDir = 0;
5609 u32 iCrc32 = 0;
5610
5611 if( pTab->pWriteFd==0 ){
5612 rc = zipfileBegin(pVtab);
@@ -5507,10 +5615,16 @@
5615
5616 /* If this is a DELETE or UPDATE, find the archive entry to delete. */
5617 if( sqlite3_value_type(apVal[0])!=SQLITE_NULL ){
5618 const char *zDelete = (const char*)sqlite3_value_text(apVal[0]);
5619 int nDelete = (int)strlen(zDelete);
5620 if( nVal>1 ){
5621 const char *zUpdate = (const char*)sqlite3_value_text(apVal[1]);
5622 if( zUpdate && zipfileComparePath(zUpdate, zDelete, nDelete)!=0 ){
5623 bUpdate = 1;
5624 }
5625 }
5626 for(pOld=pTab->pFirstEntry; 1; pOld=pOld->pNext){
5627 if( zipfileComparePath(pOld->cds.zFile, zDelete, nDelete)==0 ){
5628 break;
5629 }
5630 assert( pOld->pNext );
@@ -5584,21 +5698,22 @@
5698 zPath = (const char*)zFree;
5699 nPath++;
5700 }
5701 }
5702
5703 /* Check that we're not inserting a duplicate entry -OR- updating an
5704 ** entry with a path, thereby making it into a duplicate. */
5705 if( (pOld==0 || bUpdate) && rc==SQLITE_OK ){
5706 ZipfileEntry *p;
5707 for(p=pTab->pFirstEntry; p; p=p->pNext){
5708 if( zipfileComparePath(p->cds.zFile, zPath, nPath)==0 ){
5709 switch( sqlite3_vtab_on_conflict(pTab->db) ){
5710 case SQLITE_IGNORE: {
5711 goto zipfile_update_done;
5712 }
5713 case SQLITE_REPLACE: {
5714 pOld2 = p;
5715 break;
5716 }
5717 default: {
5718 zipfileTableErr(pTab, "duplicate name: \"%s\"", zPath);
5719 rc = SQLITE_CONSTRAINT;
@@ -5632,22 +5747,21 @@
5747 zipfileAddEntry(pTab, pOld, pNew);
5748 }
5749 }
5750 }
5751
5752 if( rc==SQLITE_OK && (pOld || pOld2) ){
 
5753 ZipfileCsr *pCsr;
5754 for(pCsr=pTab->pCsrList; pCsr; pCsr=pCsr->pCsrNext){
5755 if( pCsr->pCurrent && (pCsr->pCurrent==pOld || pCsr->pCurrent==pOld2) ){
5756 pCsr->pCurrent = pCsr->pCurrent->pNext;
5757 pCsr->bNoop = 1;
5758 }
5759 }
5760
5761 zipfileRemoveEntryFromList(pTab, pOld);
5762 zipfileRemoveEntryFromList(pTab, pOld2);
5763 }
5764
5765 zipfile_update_done:
5766 sqlite3_free(pFree);
5767 sqlite3_free(zFree);
@@ -10282,11 +10396,16 @@
10396 explain_data_delete(pArg);
10397 }
10398 sqlite3_finalize(pExplain);
10399 sqlite3_free(zEQP);
10400 }
10401 if( pArg->autoEQP>=AUTOEQP_trigger && triggerEQP==0 ){
10402 sqlite3_db_config(db, SQLITE_DBCONFIG_TRIGGER_EQP, 0, 0);
10403 /* Reprepare pStmt before reactiving trace modes */
10404 sqlite3_finalize(pStmt);
10405 sqlite3_prepare_v2(db, zSql, -1, &pStmt, 0);
10406 }
10407 restore_debug_trace_modes();
10408 }
10409
10410 if( pArg ){
10411 pArg->cMode = pArg->mode;
10412
+189 -66
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -211,11 +211,11 @@
211211
#endif
212212
#if SQLITE_ENABLE_BATCH_ATOMIC_WRITE
213213
"ENABLE_BATCH_ATOMIC_WRITE",
214214
#endif
215215
#if SQLITE_ENABLE_CEROD
216
- "ENABLE_CEROD",
216
+ "ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD),
217217
#endif
218218
#if SQLITE_ENABLE_COLUMN_METADATA
219219
"ENABLE_COLUMN_METADATA",
220220
#endif
221221
#if SQLITE_ENABLE_COLUMN_USED_MASK
@@ -1147,11 +1147,11 @@
11471147
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
11481148
** [sqlite_version()] and [sqlite_source_id()].
11491149
*/
11501150
#define SQLITE_VERSION "3.23.0"
11511151
#define SQLITE_VERSION_NUMBER 3023000
1152
-#define SQLITE_SOURCE_ID "2018-03-17 16:26:36 442e816b5fed80ebeb58c7c0ab9c2ef999bf488519bf5da670e9cec477034540"
1152
+#define SQLITE_SOURCE_ID "2018-03-22 17:13:44 eb4f452e354065d610ff57a6a9312ad119b6b0cc467f9dff105f0718bc27ef01"
11531153
11541154
/*
11551155
** CAPI3REF: Run-Time Library Version Numbers
11561156
** KEYWORDS: sqlite3_version sqlite3_sourceid
11571157
**
@@ -3076,31 +3076,40 @@
30763076
** <dd> Usually, when a database in wal mode is closed or detached from a
30773077
** database handle, SQLite checks if this will mean that there are now no
30783078
** connections at all to the database. If so, it performs a checkpoint
30793079
** operation before closing the connection. This option may be used to
30803080
** override this behaviour. The first parameter passed to this operation
3081
-** is an integer - non-zero to disable checkpoints-on-close, or zero (the
3082
-** default) to enable them. The second parameter is a pointer to an integer
3081
+** is an integer - positive to disable checkpoints-on-close, or zero (the
3082
+** default) to enable them, and negative to leave the setting unchanged.
3083
+** The second parameter is a pointer to an integer
30833084
** into which is written 0 or 1 to indicate whether checkpoints-on-close
30843085
** have been disabled - 0 if they are not disabled, 1 if they are.
30853086
** </dd>
3087
+**
30863088
** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
30873089
** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
30883090
** the [query planner stability guarantee] (QPSG). When the QPSG is active,
30893091
** a single SQL query statement will always use the same algorithm regardless
30903092
** of values of [bound parameters].)^ The QPSG disables some query optimizations
30913093
** that look at the values of bound parameters, which can make some queries
30923094
** slower. But the QPSG has the advantage of more predictable behavior. With
30933095
** the QPSG active, SQLite will always use the same query plan in the field as
30943096
** was used during testing in the lab.
3097
+** The first argument to this setting is an integer which is 0 to disable
3098
+** the QPSG, positive to enable QPSG, or negative to leave the setting
3099
+** unchanged. The second parameter is a pointer to an integer into which
3100
+** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
3101
+** following this call.
30953102
** </dd>
3103
+**
30963104
** <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
30973105
** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
30983106
** include output for any operations performed by trigger programs. This
30993107
** option is used to set or clear (the default) a flag that governs this
31003108
** behavior. The first parameter passed to this operation is an integer -
3101
-** non-zero to enable output for trigger programs, or zero to disable it.
3109
+** positive to enable output for trigger programs, or zero to disable it,
3110
+** or negative to leave the setting unchanged.
31023111
** The second parameter is a pointer to an integer into which is written
31033112
** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
31043113
** it is not disabled, 1 if it is.
31053114
** </dd>
31063115
** </dl>
@@ -15519,10 +15528,12 @@
1551915528
#define SQLITE_OmitNoopJoin 0x0100 /* Omit unused tables in joins */
1552015529
#define SQLITE_CountOfView 0x0200 /* The count-of-view optimization */
1552115530
#define SQLITE_CursorHints 0x0400 /* Add OP_CursorHint opcodes */
1552215531
#define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */
1552315532
/* TH3 expects the Stat34 ^^^^^^ value to be 0x0800. Don't change it */
15533
+#define SQLITE_PushDown 0x1000 /* The push-down optimization */
15534
+#define SQLITE_SimplifyJoin 0x2000 /* Convert LEFT JOIN to JOIN */
1552415535
#define SQLITE_AllOpts 0xffff /* All optimizations */
1552515536
1552615537
/*
1552715538
** Macros for testing whether or not optimizations are enabled or disabled.
1552815539
*/
@@ -16980,11 +16991,10 @@
1698016991
int regRowid; /* Register holding rowid of CREATE TABLE entry */
1698116992
int regRoot; /* Register holding root page number for new objects */
1698216993
int nMaxArg; /* Max args passed to user function by sub-program */
1698316994
#if SELECTTRACE_ENABLED
1698416995
int nSelect; /* Number of SELECT statements seen */
16985
- int nSelectIndent; /* How far to indent SELECTTRACE() output */
1698616996
#endif
1698716997
#ifndef SQLITE_OMIT_SHARED_CACHE
1698816998
int nTableLock; /* Number of locks in aTableLock */
1698916999
TableLock *aTableLock; /* Required table locks for shared-cache mode */
1699017000
#endif
@@ -17344,13 +17354,13 @@
1734417354
SrcList *pSrcList; /* FROM clause */
1734517355
struct SrcCount *pSrcCount; /* Counting column references */
1734617356
struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
1734717357
int *aiCol; /* array of column indexes */
1734817358
struct IdxCover *pIdxCover; /* Check for index coverage */
17349
- struct IdxExprTrans *pIdxTrans; /* Convert indexed expr to column */
17359
+ struct IdxExprTrans *pIdxTrans; /* Convert idxed expr to column */
1735017360
ExprList *pGroupBy; /* GROUP BY clause */
17351
- struct HavingToWhereCtx *pHavingCtx; /* HAVING to WHERE clause ctx */
17361
+ Select *pSelect; /* HAVING to WHERE clause ctx */
1735217362
} u;
1735317363
};
1735417364
1735517365
/* Forward declarations */
1735617366
SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
@@ -17810,10 +17820,11 @@
1781017820
SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
1781117821
SQLITE_PRIVATE int sqlite3ExprCompare(Parse*,Expr*, Expr*, int);
1781217822
SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int);
1781317823
SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
1781417824
SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse*,Expr*, Expr*, int);
17825
+SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int);
1781517826
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
1781617827
SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
1781717828
SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
1781817829
SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
1781917830
SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
@@ -27316,15 +27327,25 @@
2731627327
sqlite3TreeViewWith(pView, p->pWith, 1);
2731727328
cnt = 1;
2731827329
sqlite3TreeViewPush(pView, 1);
2731927330
}
2732027331
do{
27332
+#if SELECTTRACE_ENABLED
27333
+ sqlite3TreeViewLine(pView,
27334
+ "SELECT%s%s (%s/%p) selFlags=0x%x nSelectRow=%d",
27335
+ ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
27336
+ ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""),
27337
+ p->zSelName, p, p->selFlags,
27338
+ (int)p->nSelectRow
27339
+ );
27340
+#else
2732127341
sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x nSelectRow=%d",
2732227342
((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
2732327343
((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags,
2732427344
(int)p->nSelectRow
2732527345
);
27346
+#endif
2732627347
if( cnt++ ) sqlite3TreeViewPop(pView);
2732727348
if( p->pPrior ){
2732827349
n = 1000;
2732927350
}else{
2733027351
n = 0;
@@ -98687,10 +98708,62 @@
9868798708
testcase( pX!=pE1->pLeft );
9868898709
if( sqlite3ExprCompare(pParse, pX, pE2->pLeft, iTab)==0 ) return 1;
9868998710
}
9869098711
return 0;
9869198712
}
98713
+
98714
+/*
98715
+** This is the Expr node callback for sqlite3ExprImpliesNotNullRow().
98716
+** If the expression node requires that the table at pWalker->iCur
98717
+** have a non-NULL column, then set pWalker->eCode to 1 and abort.
98718
+*/
98719
+static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
98720
+ if( ExprHasProperty(pExpr, EP_FromJoin) ) return WRC_Prune;
98721
+ switch( pExpr->op ){
98722
+ case TK_ISNULL:
98723
+ case TK_IS:
98724
+ case TK_OR:
98725
+ case TK_FUNCTION:
98726
+ case TK_AGG_FUNCTION:
98727
+ return WRC_Prune;
98728
+ case TK_COLUMN:
98729
+ case TK_AGG_COLUMN:
98730
+ if( pWalker->u.iCur==pExpr->iTable ){
98731
+ pWalker->eCode = 1;
98732
+ return WRC_Abort;
98733
+ }
98734
+ return WRC_Prune;
98735
+ default:
98736
+ return WRC_Continue;
98737
+ }
98738
+}
98739
+
98740
+/*
98741
+** Return true (non-zero) if expression p can only be true if at least
98742
+** one column of table iTab is non-null. In other words, return true
98743
+** if expression p will always be NULL or false if every column of iTab
98744
+** is NULL.
98745
+**
98746
+** Terms of p that are marked with EP_FromJoin (and hence that come from
98747
+** the ON or USING clauses of LEFT JOINS) are excluded from the analysis.
98748
+**
98749
+** This routine is used to check if a LEFT JOIN can be converted into
98750
+** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE
98751
+** clause requires that some column of the right table of the LEFT JOIN
98752
+** be non-NULL, then the LEFT JOIN can be safely converted into an
98753
+** ordinary join.
98754
+*/
98755
+SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab){
98756
+ Walker w;
98757
+ w.xExprCallback = impliesNotNullRow;
98758
+ w.xSelectCallback = 0;
98759
+ w.xSelectCallback2 = 0;
98760
+ w.eCode = 0;
98761
+ w.u.iCur = iTab;
98762
+ sqlite3WalkExpr(&w, p);
98763
+ return w.eCode;
98764
+}
9869298765
9869398766
/*
9869498767
** An instance of the following structure is used by the tree walker
9869598768
** to determine if an expression can be evaluated by reference to the
9869698769
** index only, without having to do a search for the corresponding
@@ -112201,15 +112274,16 @@
112201112274
** same table is autoincremented multiple times due to inserts within
112202112275
** triggers. A new AutoincInfo structure is created if this is the
112203112276
** first use of table pTab. On 2nd and subsequent uses, the original
112204112277
** AutoincInfo structure is used.
112205112278
**
112206
-** Three memory locations are allocated:
112279
+** Four consecutive registers are allocated:
112207112280
**
112208
-** (1) Register to hold the name of the pTab table.
112209
-** (2) Register to hold the maximum ROWID of pTab.
112210
-** (3) Register to hold the rowid in sqlite_sequence of pTab
112281
+** (1) The name of the pTab table.
112282
+** (2) The maximum ROWID of pTab.
112283
+** (3) The rowid in sqlite_sequence of pTab
112284
+** (4) The original value of the max ROWID in pTab, or NULL if none
112211112285
**
112212112286
** The 2nd register is the one that is returned. That is all the
112213112287
** insert routine needs to know about.
112214112288
*/
112215112289
static int autoIncBegin(
@@ -112233,11 +112307,11 @@
112233112307
pToplevel->pAinc = pInfo;
112234112308
pInfo->pTab = pTab;
112235112309
pInfo->iDb = iDb;
112236112310
pToplevel->nMem++; /* Register to hold name of table */
112237112311
pInfo->regCtr = ++pToplevel->nMem; /* Max rowid register */
112238
- pToplevel->nMem++; /* Rowid in sqlite_sequence */
112312
+ pToplevel->nMem +=2; /* Rowid in sqlite_sequence + orig max val */
112239112313
}
112240112314
memId = pInfo->regCtr;
112241112315
}
112242112316
return memId;
112243112317
}
@@ -112261,19 +112335,21 @@
112261112335
assert( v ); /* We failed long ago if this is not so */
112262112336
for(p = pParse->pAinc; p; p = p->pNext){
112263112337
static const int iLn = VDBE_OFFSET_LINENO(2);
112264112338
static const VdbeOpList autoInc[] = {
112265112339
/* 0 */ {OP_Null, 0, 0, 0},
112266
- /* 1 */ {OP_Rewind, 0, 9, 0},
112340
+ /* 1 */ {OP_Rewind, 0, 10, 0},
112267112341
/* 2 */ {OP_Column, 0, 0, 0},
112268
- /* 3 */ {OP_Ne, 0, 7, 0},
112342
+ /* 3 */ {OP_Ne, 0, 9, 0},
112269112343
/* 4 */ {OP_Rowid, 0, 0, 0},
112270112344
/* 5 */ {OP_Column, 0, 1, 0},
112271
- /* 6 */ {OP_Goto, 0, 9, 0},
112272
- /* 7 */ {OP_Next, 0, 2, 0},
112273
- /* 8 */ {OP_Integer, 0, 0, 0},
112274
- /* 9 */ {OP_Close, 0, 0, 0}
112345
+ /* 6 */ {OP_AddImm, 0, 0, 0},
112346
+ /* 7 */ {OP_Copy, 0, 0, 0},
112347
+ /* 8 */ {OP_Goto, 0, 11, 0},
112348
+ /* 9 */ {OP_Next, 0, 2, 0},
112349
+ /* 10 */ {OP_Integer, 0, 0, 0},
112350
+ /* 11 */ {OP_Close, 0, 0, 0}
112275112351
};
112276112352
VdbeOp *aOp;
112277112353
pDb = &db->aDb[p->iDb];
112278112354
memId = p->regCtr;
112279112355
assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
@@ -112280,18 +112356,21 @@
112280112356
sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
112281112357
sqlite3VdbeLoadString(v, memId-1, p->pTab->zName);
112282112358
aOp = sqlite3VdbeAddOpList(v, ArraySize(autoInc), autoInc, iLn);
112283112359
if( aOp==0 ) break;
112284112360
aOp[0].p2 = memId;
112285
- aOp[0].p3 = memId+1;
112361
+ aOp[0].p3 = memId+2;
112286112362
aOp[2].p3 = memId;
112287112363
aOp[3].p1 = memId-1;
112288112364
aOp[3].p3 = memId;
112289112365
aOp[3].p5 = SQLITE_JUMPIFNULL;
112290112366
aOp[4].p2 = memId+1;
112291112367
aOp[5].p3 = memId;
112292
- aOp[8].p2 = memId;
112368
+ aOp[6].p1 = memId;
112369
+ aOp[7].p2 = memId+2;
112370
+ aOp[7].p1 = memId;
112371
+ aOp[10].p2 = memId;
112293112372
}
112294112373
}
112295112374
112296112375
/*
112297112376
** Update the maximum rowid for an autoincrement calculation.
@@ -112334,10 +112413,12 @@
112334112413
int iRec;
112335112414
int memId = p->regCtr;
112336112415
112337112416
iRec = sqlite3GetTempReg(pParse);
112338112417
assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
112418
+ sqlite3VdbeAddOp3(v, OP_Le, memId+2, sqlite3VdbeCurrentAddr(v)+7, memId);
112419
+ VdbeCoverage(v);
112339112420
sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
112340112421
aOp = sqlite3VdbeAddOpList(v, ArraySize(autoIncEnd), autoIncEnd, iLn);
112341112422
if( aOp==0 ) break;
112342112423
aOp[0].p1 = memId+1;
112343112424
aOp[1].p2 = memId+1;
@@ -119861,12 +119942,11 @@
119861119942
*/
119862119943
#if SELECTTRACE_ENABLED
119863119944
/***/ int sqlite3SelectTrace = 0;
119864119945
# define SELECTTRACE(K,P,S,X) \
119865119946
if(sqlite3SelectTrace&(K)) \
119866
- sqlite3DebugPrintf("%*s%s.%p: ",(P)->nSelectIndent*2-2,"",\
119867
- (S)->zSelName,(S)),\
119947
+ sqlite3DebugPrintf("%s/%p: ",(S)->zSelName,(S)),\
119868119948
sqlite3DebugPrintf X
119869119949
#else
119870119950
# define SELECTTRACE(K,P,S,X)
119871119951
#endif
119872119952
@@ -120222,10 +120302,33 @@
120222120302
}
120223120303
setJoinExpr(p->pLeft, iTable);
120224120304
p = p->pRight;
120225120305
}
120226120306
}
120307
+
120308
+/* Undo the work of setJoinExpr(). In the expression tree p, convert every
120309
+** term that is marked with EP_FromJoin and iRightJoinTable==iTable into
120310
+** an ordinary term that omits the EP_FromJoin mark.
120311
+**
120312
+** This happens when a LEFT JOIN is simplified into an ordinary JOIN.
120313
+*/
120314
+static void unsetJoinExpr(Expr *p, int iTable){
120315
+ while( p ){
120316
+ if( ExprHasProperty(p, EP_FromJoin)
120317
+ && (iTable<0 || p->iRightJoinTable==iTable) ){
120318
+ ExprClearProperty(p, EP_FromJoin);
120319
+ }
120320
+ if( p->op==TK_FUNCTION && p->x.pList ){
120321
+ int i;
120322
+ for(i=0; i<p->x.pList->nExpr; i++){
120323
+ unsetJoinExpr(p->x.pList->a[i].pExpr, iTable);
120324
+ }
120325
+ }
120326
+ unsetJoinExpr(p->pLeft, iTable);
120327
+ p = p->pRight;
120328
+ }
120329
+}
120227120330
120228120331
/*
120229120332
** This routine processes the join information for a SELECT statement.
120230120333
** ON and USING clauses are converted into extra terms of the WHERE clause.
120231120334
** NATURAL joins also create extra WHERE clause terms.
@@ -123675,16 +123778,25 @@
123675123778
** (2) The inner query is the recursive part of a common table expression.
123676123779
**
123677123780
** (3) The inner query has a LIMIT clause (since the changes to the WHERE
123678123781
** close would change the meaning of the LIMIT).
123679123782
**
123680
-** (4) The inner query is the right operand of a LEFT JOIN. (The caller
123681
-** enforces this restriction since this routine does not have enough
123682
-** information to know.)
123783
+** (4) (** This restriction was removed on 2018-03-21. It used to read:
123784
+** The inner query is the right operand of a LEFT JOIN. **)
123683123785
**
123684123786
** (5) The WHERE clause expression originates in the ON or USING clause
123685
-** of a LEFT JOIN.
123787
+** of a LEFT JOIN where iCursor is not the right-hand table of that
123788
+** left join. An example:
123789
+**
123790
+** SELECT *
123791
+** FROM (SELECT 1 AS a1 UNION ALL SELECT 2) AS aa
123792
+** JOIN (SELECT 1 AS b2 UNION ALL SELECT 2) AS bb ON (a1=b2)
123793
+** LEFT JOIN (SELECT 8 AS c3 UNION ALL SELECT 9) AS cc ON (b2=2);
123794
+**
123795
+** The correct answer is three rows: (1,1,NULL),(2,2,8),(2,2,9).
123796
+** But if the (b2=2) term were to be pushed down into the bb subquery,
123797
+** then the (1,1,NULL) row would be suppressed.
123686123798
**
123687123799
** Return 0 if no changes are made and non-zero if one or more WHERE clause
123688123800
** terms are duplicated into the subquery.
123689123801
*/
123690123802
static int pushDownWhereTerms(
@@ -123716,16 +123828,19 @@
123716123828
}
123717123829
while( pWhere->op==TK_AND ){
123718123830
nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, iCursor);
123719123831
pWhere = pWhere->pLeft;
123720123832
}
123721
- if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction (5) */
123833
+ if( ExprHasProperty(pWhere,EP_FromJoin) && pWhere->iRightJoinTable!=iCursor ){
123834
+ return 0; /* restriction (5) */
123835
+ }
123722123836
if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
123723123837
nChng++;
123724123838
while( pSubq ){
123725123839
SubstContext x;
123726123840
pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
123841
+ unsetJoinExpr(pNew, -1);
123727123842
x.pParse = pParse;
123728123843
x.iTable = iCursor;
123729123844
x.iNewTable = iCursor;
123730123845
x.isLeftJoin = 0;
123731123846
x.pEList = pSubq->pEList;
@@ -124753,18 +124868,10 @@
124753124868
}
124754124869
#else
124755124870
# define explainSimpleCount(a,b,c)
124756124871
#endif
124757124872
124758
-/*
124759
-** Context object for havingToWhereExprCb().
124760
-*/
124761
-struct HavingToWhereCtx {
124762
- Expr **ppWhere;
124763
- ExprList *pGroupBy;
124764
-};
124765
-
124766124873
/*
124767124874
** sqlite3WalkExpr() callback used by havingToWhere().
124768124875
**
124769124876
** If the node passed to the callback is a TK_AND node, return
124770124877
** WRC_Continue to tell sqlite3WalkExpr() to iterate through child nodes.
@@ -124774,19 +124881,20 @@
124774124881
** clause. If so, add it to the WHERE clause and replace the sub-expression
124775124882
** within the HAVING expression with a constant "1".
124776124883
*/
124777124884
static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){
124778124885
if( pExpr->op!=TK_AND ){
124779
- struct HavingToWhereCtx *p = pWalker->u.pHavingCtx;
124780
- if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, p->pGroupBy) ){
124886
+ Select *pS = pWalker->u.pSelect;
124887
+ if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, pS->pGroupBy) ){
124781124888
sqlite3 *db = pWalker->pParse->db;
124782124889
Expr *pNew = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[1], 0);
124783124890
if( pNew ){
124784
- Expr *pWhere = *(p->ppWhere);
124891
+ Expr *pWhere = pS->pWhere;
124785124892
SWAP(Expr, *pNew, *pExpr);
124786124893
pNew = sqlite3ExprAnd(db, pWhere, pNew);
124787
- *(p->ppWhere) = pNew;
124894
+ pS->pWhere = pNew;
124895
+ pWalker->eCode = 1;
124788124896
}
124789124897
}
124790124898
return WRC_Prune;
124791124899
}
124792124900
return WRC_Continue;
@@ -124805,27 +124913,23 @@
124805124913
**
124806124914
** A term of the HAVING expression is eligible for transfer if it consists
124807124915
** entirely of constants and expressions that are also GROUP BY terms that
124808124916
** use the "BINARY" collation sequence.
124809124917
*/
124810
-static void havingToWhere(
124811
- Parse *pParse,
124812
- ExprList *pGroupBy,
124813
- Expr *pHaving,
124814
- Expr **ppWhere
124815
-){
124816
- struct HavingToWhereCtx sCtx;
124918
+static void havingToWhere(Parse *pParse, Select *p){
124817124919
Walker sWalker;
124818
-
124819
- sCtx.ppWhere = ppWhere;
124820
- sCtx.pGroupBy = pGroupBy;
124821
-
124822124920
memset(&sWalker, 0, sizeof(sWalker));
124823124921
sWalker.pParse = pParse;
124824124922
sWalker.xExprCallback = havingToWhereExprCb;
124825
- sWalker.u.pHavingCtx = &sCtx;
124826
- sqlite3WalkExpr(&sWalker, pHaving);
124923
+ sWalker.u.pSelect = p;
124924
+ sqlite3WalkExpr(&sWalker, p->pHaving);
124925
+#if SELECTTRACE_ENABLED
124926
+ if( sWalker.eCode && (sqlite3SelectTrace & 0x100)!=0 ){
124927
+ SELECTTRACE(0x100,pParse,p,("Move HAVING terms into WHERE:\n"));
124928
+ sqlite3TreeViewSelect(0, p, 0);
124929
+ }
124930
+#endif
124827124931
}
124828124932
124829124933
/*
124830124934
** Check to see if the pThis entry of pTabList is a self-join of a prior view.
124831124935
** If it is, then return the SrcList_item for the prior view. If it is not,
@@ -124982,11 +125086,10 @@
124982125086
return 1;
124983125087
}
124984125088
if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
124985125089
memset(&sAggInfo, 0, sizeof(sAggInfo));
124986125090
#if SELECTTRACE_ENABLED
124987
- pParse->nSelectIndent++;
124988125091
SELECTTRACE(1,pParse,p, ("begin processing:\n"));
124989125092
if( sqlite3SelectTrace & 0x100 ){
124990125093
sqlite3TreeViewSelect(0, p, 0);
124991125094
}
124992125095
#endif
@@ -125028,17 +125131,33 @@
125028125131
if( v==0 ) goto select_end;
125029125132
if( pDest->eDest==SRT_Output ){
125030125133
generateColumnNames(pParse, p);
125031125134
}
125032125135
125033
- /* Try to flatten subqueries in the FROM clause up into the main query
125136
+ /* Try to various optimizations (flattening subqueries, and strength
125137
+ ** reduction of join operators) in the FROM clause up into the main query
125034125138
*/
125035125139
#if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
125036125140
for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
125037125141
struct SrcList_item *pItem = &pTabList->a[i];
125038125142
Select *pSub = pItem->pSelect;
125039125143
Table *pTab = pItem->pTab;
125144
+
125145
+ /* Convert LEFT JOIN into JOIN if there are terms of the right table
125146
+ ** of the LEFT JOIN used in the WHERE clause.
125147
+ */
125148
+ if( (pItem->fg.jointype & JT_LEFT)!=0
125149
+ && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor)
125150
+ && OptimizationEnabled(db, SQLITE_SimplifyJoin)
125151
+ ){
125152
+ SELECTTRACE(0x100,pParse,p,
125153
+ ("LEFT-JOIN simplifies to JOIN on term %d\n",i));
125154
+ pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER);
125155
+ unsetJoinExpr(p->pWhere, pItem->iCursor);
125156
+ }
125157
+
125158
+ /* No futher action if this term of the FROM clause is no a subquery */
125040125159
if( pSub==0 ) continue;
125041125160
125042125161
/* Catch mismatch in the declared columns of a view and the number of
125043125162
** columns in the SELECT on the RHS */
125044125163
if( pTab->nCol!=pSub->pEList->nExpr ){
@@ -125103,11 +125222,10 @@
125103125222
if( p->pPrior ){
125104125223
rc = multiSelect(pParse, p, pDest);
125105125224
explainSetInteger(pParse->iSelectId, iRestoreSelectId);
125106125225
#if SELECTTRACE_ENABLED
125107125226
SELECTTRACE(1,pParse,p,("end compound-select processing\n"));
125108
- pParse->nSelectIndent--;
125109125227
#endif
125110125228
return rc;
125111125229
}
125112125230
#endif
125113125231
@@ -125176,19 +125294,21 @@
125176125294
pParse->nHeight += sqlite3SelectExprHeight(p);
125177125295
125178125296
/* Make copies of constant WHERE-clause terms in the outer query down
125179125297
** inside the subquery. This can help the subquery to run more efficiently.
125180125298
*/
125181
- if( (pItem->fg.jointype & JT_OUTER)==0
125299
+ if( OptimizationEnabled(db, SQLITE_PushDown)
125182125300
&& pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor)
125183125301
){
125184125302
#if SELECTTRACE_ENABLED
125185125303
if( sqlite3SelectTrace & 0x100 ){
125186125304
SELECTTRACE(0x100,pParse,p,("After WHERE-clause push-down:\n"));
125187125305
sqlite3TreeViewSelect(0, p, 0);
125188125306
}
125189125307
#endif
125308
+ }else{
125309
+ SELECTTRACE(0x100,pParse,p,("Push-down not possible\n"));
125190125310
}
125191125311
125192125312
zSavedAuthContext = pParse->zAuthContext;
125193125313
pParse->zAuthContext = pItem->zName;
125194125314
@@ -125387,10 +125507,11 @@
125387125507
u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0);
125388125508
assert( WHERE_USE_LIMIT==SF_FixedLimit );
125389125509
wctrlFlags |= p->selFlags & SF_FixedLimit;
125390125510
125391125511
/* Begin the database scan. */
125512
+ SELECTTRACE(1,pParse,p,("WhereBegin\n"));
125392125513
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy,
125393125514
p->pEList, wctrlFlags, p->nSelectRow);
125394125515
if( pWInfo==0 ) goto select_end;
125395125516
if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
125396125517
p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
@@ -125488,11 +125609,13 @@
125488125609
sqlite3ExprAnalyzeAggList(&sNC, pEList);
125489125610
sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
125490125611
if( pHaving ){
125491125612
if( pGroupBy ){
125492125613
assert( pWhere==p->pWhere );
125493
- havingToWhere(pParse, pGroupBy, pHaving, &p->pWhere);
125614
+ assert( pHaving==p->pHaving );
125615
+ assert( pGroupBy==p->pGroupBy );
125616
+ havingToWhere(pParse, p);
125494125617
pWhere = p->pWhere;
125495125618
}
125496125619
sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
125497125620
}
125498125621
sAggInfo.nAccumulator = sAggInfo.nColumn;
@@ -125575,10 +125698,11 @@
125575125698
** This might involve two separate loops with an OP_Sort in between, or
125576125699
** it might be a single loop that uses an index to extract information
125577125700
** in the right order to begin with.
125578125701
*/
125579125702
sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
125703
+ SELECTTRACE(1,pParse,p,("WhereBegin\n"));
125580125704
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, 0,
125581125705
WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0), 0
125582125706
);
125583125707
if( pWInfo==0 ) goto select_end;
125584125708
if( sqlite3WhereIsOrdered(pWInfo)==pGroupBy->nExpr ){
@@ -125830,10 +125954,11 @@
125830125954
** be an appropriate ORDER BY expression for the optimization.
125831125955
*/
125832125956
assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
125833125957
assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
125834125958
125959
+ SELECTTRACE(1,pParse,p,("WhereBegin\n"));
125835125960
pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
125836125961
0, minMaxFlag, 0);
125837125962
if( pWInfo==0 ){
125838125963
goto select_end;
125839125964
}
@@ -125885,11 +126010,10 @@
125885126010
sqlite3ExprListDelete(db, pMinMaxOrderBy);
125886126011
sqlite3DbFree(db, sAggInfo.aCol);
125887126012
sqlite3DbFree(db, sAggInfo.aFunc);
125888126013
#if SELECTTRACE_ENABLED
125889126014
SELECTTRACE(1,pParse,p,("end processing\n"));
125890
- pParse->nSelectIndent--;
125891126015
#endif
125892126016
return rc;
125893126017
}
125894126018
125895126019
/************** End of select.c **********************************************/
@@ -142086,12 +142210,11 @@
142086142210
** is an integer that is incremented with each SELECT statement seen.
142087142211
*/
142088142212
if( yymsp[-8].minor.yy387!=0 ){
142089142213
const char *z = s.z+6;
142090142214
int i;
142091
- sqlite3_snprintf(sizeof(yymsp[-8].minor.yy387->zSelName), yymsp[-8].minor.yy387->zSelName, "#%d",
142092
- ++pParse->nSelect);
142215
+ sqlite3_snprintf(sizeof(yymsp[-8].minor.yy387->zSelName), yymsp[-8].minor.yy387->zSelName,"#%d",++pParse->nSelect);
142093142216
while( z[0]==' ' ) z++;
142094142217
if( z[0]=='/' && z[1]=='*' ){
142095142218
z += 2;
142096142219
while( z[0]==' ' ) z++;
142097142220
for(i=0; sqlite3Isalnum(z[i]); i++){}
@@ -175718,11 +175841,11 @@
175718175841
int bKey = sqlite3_column_int(pXInfo, 5);
175719175842
if( bKey ){
175720175843
int iCid = sqlite3_column_int(pXInfo, 1);
175721175844
int bDesc = sqlite3_column_int(pXInfo, 3);
175722175845
const char *zCollate = (const char*)sqlite3_column_text(pXInfo, 4);
175723
- zCols = rbuMPrintf(p, "%z%sc%d %s COLLATE %s", zCols, zComma,
175846
+ zCols = rbuMPrintf(p, "%z%sc%d %s COLLATE %Q", zCols, zComma,
175724175847
iCid, pIter->azTblType[iCid], zCollate
175725175848
);
175726175849
zPk = rbuMPrintf(p, "%z%sc%d%s", zPk, zComma, iCid, bDesc?" DESC":"");
175727175850
zComma = ", ";
175728175851
}
@@ -175779,11 +175902,11 @@
175779175902
if( pIter->eType==RBU_PK_IPK && pIter->abTblPk[iCol] ){
175780175903
/* If the target table column is an "INTEGER PRIMARY KEY", add
175781175904
** "PRIMARY KEY" to the imposter table column declaration. */
175782175905
zPk = "PRIMARY KEY ";
175783175906
}
175784
- zSql = rbuMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %s%s",
175907
+ zSql = rbuMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %Q%s",
175785175908
zSql, zComma, zCol, pIter->azTblType[iCol], zPk, zColl,
175786175909
(pIter->abNotNull[iCol] ? " NOT NULL" : "")
175787175910
);
175788175911
zComma = ", ";
175789175912
}
@@ -204574,11 +204697,11 @@
204574204697
int nArg, /* Number of args */
204575204698
sqlite3_value **apUnused /* Function arguments */
204576204699
){
204577204700
assert( nArg==0 );
204578204701
UNUSED_PARAM2(nArg, apUnused);
204579
- sqlite3_result_text(pCtx, "fts5: 2018-03-16 20:23:01 d75e67654aa9620b9617786553a002f54e8c6dcbbcc58948a06bd98a0916d75a", -1, SQLITE_TRANSIENT);
204702
+ sqlite3_result_text(pCtx, "fts5: 2018-03-22 17:13:44 eb4f452e354065d610ff57a6a9312ad119b6b0cc467f9dff105f0718bc27ef01", -1, SQLITE_TRANSIENT);
204580204703
}
204581204704
204582204705
static int fts5Init(sqlite3 *db){
204583204706
static const sqlite3_module fts5Mod = {
204584204707
/* iVersion */ 2,
@@ -208844,12 +208967,12 @@
208844208967
}
208845208968
#endif /* SQLITE_CORE */
208846208969
#endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
208847208970
208848208971
/************** End of stmt.c ************************************************/
208849
-#if __LINE__!=208849
208972
+#if __LINE__!=208972
208850208973
#undef SQLITE_SOURCE_ID
208851
-#define SQLITE_SOURCE_ID "2018-03-17 16:26:36 442e816b5fed80ebeb58c7c0ab9c2ef999bf488519bf5da670e9cec47703alt2"
208974
+#define SQLITE_SOURCE_ID "2018-03-22 17:13:44 eb4f452e354065d610ff57a6a9312ad119b6b0cc467f9dff105f0718bc27alt2"
208852208975
#endif
208853208976
/* Return the source-id for this library */
208854208977
SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
208855208978
/************************** End of sqlite3.c ******************************/
208856208979
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -211,11 +211,11 @@
211 #endif
212 #if SQLITE_ENABLE_BATCH_ATOMIC_WRITE
213 "ENABLE_BATCH_ATOMIC_WRITE",
214 #endif
215 #if SQLITE_ENABLE_CEROD
216 "ENABLE_CEROD",
217 #endif
218 #if SQLITE_ENABLE_COLUMN_METADATA
219 "ENABLE_COLUMN_METADATA",
220 #endif
221 #if SQLITE_ENABLE_COLUMN_USED_MASK
@@ -1147,11 +1147,11 @@
1147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1148 ** [sqlite_version()] and [sqlite_source_id()].
1149 */
1150 #define SQLITE_VERSION "3.23.0"
1151 #define SQLITE_VERSION_NUMBER 3023000
1152 #define SQLITE_SOURCE_ID "2018-03-17 16:26:36 442e816b5fed80ebeb58c7c0ab9c2ef999bf488519bf5da670e9cec477034540"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -3076,31 +3076,40 @@
3076 ** <dd> Usually, when a database in wal mode is closed or detached from a
3077 ** database handle, SQLite checks if this will mean that there are now no
3078 ** connections at all to the database. If so, it performs a checkpoint
3079 ** operation before closing the connection. This option may be used to
3080 ** override this behaviour. The first parameter passed to this operation
3081 ** is an integer - non-zero to disable checkpoints-on-close, or zero (the
3082 ** default) to enable them. The second parameter is a pointer to an integer
 
3083 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
3084 ** have been disabled - 0 if they are not disabled, 1 if they are.
3085 ** </dd>
 
3086 ** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
3087 ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
3088 ** the [query planner stability guarantee] (QPSG). When the QPSG is active,
3089 ** a single SQL query statement will always use the same algorithm regardless
3090 ** of values of [bound parameters].)^ The QPSG disables some query optimizations
3091 ** that look at the values of bound parameters, which can make some queries
3092 ** slower. But the QPSG has the advantage of more predictable behavior. With
3093 ** the QPSG active, SQLite will always use the same query plan in the field as
3094 ** was used during testing in the lab.
 
 
 
 
 
3095 ** </dd>
 
3096 ** <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
3097 ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
3098 ** include output for any operations performed by trigger programs. This
3099 ** option is used to set or clear (the default) a flag that governs this
3100 ** behavior. The first parameter passed to this operation is an integer -
3101 ** non-zero to enable output for trigger programs, or zero to disable it.
 
3102 ** The second parameter is a pointer to an integer into which is written
3103 ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
3104 ** it is not disabled, 1 if it is.
3105 ** </dd>
3106 ** </dl>
@@ -15519,10 +15528,12 @@
15519 #define SQLITE_OmitNoopJoin 0x0100 /* Omit unused tables in joins */
15520 #define SQLITE_CountOfView 0x0200 /* The count-of-view optimization */
15521 #define SQLITE_CursorHints 0x0400 /* Add OP_CursorHint opcodes */
15522 #define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */
15523 /* TH3 expects the Stat34 ^^^^^^ value to be 0x0800. Don't change it */
 
 
15524 #define SQLITE_AllOpts 0xffff /* All optimizations */
15525
15526 /*
15527 ** Macros for testing whether or not optimizations are enabled or disabled.
15528 */
@@ -16980,11 +16991,10 @@
16980 int regRowid; /* Register holding rowid of CREATE TABLE entry */
16981 int regRoot; /* Register holding root page number for new objects */
16982 int nMaxArg; /* Max args passed to user function by sub-program */
16983 #if SELECTTRACE_ENABLED
16984 int nSelect; /* Number of SELECT statements seen */
16985 int nSelectIndent; /* How far to indent SELECTTRACE() output */
16986 #endif
16987 #ifndef SQLITE_OMIT_SHARED_CACHE
16988 int nTableLock; /* Number of locks in aTableLock */
16989 TableLock *aTableLock; /* Required table locks for shared-cache mode */
16990 #endif
@@ -17344,13 +17354,13 @@
17344 SrcList *pSrcList; /* FROM clause */
17345 struct SrcCount *pSrcCount; /* Counting column references */
17346 struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
17347 int *aiCol; /* array of column indexes */
17348 struct IdxCover *pIdxCover; /* Check for index coverage */
17349 struct IdxExprTrans *pIdxTrans; /* Convert indexed expr to column */
17350 ExprList *pGroupBy; /* GROUP BY clause */
17351 struct HavingToWhereCtx *pHavingCtx; /* HAVING to WHERE clause ctx */
17352 } u;
17353 };
17354
17355 /* Forward declarations */
17356 SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
@@ -17810,10 +17820,11 @@
17810 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
17811 SQLITE_PRIVATE int sqlite3ExprCompare(Parse*,Expr*, Expr*, int);
17812 SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int);
17813 SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
17814 SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse*,Expr*, Expr*, int);
 
17815 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
17816 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
17817 SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
17818 SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
17819 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
@@ -27316,15 +27327,25 @@
27316 sqlite3TreeViewWith(pView, p->pWith, 1);
27317 cnt = 1;
27318 sqlite3TreeViewPush(pView, 1);
27319 }
27320 do{
 
 
 
 
 
 
 
 
 
27321 sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x nSelectRow=%d",
27322 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
27323 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags,
27324 (int)p->nSelectRow
27325 );
 
27326 if( cnt++ ) sqlite3TreeViewPop(pView);
27327 if( p->pPrior ){
27328 n = 1000;
27329 }else{
27330 n = 0;
@@ -98687,10 +98708,62 @@
98687 testcase( pX!=pE1->pLeft );
98688 if( sqlite3ExprCompare(pParse, pX, pE2->pLeft, iTab)==0 ) return 1;
98689 }
98690 return 0;
98691 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98692
98693 /*
98694 ** An instance of the following structure is used by the tree walker
98695 ** to determine if an expression can be evaluated by reference to the
98696 ** index only, without having to do a search for the corresponding
@@ -112201,15 +112274,16 @@
112201 ** same table is autoincremented multiple times due to inserts within
112202 ** triggers. A new AutoincInfo structure is created if this is the
112203 ** first use of table pTab. On 2nd and subsequent uses, the original
112204 ** AutoincInfo structure is used.
112205 **
112206 ** Three memory locations are allocated:
112207 **
112208 ** (1) Register to hold the name of the pTab table.
112209 ** (2) Register to hold the maximum ROWID of pTab.
112210 ** (3) Register to hold the rowid in sqlite_sequence of pTab
 
112211 **
112212 ** The 2nd register is the one that is returned. That is all the
112213 ** insert routine needs to know about.
112214 */
112215 static int autoIncBegin(
@@ -112233,11 +112307,11 @@
112233 pToplevel->pAinc = pInfo;
112234 pInfo->pTab = pTab;
112235 pInfo->iDb = iDb;
112236 pToplevel->nMem++; /* Register to hold name of table */
112237 pInfo->regCtr = ++pToplevel->nMem; /* Max rowid register */
112238 pToplevel->nMem++; /* Rowid in sqlite_sequence */
112239 }
112240 memId = pInfo->regCtr;
112241 }
112242 return memId;
112243 }
@@ -112261,19 +112335,21 @@
112261 assert( v ); /* We failed long ago if this is not so */
112262 for(p = pParse->pAinc; p; p = p->pNext){
112263 static const int iLn = VDBE_OFFSET_LINENO(2);
112264 static const VdbeOpList autoInc[] = {
112265 /* 0 */ {OP_Null, 0, 0, 0},
112266 /* 1 */ {OP_Rewind, 0, 9, 0},
112267 /* 2 */ {OP_Column, 0, 0, 0},
112268 /* 3 */ {OP_Ne, 0, 7, 0},
112269 /* 4 */ {OP_Rowid, 0, 0, 0},
112270 /* 5 */ {OP_Column, 0, 1, 0},
112271 /* 6 */ {OP_Goto, 0, 9, 0},
112272 /* 7 */ {OP_Next, 0, 2, 0},
112273 /* 8 */ {OP_Integer, 0, 0, 0},
112274 /* 9 */ {OP_Close, 0, 0, 0}
 
 
112275 };
112276 VdbeOp *aOp;
112277 pDb = &db->aDb[p->iDb];
112278 memId = p->regCtr;
112279 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
@@ -112280,18 +112356,21 @@
112280 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
112281 sqlite3VdbeLoadString(v, memId-1, p->pTab->zName);
112282 aOp = sqlite3VdbeAddOpList(v, ArraySize(autoInc), autoInc, iLn);
112283 if( aOp==0 ) break;
112284 aOp[0].p2 = memId;
112285 aOp[0].p3 = memId+1;
112286 aOp[2].p3 = memId;
112287 aOp[3].p1 = memId-1;
112288 aOp[3].p3 = memId;
112289 aOp[3].p5 = SQLITE_JUMPIFNULL;
112290 aOp[4].p2 = memId+1;
112291 aOp[5].p3 = memId;
112292 aOp[8].p2 = memId;
 
 
 
112293 }
112294 }
112295
112296 /*
112297 ** Update the maximum rowid for an autoincrement calculation.
@@ -112334,10 +112413,12 @@
112334 int iRec;
112335 int memId = p->regCtr;
112336
112337 iRec = sqlite3GetTempReg(pParse);
112338 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
 
 
112339 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
112340 aOp = sqlite3VdbeAddOpList(v, ArraySize(autoIncEnd), autoIncEnd, iLn);
112341 if( aOp==0 ) break;
112342 aOp[0].p1 = memId+1;
112343 aOp[1].p2 = memId+1;
@@ -119861,12 +119942,11 @@
119861 */
119862 #if SELECTTRACE_ENABLED
119863 /***/ int sqlite3SelectTrace = 0;
119864 # define SELECTTRACE(K,P,S,X) \
119865 if(sqlite3SelectTrace&(K)) \
119866 sqlite3DebugPrintf("%*s%s.%p: ",(P)->nSelectIndent*2-2,"",\
119867 (S)->zSelName,(S)),\
119868 sqlite3DebugPrintf X
119869 #else
119870 # define SELECTTRACE(K,P,S,X)
119871 #endif
119872
@@ -120222,10 +120302,33 @@
120222 }
120223 setJoinExpr(p->pLeft, iTable);
120224 p = p->pRight;
120225 }
120226 }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
120227
120228 /*
120229 ** This routine processes the join information for a SELECT statement.
120230 ** ON and USING clauses are converted into extra terms of the WHERE clause.
120231 ** NATURAL joins also create extra WHERE clause terms.
@@ -123675,16 +123778,25 @@
123675 ** (2) The inner query is the recursive part of a common table expression.
123676 **
123677 ** (3) The inner query has a LIMIT clause (since the changes to the WHERE
123678 ** close would change the meaning of the LIMIT).
123679 **
123680 ** (4) The inner query is the right operand of a LEFT JOIN. (The caller
123681 ** enforces this restriction since this routine does not have enough
123682 ** information to know.)
123683 **
123684 ** (5) The WHERE clause expression originates in the ON or USING clause
123685 ** of a LEFT JOIN.
 
 
 
 
 
 
 
 
 
 
123686 **
123687 ** Return 0 if no changes are made and non-zero if one or more WHERE clause
123688 ** terms are duplicated into the subquery.
123689 */
123690 static int pushDownWhereTerms(
@@ -123716,16 +123828,19 @@
123716 }
123717 while( pWhere->op==TK_AND ){
123718 nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, iCursor);
123719 pWhere = pWhere->pLeft;
123720 }
123721 if( ExprHasProperty(pWhere,EP_FromJoin) ) return 0; /* restriction (5) */
 
 
123722 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
123723 nChng++;
123724 while( pSubq ){
123725 SubstContext x;
123726 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
 
123727 x.pParse = pParse;
123728 x.iTable = iCursor;
123729 x.iNewTable = iCursor;
123730 x.isLeftJoin = 0;
123731 x.pEList = pSubq->pEList;
@@ -124753,18 +124868,10 @@
124753 }
124754 #else
124755 # define explainSimpleCount(a,b,c)
124756 #endif
124757
124758 /*
124759 ** Context object for havingToWhereExprCb().
124760 */
124761 struct HavingToWhereCtx {
124762 Expr **ppWhere;
124763 ExprList *pGroupBy;
124764 };
124765
124766 /*
124767 ** sqlite3WalkExpr() callback used by havingToWhere().
124768 **
124769 ** If the node passed to the callback is a TK_AND node, return
124770 ** WRC_Continue to tell sqlite3WalkExpr() to iterate through child nodes.
@@ -124774,19 +124881,20 @@
124774 ** clause. If so, add it to the WHERE clause and replace the sub-expression
124775 ** within the HAVING expression with a constant "1".
124776 */
124777 static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){
124778 if( pExpr->op!=TK_AND ){
124779 struct HavingToWhereCtx *p = pWalker->u.pHavingCtx;
124780 if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, p->pGroupBy) ){
124781 sqlite3 *db = pWalker->pParse->db;
124782 Expr *pNew = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[1], 0);
124783 if( pNew ){
124784 Expr *pWhere = *(p->ppWhere);
124785 SWAP(Expr, *pNew, *pExpr);
124786 pNew = sqlite3ExprAnd(db, pWhere, pNew);
124787 *(p->ppWhere) = pNew;
 
124788 }
124789 }
124790 return WRC_Prune;
124791 }
124792 return WRC_Continue;
@@ -124805,27 +124913,23 @@
124805 **
124806 ** A term of the HAVING expression is eligible for transfer if it consists
124807 ** entirely of constants and expressions that are also GROUP BY terms that
124808 ** use the "BINARY" collation sequence.
124809 */
124810 static void havingToWhere(
124811 Parse *pParse,
124812 ExprList *pGroupBy,
124813 Expr *pHaving,
124814 Expr **ppWhere
124815 ){
124816 struct HavingToWhereCtx sCtx;
124817 Walker sWalker;
124818
124819 sCtx.ppWhere = ppWhere;
124820 sCtx.pGroupBy = pGroupBy;
124821
124822 memset(&sWalker, 0, sizeof(sWalker));
124823 sWalker.pParse = pParse;
124824 sWalker.xExprCallback = havingToWhereExprCb;
124825 sWalker.u.pHavingCtx = &sCtx;
124826 sqlite3WalkExpr(&sWalker, pHaving);
 
 
 
 
 
 
124827 }
124828
124829 /*
124830 ** Check to see if the pThis entry of pTabList is a self-join of a prior view.
124831 ** If it is, then return the SrcList_item for the prior view. If it is not,
@@ -124982,11 +125086,10 @@
124982 return 1;
124983 }
124984 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
124985 memset(&sAggInfo, 0, sizeof(sAggInfo));
124986 #if SELECTTRACE_ENABLED
124987 pParse->nSelectIndent++;
124988 SELECTTRACE(1,pParse,p, ("begin processing:\n"));
124989 if( sqlite3SelectTrace & 0x100 ){
124990 sqlite3TreeViewSelect(0, p, 0);
124991 }
124992 #endif
@@ -125028,17 +125131,33 @@
125028 if( v==0 ) goto select_end;
125029 if( pDest->eDest==SRT_Output ){
125030 generateColumnNames(pParse, p);
125031 }
125032
125033 /* Try to flatten subqueries in the FROM clause up into the main query
 
125034 */
125035 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
125036 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
125037 struct SrcList_item *pItem = &pTabList->a[i];
125038 Select *pSub = pItem->pSelect;
125039 Table *pTab = pItem->pTab;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125040 if( pSub==0 ) continue;
125041
125042 /* Catch mismatch in the declared columns of a view and the number of
125043 ** columns in the SELECT on the RHS */
125044 if( pTab->nCol!=pSub->pEList->nExpr ){
@@ -125103,11 +125222,10 @@
125103 if( p->pPrior ){
125104 rc = multiSelect(pParse, p, pDest);
125105 explainSetInteger(pParse->iSelectId, iRestoreSelectId);
125106 #if SELECTTRACE_ENABLED
125107 SELECTTRACE(1,pParse,p,("end compound-select processing\n"));
125108 pParse->nSelectIndent--;
125109 #endif
125110 return rc;
125111 }
125112 #endif
125113
@@ -125176,19 +125294,21 @@
125176 pParse->nHeight += sqlite3SelectExprHeight(p);
125177
125178 /* Make copies of constant WHERE-clause terms in the outer query down
125179 ** inside the subquery. This can help the subquery to run more efficiently.
125180 */
125181 if( (pItem->fg.jointype & JT_OUTER)==0
125182 && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor)
125183 ){
125184 #if SELECTTRACE_ENABLED
125185 if( sqlite3SelectTrace & 0x100 ){
125186 SELECTTRACE(0x100,pParse,p,("After WHERE-clause push-down:\n"));
125187 sqlite3TreeViewSelect(0, p, 0);
125188 }
125189 #endif
 
 
125190 }
125191
125192 zSavedAuthContext = pParse->zAuthContext;
125193 pParse->zAuthContext = pItem->zName;
125194
@@ -125387,10 +125507,11 @@
125387 u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0);
125388 assert( WHERE_USE_LIMIT==SF_FixedLimit );
125389 wctrlFlags |= p->selFlags & SF_FixedLimit;
125390
125391 /* Begin the database scan. */
 
125392 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy,
125393 p->pEList, wctrlFlags, p->nSelectRow);
125394 if( pWInfo==0 ) goto select_end;
125395 if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
125396 p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
@@ -125488,11 +125609,13 @@
125488 sqlite3ExprAnalyzeAggList(&sNC, pEList);
125489 sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
125490 if( pHaving ){
125491 if( pGroupBy ){
125492 assert( pWhere==p->pWhere );
125493 havingToWhere(pParse, pGroupBy, pHaving, &p->pWhere);
 
 
125494 pWhere = p->pWhere;
125495 }
125496 sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
125497 }
125498 sAggInfo.nAccumulator = sAggInfo.nColumn;
@@ -125575,10 +125698,11 @@
125575 ** This might involve two separate loops with an OP_Sort in between, or
125576 ** it might be a single loop that uses an index to extract information
125577 ** in the right order to begin with.
125578 */
125579 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
 
125580 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, 0,
125581 WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0), 0
125582 );
125583 if( pWInfo==0 ) goto select_end;
125584 if( sqlite3WhereIsOrdered(pWInfo)==pGroupBy->nExpr ){
@@ -125830,10 +125954,11 @@
125830 ** be an appropriate ORDER BY expression for the optimization.
125831 */
125832 assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
125833 assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
125834
 
125835 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
125836 0, minMaxFlag, 0);
125837 if( pWInfo==0 ){
125838 goto select_end;
125839 }
@@ -125885,11 +126010,10 @@
125885 sqlite3ExprListDelete(db, pMinMaxOrderBy);
125886 sqlite3DbFree(db, sAggInfo.aCol);
125887 sqlite3DbFree(db, sAggInfo.aFunc);
125888 #if SELECTTRACE_ENABLED
125889 SELECTTRACE(1,pParse,p,("end processing\n"));
125890 pParse->nSelectIndent--;
125891 #endif
125892 return rc;
125893 }
125894
125895 /************** End of select.c **********************************************/
@@ -142086,12 +142210,11 @@
142086 ** is an integer that is incremented with each SELECT statement seen.
142087 */
142088 if( yymsp[-8].minor.yy387!=0 ){
142089 const char *z = s.z+6;
142090 int i;
142091 sqlite3_snprintf(sizeof(yymsp[-8].minor.yy387->zSelName), yymsp[-8].minor.yy387->zSelName, "#%d",
142092 ++pParse->nSelect);
142093 while( z[0]==' ' ) z++;
142094 if( z[0]=='/' && z[1]=='*' ){
142095 z += 2;
142096 while( z[0]==' ' ) z++;
142097 for(i=0; sqlite3Isalnum(z[i]); i++){}
@@ -175718,11 +175841,11 @@
175718 int bKey = sqlite3_column_int(pXInfo, 5);
175719 if( bKey ){
175720 int iCid = sqlite3_column_int(pXInfo, 1);
175721 int bDesc = sqlite3_column_int(pXInfo, 3);
175722 const char *zCollate = (const char*)sqlite3_column_text(pXInfo, 4);
175723 zCols = rbuMPrintf(p, "%z%sc%d %s COLLATE %s", zCols, zComma,
175724 iCid, pIter->azTblType[iCid], zCollate
175725 );
175726 zPk = rbuMPrintf(p, "%z%sc%d%s", zPk, zComma, iCid, bDesc?" DESC":"");
175727 zComma = ", ";
175728 }
@@ -175779,11 +175902,11 @@
175779 if( pIter->eType==RBU_PK_IPK && pIter->abTblPk[iCol] ){
175780 /* If the target table column is an "INTEGER PRIMARY KEY", add
175781 ** "PRIMARY KEY" to the imposter table column declaration. */
175782 zPk = "PRIMARY KEY ";
175783 }
175784 zSql = rbuMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %s%s",
175785 zSql, zComma, zCol, pIter->azTblType[iCol], zPk, zColl,
175786 (pIter->abNotNull[iCol] ? " NOT NULL" : "")
175787 );
175788 zComma = ", ";
175789 }
@@ -204574,11 +204697,11 @@
204574 int nArg, /* Number of args */
204575 sqlite3_value **apUnused /* Function arguments */
204576 ){
204577 assert( nArg==0 );
204578 UNUSED_PARAM2(nArg, apUnused);
204579 sqlite3_result_text(pCtx, "fts5: 2018-03-16 20:23:01 d75e67654aa9620b9617786553a002f54e8c6dcbbcc58948a06bd98a0916d75a", -1, SQLITE_TRANSIENT);
204580 }
204581
204582 static int fts5Init(sqlite3 *db){
204583 static const sqlite3_module fts5Mod = {
204584 /* iVersion */ 2,
@@ -208844,12 +208967,12 @@
208844 }
208845 #endif /* SQLITE_CORE */
208846 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
208847
208848 /************** End of stmt.c ************************************************/
208849 #if __LINE__!=208849
208850 #undef SQLITE_SOURCE_ID
208851 #define SQLITE_SOURCE_ID "2018-03-17 16:26:36 442e816b5fed80ebeb58c7c0ab9c2ef999bf488519bf5da670e9cec47703alt2"
208852 #endif
208853 /* Return the source-id for this library */
208854 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
208855 /************************** End of sqlite3.c ******************************/
208856
--- src/sqlite3.c
+++ src/sqlite3.c
@@ -211,11 +211,11 @@
211 #endif
212 #if SQLITE_ENABLE_BATCH_ATOMIC_WRITE
213 "ENABLE_BATCH_ATOMIC_WRITE",
214 #endif
215 #if SQLITE_ENABLE_CEROD
216 "ENABLE_CEROD=" CTIMEOPT_VAL(SQLITE_ENABLE_CEROD),
217 #endif
218 #if SQLITE_ENABLE_COLUMN_METADATA
219 "ENABLE_COLUMN_METADATA",
220 #endif
221 #if SQLITE_ENABLE_COLUMN_USED_MASK
@@ -1147,11 +1147,11 @@
1147 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
1148 ** [sqlite_version()] and [sqlite_source_id()].
1149 */
1150 #define SQLITE_VERSION "3.23.0"
1151 #define SQLITE_VERSION_NUMBER 3023000
1152 #define SQLITE_SOURCE_ID "2018-03-22 17:13:44 eb4f452e354065d610ff57a6a9312ad119b6b0cc467f9dff105f0718bc27ef01"
1153
1154 /*
1155 ** CAPI3REF: Run-Time Library Version Numbers
1156 ** KEYWORDS: sqlite3_version sqlite3_sourceid
1157 **
@@ -3076,31 +3076,40 @@
3076 ** <dd> Usually, when a database in wal mode is closed or detached from a
3077 ** database handle, SQLite checks if this will mean that there are now no
3078 ** connections at all to the database. If so, it performs a checkpoint
3079 ** operation before closing the connection. This option may be used to
3080 ** override this behaviour. The first parameter passed to this operation
3081 ** is an integer - positive to disable checkpoints-on-close, or zero (the
3082 ** default) to enable them, and negative to leave the setting unchanged.
3083 ** The second parameter is a pointer to an integer
3084 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
3085 ** have been disabled - 0 if they are not disabled, 1 if they are.
3086 ** </dd>
3087 **
3088 ** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
3089 ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
3090 ** the [query planner stability guarantee] (QPSG). When the QPSG is active,
3091 ** a single SQL query statement will always use the same algorithm regardless
3092 ** of values of [bound parameters].)^ The QPSG disables some query optimizations
3093 ** that look at the values of bound parameters, which can make some queries
3094 ** slower. But the QPSG has the advantage of more predictable behavior. With
3095 ** the QPSG active, SQLite will always use the same query plan in the field as
3096 ** was used during testing in the lab.
3097 ** The first argument to this setting is an integer which is 0 to disable
3098 ** the QPSG, positive to enable QPSG, or negative to leave the setting
3099 ** unchanged. The second parameter is a pointer to an integer into which
3100 ** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
3101 ** following this call.
3102 ** </dd>
3103 **
3104 ** <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
3105 ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
3106 ** include output for any operations performed by trigger programs. This
3107 ** option is used to set or clear (the default) a flag that governs this
3108 ** behavior. The first parameter passed to this operation is an integer -
3109 ** positive to enable output for trigger programs, or zero to disable it,
3110 ** or negative to leave the setting unchanged.
3111 ** The second parameter is a pointer to an integer into which is written
3112 ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
3113 ** it is not disabled, 1 if it is.
3114 ** </dd>
3115 ** </dl>
@@ -15519,10 +15528,12 @@
15528 #define SQLITE_OmitNoopJoin 0x0100 /* Omit unused tables in joins */
15529 #define SQLITE_CountOfView 0x0200 /* The count-of-view optimization */
15530 #define SQLITE_CursorHints 0x0400 /* Add OP_CursorHint opcodes */
15531 #define SQLITE_Stat34 0x0800 /* Use STAT3 or STAT4 data */
15532 /* TH3 expects the Stat34 ^^^^^^ value to be 0x0800. Don't change it */
15533 #define SQLITE_PushDown 0x1000 /* The push-down optimization */
15534 #define SQLITE_SimplifyJoin 0x2000 /* Convert LEFT JOIN to JOIN */
15535 #define SQLITE_AllOpts 0xffff /* All optimizations */
15536
15537 /*
15538 ** Macros for testing whether or not optimizations are enabled or disabled.
15539 */
@@ -16980,11 +16991,10 @@
16991 int regRowid; /* Register holding rowid of CREATE TABLE entry */
16992 int regRoot; /* Register holding root page number for new objects */
16993 int nMaxArg; /* Max args passed to user function by sub-program */
16994 #if SELECTTRACE_ENABLED
16995 int nSelect; /* Number of SELECT statements seen */
 
16996 #endif
16997 #ifndef SQLITE_OMIT_SHARED_CACHE
16998 int nTableLock; /* Number of locks in aTableLock */
16999 TableLock *aTableLock; /* Required table locks for shared-cache mode */
17000 #endif
@@ -17344,13 +17354,13 @@
17354 SrcList *pSrcList; /* FROM clause */
17355 struct SrcCount *pSrcCount; /* Counting column references */
17356 struct CCurHint *pCCurHint; /* Used by codeCursorHint() */
17357 int *aiCol; /* array of column indexes */
17358 struct IdxCover *pIdxCover; /* Check for index coverage */
17359 struct IdxExprTrans *pIdxTrans; /* Convert idxed expr to column */
17360 ExprList *pGroupBy; /* GROUP BY clause */
17361 Select *pSelect; /* HAVING to WHERE clause ctx */
17362 } u;
17363 };
17364
17365 /* Forward declarations */
17366 SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*);
@@ -17810,10 +17820,11 @@
17820 SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*);
17821 SQLITE_PRIVATE int sqlite3ExprCompare(Parse*,Expr*, Expr*, int);
17822 SQLITE_PRIVATE int sqlite3ExprCompareSkip(Expr*, Expr*, int);
17823 SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*, int);
17824 SQLITE_PRIVATE int sqlite3ExprImpliesExpr(Parse*,Expr*, Expr*, int);
17825 SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr*,int);
17826 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*);
17827 SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*);
17828 SQLITE_PRIVATE int sqlite3ExprCoveredByIndex(Expr*, int iCur, Index *pIdx);
17829 SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*);
17830 SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*);
@@ -27316,15 +27327,25 @@
27327 sqlite3TreeViewWith(pView, p->pWith, 1);
27328 cnt = 1;
27329 sqlite3TreeViewPush(pView, 1);
27330 }
27331 do{
27332 #if SELECTTRACE_ENABLED
27333 sqlite3TreeViewLine(pView,
27334 "SELECT%s%s (%s/%p) selFlags=0x%x nSelectRow=%d",
27335 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
27336 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""),
27337 p->zSelName, p, p->selFlags,
27338 (int)p->nSelectRow
27339 );
27340 #else
27341 sqlite3TreeViewLine(pView, "SELECT%s%s (0x%p) selFlags=0x%x nSelectRow=%d",
27342 ((p->selFlags & SF_Distinct) ? " DISTINCT" : ""),
27343 ((p->selFlags & SF_Aggregate) ? " agg_flag" : ""), p, p->selFlags,
27344 (int)p->nSelectRow
27345 );
27346 #endif
27347 if( cnt++ ) sqlite3TreeViewPop(pView);
27348 if( p->pPrior ){
27349 n = 1000;
27350 }else{
27351 n = 0;
@@ -98687,10 +98708,62 @@
98708 testcase( pX!=pE1->pLeft );
98709 if( sqlite3ExprCompare(pParse, pX, pE2->pLeft, iTab)==0 ) return 1;
98710 }
98711 return 0;
98712 }
98713
98714 /*
98715 ** This is the Expr node callback for sqlite3ExprImpliesNotNullRow().
98716 ** If the expression node requires that the table at pWalker->iCur
98717 ** have a non-NULL column, then set pWalker->eCode to 1 and abort.
98718 */
98719 static int impliesNotNullRow(Walker *pWalker, Expr *pExpr){
98720 if( ExprHasProperty(pExpr, EP_FromJoin) ) return WRC_Prune;
98721 switch( pExpr->op ){
98722 case TK_ISNULL:
98723 case TK_IS:
98724 case TK_OR:
98725 case TK_FUNCTION:
98726 case TK_AGG_FUNCTION:
98727 return WRC_Prune;
98728 case TK_COLUMN:
98729 case TK_AGG_COLUMN:
98730 if( pWalker->u.iCur==pExpr->iTable ){
98731 pWalker->eCode = 1;
98732 return WRC_Abort;
98733 }
98734 return WRC_Prune;
98735 default:
98736 return WRC_Continue;
98737 }
98738 }
98739
98740 /*
98741 ** Return true (non-zero) if expression p can only be true if at least
98742 ** one column of table iTab is non-null. In other words, return true
98743 ** if expression p will always be NULL or false if every column of iTab
98744 ** is NULL.
98745 **
98746 ** Terms of p that are marked with EP_FromJoin (and hence that come from
98747 ** the ON or USING clauses of LEFT JOINS) are excluded from the analysis.
98748 **
98749 ** This routine is used to check if a LEFT JOIN can be converted into
98750 ** an ordinary JOIN. The p argument is the WHERE clause. If the WHERE
98751 ** clause requires that some column of the right table of the LEFT JOIN
98752 ** be non-NULL, then the LEFT JOIN can be safely converted into an
98753 ** ordinary join.
98754 */
98755 SQLITE_PRIVATE int sqlite3ExprImpliesNonNullRow(Expr *p, int iTab){
98756 Walker w;
98757 w.xExprCallback = impliesNotNullRow;
98758 w.xSelectCallback = 0;
98759 w.xSelectCallback2 = 0;
98760 w.eCode = 0;
98761 w.u.iCur = iTab;
98762 sqlite3WalkExpr(&w, p);
98763 return w.eCode;
98764 }
98765
98766 /*
98767 ** An instance of the following structure is used by the tree walker
98768 ** to determine if an expression can be evaluated by reference to the
98769 ** index only, without having to do a search for the corresponding
@@ -112201,15 +112274,16 @@
112274 ** same table is autoincremented multiple times due to inserts within
112275 ** triggers. A new AutoincInfo structure is created if this is the
112276 ** first use of table pTab. On 2nd and subsequent uses, the original
112277 ** AutoincInfo structure is used.
112278 **
112279 ** Four consecutive registers are allocated:
112280 **
112281 ** (1) The name of the pTab table.
112282 ** (2) The maximum ROWID of pTab.
112283 ** (3) The rowid in sqlite_sequence of pTab
112284 ** (4) The original value of the max ROWID in pTab, or NULL if none
112285 **
112286 ** The 2nd register is the one that is returned. That is all the
112287 ** insert routine needs to know about.
112288 */
112289 static int autoIncBegin(
@@ -112233,11 +112307,11 @@
112307 pToplevel->pAinc = pInfo;
112308 pInfo->pTab = pTab;
112309 pInfo->iDb = iDb;
112310 pToplevel->nMem++; /* Register to hold name of table */
112311 pInfo->regCtr = ++pToplevel->nMem; /* Max rowid register */
112312 pToplevel->nMem +=2; /* Rowid in sqlite_sequence + orig max val */
112313 }
112314 memId = pInfo->regCtr;
112315 }
112316 return memId;
112317 }
@@ -112261,19 +112335,21 @@
112335 assert( v ); /* We failed long ago if this is not so */
112336 for(p = pParse->pAinc; p; p = p->pNext){
112337 static const int iLn = VDBE_OFFSET_LINENO(2);
112338 static const VdbeOpList autoInc[] = {
112339 /* 0 */ {OP_Null, 0, 0, 0},
112340 /* 1 */ {OP_Rewind, 0, 10, 0},
112341 /* 2 */ {OP_Column, 0, 0, 0},
112342 /* 3 */ {OP_Ne, 0, 9, 0},
112343 /* 4 */ {OP_Rowid, 0, 0, 0},
112344 /* 5 */ {OP_Column, 0, 1, 0},
112345 /* 6 */ {OP_AddImm, 0, 0, 0},
112346 /* 7 */ {OP_Copy, 0, 0, 0},
112347 /* 8 */ {OP_Goto, 0, 11, 0},
112348 /* 9 */ {OP_Next, 0, 2, 0},
112349 /* 10 */ {OP_Integer, 0, 0, 0},
112350 /* 11 */ {OP_Close, 0, 0, 0}
112351 };
112352 VdbeOp *aOp;
112353 pDb = &db->aDb[p->iDb];
112354 memId = p->regCtr;
112355 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
@@ -112280,18 +112356,21 @@
112356 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenRead);
112357 sqlite3VdbeLoadString(v, memId-1, p->pTab->zName);
112358 aOp = sqlite3VdbeAddOpList(v, ArraySize(autoInc), autoInc, iLn);
112359 if( aOp==0 ) break;
112360 aOp[0].p2 = memId;
112361 aOp[0].p3 = memId+2;
112362 aOp[2].p3 = memId;
112363 aOp[3].p1 = memId-1;
112364 aOp[3].p3 = memId;
112365 aOp[3].p5 = SQLITE_JUMPIFNULL;
112366 aOp[4].p2 = memId+1;
112367 aOp[5].p3 = memId;
112368 aOp[6].p1 = memId;
112369 aOp[7].p2 = memId+2;
112370 aOp[7].p1 = memId;
112371 aOp[10].p2 = memId;
112372 }
112373 }
112374
112375 /*
112376 ** Update the maximum rowid for an autoincrement calculation.
@@ -112334,10 +112413,12 @@
112413 int iRec;
112414 int memId = p->regCtr;
112415
112416 iRec = sqlite3GetTempReg(pParse);
112417 assert( sqlite3SchemaMutexHeld(db, 0, pDb->pSchema) );
112418 sqlite3VdbeAddOp3(v, OP_Le, memId+2, sqlite3VdbeCurrentAddr(v)+7, memId);
112419 VdbeCoverage(v);
112420 sqlite3OpenTable(pParse, 0, p->iDb, pDb->pSchema->pSeqTab, OP_OpenWrite);
112421 aOp = sqlite3VdbeAddOpList(v, ArraySize(autoIncEnd), autoIncEnd, iLn);
112422 if( aOp==0 ) break;
112423 aOp[0].p1 = memId+1;
112424 aOp[1].p2 = memId+1;
@@ -119861,12 +119942,11 @@
119942 */
119943 #if SELECTTRACE_ENABLED
119944 /***/ int sqlite3SelectTrace = 0;
119945 # define SELECTTRACE(K,P,S,X) \
119946 if(sqlite3SelectTrace&(K)) \
119947 sqlite3DebugPrintf("%s/%p: ",(S)->zSelName,(S)),\
 
119948 sqlite3DebugPrintf X
119949 #else
119950 # define SELECTTRACE(K,P,S,X)
119951 #endif
119952
@@ -120222,10 +120302,33 @@
120302 }
120303 setJoinExpr(p->pLeft, iTable);
120304 p = p->pRight;
120305 }
120306 }
120307
120308 /* Undo the work of setJoinExpr(). In the expression tree p, convert every
120309 ** term that is marked with EP_FromJoin and iRightJoinTable==iTable into
120310 ** an ordinary term that omits the EP_FromJoin mark.
120311 **
120312 ** This happens when a LEFT JOIN is simplified into an ordinary JOIN.
120313 */
120314 static void unsetJoinExpr(Expr *p, int iTable){
120315 while( p ){
120316 if( ExprHasProperty(p, EP_FromJoin)
120317 && (iTable<0 || p->iRightJoinTable==iTable) ){
120318 ExprClearProperty(p, EP_FromJoin);
120319 }
120320 if( p->op==TK_FUNCTION && p->x.pList ){
120321 int i;
120322 for(i=0; i<p->x.pList->nExpr; i++){
120323 unsetJoinExpr(p->x.pList->a[i].pExpr, iTable);
120324 }
120325 }
120326 unsetJoinExpr(p->pLeft, iTable);
120327 p = p->pRight;
120328 }
120329 }
120330
120331 /*
120332 ** This routine processes the join information for a SELECT statement.
120333 ** ON and USING clauses are converted into extra terms of the WHERE clause.
120334 ** NATURAL joins also create extra WHERE clause terms.
@@ -123675,16 +123778,25 @@
123778 ** (2) The inner query is the recursive part of a common table expression.
123779 **
123780 ** (3) The inner query has a LIMIT clause (since the changes to the WHERE
123781 ** close would change the meaning of the LIMIT).
123782 **
123783 ** (4) (** This restriction was removed on 2018-03-21. It used to read:
123784 ** The inner query is the right operand of a LEFT JOIN. **)
 
123785 **
123786 ** (5) The WHERE clause expression originates in the ON or USING clause
123787 ** of a LEFT JOIN where iCursor is not the right-hand table of that
123788 ** left join. An example:
123789 **
123790 ** SELECT *
123791 ** FROM (SELECT 1 AS a1 UNION ALL SELECT 2) AS aa
123792 ** JOIN (SELECT 1 AS b2 UNION ALL SELECT 2) AS bb ON (a1=b2)
123793 ** LEFT JOIN (SELECT 8 AS c3 UNION ALL SELECT 9) AS cc ON (b2=2);
123794 **
123795 ** The correct answer is three rows: (1,1,NULL),(2,2,8),(2,2,9).
123796 ** But if the (b2=2) term were to be pushed down into the bb subquery,
123797 ** then the (1,1,NULL) row would be suppressed.
123798 **
123799 ** Return 0 if no changes are made and non-zero if one or more WHERE clause
123800 ** terms are duplicated into the subquery.
123801 */
123802 static int pushDownWhereTerms(
@@ -123716,16 +123828,19 @@
123828 }
123829 while( pWhere->op==TK_AND ){
123830 nChng += pushDownWhereTerms(pParse, pSubq, pWhere->pRight, iCursor);
123831 pWhere = pWhere->pLeft;
123832 }
123833 if( ExprHasProperty(pWhere,EP_FromJoin) && pWhere->iRightJoinTable!=iCursor ){
123834 return 0; /* restriction (5) */
123835 }
123836 if( sqlite3ExprIsTableConstant(pWhere, iCursor) ){
123837 nChng++;
123838 while( pSubq ){
123839 SubstContext x;
123840 pNew = sqlite3ExprDup(pParse->db, pWhere, 0);
123841 unsetJoinExpr(pNew, -1);
123842 x.pParse = pParse;
123843 x.iTable = iCursor;
123844 x.iNewTable = iCursor;
123845 x.isLeftJoin = 0;
123846 x.pEList = pSubq->pEList;
@@ -124753,18 +124868,10 @@
124868 }
124869 #else
124870 # define explainSimpleCount(a,b,c)
124871 #endif
124872
 
 
 
 
 
 
 
 
124873 /*
124874 ** sqlite3WalkExpr() callback used by havingToWhere().
124875 **
124876 ** If the node passed to the callback is a TK_AND node, return
124877 ** WRC_Continue to tell sqlite3WalkExpr() to iterate through child nodes.
@@ -124774,19 +124881,20 @@
124881 ** clause. If so, add it to the WHERE clause and replace the sub-expression
124882 ** within the HAVING expression with a constant "1".
124883 */
124884 static int havingToWhereExprCb(Walker *pWalker, Expr *pExpr){
124885 if( pExpr->op!=TK_AND ){
124886 Select *pS = pWalker->u.pSelect;
124887 if( sqlite3ExprIsConstantOrGroupBy(pWalker->pParse, pExpr, pS->pGroupBy) ){
124888 sqlite3 *db = pWalker->pParse->db;
124889 Expr *pNew = sqlite3ExprAlloc(db, TK_INTEGER, &sqlite3IntTokens[1], 0);
124890 if( pNew ){
124891 Expr *pWhere = pS->pWhere;
124892 SWAP(Expr, *pNew, *pExpr);
124893 pNew = sqlite3ExprAnd(db, pWhere, pNew);
124894 pS->pWhere = pNew;
124895 pWalker->eCode = 1;
124896 }
124897 }
124898 return WRC_Prune;
124899 }
124900 return WRC_Continue;
@@ -124805,27 +124913,23 @@
124913 **
124914 ** A term of the HAVING expression is eligible for transfer if it consists
124915 ** entirely of constants and expressions that are also GROUP BY terms that
124916 ** use the "BINARY" collation sequence.
124917 */
124918 static void havingToWhere(Parse *pParse, Select *p){
 
 
 
 
 
 
124919 Walker sWalker;
 
 
 
 
124920 memset(&sWalker, 0, sizeof(sWalker));
124921 sWalker.pParse = pParse;
124922 sWalker.xExprCallback = havingToWhereExprCb;
124923 sWalker.u.pSelect = p;
124924 sqlite3WalkExpr(&sWalker, p->pHaving);
124925 #if SELECTTRACE_ENABLED
124926 if( sWalker.eCode && (sqlite3SelectTrace & 0x100)!=0 ){
124927 SELECTTRACE(0x100,pParse,p,("Move HAVING terms into WHERE:\n"));
124928 sqlite3TreeViewSelect(0, p, 0);
124929 }
124930 #endif
124931 }
124932
124933 /*
124934 ** Check to see if the pThis entry of pTabList is a self-join of a prior view.
124935 ** If it is, then return the SrcList_item for the prior view. If it is not,
@@ -124982,11 +125086,10 @@
125086 return 1;
125087 }
125088 if( sqlite3AuthCheck(pParse, SQLITE_SELECT, 0, 0, 0) ) return 1;
125089 memset(&sAggInfo, 0, sizeof(sAggInfo));
125090 #if SELECTTRACE_ENABLED
 
125091 SELECTTRACE(1,pParse,p, ("begin processing:\n"));
125092 if( sqlite3SelectTrace & 0x100 ){
125093 sqlite3TreeViewSelect(0, p, 0);
125094 }
125095 #endif
@@ -125028,17 +125131,33 @@
125131 if( v==0 ) goto select_end;
125132 if( pDest->eDest==SRT_Output ){
125133 generateColumnNames(pParse, p);
125134 }
125135
125136 /* Try to various optimizations (flattening subqueries, and strength
125137 ** reduction of join operators) in the FROM clause up into the main query
125138 */
125139 #if !defined(SQLITE_OMIT_SUBQUERY) || !defined(SQLITE_OMIT_VIEW)
125140 for(i=0; !p->pPrior && i<pTabList->nSrc; i++){
125141 struct SrcList_item *pItem = &pTabList->a[i];
125142 Select *pSub = pItem->pSelect;
125143 Table *pTab = pItem->pTab;
125144
125145 /* Convert LEFT JOIN into JOIN if there are terms of the right table
125146 ** of the LEFT JOIN used in the WHERE clause.
125147 */
125148 if( (pItem->fg.jointype & JT_LEFT)!=0
125149 && sqlite3ExprImpliesNonNullRow(p->pWhere, pItem->iCursor)
125150 && OptimizationEnabled(db, SQLITE_SimplifyJoin)
125151 ){
125152 SELECTTRACE(0x100,pParse,p,
125153 ("LEFT-JOIN simplifies to JOIN on term %d\n",i));
125154 pItem->fg.jointype &= ~(JT_LEFT|JT_OUTER);
125155 unsetJoinExpr(p->pWhere, pItem->iCursor);
125156 }
125157
125158 /* No futher action if this term of the FROM clause is no a subquery */
125159 if( pSub==0 ) continue;
125160
125161 /* Catch mismatch in the declared columns of a view and the number of
125162 ** columns in the SELECT on the RHS */
125163 if( pTab->nCol!=pSub->pEList->nExpr ){
@@ -125103,11 +125222,10 @@
125222 if( p->pPrior ){
125223 rc = multiSelect(pParse, p, pDest);
125224 explainSetInteger(pParse->iSelectId, iRestoreSelectId);
125225 #if SELECTTRACE_ENABLED
125226 SELECTTRACE(1,pParse,p,("end compound-select processing\n"));
 
125227 #endif
125228 return rc;
125229 }
125230 #endif
125231
@@ -125176,19 +125294,21 @@
125294 pParse->nHeight += sqlite3SelectExprHeight(p);
125295
125296 /* Make copies of constant WHERE-clause terms in the outer query down
125297 ** inside the subquery. This can help the subquery to run more efficiently.
125298 */
125299 if( OptimizationEnabled(db, SQLITE_PushDown)
125300 && pushDownWhereTerms(pParse, pSub, p->pWhere, pItem->iCursor)
125301 ){
125302 #if SELECTTRACE_ENABLED
125303 if( sqlite3SelectTrace & 0x100 ){
125304 SELECTTRACE(0x100,pParse,p,("After WHERE-clause push-down:\n"));
125305 sqlite3TreeViewSelect(0, p, 0);
125306 }
125307 #endif
125308 }else{
125309 SELECTTRACE(0x100,pParse,p,("Push-down not possible\n"));
125310 }
125311
125312 zSavedAuthContext = pParse->zAuthContext;
125313 pParse->zAuthContext = pItem->zName;
125314
@@ -125387,10 +125507,11 @@
125507 u16 wctrlFlags = (sDistinct.isTnct ? WHERE_WANT_DISTINCT : 0);
125508 assert( WHERE_USE_LIMIT==SF_FixedLimit );
125509 wctrlFlags |= p->selFlags & SF_FixedLimit;
125510
125511 /* Begin the database scan. */
125512 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
125513 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, sSort.pOrderBy,
125514 p->pEList, wctrlFlags, p->nSelectRow);
125515 if( pWInfo==0 ) goto select_end;
125516 if( sqlite3WhereOutputRowCount(pWInfo) < p->nSelectRow ){
125517 p->nSelectRow = sqlite3WhereOutputRowCount(pWInfo);
@@ -125488,11 +125609,13 @@
125609 sqlite3ExprAnalyzeAggList(&sNC, pEList);
125610 sqlite3ExprAnalyzeAggList(&sNC, sSort.pOrderBy);
125611 if( pHaving ){
125612 if( pGroupBy ){
125613 assert( pWhere==p->pWhere );
125614 assert( pHaving==p->pHaving );
125615 assert( pGroupBy==p->pGroupBy );
125616 havingToWhere(pParse, p);
125617 pWhere = p->pWhere;
125618 }
125619 sqlite3ExprAnalyzeAggregates(&sNC, pHaving);
125620 }
125621 sAggInfo.nAccumulator = sAggInfo.nColumn;
@@ -125575,10 +125698,11 @@
125698 ** This might involve two separate loops with an OP_Sort in between, or
125699 ** it might be a single loop that uses an index to extract information
125700 ** in the right order to begin with.
125701 */
125702 sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset);
125703 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
125704 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pGroupBy, 0,
125705 WHERE_GROUPBY | (orderByGrp ? WHERE_SORTBYGROUP : 0), 0
125706 );
125707 if( pWInfo==0 ) goto select_end;
125708 if( sqlite3WhereIsOrdered(pWInfo)==pGroupBy->nExpr ){
@@ -125830,10 +125954,11 @@
125954 ** be an appropriate ORDER BY expression for the optimization.
125955 */
125956 assert( minMaxFlag==WHERE_ORDERBY_NORMAL || pMinMaxOrderBy!=0 );
125957 assert( pMinMaxOrderBy==0 || pMinMaxOrderBy->nExpr==1 );
125958
125959 SELECTTRACE(1,pParse,p,("WhereBegin\n"));
125960 pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, pMinMaxOrderBy,
125961 0, minMaxFlag, 0);
125962 if( pWInfo==0 ){
125963 goto select_end;
125964 }
@@ -125885,11 +126010,10 @@
126010 sqlite3ExprListDelete(db, pMinMaxOrderBy);
126011 sqlite3DbFree(db, sAggInfo.aCol);
126012 sqlite3DbFree(db, sAggInfo.aFunc);
126013 #if SELECTTRACE_ENABLED
126014 SELECTTRACE(1,pParse,p,("end processing\n"));
 
126015 #endif
126016 return rc;
126017 }
126018
126019 /************** End of select.c **********************************************/
@@ -142086,12 +142210,11 @@
142210 ** is an integer that is incremented with each SELECT statement seen.
142211 */
142212 if( yymsp[-8].minor.yy387!=0 ){
142213 const char *z = s.z+6;
142214 int i;
142215 sqlite3_snprintf(sizeof(yymsp[-8].minor.yy387->zSelName), yymsp[-8].minor.yy387->zSelName,"#%d",++pParse->nSelect);
 
142216 while( z[0]==' ' ) z++;
142217 if( z[0]=='/' && z[1]=='*' ){
142218 z += 2;
142219 while( z[0]==' ' ) z++;
142220 for(i=0; sqlite3Isalnum(z[i]); i++){}
@@ -175718,11 +175841,11 @@
175841 int bKey = sqlite3_column_int(pXInfo, 5);
175842 if( bKey ){
175843 int iCid = sqlite3_column_int(pXInfo, 1);
175844 int bDesc = sqlite3_column_int(pXInfo, 3);
175845 const char *zCollate = (const char*)sqlite3_column_text(pXInfo, 4);
175846 zCols = rbuMPrintf(p, "%z%sc%d %s COLLATE %Q", zCols, zComma,
175847 iCid, pIter->azTblType[iCid], zCollate
175848 );
175849 zPk = rbuMPrintf(p, "%z%sc%d%s", zPk, zComma, iCid, bDesc?" DESC":"");
175850 zComma = ", ";
175851 }
@@ -175779,11 +175902,11 @@
175902 if( pIter->eType==RBU_PK_IPK && pIter->abTblPk[iCol] ){
175903 /* If the target table column is an "INTEGER PRIMARY KEY", add
175904 ** "PRIMARY KEY" to the imposter table column declaration. */
175905 zPk = "PRIMARY KEY ";
175906 }
175907 zSql = rbuMPrintf(p, "%z%s\"%w\" %s %sCOLLATE %Q%s",
175908 zSql, zComma, zCol, pIter->azTblType[iCol], zPk, zColl,
175909 (pIter->abNotNull[iCol] ? " NOT NULL" : "")
175910 );
175911 zComma = ", ";
175912 }
@@ -204574,11 +204697,11 @@
204697 int nArg, /* Number of args */
204698 sqlite3_value **apUnused /* Function arguments */
204699 ){
204700 assert( nArg==0 );
204701 UNUSED_PARAM2(nArg, apUnused);
204702 sqlite3_result_text(pCtx, "fts5: 2018-03-22 17:13:44 eb4f452e354065d610ff57a6a9312ad119b6b0cc467f9dff105f0718bc27ef01", -1, SQLITE_TRANSIENT);
204703 }
204704
204705 static int fts5Init(sqlite3 *db){
204706 static const sqlite3_module fts5Mod = {
204707 /* iVersion */ 2,
@@ -208844,12 +208967,12 @@
208967 }
208968 #endif /* SQLITE_CORE */
208969 #endif /* !defined(SQLITE_CORE) || defined(SQLITE_ENABLE_STMTVTAB) */
208970
208971 /************** End of stmt.c ************************************************/
208972 #if __LINE__!=208972
208973 #undef SQLITE_SOURCE_ID
208974 #define SQLITE_SOURCE_ID "2018-03-22 17:13:44 eb4f452e354065d610ff57a6a9312ad119b6b0cc467f9dff105f0718bc27alt2"
208975 #endif
208976 /* Return the source-id for this library */
208977 SQLITE_API const char *sqlite3_sourceid(void){ return SQLITE_SOURCE_ID; }
208978 /************************** End of sqlite3.c ******************************/
208979
+13 -4
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123123
** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124124
** [sqlite_version()] and [sqlite_source_id()].
125125
*/
126126
#define SQLITE_VERSION "3.23.0"
127127
#define SQLITE_VERSION_NUMBER 3023000
128
-#define SQLITE_SOURCE_ID "2018-03-17 16:26:36 442e816b5fed80ebeb58c7c0ab9c2ef999bf488519bf5da670e9cec477034540"
128
+#define SQLITE_SOURCE_ID "2018-03-22 17:13:44 eb4f452e354065d610ff57a6a9312ad119b6b0cc467f9dff105f0718bc27ef01"
129129
130130
/*
131131
** CAPI3REF: Run-Time Library Version Numbers
132132
** KEYWORDS: sqlite3_version sqlite3_sourceid
133133
**
@@ -2052,31 +2052,40 @@
20522052
** <dd> Usually, when a database in wal mode is closed or detached from a
20532053
** database handle, SQLite checks if this will mean that there are now no
20542054
** connections at all to the database. If so, it performs a checkpoint
20552055
** operation before closing the connection. This option may be used to
20562056
** override this behaviour. The first parameter passed to this operation
2057
-** is an integer - non-zero to disable checkpoints-on-close, or zero (the
2058
-** default) to enable them. The second parameter is a pointer to an integer
2057
+** is an integer - positive to disable checkpoints-on-close, or zero (the
2058
+** default) to enable them, and negative to leave the setting unchanged.
2059
+** The second parameter is a pointer to an integer
20592060
** into which is written 0 or 1 to indicate whether checkpoints-on-close
20602061
** have been disabled - 0 if they are not disabled, 1 if they are.
20612062
** </dd>
2063
+**
20622064
** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
20632065
** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
20642066
** the [query planner stability guarantee] (QPSG). When the QPSG is active,
20652067
** a single SQL query statement will always use the same algorithm regardless
20662068
** of values of [bound parameters].)^ The QPSG disables some query optimizations
20672069
** that look at the values of bound parameters, which can make some queries
20682070
** slower. But the QPSG has the advantage of more predictable behavior. With
20692071
** the QPSG active, SQLite will always use the same query plan in the field as
20702072
** was used during testing in the lab.
2073
+** The first argument to this setting is an integer which is 0 to disable
2074
+** the QPSG, positive to enable QPSG, or negative to leave the setting
2075
+** unchanged. The second parameter is a pointer to an integer into which
2076
+** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
2077
+** following this call.
20712078
** </dd>
2079
+**
20722080
** <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
20732081
** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
20742082
** include output for any operations performed by trigger programs. This
20752083
** option is used to set or clear (the default) a flag that governs this
20762084
** behavior. The first parameter passed to this operation is an integer -
2077
-** non-zero to enable output for trigger programs, or zero to disable it.
2085
+** positive to enable output for trigger programs, or zero to disable it,
2086
+** or negative to leave the setting unchanged.
20782087
** The second parameter is a pointer to an integer into which is written
20792088
** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
20802089
** it is not disabled, 1 if it is.
20812090
** </dd>
20822091
** </dl>
20832092
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.23.0"
127 #define SQLITE_VERSION_NUMBER 3023000
128 #define SQLITE_SOURCE_ID "2018-03-17 16:26:36 442e816b5fed80ebeb58c7c0ab9c2ef999bf488519bf5da670e9cec477034540"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -2052,31 +2052,40 @@
2052 ** <dd> Usually, when a database in wal mode is closed or detached from a
2053 ** database handle, SQLite checks if this will mean that there are now no
2054 ** connections at all to the database. If so, it performs a checkpoint
2055 ** operation before closing the connection. This option may be used to
2056 ** override this behaviour. The first parameter passed to this operation
2057 ** is an integer - non-zero to disable checkpoints-on-close, or zero (the
2058 ** default) to enable them. The second parameter is a pointer to an integer
 
2059 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
2060 ** have been disabled - 0 if they are not disabled, 1 if they are.
2061 ** </dd>
 
2062 ** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
2063 ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
2064 ** the [query planner stability guarantee] (QPSG). When the QPSG is active,
2065 ** a single SQL query statement will always use the same algorithm regardless
2066 ** of values of [bound parameters].)^ The QPSG disables some query optimizations
2067 ** that look at the values of bound parameters, which can make some queries
2068 ** slower. But the QPSG has the advantage of more predictable behavior. With
2069 ** the QPSG active, SQLite will always use the same query plan in the field as
2070 ** was used during testing in the lab.
 
 
 
 
 
2071 ** </dd>
 
2072 ** <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
2073 ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
2074 ** include output for any operations performed by trigger programs. This
2075 ** option is used to set or clear (the default) a flag that governs this
2076 ** behavior. The first parameter passed to this operation is an integer -
2077 ** non-zero to enable output for trigger programs, or zero to disable it.
 
2078 ** The second parameter is a pointer to an integer into which is written
2079 ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
2080 ** it is not disabled, 1 if it is.
2081 ** </dd>
2082 ** </dl>
2083
--- src/sqlite3.h
+++ src/sqlite3.h
@@ -123,11 +123,11 @@
123 ** [sqlite3_libversion_number()], [sqlite3_sourceid()],
124 ** [sqlite_version()] and [sqlite_source_id()].
125 */
126 #define SQLITE_VERSION "3.23.0"
127 #define SQLITE_VERSION_NUMBER 3023000
128 #define SQLITE_SOURCE_ID "2018-03-22 17:13:44 eb4f452e354065d610ff57a6a9312ad119b6b0cc467f9dff105f0718bc27ef01"
129
130 /*
131 ** CAPI3REF: Run-Time Library Version Numbers
132 ** KEYWORDS: sqlite3_version sqlite3_sourceid
133 **
@@ -2052,31 +2052,40 @@
2052 ** <dd> Usually, when a database in wal mode is closed or detached from a
2053 ** database handle, SQLite checks if this will mean that there are now no
2054 ** connections at all to the database. If so, it performs a checkpoint
2055 ** operation before closing the connection. This option may be used to
2056 ** override this behaviour. The first parameter passed to this operation
2057 ** is an integer - positive to disable checkpoints-on-close, or zero (the
2058 ** default) to enable them, and negative to leave the setting unchanged.
2059 ** The second parameter is a pointer to an integer
2060 ** into which is written 0 or 1 to indicate whether checkpoints-on-close
2061 ** have been disabled - 0 if they are not disabled, 1 if they are.
2062 ** </dd>
2063 **
2064 ** <dt>SQLITE_DBCONFIG_ENABLE_QPSG</dt>
2065 ** <dd>^(The SQLITE_DBCONFIG_ENABLE_QPSG option activates or deactivates
2066 ** the [query planner stability guarantee] (QPSG). When the QPSG is active,
2067 ** a single SQL query statement will always use the same algorithm regardless
2068 ** of values of [bound parameters].)^ The QPSG disables some query optimizations
2069 ** that look at the values of bound parameters, which can make some queries
2070 ** slower. But the QPSG has the advantage of more predictable behavior. With
2071 ** the QPSG active, SQLite will always use the same query plan in the field as
2072 ** was used during testing in the lab.
2073 ** The first argument to this setting is an integer which is 0 to disable
2074 ** the QPSG, positive to enable QPSG, or negative to leave the setting
2075 ** unchanged. The second parameter is a pointer to an integer into which
2076 ** is written 0 or 1 to indicate whether the QPSG is disabled or enabled
2077 ** following this call.
2078 ** </dd>
2079 **
2080 ** <dt>SQLITE_DBCONFIG_TRIGGER_EQP</dt>
2081 ** <dd> By default, the output of EXPLAIN QUERY PLAN commands does not
2082 ** include output for any operations performed by trigger programs. This
2083 ** option is used to set or clear (the default) a flag that governs this
2084 ** behavior. The first parameter passed to this operation is an integer -
2085 ** positive to enable output for trigger programs, or zero to disable it,
2086 ** or negative to leave the setting unchanged.
2087 ** The second parameter is a pointer to an integer into which is written
2088 ** 0 or 1 to indicate whether output-for-triggers has been disabled - 0 if
2089 ** it is not disabled, 1 if it is.
2090 ** </dd>
2091 ** </dl>
2092

Keyboard Shortcuts

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