Enhance the use of the column cache for UPDATE statements, making them
more efficient for the case where a column is modified to be an expression
of other unmodified columns.
check-in: 871e091d user: drh tags: trunk

#!/usr/make## Makefile for SQLITE## This is a template makefile for SQLite. Most people prefer to# use the autoconf generated "configure" script to generate the# makefile automatically. But that does not work for everybody# and in every situation. If you are having problems with the# "configure" script, you might want to try this makefile as an# alternative. Create a copy of this file, edit the parameters# below and type "make".##### The directory where to find the mingw32ce toolsMINGW32CE = /opt/mingw32ce/bin#### The target prefix of the mingw32ce toolsTARGET = arm-wince-mingw32ce#### The toplevel directory of the source tree. This is the directory# that contains this "Makefile.in" and the "configure.in" script.#TOP = ../sqlite#### C Compiler and options for use in building executables that# will run on the platform that is doing the build.#BCC = gcc -g -O2#BCC = /opt/ancic/bin/c89 -0#### If the target operating system supports the "usleep()" system# call, then define the HAVE_USLEEP macro for all C modules.#USLEEP = #USLEEP = -DHAVE_USLEEP=1#### If you want the SQLite library to be safe for use within a # multi-threaded program, then define the following macro# appropriately:#THREADSAFE = -DTHREADSAFE=1#THREADSAFE = -DTHREADSAFE=0#### Specify any extra linker options needed to make the library# thread safe##THREADLIB = -lpthreadTHREADLIB = #### Specify any extra libraries needed to access required functions.##TLIBS = -lrt # fdatasync on Solaris 8TLIBS = #### Leave SQLITE_DEBUG undefined for maximum speed. Use SQLITE_DEBUG=1# to check for memory leaks. Use SQLITE_DEBUG=2 to print a log of all# malloc()s and free()s in order to track down memory leaks.# # SQLite uses some expensive assert() statements in the inner loop.# You can make the library go almost twice as fast if you compile# with -DNDEBUG=1##OPTS = -DSQLITE_DEBUG=2#OPTS = -DSQLITE_DEBUG=1#OPTS = OPTS = -DNDEBUG=1 -DSQLITE_OS_WIN=1 -D_WIN32_WCE=1#OPTS += -DHAVE_FDATASYNC=1#### The suffix to add to executable files. ".exe" for windows.# Nothing for unix.#EXE = .exe#EXE =#### C Compile and options for use in building executables that # will run on the target platform. This is usually the same# as BCC, unless you are cross-compiling.##TCC = gcc -O6#TCC = gcc -g -O0 -Wall#TCC = gcc -g -O0 -Wall -fprofile-arcs -ftest-coverage#TCC = /opt/mingw/bin/i386-mingw32-gcc -O6TCC = $(MINGW32CE)/$(TARGET)-gcc -O2#TCC = /opt/ansic/bin/c89 -O +z -Wl,-a,archive#### Tools used to build a static library.##AR = ar cr#AR = /opt/mingw/bin/i386-mingw32-ar crAR = $(MINGW32CE)/$(TARGET)-ar cr#RANLIB = ranlib#RANLIB = /opt/mingw/bin/i386-mingw32-ranlibRANLIB = $(MINGW32CE)/$(TARGET)-ranlib#MKSHLIB = gcc -shared#SO = so#SHPREFIX = libMKSHLIB = $(MINGW32CE)/$(TARGET)-gcc -sharedSO = dllSHPREFIX =#### Extra compiler options needed for programs that use the TCL library.##TCL_FLAGS =#TCL_FLAGS = -DSTATIC_BUILD=1TCL_FLAGS = -I/home/drh/tcltk/8.5linux#TCL_FLAGS = -I/home/drh/tcltk/8.5win -DSTATIC_BUILD=1#TCL_FLAGS = -I/home/drh/tcltk/8.3hpux#### Linker options needed to link against the TCL library.##LIBTCL = -ltcl -lm -ldlLIBTCL = /home/drh/tcltk/8.5linux/libtcl8.5g.a -lm -ldl#LIBTCL = /home/drh/tcltk/8.5win/libtcl85s.a -lmsvcrt#LIBTCL = /home/drh/tcltk/8.3hpux/libtcl8.3.a -ldld -lm -lc#### Additional objects for SQLite library when TCL support is enabled.TCLOBJ =#TCLOBJ = tclsqlite.o#### Compiler options needed for programs that use the readline() library.#READLINE_FLAGS =#READLINE_FLAGS = -DHAVE_READLINE=1 -I/usr/include/readline#### Linker options needed by programs using readline() must link against.#LIBREADLINE =#LIBREADLINE = -static -lreadline -ltermcap#### Which "awk" program provides nawk compatibilty## NAWK = nawkNAWK = awk# You should not have to change anything below this line###############################################################################include $(TOP)/main.mk

** May you share freely, never taking more than you give.
**
******************************************************************************
*/
#include "fts5Int.h"
#include <math.h>
/*
** Object used to iterate through all "coalesced phrase instances" in
** a single column of the current row. If the phrase instances in the
** column being considered do not overlap, this object simply iterates
** through them. Or, if they do overlap (share one or more tokens in
** common), each set of overlapping instances is treated as a single
................................................................................
*/
static void fts5HighlightAppend(
int *pRc,
HighlightContext *p,
const char *z, int n
){
if( *pRc==SQLITE_OK ){
if( n<0 ) n = strlen(z);
p->zOut = sqlite3_mprintf("%z%.*s", p->zOut, n, z);
if( p->zOut==0 ) *pRc = SQLITE_NOMEM;
}
}
/*
** Tokenizer callback used by implementation of highlight() function.

** May you share freely, never taking more than you give.
**
******************************************************************************
*/
#include "fts5Int.h"
#include <math.h> /* amalgamator: keep */
/*
** Object used to iterate through all "coalesced phrase instances" in
** a single column of the current row. If the phrase instances in the
** column being considered do not overlap, this object simply iterates
** through them. Or, if they do overlap (share one or more tokens in
** common), each set of overlapping instances is treated as a single
................................................................................
*/
static void fts5HighlightAppend(
int *pRc,
HighlightContext *p,
const char *z, int n
){
if( *pRc==SQLITE_OK ){
if( n<0 ) n = (int)strlen(z);
p->zOut = sqlite3_mprintf("%z%.*s", p->zOut, n, z);
if( p->zOut==0 ) *pRc = SQLITE_NOMEM;
}
}
/*
** Tokenizer callback used by implementation of highlight() function.

** from this function, not directly by the user.
*/
memset(&b, 0, sizeof(b));
b.pSrcDb = pFrom->db;
b.pSrc = pFrom;
b.pDest = pTo;
b.iNext = 1;
/* 0x7FFFFFFF is the hard limit for the number of pages in a database
** file. By passing this as the number of pages to copy to
** sqlite3_backup_step(), we can guarantee that the copy finishes
** within a single call (unless an error occurs). The assert() statement
** checks this assumption - (p->rc) should be set to either SQLITE_DONE
** or an error code.

** from this function, not directly by the user.
*/
memset(&b, 0, sizeof(b));
b.pSrcDb = pFrom->db;
b.pSrc = pFrom;
b.pDest = pTo;
b.iNext = 1;
#ifdef SQLITE_HAS_CODEC sqlite3PagerAlignReserve(sqlite3BtreePager(pTo), sqlite3BtreePager(pFrom));#endif
/* 0x7FFFFFFF is the hard limit for the number of pages in a database
** file. By passing this as the number of pages to copy to
** sqlite3_backup_step(), we can guarantee that the copy finishes
** within a single call (unless an error occurs). The assert() statement
** checks this assumption - (p->rc) should be set to either SQLITE_DONE
** or an error code.

sqlite3_result_text64,
sqlite3_strglob,
/* Version 3.8.11 and later */
(sqlite3_value*(*)(const sqlite3_value*))sqlite3_value_dup,
sqlite3_value_free,
sqlite3_result_zeroblob64,
sqlite3_bind_zeroblob64,
/* Version 3.8.12 and later */
sqlite3_value_subtype,
sqlite3_result_subtype
};
/*
** Attempt to load an SQLite extension library contained in the file
** zFile. The entry point is zProc. zProc may be 0 in which case a

|

404
405
406
407
408
409
410
411
412
413
414
415
416
417
418

sqlite3_result_text64,
sqlite3_strglob,
/* Version 3.8.11 and later */
(sqlite3_value*(*)(const sqlite3_value*))sqlite3_value_dup,
sqlite3_value_free,
sqlite3_result_zeroblob64,
sqlite3_bind_zeroblob64,
/* Version 3.9.0 and later */
sqlite3_value_subtype,
sqlite3_result_subtype
};
/*
** Attempt to load an SQLite extension library contained in the file
** zFile. The entry point is zProc. zProc may be 0 in which case a

** All loads and stores begun before the barrier must complete before
** any load or store begun after the barrier.
*/
static void winShmBarrier(
sqlite3_file *fd /* Database holding the shared memory */
){
UNUSED_PARAMETER(fd);
/* MemoryBarrier(); // does not work -- do not know why not */
winShmEnterMutex();
winShmLeaveMutex();
}
/*
** This function is called to obtain a pointer to region iRegion of the
** shared-memory associated with the database file fd. Shared-memory regions
** are numbered starting from zero. Each shared-memory region is szRegion

** All loads and stores begun before the barrier must complete before
** any load or store begun after the barrier.
*/
static void winShmBarrier(
sqlite3_file *fd /* Database holding the shared memory */
){
UNUSED_PARAMETER(fd);
sqlite3MemoryBarrier(); /* compiler-defined memory barrier */
winShmEnterMutex(); /* Also mutex, for redundancy */
winShmLeaveMutex();
}
/*
** This function is called to obtain a pointer to region iRegion of the
** shared-memory associated with the database file fd. Shared-memory regions
** are numbered starting from zero. Each shared-memory region is szRegion

Changes to src/pager.c.

2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124

pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize,
(int)pPager->nReserve);
}
}
#else
# define pagerReportSize(X) /* No-op if we do not support a codec */
#endif
/*
** Read a single page from either the journal file (if isMainJrnl==1) or
** from the sub-journal (if isMainJrnl==0) and playback that page.
** The page begins at offset *pOffset into the file. The *pOffset
** value is increased to the start of the next page in the journal.
**

pPager->xCodecSizeChng(pPager->pCodec, pPager->pageSize,
(int)pPager->nReserve);
}
}
#else
# define pagerReportSize(X) /* No-op if we do not support a codec */
#endif
#ifdef SQLITE_HAS_CODEC/*** Make sure the number of reserved bits is the same in the destination** pager as it is in the source. This comes up when a VACUUM changes the** number of reserved bits to the "optimal" amount.*/void sqlite3PagerAlignReserve(Pager *pDest, Pager *pSrc){ if( pDest->nReserve!=pSrc->nReserve ){ pDest->nReserve = pSrc->nReserve; pagerReportSize(pDest); }}#endif
/*
** Read a single page from either the journal file (if isMainJrnl==1) or
** from the sub-journal (if isMainJrnl==0) and playback that page.
** The page begins at offset *pOffset into the file. The *pOffset
** value is increased to the start of the next page in the journal.
**

const void *sqlite3_value_text16(sqlite3_value*);
const void *sqlite3_value_text16le(sqlite3_value*);
const void *sqlite3_value_text16be(sqlite3_value*);
int sqlite3_value_type(sqlite3_value*);
int sqlite3_value_numeric_type(sqlite3_value*);
/*
** CAPI3REF: Obtaining SQL Values
** METHOD: sqlite3_value
**
** The sqlite3_value_subtype(V) function returns the subtype for
** an [application-defined SQL function] argument V. The subtype
** information can be used to pass a limited amount of context from
** one SQL function to another. Use the [sqlite3_result_subtype()]
** routine to set the subtype for the return value of an SQL function.
................................................................................
** strategy. A cost of N indicates that the cost of the strategy is similar
** to a linear scan of an SQLite table with N rows. A cost of log(N)
** indicates that the expense of the operation is similar to that of a
** binary search on a unique indexed field of an SQLite table with N rows.
**
** ^The estimatedRows value is an estimate of the number of rows that
** will be returned by the strategy.
**
** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
** structure for SQLite version 3.8.2. If a virtual table extension is
** used with an SQLite version earlier than 3.8.2, the results of attempting
** to read or write the estimatedRows field are undefined (but are likely
** to included crashing the application). The estimatedRows field should
** therefore only be used if [sqlite3_libversion_number()] returns a
** value greater than or equal to 3008002.
*/
struct sqlite3_index_info {
/* Inputs */
int nConstraint; /* Number of entries in aConstraint */
struct sqlite3_index_constraint {
int iColumn; /* Column on left-hand side of constraint */
unsigned char op; /* Constraint operator */
................................................................................
int idxNum; /* Number used to identify the index */
char *idxStr; /* String, possibly obtained from sqlite3_malloc */
int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
int orderByConsumed; /* True if output is already ordered */
double estimatedCost; /* Estimated cost of using this index */
/* Fields below are only available in SQLite 3.8.2 and later */
sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
};
/*
** CAPI3REF: Virtual Table Constraint Operator Codes
**
** These macros defined the allowed values for the
** [sqlite3_index_info].aConstraint[].op field. Each value represents
** an operator that is part of a constraint term in the wHERE clause of
** a query that uses a [virtual table].
................................................................................
** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
** <dd>This parameter records the largest memory allocation request
** handed to [scratch memory allocator]. Only the value returned in the
** *pHighwater parameter to [sqlite3_status()] is of interest.
** The value written into the *pCurrent parameter is undefined.</dd>)^
**
** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
** <dd>This parameter records the deepest parser stack. It is only
** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
** </dl>
**
** New status parameters may be added from time to time.
*/
#define SQLITE_STATUS_MEMORY_USED 0
#define SQLITE_STATUS_PAGECACHE_USED 1

const void *sqlite3_value_text16(sqlite3_value*);
const void *sqlite3_value_text16le(sqlite3_value*);
const void *sqlite3_value_text16be(sqlite3_value*);
int sqlite3_value_type(sqlite3_value*);
int sqlite3_value_numeric_type(sqlite3_value*);
/*
** CAPI3REF: Finding The Subtype Of SQL Values
** METHOD: sqlite3_value
**
** The sqlite3_value_subtype(V) function returns the subtype for
** an [application-defined SQL function] argument V. The subtype
** information can be used to pass a limited amount of context from
** one SQL function to another. Use the [sqlite3_result_subtype()]
** routine to set the subtype for the return value of an SQL function.
................................................................................
** strategy. A cost of N indicates that the cost of the strategy is similar
** to a linear scan of an SQLite table with N rows. A cost of log(N)
** indicates that the expense of the operation is similar to that of a
** binary search on a unique indexed field of an SQLite table with N rows.
**
** ^The estimatedRows value is an estimate of the number of rows that
** will be returned by the strategy.
**** The xBestIndex method may optionally populate the idxFlags field with a ** mask of SQLITE_INDEX_SCAN_* flags. Currently there is only one such flag -** SQLITE_INDEX_SCAN_UNIQUE. If the xBestIndex method sets this flag, SQLite** assumes that the strategy may visit at most one row. **** Additionally, if xBestIndex sets the SQLITE_INDEX_SCAN_UNIQUE flag, then** SQLite also assumes that if a call to the xUpdate() method is made as** part of the same statement to delete or update a virtual table row and the** implementation returns SQLITE_CONSTRAINT, then there is no need to rollback** any database changes. In other words, if the xUpdate() returns** SQLITE_CONSTRAINT, the database contents must be exactly as they were** before xUpdate was called. By contrast, if SQLITE_INDEX_SCAN_UNIQUE is not** set and xUpdate returns SQLITE_CONSTRAINT, any database changes made by** the xUpdate method are automatically rolled back by SQLite.
**
** IMPORTANT: The estimatedRows field was added to the sqlite3_index_info
** structure for SQLite version 3.8.2. If a virtual table extension is
** used with an SQLite version earlier than 3.8.2, the results of attempting
** to read or write the estimatedRows field are undefined (but are likely
** to included crashing the application). The estimatedRows field should
** therefore only be used if [sqlite3_libversion_number()] returns a
** value greater than or equal to 3008002. Similarly, the idxFlags field** was added for version 3.9.0. It may therefore only be used if** sqlite3_libversion_number() returns a value greater than or equal to** 3009000.
*/
struct sqlite3_index_info {
/* Inputs */
int nConstraint; /* Number of entries in aConstraint */
struct sqlite3_index_constraint {
int iColumn; /* Column on left-hand side of constraint */
unsigned char op; /* Constraint operator */
................................................................................
int idxNum; /* Number used to identify the index */
char *idxStr; /* String, possibly obtained from sqlite3_malloc */
int needToFreeIdxStr; /* Free idxStr using sqlite3_free() if true */
int orderByConsumed; /* True if output is already ordered */
double estimatedCost; /* Estimated cost of using this index */
/* Fields below are only available in SQLite 3.8.2 and later */
sqlite3_int64 estimatedRows; /* Estimated number of rows returned */
/* Fields below are only available in SQLite 3.9.0 and later */ int idxFlags; /* Mask of SQLITE_INDEX_SCAN_* flags */
};
/*** CAPI3REF: Virtual Table Scan Flags*/#define SQLITE_INDEX_SCAN_UNIQUE 1 /* Scan visits at most 1 row */
/*
** CAPI3REF: Virtual Table Constraint Operator Codes
**
** These macros defined the allowed values for the
** [sqlite3_index_info].aConstraint[].op field. Each value represents
** an operator that is part of a constraint term in the wHERE clause of
** a query that uses a [virtual table].
................................................................................
** [[SQLITE_STATUS_SCRATCH_SIZE]] ^(<dt>SQLITE_STATUS_SCRATCH_SIZE</dt>
** <dd>This parameter records the largest memory allocation request
** handed to [scratch memory allocator]. Only the value returned in the
** *pHighwater parameter to [sqlite3_status()] is of interest.
** The value written into the *pCurrent parameter is undefined.</dd>)^
**
** [[SQLITE_STATUS_PARSER_STACK]] ^(<dt>SQLITE_STATUS_PARSER_STACK</dt>
** <dd>The *pHighwater parameter records the deepest parser stack.
** The *pCurrent value is undefined. The *pHighwater value is only
** meaningful if SQLite is compiled with [YYTRACKMAXSTACKDEPTH].</dd>)^
** </dl>
**
** New status parameters may be added from time to time.
*/
#define SQLITE_STATUS_MEMORY_USED 0
#define SQLITE_STATUS_PAGECACHE_USED 1