| | @@ -673,11 +673,11 @@ |
| 673 | 673 | ** [sqlite3_libversion_number()], [sqlite3_sourceid()], |
| 674 | 674 | ** [sqlite_version()] and [sqlite_source_id()]. |
| 675 | 675 | */ |
| 676 | 676 | #define SQLITE_VERSION "3.7.14" |
| 677 | 677 | #define SQLITE_VERSION_NUMBER 3007014 |
| 678 | | -#define SQLITE_SOURCE_ID "2012-08-14 17:29:27 6954fef006431d153de6e63e362b8d260ebeb1c6" |
| 678 | +#define SQLITE_SOURCE_ID "2012-08-24 23:56:19 62678be3df35cdcb09172ba8c860f7b73517f1ea" |
| 679 | 679 | |
| 680 | 680 | /* |
| 681 | 681 | ** CAPI3REF: Run-Time Library Version Numbers |
| 682 | 682 | ** KEYWORDS: sqlite3_version, sqlite3_sourceid |
| 683 | 683 | ** |
| | @@ -3723,12 +3723,15 @@ |
| 3723 | 3723 | ** ^The third argument is the value to bind to the parameter. |
| 3724 | 3724 | ** |
| 3725 | 3725 | ** ^(In those routines that have a fourth argument, its value is the |
| 3726 | 3726 | ** number of bytes in the parameter. To be clear: the value is the |
| 3727 | 3727 | ** number of <u>bytes</u> in the value, not the number of characters.)^ |
| 3728 | | -** ^If the fourth parameter is negative, the length of the string is |
| 3728 | +** ^If the fourth parameter to sqlite3_bind_text() or sqlite3_bind_text16() |
| 3729 | +** is negative, then the length of the string is |
| 3729 | 3730 | ** the number of bytes up to the first zero terminator. |
| 3731 | +** If the fourth parameter to sqlite3_bind_blob() is negative, then |
| 3732 | +** the behavior is undefined. |
| 3730 | 3733 | ** If a non-negative fourth parameter is provided to sqlite3_bind_text() |
| 3731 | 3734 | ** or sqlite3_bind_text16() then that parameter must be the byte offset |
| 3732 | 3735 | ** where the NUL terminator would occur assuming the string were NUL |
| 3733 | 3736 | ** terminated. If any NUL characters occur at byte offsets less than |
| 3734 | 3737 | ** the value of the fourth parameter then the resulting string value will |
| | @@ -10663,12 +10666,13 @@ |
| 10663 | 10666 | ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid. |
| 10664 | 10667 | ** TK_VARIABLE: variable number (always >= 1). */ |
| 10665 | 10668 | i16 iAgg; /* Which entry in pAggInfo->aCol[] or ->aFunc[] */ |
| 10666 | 10669 | i16 iRightJoinTable; /* If EP_FromJoin, the right table of the join */ |
| 10667 | 10670 | u8 flags2; /* Second set of flags. EP2_... */ |
| 10668 | | - u8 op2; /* If a TK_REGISTER, the original value of Expr.op */ |
| 10669 | | - /* If TK_COLUMN, the value of p5 for OP_Column */ |
| 10671 | + u8 op2; /* TK_REGISTER: original value of Expr.op |
| 10672 | + ** TK_COLUMN: the value of p5 for OP_Column |
| 10673 | + ** TK_AGG_FUNCTION: nesting depth */ |
| 10670 | 10674 | AggInfo *pAggInfo; /* Used by TK_AGG_COLUMN and TK_AGG_FUNCTION */ |
| 10671 | 10675 | Table *pTab; /* Table for TK_COLUMN expressions. */ |
| 10672 | 10676 | #if SQLITE_MAX_EXPR_DEPTH>0 |
| 10673 | 10677 | int nHeight; /* Height of the tree headed by this node */ |
| 10674 | 10678 | #endif |
| | @@ -10919,10 +10923,11 @@ |
| 10919 | 10923 | struct InLoop { |
| 10920 | 10924 | int iCur; /* The VDBE cursor used by this IN operator */ |
| 10921 | 10925 | int addrInTop; /* Top of the IN loop */ |
| 10922 | 10926 | } *aInLoop; /* Information about each nested IN operator */ |
| 10923 | 10927 | } in; /* Used when plan.wsFlags&WHERE_IN_ABLE */ |
| 10928 | + Index *pCovidx; /* Possible covering index for WHERE_MULTI_OR */ |
| 10924 | 10929 | } u; |
| 10925 | 10930 | |
| 10926 | 10931 | /* The following field is really not part of the current level. But |
| 10927 | 10932 | ** we need a place to cache virtual table index information for each |
| 10928 | 10933 | ** virtual table in the FROM clause and the WhereLevel structure is |
| | @@ -11471,14 +11476,16 @@ |
| 11471 | 11476 | */ |
| 11472 | 11477 | struct Walker { |
| 11473 | 11478 | int (*xExprCallback)(Walker*, Expr*); /* Callback for expressions */ |
| 11474 | 11479 | int (*xSelectCallback)(Walker*,Select*); /* Callback for SELECTs */ |
| 11475 | 11480 | Parse *pParse; /* Parser context. */ |
| 11481 | + int walkerDepth; /* Number of subqueries */ |
| 11476 | 11482 | union { /* Extra data for callback */ |
| 11477 | 11483 | NameContext *pNC; /* Naming context */ |
| 11478 | 11484 | int i; /* Integer value */ |
| 11479 | 11485 | SrcList *pSrcList; /* FROM clause */ |
| 11486 | + struct SrcCount *pSrcCount; /* Counting column references */ |
| 11480 | 11487 | } u; |
| 11481 | 11488 | }; |
| 11482 | 11489 | |
| 11483 | 11490 | /* Forward declarations */ |
| 11484 | 11491 | SQLITE_PRIVATE int sqlite3WalkExpr(Walker*, Expr*); |
| | @@ -11776,11 +11783,12 @@ |
| 11776 | 11783 | #if defined(SQLITE_ENABLE_UPDATE_DELETE_LIMIT) && !defined(SQLITE_OMIT_SUBQUERY) |
| 11777 | 11784 | SQLITE_PRIVATE Expr *sqlite3LimitWhere(Parse *, SrcList *, Expr *, ExprList *, Expr *, Expr *, char *); |
| 11778 | 11785 | #endif |
| 11779 | 11786 | SQLITE_PRIVATE void sqlite3DeleteFrom(Parse*, SrcList*, Expr*); |
| 11780 | 11787 | SQLITE_PRIVATE void sqlite3Update(Parse*, SrcList*, ExprList*, Expr*, int); |
| 11781 | | -SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin(Parse*, SrcList*, Expr*, ExprList**,ExprList*,u16); |
| 11788 | +SQLITE_PRIVATE WhereInfo *sqlite3WhereBegin( |
| 11789 | + Parse*,SrcList*,Expr*,ExprList**,ExprList*,u16,int); |
| 11782 | 11790 | SQLITE_PRIVATE void sqlite3WhereEnd(WhereInfo*); |
| 11783 | 11791 | SQLITE_PRIVATE int sqlite3ExprCodeGetColumn(Parse*, Table*, int, int, int, u8); |
| 11784 | 11792 | SQLITE_PRIVATE void sqlite3ExprCodeGetColumnOfTable(Vdbe*, Table*, int, int, int); |
| 11785 | 11793 | SQLITE_PRIVATE void sqlite3ExprCodeMove(Parse*, int, int, int); |
| 11786 | 11794 | SQLITE_PRIVATE void sqlite3ExprCodeCopy(Parse*, int, int, int); |
| | @@ -11808,10 +11816,11 @@ |
| 11808 | 11816 | SQLITE_PRIVATE char *sqlite3NameFromToken(sqlite3*, Token*); |
| 11809 | 11817 | SQLITE_PRIVATE int sqlite3ExprCompare(Expr*, Expr*); |
| 11810 | 11818 | SQLITE_PRIVATE int sqlite3ExprListCompare(ExprList*, ExprList*); |
| 11811 | 11819 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggregates(NameContext*, Expr*); |
| 11812 | 11820 | SQLITE_PRIVATE void sqlite3ExprAnalyzeAggList(NameContext*,ExprList*); |
| 11821 | +SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr*, SrcList*); |
| 11813 | 11822 | SQLITE_PRIVATE Vdbe *sqlite3GetVdbe(Parse*); |
| 11814 | 11823 | SQLITE_PRIVATE void sqlite3PrngSaveState(void); |
| 11815 | 11824 | SQLITE_PRIVATE void sqlite3PrngRestoreState(void); |
| 11816 | 11825 | SQLITE_PRIVATE void sqlite3PrngResetState(void); |
| 11817 | 11826 | SQLITE_PRIVATE void sqlite3RollbackAll(sqlite3*,int); |
| | @@ -15513,18 +15522,18 @@ |
| 15513 | 15522 | /* defer MT decisions to system malloc */ |
| 15514 | 15523 | _sqliteZone_ = malloc_default_zone(); |
| 15515 | 15524 | }else{ |
| 15516 | 15525 | /* only 1 core, use our own zone to contention over global locks, |
| 15517 | 15526 | ** e.g. we have our own dedicated locks */ |
| 15518 | | - bool success; |
| 15527 | + bool success; |
| 15519 | 15528 | malloc_zone_t* newzone = malloc_create_zone(4096, 0); |
| 15520 | 15529 | malloc_set_zone_name(newzone, "Sqlite_Heap"); |
| 15521 | 15530 | do{ |
| 15522 | 15531 | success = OSAtomicCompareAndSwapPtrBarrier(NULL, newzone, |
| 15523 | 15532 | (void * volatile *)&_sqliteZone_); |
| 15524 | 15533 | }while(!_sqliteZone_); |
| 15525 | | - if( !success ){ |
| 15534 | + if( !success ){ |
| 15526 | 15535 | /* somebody registered a zone first */ |
| 15527 | 15536 | malloc_destroy_zone(newzone); |
| 15528 | 15537 | } |
| 15529 | 15538 | } |
| 15530 | 15539 | #endif |
| | @@ -23448,13 +23457,13 @@ |
| 23448 | 23457 | return SQLITE_BUSY; |
| 23449 | 23458 | |
| 23450 | 23459 | case EACCES: |
| 23451 | 23460 | /* EACCES is like EAGAIN during locking operations, but not any other time*/ |
| 23452 | 23461 | if( (sqliteIOErr == SQLITE_IOERR_LOCK) || |
| 23453 | | - (sqliteIOErr == SQLITE_IOERR_UNLOCK) || |
| 23454 | | - (sqliteIOErr == SQLITE_IOERR_RDLOCK) || |
| 23455 | | - (sqliteIOErr == SQLITE_IOERR_CHECKRESERVEDLOCK) ){ |
| 23462 | + (sqliteIOErr == SQLITE_IOERR_UNLOCK) || |
| 23463 | + (sqliteIOErr == SQLITE_IOERR_RDLOCK) || |
| 23464 | + (sqliteIOErr == SQLITE_IOERR_CHECKRESERVEDLOCK) ){ |
| 23456 | 23465 | return SQLITE_BUSY; |
| 23457 | 23466 | } |
| 23458 | 23467 | /* else fall through */ |
| 23459 | 23468 | case EPERM: |
| 23460 | 23469 | return SQLITE_PERM; |
| | @@ -24497,11 +24506,11 @@ |
| 24497 | 24506 | lock.l_start = lock.l_len = 0L; |
| 24498 | 24507 | if( unixFileLock(pFile, &lock)==0 ){ |
| 24499 | 24508 | pInode->eFileLock = NO_LOCK; |
| 24500 | 24509 | }else{ |
| 24501 | 24510 | rc = SQLITE_IOERR_UNLOCK; |
| 24502 | | - pFile->lastErrno = errno; |
| 24511 | + pFile->lastErrno = errno; |
| 24503 | 24512 | pInode->eFileLock = NO_LOCK; |
| 24504 | 24513 | pFile->eFileLock = NO_LOCK; |
| 24505 | 24514 | } |
| 24506 | 24515 | } |
| 24507 | 24516 | |
| | @@ -24513,11 +24522,11 @@ |
| 24513 | 24522 | assert( pInode->nLock>=0 ); |
| 24514 | 24523 | if( pInode->nLock==0 ){ |
| 24515 | 24524 | closePendingFds(pFile); |
| 24516 | 24525 | } |
| 24517 | 24526 | } |
| 24518 | | - |
| 24527 | + |
| 24519 | 24528 | end_unlock: |
| 24520 | 24529 | unixLeaveMutex(); |
| 24521 | 24530 | if( rc==SQLITE_OK ) pFile->eFileLock = eFileLock; |
| 24522 | 24531 | return rc; |
| 24523 | 24532 | } |
| | @@ -24780,11 +24789,11 @@ |
| 24780 | 24789 | char *zLockFile = (char *)pFile->lockingContext; |
| 24781 | 24790 | int rc; |
| 24782 | 24791 | |
| 24783 | 24792 | assert( pFile ); |
| 24784 | 24793 | OSTRACE(("UNLOCK %d %d was %d pid=%d (dotlock)\n", pFile->h, eFileLock, |
| 24785 | | - pFile->eFileLock, getpid())); |
| 24794 | + pFile->eFileLock, getpid())); |
| 24786 | 24795 | assert( eFileLock<=SHARED_LOCK ); |
| 24787 | 24796 | |
| 24788 | 24797 | /* no-op if possible */ |
| 24789 | 24798 | if( pFile->eFileLock==eFileLock ){ |
| 24790 | 24799 | return SQLITE_OK; |
| | @@ -25167,11 +25176,11 @@ |
| 25167 | 25176 | sem_t *pSem = pFile->pInode->pSem; |
| 25168 | 25177 | |
| 25169 | 25178 | assert( pFile ); |
| 25170 | 25179 | assert( pSem ); |
| 25171 | 25180 | OSTRACE(("UNLOCK %d %d was %d pid=%d (sem)\n", pFile->h, eFileLock, |
| 25172 | | - pFile->eFileLock, getpid())); |
| 25181 | + pFile->eFileLock, getpid())); |
| 25173 | 25182 | assert( eFileLock<=SHARED_LOCK ); |
| 25174 | 25183 | |
| 25175 | 25184 | /* no-op if possible */ |
| 25176 | 25185 | if( pFile->eFileLock==eFileLock ){ |
| 25177 | 25186 | return SQLITE_OK; |
| | @@ -25757,11 +25766,11 @@ |
| 25757 | 25766 | SimulateIOError( newOffset-- ); |
| 25758 | 25767 | if( newOffset!=offset ){ |
| 25759 | 25768 | if( newOffset == -1 ){ |
| 25760 | 25769 | ((unixFile*)id)->lastErrno = errno; |
| 25761 | 25770 | }else{ |
| 25762 | | - ((unixFile*)id)->lastErrno = 0; |
| 25771 | + ((unixFile*)id)->lastErrno = 0; |
| 25763 | 25772 | } |
| 25764 | 25773 | return -1; |
| 25765 | 25774 | } |
| 25766 | 25775 | got = osRead(id->h, pBuf, cnt); |
| 25767 | 25776 | #endif |
| | @@ -25845,11 +25854,11 @@ |
| 25845 | 25854 | SimulateIOError( newOffset-- ); |
| 25846 | 25855 | if( newOffset!=offset ){ |
| 25847 | 25856 | if( newOffset == -1 ){ |
| 25848 | 25857 | ((unixFile*)id)->lastErrno = errno; |
| 25849 | 25858 | }else{ |
| 25850 | | - ((unixFile*)id)->lastErrno = 0; |
| 25859 | + ((unixFile*)id)->lastErrno = 0; |
| 25851 | 25860 | } |
| 25852 | 25861 | return -1; |
| 25853 | 25862 | } |
| 25854 | 25863 | got = osWrite(id->h, pBuf, cnt); |
| 25855 | 25864 | }while( got<0 && errno==EINTR ); |
| | @@ -28359,11 +28368,11 @@ |
| 28359 | 28368 | ** with _IOWR('z', 23, struct ByteRangeLockPB2) to track the same 5 states. |
| 28360 | 28369 | ** To simulate a F_RDLCK on the shared range, on AFP a randomly selected |
| 28361 | 28370 | ** address in the shared range is taken for a SHARED lock, the entire |
| 28362 | 28371 | ** shared range is taken for an EXCLUSIVE lock): |
| 28363 | 28372 | ** |
| 28364 | | -** PENDING_BYTE 0x40000000 |
| 28373 | +** PENDING_BYTE 0x40000000 |
| 28365 | 28374 | ** RESERVED_BYTE 0x40000001 |
| 28366 | 28375 | ** SHARED_RANGE 0x40000002 -> 0x40000200 |
| 28367 | 28376 | ** |
| 28368 | 28377 | ** This works well on the local file system, but shows a nearly 100x |
| 28369 | 28378 | ** slowdown in read performance on AFP because the AFP client disables |
| | @@ -29879,13 +29888,15 @@ |
| 29879 | 29888 | |
| 29880 | 29889 | #ifndef FILE_ATTRIBUTE_MASK |
| 29881 | 29890 | # define FILE_ATTRIBUTE_MASK (0x0003FFF7) |
| 29882 | 29891 | #endif |
| 29883 | 29892 | |
| 29893 | +#ifndef SQLITE_OMIT_WAL |
| 29884 | 29894 | /* Forward references */ |
| 29885 | 29895 | typedef struct winShm winShm; /* A connection to shared-memory */ |
| 29886 | 29896 | typedef struct winShmNode winShmNode; /* A region of shared-memory */ |
| 29897 | +#endif |
| 29887 | 29898 | |
| 29888 | 29899 | /* |
| 29889 | 29900 | ** WinCE lacks native support for file locking so we have to fake it |
| 29890 | 29901 | ** with some code of our own. |
| 29891 | 29902 | */ |
| | @@ -29909,11 +29920,13 @@ |
| 29909 | 29920 | HANDLE h; /* Handle for accessing the file */ |
| 29910 | 29921 | u8 locktype; /* Type of lock currently held on this file */ |
| 29911 | 29922 | short sharedLockByte; /* Randomly chosen byte used as a shared lock */ |
| 29912 | 29923 | u8 ctrlFlags; /* Flags. See WINFILE_* below */ |
| 29913 | 29924 | DWORD lastErrno; /* The Windows errno from the last I/O error */ |
| 29925 | +#ifndef SQLITE_OMIT_WAL |
| 29914 | 29926 | winShm *pShm; /* Instance of shared memory on this file */ |
| 29927 | +#endif |
| 29915 | 29928 | const char *zPath; /* Full pathname of this file */ |
| 29916 | 29929 | int szChunk; /* Chunk size configured by FCNTL_CHUNK_SIZE */ |
| 29917 | 29930 | #if SQLITE_OS_WINCE |
| 29918 | 29931 | LPWSTR zDeleteOnClose; /* Name of file to delete when closing */ |
| 29919 | 29932 | HANDLE hMutex; /* Mutex used to control access to shared lock */ |
| | @@ -29934,10 +29947,26 @@ |
| 29934 | 29947 | */ |
| 29935 | 29948 | #ifndef SQLITE_WIN32_DBG_BUF_SIZE |
| 29936 | 29949 | # define SQLITE_WIN32_DBG_BUF_SIZE ((int)(4096-sizeof(DWORD))) |
| 29937 | 29950 | #endif |
| 29938 | 29951 | |
| 29952 | +/* |
| 29953 | + * The value used with sqlite3_win32_set_directory() to specify that |
| 29954 | + * the data directory should be changed. |
| 29955 | + */ |
| 29956 | +#ifndef SQLITE_WIN32_DATA_DIRECTORY_TYPE |
| 29957 | +# define SQLITE_WIN32_DATA_DIRECTORY_TYPE (1) |
| 29958 | +#endif |
| 29959 | + |
| 29960 | +/* |
| 29961 | + * The value used with sqlite3_win32_set_directory() to specify that |
| 29962 | + * the temporary directory should be changed. |
| 29963 | + */ |
| 29964 | +#ifndef SQLITE_WIN32_TEMP_DIRECTORY_TYPE |
| 29965 | +# define SQLITE_WIN32_TEMP_DIRECTORY_TYPE (2) |
| 29966 | +#endif |
| 29967 | + |
| 29939 | 29968 | /* |
| 29940 | 29969 | * If compiled with SQLITE_WIN32_MALLOC on Windows, we will use the |
| 29941 | 29970 | * various Win32 API heap functions instead of our own. |
| 29942 | 29971 | */ |
| 29943 | 29972 | #ifdef SQLITE_WIN32_MALLOC |
| | @@ -31147,10 +31176,46 @@ |
| 31147 | 31176 | zFilenameMbcs = unicodeToMbcs(zTmpWide); |
| 31148 | 31177 | sqlite3_free(zTmpWide); |
| 31149 | 31178 | return zFilenameMbcs; |
| 31150 | 31179 | } |
| 31151 | 31180 | |
| 31181 | +/* |
| 31182 | +** This function sets the data directory or the temporary directory based on |
| 31183 | +** the provided arguments. The type argument must be 1 in order to set the |
| 31184 | +** data directory or 2 in order to set the temporary directory. The zValue |
| 31185 | +** argument is the name of the directory to use. The return value will be |
| 31186 | +** SQLITE_OK if successful. |
| 31187 | +*/ |
| 31188 | +SQLITE_API int sqlite3_win32_set_directory(DWORD type, LPCWSTR zValue){ |
| 31189 | + char **ppDirectory = 0; |
| 31190 | +#ifndef SQLITE_OMIT_AUTOINIT |
| 31191 | + int rc = sqlite3_initialize(); |
| 31192 | + if( rc ) return rc; |
| 31193 | +#endif |
| 31194 | + if( type==SQLITE_WIN32_DATA_DIRECTORY_TYPE ){ |
| 31195 | + ppDirectory = &sqlite3_data_directory; |
| 31196 | + }else if( type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE ){ |
| 31197 | + ppDirectory = &sqlite3_temp_directory; |
| 31198 | + } |
| 31199 | + assert( !ppDirectory || type==SQLITE_WIN32_DATA_DIRECTORY_TYPE |
| 31200 | + || type==SQLITE_WIN32_TEMP_DIRECTORY_TYPE |
| 31201 | + ); |
| 31202 | + assert( !ppDirectory || sqlite3MemdebugHasType(*ppDirectory, MEMTYPE_HEAP) ); |
| 31203 | + if( ppDirectory ){ |
| 31204 | + char *zValueUtf8 = 0; |
| 31205 | + if( zValue && zValue[0] ){ |
| 31206 | + zValueUtf8 = unicodeToUtf8(zValue); |
| 31207 | + if ( zValueUtf8==0 ){ |
| 31208 | + return SQLITE_NOMEM; |
| 31209 | + } |
| 31210 | + } |
| 31211 | + sqlite3_free(*ppDirectory); |
| 31212 | + *ppDirectory = zValueUtf8; |
| 31213 | + return SQLITE_OK; |
| 31214 | + } |
| 31215 | + return SQLITE_ERROR; |
| 31216 | +} |
| 31152 | 31217 | |
| 31153 | 31218 | /* |
| 31154 | 31219 | ** The return value of getLastErrorMsg |
| 31155 | 31220 | ** is zero if the error message fits in the buffer, or non-zero |
| 31156 | 31221 | ** otherwise (if the message was truncated). |
| | @@ -31763,11 +31828,13 @@ |
| 31763 | 31828 | static int winClose(sqlite3_file *id){ |
| 31764 | 31829 | int rc, cnt = 0; |
| 31765 | 31830 | winFile *pFile = (winFile*)id; |
| 31766 | 31831 | |
| 31767 | 31832 | assert( id!=0 ); |
| 31833 | +#ifndef SQLITE_OMIT_WAL |
| 31768 | 31834 | assert( pFile->pShm==0 ); |
| 31835 | +#endif |
| 31769 | 31836 | OSTRACE(("CLOSE %d\n", pFile->h)); |
| 31770 | 31837 | do{ |
| 31771 | 31838 | rc = osCloseHandle(pFile->h); |
| 31772 | 31839 | /* SimulateIOError( rc=0; cnt=MX_CLOSE_ATTEMPT; ); */ |
| 31773 | 31840 | }while( rc==0 && ++cnt < MX_CLOSE_ATTEMPT && (sqlite3_win32_sleep(100), 1) ); |
| | @@ -33513,11 +33580,13 @@ |
| 33513 | 33580 | memset(pFile, 0, sizeof(*pFile)); |
| 33514 | 33581 | pFile->pMethod = &winIoMethod; |
| 33515 | 33582 | pFile->h = h; |
| 33516 | 33583 | pFile->lastErrno = NO_ERROR; |
| 33517 | 33584 | pFile->pVfs = pVfs; |
| 33585 | +#ifndef SQLITE_OMIT_WAL |
| 33518 | 33586 | pFile->pShm = 0; |
| 33587 | +#endif |
| 33519 | 33588 | pFile->zPath = zName; |
| 33520 | 33589 | if( sqlite3_uri_boolean(zName, "psow", SQLITE_POWERSAFE_OVERWRITE) ){ |
| 33521 | 33590 | pFile->ctrlFlags |= WINFILE_PSOW; |
| 33522 | 33591 | } |
| 33523 | 33592 | |
| | @@ -49289,11 +49358,11 @@ |
| 49289 | 49358 | } |
| 49290 | 49359 | next = get2byte(&data[pc]); |
| 49291 | 49360 | size = get2byte(&data[pc+2]); |
| 49292 | 49361 | if( (next>0 && next<=pc+size+3) || pc+size>usableSize ){ |
| 49293 | 49362 | /* Free blocks must be in ascending order. And the last byte of |
| 49294 | | - ** the free-block must lie on the database page. */ |
| 49363 | + ** the free-block must lie on the database page. */ |
| 49295 | 49364 | return SQLITE_CORRUPT_BKPT; |
| 49296 | 49365 | } |
| 49297 | 49366 | nFree = nFree + size; |
| 49298 | 49367 | pc = next; |
| 49299 | 49368 | } |
| | @@ -50463,11 +50532,11 @@ |
| 50463 | 50532 | if( rc==SQLITE_OK ){ |
| 50464 | 50533 | if( p->inTrans==TRANS_NONE ){ |
| 50465 | 50534 | pBt->nTransaction++; |
| 50466 | 50535 | #ifndef SQLITE_OMIT_SHARED_CACHE |
| 50467 | 50536 | if( p->sharable ){ |
| 50468 | | - assert( p->lock.pBtree==p && p->lock.iTable==1 ); |
| 50537 | + assert( p->lock.pBtree==p && p->lock.iTable==1 ); |
| 50469 | 50538 | p->lock.eLock = READ_LOCK; |
| 50470 | 50539 | p->lock.pNext = pBt->pLock; |
| 50471 | 50540 | pBt->pLock = &p->lock; |
| 50472 | 50541 | } |
| 50473 | 50542 | #endif |
| | @@ -54301,10 +54370,11 @@ |
| 54301 | 54370 | while( i==iNextOld ){ |
| 54302 | 54371 | /* Cell i is the cell immediately following the last cell on old |
| 54303 | 54372 | ** sibling page j. If the siblings are not leaf pages of an |
| 54304 | 54373 | ** intkey b-tree, then cell i was a divider cell. */ |
| 54305 | 54374 | assert( j+1 < ArraySize(apCopy) ); |
| 54375 | + assert( j+1 < nOld ); |
| 54306 | 54376 | pOld = apCopy[++j]; |
| 54307 | 54377 | iNextOld = i + !leafData + pOld->nCell + pOld->nOverflow; |
| 54308 | 54378 | if( pOld->nOverflow ){ |
| 54309 | 54379 | nOverflow = pOld->nOverflow; |
| 54310 | 54380 | iOverflow = i + !leafData + pOld->aiOvfl[0]; |
| | @@ -56135,11 +56205,10 @@ |
| 56135 | 56205 | */ |
| 56136 | 56206 | SQLITE_PRIVATE void sqlite3BtreeCursorHints(BtCursor *pCsr, unsigned int mask){ |
| 56137 | 56207 | assert( mask==BTREE_BULKLOAD || mask==0 ); |
| 56138 | 56208 | pCsr->hints = mask; |
| 56139 | 56209 | } |
| 56140 | | - |
| 56141 | 56210 | |
| 56142 | 56211 | /************** End of btree.c ***********************************************/ |
| 56143 | 56212 | /************** Begin file backup.c ******************************************/ |
| 56144 | 56213 | /* |
| 56145 | 56214 | ** 2009 January 28 |
| | @@ -70367,11 +70436,11 @@ |
| 70367 | 70436 | if( iBuf==0 ){ |
| 70368 | 70437 | int nRead; /* Bytes to read from disk */ |
| 70369 | 70438 | int rc; /* sqlite3OsRead() return code */ |
| 70370 | 70439 | |
| 70371 | 70440 | /* Determine how many bytes of data to read. */ |
| 70372 | | - nRead = p->iEof - p->iReadOff; |
| 70441 | + nRead = (int)(p->iEof - p->iReadOff); |
| 70373 | 70442 | if( nRead>p->nBuffer ) nRead = p->nBuffer; |
| 70374 | 70443 | assert( nRead>0 ); |
| 70375 | 70444 | |
| 70376 | 70445 | /* Read data from the file. Return early if an error occurs. */ |
| 70377 | 70446 | rc = sqlite3OsRead(p->pFile, p->aBuffer, nRead, p->iReadOff); |
| | @@ -70472,11 +70541,11 @@ |
| 70472 | 70541 | } |
| 70473 | 70542 | |
| 70474 | 70543 | rc = vdbeSorterIterVarint(db, pIter, &nRec); |
| 70475 | 70544 | if( rc==SQLITE_OK ){ |
| 70476 | 70545 | pIter->nKey = (int)nRec; |
| 70477 | | - rc = vdbeSorterIterRead(db, pIter, nRec, &pIter->aKey); |
| 70546 | + rc = vdbeSorterIterRead(db, pIter, (int)nRec, &pIter->aKey); |
| 70478 | 70547 | } |
| 70479 | 70548 | |
| 70480 | 70549 | return rc; |
| 70481 | 70550 | } |
| 70482 | 70551 | |
| | @@ -70515,11 +70584,11 @@ |
| 70515 | 70584 | |
| 70516 | 70585 | iBuf = iStart % nBuf; |
| 70517 | 70586 | if( iBuf ){ |
| 70518 | 70587 | int nRead = nBuf - iBuf; |
| 70519 | 70588 | if( (iStart + nRead) > pSorter->iWriteOff ){ |
| 70520 | | - nRead = pSorter->iWriteOff - iStart; |
| 70589 | + nRead = (int)(pSorter->iWriteOff - iStart); |
| 70521 | 70590 | } |
| 70522 | 70591 | rc = sqlite3OsRead( |
| 70523 | 70592 | pSorter->pTemp1, &pIter->aBuffer[iBuf], nRead, iStart |
| 70524 | 70593 | ); |
| 70525 | 70594 | assert( rc!=SQLITE_IOERR_SHORT_READ ); |
| | @@ -71838,17 +71907,23 @@ |
| 71838 | 71907 | */ |
| 71839 | 71908 | SQLITE_PRIVATE int sqlite3WalkSelect(Walker *pWalker, Select *p){ |
| 71840 | 71909 | int rc; |
| 71841 | 71910 | if( p==0 || pWalker->xSelectCallback==0 ) return WRC_Continue; |
| 71842 | 71911 | rc = WRC_Continue; |
| 71843 | | - while( p ){ |
| 71912 | + pWalker->walkerDepth++; |
| 71913 | + while( p ){ |
| 71844 | 71914 | rc = pWalker->xSelectCallback(pWalker, p); |
| 71845 | 71915 | if( rc ) break; |
| 71846 | | - if( sqlite3WalkSelectExpr(pWalker, p) ) return WRC_Abort; |
| 71847 | | - if( sqlite3WalkSelectFrom(pWalker, p) ) return WRC_Abort; |
| 71916 | + if( sqlite3WalkSelectExpr(pWalker, p) |
| 71917 | + || sqlite3WalkSelectFrom(pWalker, p) |
| 71918 | + ){ |
| 71919 | + pWalker->walkerDepth--; |
| 71920 | + return WRC_Abort; |
| 71921 | + } |
| 71848 | 71922 | p = p->pPrior; |
| 71849 | 71923 | } |
| 71924 | + pWalker->walkerDepth--; |
| 71850 | 71925 | return rc & WRC_Abort; |
| 71851 | 71926 | } |
| 71852 | 71927 | |
| 71853 | 71928 | /************** End of walker.c **********************************************/ |
| 71854 | 71929 | /************** Begin file resolve.c *****************************************/ |
| | @@ -71868,10 +71943,33 @@ |
| 71868 | 71943 | ** resolve all identifiers by associating them with a particular |
| 71869 | 71944 | ** table and column. |
| 71870 | 71945 | */ |
| 71871 | 71946 | /* #include <stdlib.h> */ |
| 71872 | 71947 | /* #include <string.h> */ |
| 71948 | + |
| 71949 | +/* |
| 71950 | +** Walk the expression tree pExpr and increase the aggregate function |
| 71951 | +** depth (the Expr.op2 field) by N on every TK_AGG_FUNCTION node. |
| 71952 | +** This needs to occur when copying a TK_AGG_FUNCTION node from an |
| 71953 | +** outer query into an inner subquery. |
| 71954 | +** |
| 71955 | +** incrAggFunctionDepth(pExpr,n) is the main routine. incrAggDepth(..) |
| 71956 | +** is a helper function - a callback for the tree walker. |
| 71957 | +*/ |
| 71958 | +static int incrAggDepth(Walker *pWalker, Expr *pExpr){ |
| 71959 | + if( pExpr->op==TK_AGG_FUNCTION ) pExpr->op2 += pWalker->u.i; |
| 71960 | + return WRC_Continue; |
| 71961 | +} |
| 71962 | +static void incrAggFunctionDepth(Expr *pExpr, int N){ |
| 71963 | + if( N>0 ){ |
| 71964 | + Walker w; |
| 71965 | + memset(&w, 0, sizeof(w)); |
| 71966 | + w.xExprCallback = incrAggDepth; |
| 71967 | + w.u.i = N; |
| 71968 | + sqlite3WalkExpr(&w, pExpr); |
| 71969 | + } |
| 71970 | +} |
| 71873 | 71971 | |
| 71874 | 71972 | /* |
| 71875 | 71973 | ** Turn the pExpr expression into an alias for the iCol-th column of the |
| 71876 | 71974 | ** result set in pEList. |
| 71877 | 71975 | ** |
| | @@ -71895,17 +71993,24 @@ |
| 71895 | 71993 | ** SELECT random()%5 AS x, count(*) FROM tab GROUP BY random()%5 |
| 71896 | 71994 | ** |
| 71897 | 71995 | ** The result of random()%5 in the GROUP BY clause is probably different |
| 71898 | 71996 | ** from the result in the result-set. We might fix this someday. Or |
| 71899 | 71997 | ** then again, we might not... |
| 71998 | +** |
| 71999 | +** The nSubquery parameter specifies how many levels of subquery the |
| 72000 | +** alias is removed from the original expression. The usually value is |
| 72001 | +** zero but it might be more if the alias is contained within a subquery |
| 72002 | +** of the original expression. The Expr.op2 field of TK_AGG_FUNCTION |
| 72003 | +** structures must be increased by the nSubquery amount. |
| 71900 | 72004 | */ |
| 71901 | 72005 | static void resolveAlias( |
| 71902 | 72006 | Parse *pParse, /* Parsing context */ |
| 71903 | 72007 | ExprList *pEList, /* A result set */ |
| 71904 | 72008 | int iCol, /* A column in the result set. 0..pEList->nExpr-1 */ |
| 71905 | 72009 | Expr *pExpr, /* Transform this into an alias to the result set */ |
| 71906 | | - const char *zType /* "GROUP" or "ORDER" or "" */ |
| 72010 | + const char *zType, /* "GROUP" or "ORDER" or "" */ |
| 72011 | + int nSubquery /* Number of subqueries that the label is moving */ |
| 71907 | 72012 | ){ |
| 71908 | 72013 | Expr *pOrig; /* The iCol-th column of the result set */ |
| 71909 | 72014 | Expr *pDup; /* Copy of pOrig */ |
| 71910 | 72015 | sqlite3 *db; /* The database connection */ |
| 71911 | 72016 | |
| | @@ -71914,10 +72019,11 @@ |
| 71914 | 72019 | assert( pOrig!=0 ); |
| 71915 | 72020 | assert( pOrig->flags & EP_Resolved ); |
| 71916 | 72021 | db = pParse->db; |
| 71917 | 72022 | if( pOrig->op!=TK_COLUMN && zType[0]!='G' ){ |
| 71918 | 72023 | pDup = sqlite3ExprDup(db, pOrig, 0); |
| 72024 | + incrAggFunctionDepth(pDup, nSubquery); |
| 71919 | 72025 | pDup = sqlite3PExpr(pParse, TK_AS, pDup, 0, 0); |
| 71920 | 72026 | if( pDup==0 ) return; |
| 71921 | 72027 | if( pEList->a[iCol].iAlias==0 ){ |
| 71922 | 72028 | pEList->a[iCol].iAlias = (u16)(++pParse->nAlias); |
| 71923 | 72029 | } |
| | @@ -72002,13 +72108,14 @@ |
| 72002 | 72108 | const char *zTab, /* Name of table containing column, or NULL */ |
| 72003 | 72109 | const char *zCol, /* Name of the column. */ |
| 72004 | 72110 | NameContext *pNC, /* The name context used to resolve the name */ |
| 72005 | 72111 | Expr *pExpr /* Make this EXPR node point to the selected column */ |
| 72006 | 72112 | ){ |
| 72007 | | - int i, j; /* Loop counters */ |
| 72113 | + int i, j; /* Loop counters */ |
| 72008 | 72114 | int cnt = 0; /* Number of matching column names */ |
| 72009 | 72115 | int cntTab = 0; /* Number of matching table names */ |
| 72116 | + int nSubquery = 0; /* How many levels of subquery */ |
| 72010 | 72117 | sqlite3 *db = pParse->db; /* The database connection */ |
| 72011 | 72118 | struct SrcList_item *pItem; /* Use for looping over pSrcList items */ |
| 72012 | 72119 | struct SrcList_item *pMatch = 0; /* The matching pSrcList item */ |
| 72013 | 72120 | NameContext *pTopNC = pNC; /* First namecontext in the list */ |
| 72014 | 72121 | Schema *pSchema = 0; /* Schema of the expression */ |
| | @@ -72166,11 +72273,11 @@ |
| 72166 | 72273 | pOrig = pEList->a[j].pExpr; |
| 72167 | 72274 | if( (pNC->ncFlags&NC_AllowAgg)==0 && ExprHasProperty(pOrig, EP_Agg) ){ |
| 72168 | 72275 | sqlite3ErrorMsg(pParse, "misuse of aliased aggregate %s", zAs); |
| 72169 | 72276 | return WRC_Abort; |
| 72170 | 72277 | } |
| 72171 | | - resolveAlias(pParse, pEList, j, pExpr, ""); |
| 72278 | + resolveAlias(pParse, pEList, j, pExpr, "", nSubquery); |
| 72172 | 72279 | cnt = 1; |
| 72173 | 72280 | pMatch = 0; |
| 72174 | 72281 | assert( zTab==0 && zDb==0 ); |
| 72175 | 72282 | goto lookupname_end; |
| 72176 | 72283 | } |
| | @@ -72180,10 +72287,11 @@ |
| 72180 | 72287 | /* Advance to the next name context. The loop will exit when either |
| 72181 | 72288 | ** we have a match (cnt>0) or when we run out of name contexts. |
| 72182 | 72289 | */ |
| 72183 | 72290 | if( cnt==0 ){ |
| 72184 | 72291 | pNC = pNC->pNext; |
| 72292 | + nSubquery++; |
| 72185 | 72293 | } |
| 72186 | 72294 | } |
| 72187 | 72295 | |
| 72188 | 72296 | /* |
| 72189 | 72297 | ** If X and Y are NULL (in other words if only the column name Z is |
| | @@ -72419,17 +72527,23 @@ |
| 72419 | 72527 | }else if( wrong_num_args ){ |
| 72420 | 72528 | sqlite3ErrorMsg(pParse,"wrong number of arguments to function %.*s()", |
| 72421 | 72529 | nId, zId); |
| 72422 | 72530 | pNC->nErr++; |
| 72423 | 72531 | } |
| 72424 | | - if( is_agg ){ |
| 72425 | | - pExpr->op = TK_AGG_FUNCTION; |
| 72426 | | - pNC->ncFlags |= NC_HasAgg; |
| 72427 | | - } |
| 72428 | 72532 | if( is_agg ) pNC->ncFlags &= ~NC_AllowAgg; |
| 72429 | 72533 | sqlite3WalkExprList(pWalker, pList); |
| 72430 | | - if( is_agg ) pNC->ncFlags |= NC_AllowAgg; |
| 72534 | + if( is_agg ){ |
| 72535 | + NameContext *pNC2 = pNC; |
| 72536 | + pExpr->op = TK_AGG_FUNCTION; |
| 72537 | + pExpr->op2 = 0; |
| 72538 | + while( pNC2 && !sqlite3FunctionUsesThisSrc(pExpr, pNC2->pSrcList) ){ |
| 72539 | + pExpr->op2++; |
| 72540 | + pNC2 = pNC2->pNext; |
| 72541 | + } |
| 72542 | + if( pNC2 ) pNC2->ncFlags |= NC_HasAgg; |
| 72543 | + pNC->ncFlags |= NC_AllowAgg; |
| 72544 | + } |
| 72431 | 72545 | /* FIX ME: Compute pExpr->affinity based on the expected return |
| 72432 | 72546 | ** type of the function |
| 72433 | 72547 | */ |
| 72434 | 72548 | return WRC_Prune; |
| 72435 | 72549 | } |
| | @@ -72704,11 +72818,11 @@ |
| 72704 | 72818 | if( pItem->iOrderByCol ){ |
| 72705 | 72819 | if( pItem->iOrderByCol>pEList->nExpr ){ |
| 72706 | 72820 | resolveOutOfRangeError(pParse, zType, i+1, pEList->nExpr); |
| 72707 | 72821 | return 1; |
| 72708 | 72822 | } |
| 72709 | | - resolveAlias(pParse, pEList, pItem->iOrderByCol-1, pItem->pExpr, zType); |
| 72823 | + resolveAlias(pParse, pEList, pItem->iOrderByCol-1, pItem->pExpr, zType,0); |
| 72710 | 72824 | } |
| 72711 | 72825 | } |
| 72712 | 72826 | return 0; |
| 72713 | 72827 | } |
| 72714 | 72828 | |
| | @@ -76204,13 +76318,16 @@ |
| 76204 | 76318 | if( ExprHasAnyProperty(pExpr, EP_TokenOnly) ){ |
| 76205 | 76319 | pFarg = 0; |
| 76206 | 76320 | }else{ |
| 76207 | 76321 | pFarg = pExpr->x.pList; |
| 76208 | 76322 | } |
| 76209 | | - sqlite3ExplainPrintf(pOut, "%sFUNCTION:%s(", |
| 76210 | | - op==TK_AGG_FUNCTION ? "AGG_" : "", |
| 76211 | | - pExpr->u.zToken); |
| 76323 | + if( op==TK_AGG_FUNCTION ){ |
| 76324 | + sqlite3ExplainPrintf(pOut, "AGG_FUNCTION%d:%s(", |
| 76325 | + pExpr->op2, pExpr->u.zToken); |
| 76326 | + }else{ |
| 76327 | + sqlite3ExplainPrintf(pOut, "FUNCTION:%s(", pExpr->u.zToken); |
| 76328 | + } |
| 76212 | 76329 | if( pFarg ){ |
| 76213 | 76330 | sqlite3ExplainExprList(pOut, pFarg); |
| 76214 | 76331 | } |
| 76215 | 76332 | sqlite3ExplainPrintf(pOut, ")"); |
| 76216 | 76333 | break; |
| | @@ -76897,42 +77014,64 @@ |
| 76897 | 77014 | } |
| 76898 | 77015 | return 0; |
| 76899 | 77016 | } |
| 76900 | 77017 | |
| 76901 | 77018 | /* |
| 76902 | | -** This is the expression callback for sqlite3FunctionUsesOtherSrc(). |
| 76903 | | -** |
| 76904 | | -** Determine if an expression references any table other than one of the |
| 76905 | | -** tables in pWalker->u.pSrcList and abort if it does. |
| 77019 | +** An instance of the following structure is used by the tree walker |
| 77020 | +** to count references to table columns in the arguments of an |
| 77021 | +** aggregate function, in order to implement the |
| 77022 | +** sqlite3FunctionThisSrc() routine. |
| 76906 | 77023 | */ |
| 76907 | | -static int exprUsesOtherSrc(Walker *pWalker, Expr *pExpr){ |
| 76908 | | - if( pExpr->op==TK_COLUMN || pExpr->op==TK_AGG_COLUMN ){ |
| 77024 | +struct SrcCount { |
| 77025 | + SrcList *pSrc; /* One particular FROM clause in a nested query */ |
| 77026 | + int nThis; /* Number of references to columns in pSrcList */ |
| 77027 | + int nOther; /* Number of references to columns in other FROM clauses */ |
| 77028 | +}; |
| 77029 | + |
| 77030 | +/* |
| 77031 | +** Count the number of references to columns. |
| 77032 | +*/ |
| 77033 | +static int exprSrcCount(Walker *pWalker, Expr *pExpr){ |
| 77034 | + /* The NEVER() on the second term is because sqlite3FunctionUsesThisSrc() |
| 77035 | + ** is always called before sqlite3ExprAnalyzeAggregates() and so the |
| 77036 | + ** TK_COLUMNs have not yet been converted into TK_AGG_COLUMN. If |
| 77037 | + ** sqlite3FunctionUsesThisSrc() is used differently in the future, the |
| 77038 | + ** NEVER() will need to be removed. */ |
| 77039 | + if( pExpr->op==TK_COLUMN || NEVER(pExpr->op==TK_AGG_COLUMN) ){ |
| 76909 | 77040 | int i; |
| 76910 | | - SrcList *pSrc = pWalker->u.pSrcList; |
| 77041 | + struct SrcCount *p = pWalker->u.pSrcCount; |
| 77042 | + SrcList *pSrc = p->pSrc; |
| 76911 | 77043 | for(i=0; i<pSrc->nSrc; i++){ |
| 76912 | | - if( pExpr->iTable==pSrc->a[i].iCursor ) return WRC_Continue; |
| 77044 | + if( pExpr->iTable==pSrc->a[i].iCursor ) break; |
| 76913 | 77045 | } |
| 76914 | | - return WRC_Abort; |
| 76915 | | - }else{ |
| 76916 | | - return WRC_Continue; |
| 77046 | + if( i<pSrc->nSrc ){ |
| 77047 | + p->nThis++; |
| 77048 | + }else{ |
| 77049 | + p->nOther++; |
| 77050 | + } |
| 76917 | 77051 | } |
| 77052 | + return WRC_Continue; |
| 76918 | 77053 | } |
| 76919 | 77054 | |
| 76920 | 77055 | /* |
| 76921 | | -** Determine if any of the arguments to the pExpr Function references |
| 76922 | | -** any SrcList other than pSrcList. Return true if they do. Return |
| 76923 | | -** false if pExpr has no argument or has only constant arguments or |
| 76924 | | -** only references tables named in pSrcList. |
| 77056 | +** Determine if any of the arguments to the pExpr Function reference |
| 77057 | +** pSrcList. Return true if they do. Also return true if the function |
| 77058 | +** has no arguments or has only constant arguments. Return false if pExpr |
| 77059 | +** references columns but not columns of tables found in pSrcList. |
| 76925 | 77060 | */ |
| 76926 | | -static int sqlite3FunctionUsesOtherSrc(Expr *pExpr, SrcList *pSrcList){ |
| 77061 | +SQLITE_PRIVATE int sqlite3FunctionUsesThisSrc(Expr *pExpr, SrcList *pSrcList){ |
| 76927 | 77062 | Walker w; |
| 77063 | + struct SrcCount cnt; |
| 76928 | 77064 | assert( pExpr->op==TK_AGG_FUNCTION ); |
| 76929 | 77065 | memset(&w, 0, sizeof(w)); |
| 76930 | | - w.xExprCallback = exprUsesOtherSrc; |
| 76931 | | - w.u.pSrcList = pSrcList; |
| 76932 | | - if( sqlite3WalkExprList(&w, pExpr->x.pList)!=WRC_Continue ) return 1; |
| 76933 | | - return 0; |
| 77066 | + w.xExprCallback = exprSrcCount; |
| 77067 | + w.u.pSrcCount = &cnt; |
| 77068 | + cnt.pSrc = pSrcList; |
| 77069 | + cnt.nThis = 0; |
| 77070 | + cnt.nOther = 0; |
| 77071 | + sqlite3WalkExprList(&w, pExpr->x.pList); |
| 77072 | + return cnt.nThis>0 || cnt.nOther==0; |
| 76934 | 77073 | } |
| 76935 | 77074 | |
| 76936 | 77075 | /* |
| 76937 | 77076 | ** Add a new element to the pAggInfo->aCol[] array. Return the index of |
| 76938 | 77077 | ** the new element. Return a negative number if malloc fails. |
| | @@ -77047,11 +77186,11 @@ |
| 77047 | 77186 | } |
| 77048 | 77187 | return WRC_Prune; |
| 77049 | 77188 | } |
| 77050 | 77189 | case TK_AGG_FUNCTION: { |
| 77051 | 77190 | if( (pNC->ncFlags & NC_InAggFunc)==0 |
| 77052 | | - && !sqlite3FunctionUsesOtherSrc(pExpr, pSrcList) |
| 77191 | + && pWalker->walkerDepth==pExpr->op2 |
| 77053 | 77192 | ){ |
| 77054 | 77193 | /* Check to see if pExpr is a duplicate of another aggregate |
| 77055 | 77194 | ** function that is already in the pAggInfo structure |
| 77056 | 77195 | */ |
| 77057 | 77196 | struct AggInfo_func *pItem = pAggInfo->aFunc; |
| | @@ -80497,11 +80636,11 @@ |
| 80497 | 80636 | pNext = pIndex->pNext; |
| 80498 | 80637 | assert( pIndex->pSchema==pTable->pSchema ); |
| 80499 | 80638 | if( !db || db->pnBytesFreed==0 ){ |
| 80500 | 80639 | char *zName = pIndex->zName; |
| 80501 | 80640 | TESTONLY ( Index *pOld = ) sqlite3HashInsert( |
| 80502 | | - &pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0 |
| 80641 | + &pIndex->pSchema->idxHash, zName, sqlite3Strlen30(zName), 0 |
| 80503 | 80642 | ); |
| 80504 | 80643 | assert( db==0 || sqlite3SchemaMutexHeld(db, 0, pIndex->pSchema) ); |
| 80505 | 80644 | assert( pOld==pIndex || pOld==0 ); |
| 80506 | 80645 | } |
| 80507 | 80646 | freeIndex(db, pIndex); |
| | @@ -84653,11 +84792,11 @@ |
| 84653 | 84792 | |
| 84654 | 84793 | /* Collect rowids of every row to be deleted. |
| 84655 | 84794 | */ |
| 84656 | 84795 | sqlite3VdbeAddOp2(v, OP_Null, 0, iRowSet); |
| 84657 | 84796 | pWInfo = sqlite3WhereBegin( |
| 84658 | | - pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK |
| 84797 | + pParse, pTabList, pWhere, 0, 0, WHERE_DUPLICATES_OK, 0 |
| 84659 | 84798 | ); |
| 84660 | 84799 | if( pWInfo==0 ) goto delete_from_cleanup; |
| 84661 | 84800 | regRowid = sqlite3ExprCodeGetColumn(pParse, pTab, -1, iCur, iRowid, 0); |
| 84662 | 84801 | sqlite3VdbeAddOp2(v, OP_RowSetAdd, iRowSet, regRowid); |
| 84663 | 84802 | if( db->flags & SQLITE_CountRows ){ |
| | @@ -87121,11 +87260,11 @@ |
| 87121 | 87260 | |
| 87122 | 87261 | /* Create VDBE to loop through the entries in pSrc that match the WHERE |
| 87123 | 87262 | ** clause. If the constraint is not deferred, throw an exception for |
| 87124 | 87263 | ** each row found. Otherwise, for deferred constraints, increment the |
| 87125 | 87264 | ** deferred constraint counter by nIncr for each row selected. */ |
| 87126 | | - pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0); |
| 87265 | + pWInfo = sqlite3WhereBegin(pParse, pSrc, pWhere, 0, 0, 0, 0); |
| 87127 | 87266 | if( nIncr>0 && pFKey->isDeferred==0 ){ |
| 87128 | 87267 | sqlite3ParseToplevel(pParse)->mayAbort = 1; |
| 87129 | 87268 | } |
| 87130 | 87269 | sqlite3VdbeAddOp2(v, OP_FkCounter, pFKey->isDeferred, nIncr); |
| 87131 | 87270 | if( pWInfo ){ |
| | @@ -96539,11 +96678,11 @@ |
| 96539 | 96678 | pExpr = p->pEList->a[0].pExpr; |
| 96540 | 96679 | assert( pTab && !pTab->pSelect && pExpr ); |
| 96541 | 96680 | |
| 96542 | 96681 | if( IsVirtual(pTab) ) return 0; |
| 96543 | 96682 | if( pExpr->op!=TK_AGG_FUNCTION ) return 0; |
| 96544 | | - if( pAggInfo->nFunc==0 ) return 0; |
| 96683 | + if( NEVER(pAggInfo->nFunc==0) ) return 0; |
| 96545 | 96684 | if( (pAggInfo->aFunc[0].pFunc->flags&SQLITE_FUNC_COUNT)==0 ) return 0; |
| 96546 | 96685 | if( pExpr->flags&EP_Distinct ) return 0; |
| 96547 | 96686 | |
| 96548 | 96687 | return pTab; |
| 96549 | 96688 | } |
| | @@ -96911,11 +97050,11 @@ |
| 96911 | 97050 | #endif |
| 96912 | 97051 | } |
| 96913 | 97052 | |
| 96914 | 97053 | |
| 96915 | 97054 | /* |
| 96916 | | -** This routine sets of a SELECT statement for processing. The |
| 97055 | +** This routine sets up a SELECT statement for processing. The |
| 96917 | 97056 | ** following is accomplished: |
| 96918 | 97057 | ** |
| 96919 | 97058 | ** * VDBE Cursor numbers are assigned to all FROM-clause terms. |
| 96920 | 97059 | ** * Ephemeral Table objects are created for all FROM-clause subqueries. |
| 96921 | 97060 | ** * ON and USING clauses are shifted into WHERE statements |
| | @@ -96943,11 +97082,12 @@ |
| 96943 | 97082 | /* |
| 96944 | 97083 | ** Reset the aggregate accumulator. |
| 96945 | 97084 | ** |
| 96946 | 97085 | ** The aggregate accumulator is a set of memory cells that hold |
| 96947 | 97086 | ** intermediate results while calculating an aggregate. This |
| 96948 | | -** routine simply stores NULLs in all of those memory cells. |
| 97087 | +** routine generates code that stores NULLs in all of those memory |
| 97088 | +** cells. |
| 96949 | 97089 | */ |
| 96950 | 97090 | static void resetAccumulator(Parse *pParse, AggInfo *pAggInfo){ |
| 96951 | 97091 | Vdbe *v = pParse->pVdbe; |
| 96952 | 97092 | int i; |
| 96953 | 97093 | struct AggInfo_func *pFunc; |
| | @@ -97413,11 +97553,11 @@ |
| 97413 | 97553 | /* Aggregate and non-aggregate queries are handled differently */ |
| 97414 | 97554 | if( !isAgg && pGroupBy==0 ){ |
| 97415 | 97555 | ExprList *pDist = (isDistinct ? p->pEList : 0); |
| 97416 | 97556 | |
| 97417 | 97557 | /* Begin the database scan. */ |
| 97418 | | - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy, pDist, 0); |
| 97558 | + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pOrderBy, pDist, 0,0); |
| 97419 | 97559 | if( pWInfo==0 ) goto select_end; |
| 97420 | 97560 | if( pWInfo->nRowOut < p->nSelectRow ) p->nSelectRow = pWInfo->nRowOut; |
| 97421 | 97561 | |
| 97422 | 97562 | /* If sorting index that was created by a prior OP_OpenEphemeral |
| 97423 | 97563 | ** instruction ended up not being needed, then change the OP_OpenEphemeral |
| | @@ -97586,11 +97726,11 @@ |
| 97586 | 97726 | ** This might involve two separate loops with an OP_Sort in between, or |
| 97587 | 97727 | ** it might be a single loop that uses an index to extract information |
| 97588 | 97728 | ** in the right order to begin with. |
| 97589 | 97729 | */ |
| 97590 | 97730 | sqlite3VdbeAddOp2(v, OP_Gosub, regReset, addrReset); |
| 97591 | | - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy, 0, 0); |
| 97731 | + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pGroupBy, 0, 0, 0); |
| 97592 | 97732 | if( pWInfo==0 ) goto select_end; |
| 97593 | 97733 | if( pGroupBy==0 ){ |
| 97594 | 97734 | /* The optimizer is able to deliver rows in group by order so |
| 97595 | 97735 | ** we do not have to sort. The OP_OpenEphemeral table will be |
| 97596 | 97736 | ** cancelled later because we still need to use the pKeyInfo |
| | @@ -97855,11 +97995,11 @@ |
| 97855 | 97995 | /* This case runs if the aggregate has no GROUP BY clause. The |
| 97856 | 97996 | ** processing is much simpler since there is only a single row |
| 97857 | 97997 | ** of output. |
| 97858 | 97998 | */ |
| 97859 | 97999 | resetAccumulator(pParse, &sAggInfo); |
| 97860 | | - pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pMinMax, 0, flag); |
| 98000 | + pWInfo = sqlite3WhereBegin(pParse, pTabList, pWhere, &pMinMax,0,flag,0); |
| 97861 | 98001 | if( pWInfo==0 ){ |
| 97862 | 98002 | sqlite3ExprListDelete(db, pDel); |
| 97863 | 98003 | goto select_end; |
| 97864 | 98004 | } |
| 97865 | 98005 | updateAccumulator(pParse, &sAggInfo); |
| | @@ -99655,11 +99795,11 @@ |
| 99655 | 99795 | |
| 99656 | 99796 | /* Begin the database scan |
| 99657 | 99797 | */ |
| 99658 | 99798 | sqlite3VdbeAddOp3(v, OP_Null, 0, regRowSet, regOldRowid); |
| 99659 | 99799 | pWInfo = sqlite3WhereBegin( |
| 99660 | | - pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED |
| 99800 | + pParse, pTabList, pWhere, 0, 0, WHERE_ONEPASS_DESIRED, 0 |
| 99661 | 99801 | ); |
| 99662 | 99802 | if( pWInfo==0 ) goto update_cleanup; |
| 99663 | 99803 | okOnePass = pWInfo->okOnePass; |
| 99664 | 99804 | |
| 99665 | 99805 | /* Remember the rowid of every item to be updated. |
| | @@ -105084,11 +105224,11 @@ |
| 105084 | 105224 | assert( pIdx->nColumn>=nEq ); |
| 105085 | 105225 | for(j=0; j<nEq; j++){ |
| 105086 | 105226 | int r1; |
| 105087 | 105227 | int k = pIdx->aiColumn[j]; |
| 105088 | 105228 | pTerm = findTerm(pWC, iCur, k, notReady, pLevel->plan.wsFlags, pIdx); |
| 105089 | | - if( NEVER(pTerm==0) ) break; |
| 105229 | + if( pTerm==0 ) break; |
| 105090 | 105230 | /* The following true for indices with redundant columns. |
| 105091 | 105231 | ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */ |
| 105092 | 105232 | testcase( (pTerm->wtFlags & TERM_CODED)!=0 ); |
| 105093 | 105233 | testcase( pTerm->wtFlags & TERM_VIRTUAL ); /* EV: R-30575-11662 */ |
| 105094 | 105234 | r1 = codeEqualityTerm(pParse, pTerm, pLevel, regBase+j); |
| | @@ -105759,10 +105899,12 @@ |
| 105759 | 105899 | ** B: <after the loop> |
| 105760 | 105900 | ** |
| 105761 | 105901 | */ |
| 105762 | 105902 | WhereClause *pOrWc; /* The OR-clause broken out into subterms */ |
| 105763 | 105903 | SrcList *pOrTab; /* Shortened table list or OR-clause generation */ |
| 105904 | + Index *pCov = 0; /* Potential covering index (or NULL) */ |
| 105905 | + int iCovCur = pParse->nTab++; /* Cursor used for index scans (if any) */ |
| 105764 | 105906 | |
| 105765 | 105907 | int regReturn = ++pParse->nMem; /* Register used with OP_Gosub */ |
| 105766 | 105908 | int regRowset = 0; /* Register for RowSet object */ |
| 105767 | 105909 | int regRowid = 0; /* Register holding rowid */ |
| 105768 | 105910 | int iLoopBody = sqlite3VdbeMakeLabel(v); /* Start of loop body */ |
| | @@ -105777,11 +105919,11 @@ |
| 105777 | 105919 | assert( (pTerm->wtFlags & TERM_ORINFO)!=0 ); |
| 105778 | 105920 | pOrWc = &pTerm->u.pOrInfo->wc; |
| 105779 | 105921 | pLevel->op = OP_Return; |
| 105780 | 105922 | pLevel->p1 = regReturn; |
| 105781 | 105923 | |
| 105782 | | - /* Set up a new SrcList ni pOrTab containing the table being scanned |
| 105924 | + /* Set up a new SrcList in pOrTab containing the table being scanned |
| 105783 | 105925 | ** by this loop in the a[0] slot and all notReady tables in a[1..] slots. |
| 105784 | 105926 | ** This becomes the SrcList in the recursive call to sqlite3WhereBegin(). |
| 105785 | 105927 | */ |
| 105786 | 105928 | if( pWInfo->nLevel>1 ){ |
| 105787 | 105929 | int nNotReady; /* The number of notReady tables */ |
| | @@ -105854,12 +105996,14 @@ |
| 105854 | 105996 | pOrExpr = pAndExpr; |
| 105855 | 105997 | } |
| 105856 | 105998 | /* Loop through table entries that match term pOrTerm. */ |
| 105857 | 105999 | pSubWInfo = sqlite3WhereBegin(pParse, pOrTab, pOrExpr, 0, 0, |
| 105858 | 106000 | WHERE_OMIT_OPEN_CLOSE | WHERE_AND_ONLY | |
| 105859 | | - WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY); |
| 106001 | + WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY, iCovCur); |
| 106002 | + assert( pSubWInfo || pParse->nErr || pParse->db->mallocFailed ); |
| 105860 | 106003 | if( pSubWInfo ){ |
| 106004 | + WhereLevel *pLvl; |
| 105861 | 106005 | explainOneScan( |
| 105862 | 106006 | pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0 |
| 105863 | 106007 | ); |
| 105864 | 106008 | if( (wctrlFlags & WHERE_DUPLICATES_OK)==0 ){ |
| 105865 | 106009 | int iSet = ((ii==pOrWc->nTerm-1)?-1:ii); |
| | @@ -105875,16 +106019,41 @@ |
| 105875 | 106019 | ** contained one or more AND term from a notReady table. The |
| 105876 | 106020 | ** terms from the notReady table could not be tested and will |
| 105877 | 106021 | ** need to be tested later. |
| 105878 | 106022 | */ |
| 105879 | 106023 | if( pSubWInfo->untestedTerms ) untestedTerms = 1; |
| 106024 | + |
| 106025 | + /* If all of the OR-connected terms are optimized using the same |
| 106026 | + ** index, and the index is opened using the same cursor number |
| 106027 | + ** by each call to sqlite3WhereBegin() made by this loop, it may |
| 106028 | + ** be possible to use that index as a covering index. |
| 106029 | + ** |
| 106030 | + ** If the call to sqlite3WhereBegin() above resulted in a scan that |
| 106031 | + ** uses an index, and this is either the first OR-connected term |
| 106032 | + ** processed or the index is the same as that used by all previous |
| 106033 | + ** terms, set pCov to the candidate covering index. Otherwise, set |
| 106034 | + ** pCov to NULL to indicate that no candidate covering index will |
| 106035 | + ** be available. |
| 106036 | + */ |
| 106037 | + pLvl = &pSubWInfo->a[0]; |
| 106038 | + if( (pLvl->plan.wsFlags & WHERE_INDEXED)!=0 |
| 106039 | + && (pLvl->plan.wsFlags & WHERE_TEMP_INDEX)==0 |
| 106040 | + && (ii==0 || pLvl->plan.u.pIdx==pCov) |
| 106041 | + ){ |
| 106042 | + assert( pLvl->iIdxCur==iCovCur ); |
| 106043 | + pCov = pLvl->plan.u.pIdx; |
| 106044 | + }else{ |
| 106045 | + pCov = 0; |
| 106046 | + } |
| 105880 | 106047 | |
| 105881 | 106048 | /* Finish the loop through table entries that match term pOrTerm. */ |
| 105882 | 106049 | sqlite3WhereEnd(pSubWInfo); |
| 105883 | 106050 | } |
| 105884 | 106051 | } |
| 105885 | 106052 | } |
| 106053 | + pLevel->u.pCovidx = pCov; |
| 106054 | + pLevel->iIdxCur = iCovCur; |
| 105886 | 106055 | if( pAndExpr ){ |
| 105887 | 106056 | pAndExpr->pLeft = 0; |
| 105888 | 106057 | sqlite3ExprDelete(pParse->db, pAndExpr); |
| 105889 | 106058 | } |
| 105890 | 106059 | sqlite3VdbeChangeP1(v, iRetInit, sqlite3VdbeCurrentAddr(v)); |
| | @@ -106098,11 +106267,12 @@ |
| 106098 | 106267 | Parse *pParse, /* The parser context */ |
| 106099 | 106268 | SrcList *pTabList, /* A list of all tables to be scanned */ |
| 106100 | 106269 | Expr *pWhere, /* The WHERE clause */ |
| 106101 | 106270 | ExprList **ppOrderBy, /* An ORDER BY clause, or NULL */ |
| 106102 | 106271 | ExprList *pDistinct, /* The select-list for DISTINCT queries - or NULL */ |
| 106103 | | - u16 wctrlFlags /* One of the WHERE_* flags defined in sqliteInt.h */ |
| 106272 | + u16 wctrlFlags, /* One of the WHERE_* flags defined in sqliteInt.h */ |
| 106273 | + int iIdxCur /* If WHERE_ONETABLE_ONLY is set, index cursor number */ |
| 106104 | 106274 | ){ |
| 106105 | 106275 | int i; /* Loop counter */ |
| 106106 | 106276 | int nByteWInfo; /* Num. bytes allocated for WhereInfo struct */ |
| 106107 | 106277 | int nTabList; /* Number of elements in pTabList */ |
| 106108 | 106278 | WhereInfo *pWInfo; /* Will become the return value of this function */ |
| | @@ -106418,11 +106588,17 @@ |
| 106418 | 106588 | andFlags &= bestPlan.plan.wsFlags; |
| 106419 | 106589 | pLevel->plan = bestPlan.plan; |
| 106420 | 106590 | testcase( bestPlan.plan.wsFlags & WHERE_INDEXED ); |
| 106421 | 106591 | testcase( bestPlan.plan.wsFlags & WHERE_TEMP_INDEX ); |
| 106422 | 106592 | if( bestPlan.plan.wsFlags & (WHERE_INDEXED|WHERE_TEMP_INDEX) ){ |
| 106423 | | - pLevel->iIdxCur = pParse->nTab++; |
| 106593 | + if( (wctrlFlags & WHERE_ONETABLE_ONLY) |
| 106594 | + && (bestPlan.plan.wsFlags & WHERE_TEMP_INDEX)==0 |
| 106595 | + ){ |
| 106596 | + pLevel->iIdxCur = iIdxCur; |
| 106597 | + }else{ |
| 106598 | + pLevel->iIdxCur = pParse->nTab++; |
| 106599 | + } |
| 106424 | 106600 | }else{ |
| 106425 | 106601 | pLevel->iIdxCur = -1; |
| 106426 | 106602 | } |
| 106427 | 106603 | notReady &= ~getMask(pMaskSet, pTabList->a[bestJ].iCursor); |
| 106428 | 106604 | pLevel->iFrom = (u8)bestJ; |
| | @@ -106670,10 +106846,11 @@ |
| 106670 | 106846 | |
| 106671 | 106847 | /* Close all of the cursors that were opened by sqlite3WhereBegin. |
| 106672 | 106848 | */ |
| 106673 | 106849 | assert( pWInfo->nLevel==1 || pWInfo->nLevel==pTabList->nSrc ); |
| 106674 | 106850 | for(i=0, pLevel=pWInfo->a; i<pWInfo->nLevel; i++, pLevel++){ |
| 106851 | + Index *pIdx = 0; |
| 106675 | 106852 | struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom]; |
| 106676 | 106853 | Table *pTab = pTabItem->pTab; |
| 106677 | 106854 | assert( pTab!=0 ); |
| 106678 | 106855 | if( (pTab->tabFlags & TF_Ephemeral)==0 |
| 106679 | 106856 | && pTab->pSelect==0 |
| | @@ -106699,16 +106876,19 @@ |
| 106699 | 106876 | ** sqlite3WhereEnd will have created code that references the table |
| 106700 | 106877 | ** directly. This loop scans all that code looking for opcodes |
| 106701 | 106878 | ** that reference the table and converts them into opcodes that |
| 106702 | 106879 | ** reference the index. |
| 106703 | 106880 | */ |
| 106704 | | - if( (pLevel->plan.wsFlags & WHERE_INDEXED)!=0 && !db->mallocFailed){ |
| 106881 | + if( pLevel->plan.wsFlags & WHERE_INDEXED ){ |
| 106882 | + pIdx = pLevel->plan.u.pIdx; |
| 106883 | + }else if( pLevel->plan.wsFlags & WHERE_MULTI_OR ){ |
| 106884 | + pIdx = pLevel->u.pCovidx; |
| 106885 | + } |
| 106886 | + if( pIdx && !db->mallocFailed){ |
| 106705 | 106887 | int k, j, last; |
| 106706 | 106888 | VdbeOp *pOp; |
| 106707 | | - Index *pIdx = pLevel->plan.u.pIdx; |
| 106708 | 106889 | |
| 106709 | | - assert( pIdx!=0 ); |
| 106710 | 106890 | pOp = sqlite3VdbeGetOp(v, pWInfo->iTop); |
| 106711 | 106891 | last = sqlite3VdbeCurrentAddr(v); |
| 106712 | 106892 | for(k=pWInfo->iTop; k<last; k++, pOp++){ |
| 106713 | 106893 | if( pOp->p1!=pLevel->iTabCur ) continue; |
| 106714 | 106894 | if( pOp->opcode==OP_Column ){ |
| | @@ -115878,14 +116058,24 @@ |
| 115878 | 116058 | SQLITE_PRIVATE int sqlite3Fts3ReadBlock(Fts3Table*, sqlite3_int64, char **, int*, int*); |
| 115879 | 116059 | |
| 115880 | 116060 | SQLITE_PRIVATE int sqlite3Fts3SelectDoctotal(Fts3Table *, sqlite3_stmt **); |
| 115881 | 116061 | SQLITE_PRIVATE int sqlite3Fts3SelectDocsize(Fts3Table *, sqlite3_int64, sqlite3_stmt **); |
| 115882 | 116062 | |
| 116063 | +#ifndef SQLITE_DISABLE_FTS4_DEFERRED |
| 115883 | 116064 | SQLITE_PRIVATE void sqlite3Fts3FreeDeferredTokens(Fts3Cursor *); |
| 115884 | 116065 | SQLITE_PRIVATE int sqlite3Fts3DeferToken(Fts3Cursor *, Fts3PhraseToken *, int); |
| 115885 | 116066 | SQLITE_PRIVATE int sqlite3Fts3CacheDeferredDoclists(Fts3Cursor *); |
| 115886 | 116067 | SQLITE_PRIVATE void sqlite3Fts3FreeDeferredDoclists(Fts3Cursor *); |
| 116068 | +SQLITE_PRIVATE int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, int *); |
| 116069 | +#else |
| 116070 | +# define sqlite3Fts3FreeDeferredTokens(x) |
| 116071 | +# define sqlite3Fts3DeferToken(x,y,z) SQLITE_OK |
| 116072 | +# define sqlite3Fts3CacheDeferredDoclists(x) SQLITE_OK |
| 116073 | +# define sqlite3Fts3FreeDeferredDoclists(x) |
| 116074 | +# define sqlite3Fts3DeferredTokenList(x,y,z) SQLITE_OK |
| 116075 | +#endif |
| 116076 | + |
| 115887 | 116077 | SQLITE_PRIVATE void sqlite3Fts3SegmentsClose(Fts3Table *); |
| 115888 | 116078 | SQLITE_PRIVATE int sqlite3Fts3MaxLevel(Fts3Table *, int *); |
| 115889 | 116079 | |
| 115890 | 116080 | /* Special values interpreted by sqlite3SegReaderCursor() */ |
| 115891 | 116081 | #define FTS3_SEGCURSOR_PENDING -1 |
| | @@ -115990,12 +116180,10 @@ |
| 115990 | 116180 | Fts3Table *, Fts3MultiSegReader *, sqlite3_int64 *, char **, int *); |
| 115991 | 116181 | SQLITE_PRIVATE int sqlite3Fts3EvalPhrasePoslist(Fts3Cursor *, Fts3Expr *, int iCol, char **); |
| 115992 | 116182 | SQLITE_PRIVATE int sqlite3Fts3MsrOvfl(Fts3Cursor *, Fts3MultiSegReader *, int *); |
| 115993 | 116183 | SQLITE_PRIVATE int sqlite3Fts3MsrIncrRestart(Fts3MultiSegReader *pCsr); |
| 115994 | 116184 | |
| 115995 | | -SQLITE_PRIVATE int sqlite3Fts3DeferredTokenList(Fts3DeferredToken *, char **, int *); |
| 115996 | | - |
| 115997 | 116185 | /* fts3_unicode2.c (functions generated by parsing unicode text files) */ |
| 115998 | 116186 | #ifdef SQLITE_ENABLE_FTS4_UNICODE61 |
| 115999 | 116187 | SQLITE_PRIVATE int sqlite3FtsUnicodeFold(int, int); |
| 116000 | 116188 | SQLITE_PRIVATE int sqlite3FtsUnicodeIsalnum(int); |
| 116001 | 116189 | SQLITE_PRIVATE int sqlite3FtsUnicodeIsdiacritic(int); |
| | @@ -120149,10 +120337,11 @@ |
| 120149 | 120337 | |
| 120150 | 120338 | /* Allocate a MultiSegReader for each token in the expression. */ |
| 120151 | 120339 | fts3EvalAllocateReaders(pCsr, pCsr->pExpr, &nToken, &nOr, &rc); |
| 120152 | 120340 | |
| 120153 | 120341 | /* Determine which, if any, tokens in the expression should be deferred. */ |
| 120342 | +#ifndef SQLITE_DISABLE_FTS4_DEFERRED |
| 120154 | 120343 | if( rc==SQLITE_OK && nToken>1 && pTab->bFts4 ){ |
| 120155 | 120344 | Fts3TokenAndCost *aTC; |
| 120156 | 120345 | Fts3Expr **apOr; |
| 120157 | 120346 | aTC = (Fts3TokenAndCost *)sqlite3_malloc( |
| 120158 | 120347 | sizeof(Fts3TokenAndCost) * nToken |
| | @@ -120179,10 +120368,11 @@ |
| 120179 | 120368 | } |
| 120180 | 120369 | |
| 120181 | 120370 | sqlite3_free(aTC); |
| 120182 | 120371 | } |
| 120183 | 120372 | } |
| 120373 | +#endif |
| 120184 | 120374 | |
| 120185 | 120375 | fts3EvalStartReaders(pCsr, pCsr->pExpr, 1, &rc); |
| 120186 | 120376 | return rc; |
| 120187 | 120377 | } |
| 120188 | 120378 | |
| | @@ -120562,10 +120752,11 @@ |
| 120562 | 120752 | && !fts3EvalTestExpr(pCsr, pExpr->pRight, pRc) |
| 120563 | 120753 | ); |
| 120564 | 120754 | break; |
| 120565 | 120755 | |
| 120566 | 120756 | default: { |
| 120757 | +#ifndef SQLITE_DISABLE_FTS4_DEFERRED |
| 120567 | 120758 | if( pCsr->pDeferred |
| 120568 | 120759 | && (pExpr->iDocid==pCsr->iPrevId || pExpr->bDeferred) |
| 120569 | 120760 | ){ |
| 120570 | 120761 | Fts3Phrase *pPhrase = pExpr->pPhrase; |
| 120571 | 120762 | assert( pExpr->bDeferred || pPhrase->doclist.bFreeList==0 ); |
| | @@ -120573,11 +120764,13 @@ |
| 120573 | 120764 | fts3EvalInvalidatePoslist(pPhrase); |
| 120574 | 120765 | } |
| 120575 | 120766 | *pRc = fts3EvalDeferredPhrase(pCsr, pPhrase); |
| 120576 | 120767 | bHit = (pPhrase->doclist.pList!=0); |
| 120577 | 120768 | pExpr->iDocid = pCsr->iPrevId; |
| 120578 | | - }else{ |
| 120769 | + }else |
| 120770 | +#endif |
| 120771 | + { |
| 120579 | 120772 | bHit = (pExpr->bEof==0 && pExpr->iDocid==pCsr->iPrevId); |
| 120580 | 120773 | } |
| 120581 | 120774 | break; |
| 120582 | 120775 | } |
| 120583 | 120776 | } |
| | @@ -129349,10 +129542,11 @@ |
| 129349 | 129542 | } |
| 129350 | 129543 | |
| 129351 | 129544 | return rc; |
| 129352 | 129545 | } |
| 129353 | 129546 | |
| 129547 | +#ifndef SQLITE_DISABLE_FTS4_DEFERRED |
| 129354 | 129548 | /* |
| 129355 | 129549 | ** Delete all cached deferred doclists. Deferred doclists are cached |
| 129356 | 129550 | ** (allocated) by the sqlite3Fts3CacheDeferredDoclists() function. |
| 129357 | 129551 | */ |
| 129358 | 129552 | SQLITE_PRIVATE void sqlite3Fts3FreeDeferredDoclists(Fts3Cursor *pCsr){ |
| | @@ -129486,10 +129680,11 @@ |
| 129486 | 129680 | assert( pToken->pDeferred==0 ); |
| 129487 | 129681 | pToken->pDeferred = pDeferred; |
| 129488 | 129682 | |
| 129489 | 129683 | return SQLITE_OK; |
| 129490 | 129684 | } |
| 129685 | +#endif |
| 129491 | 129686 | |
| 129492 | 129687 | /* |
| 129493 | 129688 | ** SQLite value pRowid contains the rowid of a row that may or may not be |
| 129494 | 129689 | ** present in the FTS3 table. If it is, delete it and adjust the contents |
| 129495 | 129690 | ** of subsiduary data structures accordingly. |
| 129496 | 129691 | |