Lines Matching refs:Index
100 ** limits the size of a row in a table or index.
113 ** * Columns in an index
320 ** The number of samples of an index that SQLite takes in order to
1510 ** CAPI3REF: Maximum xShmLock index
2709 #define SQLITE_CREATE_INDEX 1 /* Index Name Table Name */
2711 #define SQLITE_CREATE_TEMP_INDEX 3 /* Index Name Table Name */
2718 #define SQLITE_DROP_INDEX 10 /* Index Name Table Name */
2720 #define SQLITE_DROP_TEMP_INDEX 12 /* Index Name Table Name */
2735 #define SQLITE_REINDEX 27 /* Index Name NULL */
3031 ** result set of a [SELECT] or the maximum number of columns in an index
3057 ** <dd>The maximum index number of any [parameter] in an SQL statement.)^
3286 ** ^The second argument is the index of the SQL parameter to be set.
3287 ** ^The leftmost SQL parameter has an index of 1. ^When the same named
3289 ** occurrences have the same index as the first occurrence.
3290 ** ^The index for named parameters can be looked up using the
3291 ** [sqlite3_bind_parameter_index()] API if desired. ^The index
3337 ** index is out of range. ^[SQLITE_NOMEM] is returned if malloc() fails.
3361 ** ^(This routine actually returns the index of the largest (rightmost)
3385 ** ^The first host parameter has an index of 1, not 0.
3400 ** CAPI3REF: Index Of A Parameter With A Given Name
3402 ** ^Return the index of an SQL parameter given its name. ^The
3403 ** index value returned is suitable for use as the second
3675 ** and the second argument is the index of the column for which information
3676 ** should be returned. ^The leftmost column of the result set has the index 0.
3681 ** column index is out of range, the result is undefined.
5089 ** ^(The index of the column is stored in
5143 int idxNum; /* Number used to identify the index */
5147 double estimatedCost; /* Estimated cost of using this index */
5316 ** ^It is not possible to open a column that is part of an index or primary
6077 ** an index.
6594 ** one exception. When executing a "DROP TABLE" or "DROP INDEX" statement,
6600 ** or "DROP INDEX" query, an infinite loop might be the result.
6605 ** the special "DROP TABLE/INDEX" case, the extended error code is just
7374 typedef struct Index Index;
7559 int iTable, /* Index of root page */
9075 #define SQLITE_IndexCover 0x10 /* Disable index covering table */
9371 ** If the table has an INTEGER PRIMARY KEY, then Table.iPKey is the index of
9380 ** database file. If Table.iDb is the index of the database table backend
9395 Index *pIndex; /* List of SQL indexes on this table. */
9476 int iFrom; /* Index of column in pFrom */
9524 ** comparison of the two index keys.
9536 ** single index record that has already been parsed out into individual
9541 ** the key of an index. A blob encoding of a record is created by
9567 ** Each SQL index is represented in memory by an
9572 ** we have the following table and index:
9575 ** CREATE INDEX Ex2 ON Ex1(c3,c1);
9578 ** three columns in the table. In the Index structure describing
9581 ** first column to be indexed (c3) has an index of 2 in Ex1.aCol[].
9582 ** The second column to be indexed (c1) has an index of 0 in
9585 ** The Index.onError field determines whether or not the indexed columns
9586 ** must be unique and what to do if they are not. When Index.onError=OE_None,
9587 ** it means this is not a unique index. Otherwise it is a unique index
9588 ** and the value of Index.onError indicate the which conflict resolution
9592 struct Index {
9593 char *zName; /* Name of this index */
9594 int nColumn; /* Number of columns in the table used by this index */
9595 int *aiColumn; /* Which columns are used by this index. 1st is 0 */
9598 int tnum; /* Page containing root of this index in database file */
9602 Index *pNext; /* The next index associated with the same table */
9603 Schema *pSchema; /* Schema containing this index */
9604 u8 *aSortOrder; /* Array of size Index.nColumn. True==DESC, False==ASC */
9605 char **azColl; /* Array of collation sequence names for index */
9640 ** pointer to this structure. The Expr.iColumn field is the index in
9651 u8 useSortingIdx; /* In direct mode, reference the sorting index rather
9653 int sortingIdx; /* Cursor number of the sorting index */
9655 int nSortingColumn; /* Number of columns in the sorting index */
9660 int iSorterColumn; /* Column number in the sorting index */
9730 ** character '?' in the original SQL) then the Expr.iTable holds the index
9788 ynVar iColumn; /* TK_COLUMN: column index. -1 for rowid.
9882 u16 iAlias; /* Index into Parse.aAlias[] for zName */
9902 ** CREATE INDEX idx ON t(a,b,c);
9915 int idx; /* Index in some Table.aCol[] of a column named zName */
9974 Index *pIndex; /* Index structure corresponding to zIndex, if any */
10009 Index *pIdx; /* Index when WHERE_INDEXED is true */
10011 sqlite3_index_info *pVtabIdx; /* Virtual table index to use */
10021 ** The pIdxInfo field is used to help pick the best index on a
10051 ** we need a place to cache virtual table index information for each
10056 sqlite3_index_info *pIdxInfo; /* Index info for n-th source table */
10069 #define WHERE_OMIT_CLOSE 0x0020 /* Omit close of table & index cursors */
10070 #define WHERE_FORCE_TABLE 0x0040 /* Do not use an index-only search */
10187 #define SRT_Union 1 /* Store result as keys in an index */
10188 #define SRT_Except 2 /* Remove result from a UNION index */
10197 #define SRT_Set 7 /* Store results as keys in an index */
10227 int iDb; /* Index in sqlite3.aDb[] of database holding pTab */
10830 SQLITE_PRIVATE Index *sqlite3CreateIndex(Parse*,Token*,Token*,SrcList*,ExprList*,int,Token*,
10867 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3*,const char*, const char*);
10898 SQLITE_PRIVATE int sqlite3GenerateIndexKey(Parse*, Index*, int, int, int);
11025 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *, Index *);
11090 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3*,Index*);
11091 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index*);
11098 SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *, Index *);
12013 int iDb; /* Index of cursor database in db->aDb[] (or -1) */
12022 Bool isIndex; /* True if an index containing keys only - no data */
12027 KeyInfo *pKeyInfo; /* Info about index keys needed by index cursors */
14926 ** We often identify a chunk by its index in mem3.aPool[]. When
14927 ** this is done, the chunk index refers to the second block of
14928 ** the chunk. In this way, the first chunk has an index of 1.
14929 ** A chunk index of 0 means "no such chunk" and is the equivalent
14949 u32 next; /* Index in mem3.aPool[] of next free chunk */
14950 u32 prev; /* Index in mem3.aPool[] of previous free chunk */
14985 ** iMaster is the index of the master chunk. Most new allocations
15025 ** Unlink the chunk at index i from
15059 ** Link the chunk at index i into either the appropriate
15619 int next; /* Index of next free chunk */
15620 int prev; /* Index of previous free chunk */
15764 ** entry and return its index.
15792 int i; /* Index of a mem5.aPool[] slot */
15793 int iBin; /* Index into mem5.aiFreelist[] */
15857 /* Set iBlock to the index of the block pointed to by pOld in
26257 ** When multiple threads all reference the same wal-index, each thread
26259 ** of this unixShmNode object. In other words, each wal-index is opened
26617 ** Check to see if it has been allocated (i.e. if the wal-index file is
31378 sqlite3_int64 sz; /* Current size of wal-index file */
31383 ** Check to see if it has been allocated (i.e. if the wal-index file is
32506 u32 iSize; /* Maximum bit index. Max iSize is 4,294,967,296. */
34818 ** heap-memory for the wal-index. Otherwise, if the argument is NULL or the
35254 Pgno iSubRec; /* Index of first record in sub-journal */
40909 ** index iSavepoint. If it is SAVEPOINT_ROLLBACK, then rollback all changes
40924 ** In any case, all savepoints with an index greater than iSavepoint
41055 ** has been removed (CREATE INDEX needs to move a page when a statement
41436 ** lock on the database file and use heap-memory to store the wal-index
41446 ** heap-memory for the wal-index instead of the VFS shared-memory
41687 ** To start a read transaction, the reader records the index of the last
41701 ** data structure called the wal-index is maintained to expedite the
41704 ** WAL-INDEX FORMAT
41706 ** Conceptually, the wal-index is shared memory, though VFS implementations
41707 ** might choose to implement the wal-index using a mmapped file. Because
41708 ** the wal-index is shared memory, SQLite does not support journal_mode=WAL
41712 ** The wal-index is transient. After a crash, the wal-index can (and should
41714 ** to either truncate or zero the header of the wal-index when the last
41715 ** connection to it closes. Because the wal-index is transient, it can
41718 ** as big endian, the wal-index can store multi-byte values in the native
41721 ** The purpose of the wal-index is to answer this question quickly: Given
41722 ** a page number P, return the index of the last frame for page P in the WAL,
41725 ** The wal-index consists of a header region, followed by an one or
41726 ** more index blocks.
41728 ** The wal-index header contains the total number of frames within the WAL
41731 ** Each index block except for the first contains information on
41732 ** HASHTABLE_NPAGE frames. The first index block contains information on
41734 ** HASHTABLE_NPAGE are selected so that together the wal-index header and
41735 ** first index block are the same size as all other index blocks in the
41736 ** wal-index.
41738 ** Each index block contains two sections, a page-mapping that contains the
41740 ** that allows readers to query an index block for a specific page number.
41742 ** for the first index block) 32-bit page numbers. The first entry in the
41743 ** first index-block contains the database page number corresponding to the
41744 ** first frame in the WAL file. The first entry in the second index block
41748 ** The last index block in a wal-index usually contains less than the full
41755 ** can be found by scanning the page-mapping sections of each index block
41756 ** starting with the last index block and moving toward the first, and
41757 ** within each index block, starting at the end and moving toward the
41766 ** 1-based index of an entry in the mapping section of the same
41767 ** index block. Let K be the 1-based index of the largest entry in
41768 ** the mapping section. (For index blocks other than the last, K will
41769 ** always be exactly HASHTABLE_NPAGE (4096) and for the last index block
41781 ** be at index iUnused. (iUnused might be less than iKey if there was
41787 ** current index block. Otherwise the iMax-th mapping entry of the
41788 ** current index block corresponds to the last entry that references
41791 ** A hash search begins with the last index block and moves toward the
41792 ** first index block, looking for entries corresponding to page P. On
41793 ** average, only two or three slots in each index block need to be
41795 ** establish that no such entry exists in the block. Each index block
41796 ** holds over 4000 entries. So two or three index blocks are sufficient
41805 ** and to the wal-index) might be using a different value K1, where K1>K0.
41833 ** The maximum (and only) versions of the wal and wal-index formats
41840 ** Similarly, if a client successfully reads a wal-index header (i.e. the
41867 ** The following object holds a copy of the wal-index header content.
41869 ** The actual header in the wal-index consists of two copies of this
41877 u32 iVersion; /* Wal-index version */
41883 u32 mxFrame; /* Index of last valid frame in the WAL */
41891 ** A copy of the following object occurs in the wal-index immediately
41992 volatile u32 **apWiData; /* Pointer to wal-index content in memory */
41999 WalIndexHdr hdr; /* Wal-index header for current transaction */
42015 ** Each page of the wal-index mapping contains a hash-table made up of
42025 ** the largest index).
42048 ** Define the parameters of the hash tables in the wal-index file. There
42050 ** wal-index.
42052 ** Changing any of these constants will alter the wal-index format and
42061 ** wal-index is smaller than usual. This is so that there is a complete
42062 ** hash-table on each aligned 32KB page of the wal-index.
42066 /* The wal-index is divided into pages of WALINDEX_PGSZ bytes each. */
42072 ** Obtain a pointer to the iPage'th page of the wal-index. The wal-index
42073 ** is broken into pages of WALINDEX_PGSZ bytes. Wal-index pages are
42076 ** If this call is successful, *ppPage is set to point to the wal-index
42116 ** Return a pointer to the WalCkptInfo structure in the wal-index.
42124 ** Return a pointer to the WalIndexHdr structure in the wal-index.
42197 ** Write the header information in pWal->hdr into the wal-index.
42383 ** page iHash of the wal-index. The wal-index is broken into 32KB pages
42387 ** in the wal-index file. Set *piZero to one less than the frame
42398 volatile ht_slot **paHash, /* OUT: Pointer to hash index */
42428 ** Return the number of the wal-index page that contains the hash-table
42430 ** iFrame. The wal-index is broken up into 32KB pages. Wal-index pages
42526 ** Set an entry in the wal-index that will map database page number
42537 /* Assuming the wal-index file was successfully mapped, populate the
42609 ** Recover the wal-index by reading the write-ahead log file.
42612 ** wal-index to prevent other threads/processes from doing anything
42613 ** with the WAL or wal-index while recovery is running. The
42655 int iFrame; /* Index of last frame read */
42779 ** Close an open wal-index.
42800 index file. If another process
42809 sqlite3_vfs *pVfs, /* vfs module to open wal and wal-index */
42869 ** same WalIterator object. Write into *piFrame the frame index where
42879 u32 *piFrame /* OUT: Wal frame index of next page */
42917 int iLeft = 0; /* Current index in aLeft */
42918 int iRight = 0; /* Current index in aRight */
42919 int iOut = 0; /* Current index in output buffer */
42966 int iList; /* Index into input list */
42967 int iSub = 0; /* Index into aSub array */
43072 ht_slot *aIndex; /* Sorted index for this segment */
43124 ** This routine uses and updates the nBackfill field of the wal-index header.
43168 /* Compute in mxSafeFrame the index of the last frame of the WAL that is
43268 int isDelete = 0; /* True to unlink wal and wal-index files */
43274 ** the wal and wal-index files.
43302 ** Try to read the wal-index header. Return 0 on success and 1 if
43305 ** The wal-index is in shared memory. Another thread or process might
43323 /* The first page of the wal-index must be mapped at this point. */
43331 ** There are two copies of the header at the beginning of the wal-index.
43365 ** Read the wal-index header from the wal-index and into pWal->hdr.
43367 ** wal-index from the WAL before returning.
43369 ** Set *pChanged to 1 if the wal-index header value in pWal->hdr is
43373 ** If the wal-index header is successfully read, return SQLITE_OK.
43379 volatile u32 *page0; /* Chunk of wal-index containing header */
43381 /* Ensure that page 0 of the wal-index (the page that contains the
43382 ** wal-index header) is mapped. Return early if an error occurs here.
43391 /* If the first page of the wal-index has been mapped, try to read the
43392 ** wal-index header immediately, without holding any lock. This usually
43393 ** works, but may fail if the wal-index header is corrupt or currently
43407 /* If the wal-index header is still malformed even while holding
43420 ** sure the wal-index was not constructed with some future format that
43448 ** to make a copy of the wal-index header into pWal->hdr. If the
43449 ** wal-index header has changed, *pChanged is set to 1 (as an indication
43451 ** flushed.) When useWal==1, the wal-index header is assumed to already
43462 ** bad luck when there is lots of contention for the wal-index, but that
43487 volatile WalCkptInfo *pInfo; /* Checkpoint information in wal-index */
43489 int mxI; /* Index of largest aReadMark[] value */
43626 ** value in the aReadMark[] array or the contents of the wal-index
43629 ** It is necessary to check that the wal-index header did not change
43639 ** This does not guarantee that the copy of the wal-index header is up to
43663 ** it takes a snapshot of the state of the WAL and wal-index for the current
43665 ** Other threads might append new content to the WAL and wal-index but
43721 /* If the "last page" field of the wal-index header snapshot is 0, then
43737 ** that adds entries to the wal-index (and possibly to this hash
43761 int iKey; /* Hash slot index */
43784 ** of the wal-index file content. Make sure the results agree with the
43907 /* Restore the clients cache of the wal-index header to the state it
44008 ** wal-index header to reflect this.
44011 ** at this point. But updating the actual wal-index header is also
44177 /* Append data to the wal-index. It is not necessary to lock the
44178 ** wal-index to do this as the SQLITE_SHM_WRITE lock held on the wal-index
44203 /* If this is a commit, update the wal-index header too. */
44228 int isChanged = 0; /* True if a new wal-index header is loaded */
44248 /* If a new wal-index header was loaded before the checkpoint was
44250 ** out of date. So zero the cached wal-index header to ensure that
44341 ** heap-memory for the wal-index. Otherwise, if the argument is NULL or the
44406 ** BTrees. Each BTree is identified by the index of its root page. The
44594 ** plus 2 bytes for the index to the cell in the page header). Such
44651 u16 cellOffset; /* Index in aData of first cell pointer */
44843 ** The entry is identified by its MemPage and the index in
44872 i16 iPage; /* Index of current page in apPage */
44874 u16 aiIdx[BTCURSOR_MAX_DEPTH]; /* Current index in apPage[i] */
45467 ** When writing to an index that resides in a sharable database, the
45471 ** the table corresponding to the index being written, this
45474 ** Instead of a lock on the table/index rooted at page iRoot, the caller may
45481 int isIndex, /* True if iRoot is the root of an index b-tree */
45498 /* If the client is reading or writing an index and the schema is
45509 ** written. For index b-trees, it is the root page of the associated
45514 Index *pIdx = (Index *)sqliteHashData(p);
45545 ** table or index rooted at iRoot because other shared connections are
45546 ** simultaneously reading that same table or index.
45554 ** For example, before writing to any part of the table or index
46002 ** In this version of BtreeMoveto, pKey is a packed index record
46008 const void *pKey, /* Packed key if the btree is an index */
46014 UnpackedRecord *pIdxKey; /* Unpacked index key */
46172 int iPtrmap; /* Pointer map page index */
46203 ** Given a btree page and a cell index (0 means the first cell on
46237 ** cell index as the second argument and btreeParseCellPtr()
46318 int iCell, /* The cell index. First cell is 0 */
46428 int iCellFirst; /* First allowable cell index */
46429 int iCellLast; /* Last possible cell index */
46496 ** as the first argument. Write into *pIdx the index into pPage->aData[]
46782 int i; /* Index into the cell pointer array */
48272 Pgno iFreePg; /* Index of free page to move pLastPg to */
48710 ** an index greater than all savepoints created explicitly using
49502 ** pCur->idx is set to the cell index that contains the pointer
49505 ** the largest cell index.
49541 ** structure the flags byte is set to 0x02 or 0x0A, indicating an index
49577 ** expected to open it on an index b-tree. Otherwise, if pKeyInfo is
49732 ** must be NULL. For index tables, pIdxKey is used and intKey
49758 UnpackedRecord *pIdxKey, /* Unpacked index key */
49808 ** be the right kind (index or table) of b-tree page. Otherwise
49820 int idx = pCur->aiIdx[pCur->iPage]; /* Index of current cell in pPage */
49844 ** the maximum number of record bytes stored on an index B-Tree
50144 /* Decrement the free-list count by 1. Set iTrunk to the index of the
50780 ** Insert a new cell on pPage at cell index "i". pCell points to the
50787 ** in pTemp or the original pCell) and also record its index.
50808 int ins; /* Index in data[] where new cell pointer is inserted */
51182 int iParentIdx, /* Index of "the page" in pParent */
51207 int cntNew[NB+2]; /* Index in aCell[] of cell after i-th page */
51224 ** index iParentIdx. This scenario comes about when this function
51404 ** size of all cells on the i-th page and cntNew[] which is the index
51412 ** cntNew[i]: Index in apCell[] and szCell[] for the first cell to
51447 int r; /* Index of right-most cell in left sibling */
51448 int d; /* Index of first cell to the left of right sibling */
52024 ** expecting an index b-tree, then the caller should be inserting blob
52144 int iCellIdx; /* Index of cell to delete */
52696 int iIdx; /* Index of child node in parent */
52711 ** pCur->aiIdx[pCur->iPage] value is set to the index of the parent cell
54709 ** empty boolean index.
56914 int idx, /* Index of column zName applies to */
57753 ** data and index records. Each serialized value consists of a
57757 ** In an SQLite index record, the serial type is stored directly before
58144 ** This function compares the two table rows or index records
58162 ** an index key, and thus ends with a rowid value. The last byte
58271 ** pCur points at an index entry created using the OP_MakeRecord opcode.
58288 /* Get the size of the index entry. Only indices entries of less
58298 /* Read in the complete content of the index entry */
58305 /* The index entry must begin with a header size */
58313 /* The last field of the index should be an integer - the ROWID.
58333 /* Fetch the integer off the end of the index record */
58348 ** Compare the key of the index entry that cursor pC is pointing to against
58354 ** omits the rowid at the end. The rowid at the end of the index entry
59471 int i, /* Index of the parameter to bind */
59642 ** Return the name of a wildcard parameter. Return NULL if the index
59657 ** Given a wildcard parameter name, return the index of the variable
59829 ** the host parameter index is found by scanning the perpared
59831 ** parameter index is known, locate the value in p->aVar[]. Then render
59839 int idx = 0; /* Index of a host parameter */
59840 int nextIndex = 1; /* Index of next ? host parameter */
60105 int iCur, /* Index of the new VdbeCursor */
60106 int nField, /* Number of fields in the table or index */
60660 u8 *zIdx; /* Index into header */
60764 UnpackedRecord r; /* B-Tree index search key */
61148 ** the one at index P2 from the beginning of
62498 u8 *zIdx; /* Index into header */
62800 ** in an index. The OP_Column opcode can decode the record later.
62804 ** field of the index key.
62809 ** If P4 is NULL then all index fields have the affinity NONE.
62933 ** Store the number of entries (an integer value) in the table or index
63185 ** P1 is the index of the database file on which the transaction is
63186 ** started. Index 0 is the main database file and index 1 is the
63302 /* See note about index shifting on OP_ReadCookie */
63401 ** sequence of the index being opened. Otherwise, if P4 is an integer
63408 ** Open a read/write cursor named P1 on the table or index whose root
63415 ** sequence of the index being opened. Otherwise, if P4 is an integer
63417 ** largest index of any column of the table that is actually used.
63519 ** The cursor points to a BTree table if P4==0 and to a BTree index
63521 ** that defines the format of keys in the index.
63558 /* If a transient index is required, create it by calling
63631 ** to an SQL index, then P3 is the first in an array of P4 registers
63632 ** that are used as an unpacked index key.
63644 ** to an SQL index, then P3 is the first in an array of P4 registers
63645 ** that are used as an unpacked index key.
63657 ** to an SQL index, then P3 is the first in an array of P4 registers
63658 ** that are used as an unpacked index key.
63670 ** to an SQL index, then P3 is the first in an array of P4 registers
63671 ** that are used as an unpacked index key.
63868 ** Cursor P1 is on an index btree. If the record identified by P3 and P4
63878 ** Cursor P1 is on an index btree. If the record identified by P3 and P4
63950 ** Cursor P1 is open on an index b-tree - that is to say, a btree which
63952 ** the list field being the integer ROWID of the entry that the index
63957 ** that make up an unpacked index key that can be used with cursor P1.
63959 ** value appended to the end of the index
63967 ** of the index entry is not R. If there is no such entry, control jumps
63968 ** to instruction P2. Otherwise, the rowid of the conflicting index
63981 UnpackedRecord r; /* B-Tree index search key */
63992 /* Find the index cursor. */
64011 /* Populate the index search key. */
64024 /* Search the B-Tree index. If no conflicting record is found, jump
64047 ** P1 is an index.
64609 ** will refer to the last entry in the database table or index.
64610 ** If the table or index is empty and P2>0, then jump immediately to P2.
64611 ** If P2 is 0 or if the table or index is not empty, fall through
64646 ** Sorting is accomplished by writing records into a sorting index,
64647 ** then rewinding that index and playing it back from beginning to
64664 ** will refer to the first entry in the database table or index.
64665 ** If the table or index is empty and P2>0, then jump immediately to P2.
64666 ** If P2 is 0 or if the table or index is not empty, fall through
64698 ** table or index. If there are no more key/value pairs then fall through
64712 ** table or index. If there is no previous key/value pairs then fall through
64760 ** Register P2 holds a SQL index key made using the
64762 ** into the index P1. Data for the entry is nil.
64803 ** an unpacked index key. This opcode removes that entry from the
64804 ** index opened by cursor P1.
64841 ** the end of the index key pointed to by cursor P1. This integer should be
64842 ** the rowid of the table entry to which this index entry points.
64877 ** The P4 register values beginning with P3 form an unpacked index
64878 ** key that omits the ROWID. Compare this key value against the index
64879 ** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
64881 ** If the P1 index entry is greater than or equal to the key value
64891 ** The P4 register values beginning with P3 form an unpacked index
64892 ** key that omits the ROWID. Compare this key value against the index
64893 ** that P1 is currently pointing to, ignoring the ROWID on the P1 index.
64895 ** If the P1 index entry is less than the key value then jump to P2.
64944 ** Delete an entire database table or index whose root page in the database
65002 ** Delete all contents of the database table or index whose root page
65004 ** remove the table or index from the database file.
65011 ** intkey table (an SQL table, not an index). In this case the row change
65046 ** The difference between a table and an index is this: A table must
65047 ** have a 4-byte integer key and can have arbitrary data. An index
65054 ** Allocate a new index in the main database file if P1==0 or in the
65109 ** single row, for example the row corresponding to a new index
65112 ** loaded. Otherwise, the new index definition can be loaded along
65163 ** of that table into the internal index hash table. This will cause
65188 ** the index named P4 in database P1. This is called after an index
65276 ** Insert the integer value held by register P2 into a boolean index
65295 ** Extract the smallest value from boolean index P1 and put that value into
65296 ** register P3. Or, if boolean index P1 is initially empty, leave P3
65308 /* The boolean index is empty */
65312 /* A value was pulled from the index */
65779 ** iDb index of the database as a parameter, and the database has not
65780 ** yet been attached so that index is unavailable. We have to wait
65927 ** P1 is the index of the database in sqlite3.aDb[] of the database
66084 /* Grab the index number and argc parameters */
66610 int iCol; /* Index of zColumn in row-record */
66710 Index *pIdx;
67701 ** pExpr->iDb Set the index in db->aDb[] of the database X
68244 ** ORDER BY term is not an integer index into the result set. That
68248 ** SELECT statement. Return the index i of the matching column,
68287 ** in the result set. Return an 1-based index of the matching
68306 int i, /* The index (1-based) of the term out of range */
68707 ** Expr.iColumn The column index in X.Y. -1 for the rowid.
68978 ** if the index with affinity idx_affinity may be used to implement
70182 ** The index of the cursor opened on the b-tree (database table, database index
70187 ** IN_INDEX_INDEX - The cursor was opened on a database index.
70200 ** has a UNIQUE constraint or UNIQUE index.
70204 ** be used unless <column> is an INTEGER PRIMARY KEY or an index can
70239 /* Check to see if an existing table or index can be used to
70247 int iCol = pExpr->iColumn; /* Index of column <column> */
70274 Index *pIdx; /* Iterator variable */
70276 /* The collation sequence used by the comparison. If an index is to
70283 ** it is not, it is not possible to use any index.
70316 /* Could not found an existing table or index to use as the RHS b-tree.
70428 ** filled with single-field index keys representing the results
70433 ** column is used to build the index keys. If both 'x' and the
70470 ** For each expression, build an index key from the evaluation and
70472 ** that columns affinity when building index keys. If <expr> is not
70648 /* In this case, the RHS is an index b-tree.
70933 int iCol, /* Index of the column to extract */
70959 int iColumn, /* Index of the table column */
71497 ** i is the index of the column. For a new.rowid reference, p1 is
72290 ** Add a new element to the pAggInfo->aCol[] array. Return the index of
72308 ** Add a new element to the pAggInfo->aFunc[] array. Return the index of
72582 ** CREATE INDEX command. The second is a table name. The table name in
72583 ** the CREATE TABLE or CREATE INDEX statement is replaced with the third
72589 ** sqlite_rename_table('CREATE INDEX i ON abc(a)', 'def')
72590 ** -> 'CREATE INDEX i ON def(a, b, c)'
72710 ** TRIGGER, not CREATE INDEX and CREATE TABLE.
72890 int iDb; /* Index of database containing pTab */
72910 /* Drop the table and index from the internal schema. */
72913 /* Reload the table, index and permanent trigger schemas. */
72966 /* Check that a table or index named 'zName' does not already exist
72971 "there is already another table or index with this name: %s", zName);
73072 "WHEN name LIKE 'sqlite_autoindex%%' AND type='index' THEN "
73076 "(type='table' OR type='index' OR type='trigger');",
73473 int iStatCur, /* Index of VdbeCursor that writes the sqlite_stat1 table */
73477 Index *pIdx; /* An index to being analyzed */
73478 int iIdxCur; /* Cursor open on index being analyzed */
73485 int iDb; /* Index of database containing pTab */
73487 int regIdxname = iMem++; /* Register containing index name */
73496 int regSamplerecno = iMem++; /* Index of next sample to record */
73497 int regRecno = iMem++; /* Current sample index */
73498 int regLast = iMem++; /* Index of last sample to record */
73499 int regFirst = iMem++; /* Index of first sample to record */
73537 /* Open a cursor to the index to be analyzed. */
73543 /* Populate the register containing the index name. */
73549 ** first index in the pTab->pIndex list, then register regLast has
73578 ** Number of distinct entries in index considering the
73596 ** the index b-tree. */
73663 ** two columns are the names of the table and index. The third column
73665 ** index. The first integer in the list is the total number of entries
73666 ** in the index. There is one additional integer in the list for each
73668 ** rows of the table the index will select. If D is the count of distinct
73698 ** containing NULL as the index name and the row count as the content.
73722 ** Generate code that will cause the most recent index analysis to
73850 ** This callback is invoked once for each index when reading the
73854 ** argv[1] = name of the index (might be NULL)
73862 Index *pIndex;
73900 ** If the Index.aSample variable is not NULL, delete the aSample[] array
73903 SQLITE_PRIVATE void sqlite3DeleteIndexSamples(sqlite3 *db, Index *pIdx){
73923 ** contents of sqlite_stat1 are used to populate the Index.aiRowEst[]
73925 ** Index.aSample[] arrays.
73953 Index *pIdx = sqliteHashData(i);
73997 Index *pIdx = sqlite3FindIndex(db, zIndex, sInfo.zDatabase);
74467 const char *zType, /* "view", "trigger", or "index" */
74468 const Token *pName /* Name of the view, trigger, or index */
74488 ** These routines are used to make sure that an index, trigger, or
74704 Index of containing database. */
74742 int iSrc; /* Index in pTabList->a[] of table being read */
74743 int iDb; /* The index of the database the expression refers to */
74744 int iCol; /* Index of column in table */
74869 ** CREATE INDEX
74870 ** DROP INDEX
74910 int iDb, /* Index of the database containing the table to lock */
75170 ** a particular index given the name of that index
75171 ** and the name of the database that contains the index.
75175 ** table and the first matching index is returned. (No checking
75176 ** for duplicate index names is done.) The search order is
75180 SQLITE_PRIVATE Index *sqlite3FindIndex(sqlite3 *db, const char *zName, const char *zDb){
75181 Index *p = 0;
75196 ** Reclaim the memory used by an index
75198 static void freeIndex(sqlite3 *db, Index *p){
75207 ** For the index called zIdxName which is found in the database iDb,
75208 ** unlike that index from its Table then remove the index from
75209 ** the index hash table and free all memory structures associated
75210 ** with the index
75213 Index *pIndex;
75223 Index *p;
75224 /* Justification of ALWAYS(); The index must be on the list of
75332 Index *pIndex, *pNext;
75346 TESTONLY ( Index *pOld = ) sqlite3HashInsert(
75432 ** function returns the index of the named database in db->aDb[], or
75453 ** index of the named database in db->aDb[], or -1 if the named db
75478 ** pName2) that stores the unqualified table name. The index of the
75513 ** unqualified name for a new schema object (table, index, view or
75574 ** set to the index of the database that the table or view is to be
75622 ** index or table name in the same database. Issue an error message if
75641 sqlite3ErrorMsg(pParse, "there is already an index named %s", zName);
75947 ** field of the table under construction to be the index of the
75952 ** index for the key. No index is created for INTEGER PRIMARY KEYs.
76002 Index *p;
76051 Index *pIdx;
76055 ** then an index may have been created on this column before the
76671 ** root-page of a table or index in database iDb has changed from iFrom
76677 ** have the same rootpage number as the real table or index that is
76680 ** or tables and not the table/index that is actually being moved.
76699 Index *pIdx = sqliteHashData(pElem);
76743 Index *pIdx;
76752 ** table and index root-pages in order, starting with the numerically
76770 Index *pIdx;
76922 /* Drop all SQLITE_MASTER table and index entries that refer to the
77106 ** Generate code that will erase and refill index *pIdx. This is
77107 ** used to initialize a newly created index or to recompute the
77108 ** content of an index in response to a REINDEX command.
77110 ** if memRootPage is not negative, it means that the index is newly
77112 ** root page number of the index. If memRootPage is negative, then
77113 ** the index already exists and must be cleared before being refilled and
77114 ** the root page number of the index is taken from pIndex->tnum.
77116 static void sqlite3RefillIndex(Parse *pParse, Index *pIndex, int memRootPage){
77121 int tnum; /* Root page of index */
77123 KeyInfo *pKey; /* KeyInfo for index */
77124 int regIdxKey; /* Registers containing the index key */
77125 int regRecord; /* Register holding assemblied index record */
77185 ** Create a new index for an SQL table. pName1.pName2 is the name of the index
77187 ** be NULL for a primary key or an index that is created to satisfy a
77196 ** If the index is created successfully, return a pointer to the new Index
77197 ** structure. This is used by sqlite3AddPrimaryKey() to mark the index
77198 ** as the tables primary key (Index.autoIndex==2).
77200 SQLITE_PRIVATE Index *sqlite3CreateIndex(
77202 Token *pName1, /* First part of index name. May be NULL */
77203 Token *pName2, /* Second part of index name. May be NULL */
77204 SrcList *pTblName, /* Table to index. Use pParse->pNewTable if 0 */
77208 Token *pEnd, /* The ")" that closes the CREATE INDEX statement */
77210 int ifNotExist /* Omit error if index already exists */
77212 Index *pRet = 0; /* Pointer to return */
77214 Index *pIndex = 0; /* The index to be created */
77215 char *zName = 0; /* Name of the index */
77220 int sortOrderMask; /* 1 to honor DESC in index. 0 to ignore. */
77223 int iDb; /* Index of the database that is being written */
77224 Token *pName = 0; /* Unqualified name of the index to create */
77244 /* Use the two-part index name to determine the database
77253 /* If the index name was unqualified, check if the the table
77265 if( sqlite3FixInit(&sFix, pParse, iDb, "index", pName) &&
77305 ** Find the name of the index. Make sure there is not already another
77306 ** index or table with the same name.
77310 ** one of the index names collides with the name of a temporary table or
77311 ** index, then we will continue to process this index.
77331 sqlite3ErrorMsg(pParse, "index %s already exists", zName);
77337 Index *pLoop;
77345 /* Check for authorization to create an index.
77390 ** Allocate the index structure.
77395 sizeof(Index) + /* Index structure */
77396 sizeof(int)*nCol + /* Index.aiColumn */
77397 sizeof(int)*(nCol+1) + /* Index.aiRowEst */
77398 sizeof(char *)*nCol + /* Index.azColl */
77399 sizeof(u8)*nCol + /* Index.aSortOrder */
77400 nName + 1 + /* Index.zName */
77419 /* Check to see if we should honor DESC requests on index columns
77428 ** load the column indices into the Index structure. Report an error
77432 ** more than once within the same index. Only the first instance of
77483 /* This routine has been called to create an automatic index as a
77491 ** Either way, check to see if the table already has such an index. If
77504 Index *pIdx;
77522 /* This constraint creates the same index as a previous
77527 ** explicitly specified behaviour for the index.
77542 /* Link the new Index structure to its table and to the other
77546 Index *p;
77561 /* If the db->init.busy is 0 then create the index on disk. This
77562 ** involves writing the index into the master table and filling in the
77563 ** index with the current table contents.
77565 ** The db->init.busy is 0 when the user first enters a CREATE INDEX
77567 ** CREATE INDEX statements are read out of the master table. In
77568 ** the latter case the index already exists on disk, which is why
77571 ** If pTblName==0 it means this index is generated as a primary key
77573 ** has just been created, it contains no data and the index initialization
77585 /* Create the rootpage for the index
77590 /* Gather the complete text of the CREATE INDEX statement into
77595 /* A named index with an explicit CREATE INDEX statement */
77596 zStmt = sqlite3MPrintf(db, "CREATE%s INDEX %.*s",
77601 /* An automatic index created by a PRIMARY KEY or UNIQUE constraint */
77606 /* Add an entry in sqlite_master for this index
77609 "INSERT INTO %Q.%s VALUES('index',%Q,%Q,#%d,%Q);",
77618 /* Fill the index with data and reparse the schema. Code an OP_Expire
77625 sqlite3MPrintf(db, "name='%q' AND type='index'", pIndex->zName),
77631 /* When adding an index to the list of indices for a table, make
77643 Index *pOther = pTab->pIndex;
77667 ** Fill the Index.aiRowEst[] array with default information - information
77670 ** aiRowEst[0] is suppose to contain the number of elements in the index.
77673 ** first column of the index. aiRowEst[2] is an estimate of the number
77675 ** of the index. And so forth. It must always be the case that
77684 SQLITE_PRIVATE void sqlite3DefaultRowEst(Index *pIdx){
77702 ** This routine will drop an existing named index. This routine
77703 ** implements the DROP INDEX statement.
77706 Index *pIndex;
77722 sqlite3ErrorMsg(pParse, "no such index: %S", pName, 0);
77728 sqlite3ErrorMsg(pParse, "index associated with UNIQUE "
77749 /* Generate code to remove the index and from the master table */
77754 "DELETE FROM %Q.%s WHERE name=%Q AND type='index'",
77782 ** The index of the new entry is returned in *pIdx.
77795 int *pIdx /* Write the index of a new slot here */
77861 ** Return the index in pList of the identifier named zId. Return -1
77896 int iStart /* Index in pSrc->a[] of first new slot */
78007 ** Assign VdbeCursor index numbers to all tables in a SrcList
78334 ** inserting multiple rows in a table, or inserting a row and index entries.)
78382 static int collationMatch(const char *zColl, Index *pIndex){
78402 Index *pIndex; /* An index associated with pTab */
78422 int iDb; /* The database index number */
78447 ** collating function. Forms 3 and 4 rebuild the named index or all
78453 char *z; /* Name of a table or index */
78456 Index *pIndex; /* An index associated with pTab */
78457 int iDb; /* The database index number */
78459 Token *pObjName; /* Name of the table or index to be reindexed */
78507 ** with OP_OpenRead or OP_OpenWrite to access database index pIdx.
78515 SQLITE_PRIVATE KeyInfo *sqlite3IndexKeyinfo(Parse *pParse, Index *pIdx){
79223 Index *pIdx; /* For looping over indices of the table */
79459 ** cursor number base+i for the i-th index.
79465 ** index entries that point to that record.
79530 /* Delete the index and table entries. Skip this step if pTab is really
79559 ** index entries associated with a single row of a single table.
79568 ** cursor number iCur+i for the i-th index.
79580 Index *pIdx;
79591 ** Generate code that will assemble an index key and put it in register
79592 ** regOut. The key with be for index pIdx which is an index on pTab.
79593 ** iCur is the index of a cursor open on the pTab table and pointing to
79597 ** registers that holds the elements of the index key. The
79603 Index *pIdx, /* The index for which to generate a key */
79605 int regOut, /* Write the new index key to this register */
81374 ** search the schema a unique index on the parent key columns.
81378 ** is set to point to the unique index.
81384 ** array is the index of the child table column that is mapped by the FK
81386 ** of index *ppIdx. The second element of the array is the index of the
81390 ** If the required index cannot be found, either because:
81413 FKey *pFKey, /* Foreign key to find index for */
81414 Index **ppIdx, /* OUT: Unique index on parent table */
81415 int **paiCol /* OUT: Map of index columns in pFKey */
81417 Index *pIdx = 0; /* Value to return via *ppIdx */
81456 /* pIdx is a UNIQUE index (or a PRIMARY KEY) and has the right number
81458 ** column of pFKey, then this index is a winner. */
81462 ** the PRIMARY KEY of table pParent. The PRIMARY KEY index may be
81463 ** identified by the test (Index.autoIndex==2). */
81474 ** index matches those columns. Also, check that the index uses
81478 int iCol = pIdx->aiColumn[i]; /* Index of column in parent tbl */
81482 /* If the index uses a collation sequence that is different from
81483 ** the default collation sequence for the column, this index is
81545 int iDb, /* Index of database housing pTab */
81547 Index *pIdx, /* Unique index on parent key columns in pTab */
81690 Index *pIdx, /* Foreign key index */
81722 int iCol; /* Index of column in child table */
81897 ** For a DELETE operation, parameter regOld is passed the index of the
81921 int iDb; /* Index of database containing pTab */
81939 Index *pIdx = 0; /* Index on key columns in pTo */
81946 /* Find the parent table of this foreign key. Also find a unique index
81985 ** a cursor to use to search the unique index on the parent key columns
82007 Index *pIdx = 0; /* Foreign key index for pFKey */
82072 Index *pIdx = 0;
82189 Index *pIdx = 0; /* Parent key index for this FK */
82444 int iDb, /* The database index in sqlite3.aDb[] */
82459 ** Return a pointer to the column affinity string associated with index
82472 ** rowid that appears as the last column in every index.
82474 ** Memory for the buffer containing the column index affinity string
82475 ** is managed along with the rest of the Index structure. It will be
82478 SQLITE_PRIVATE const char *sqlite3IndexAffinityStr(Vdbe *v, Index *pIdx){
82480 /* The first time a column affinity string for a particular index is
82482 ** a member of the Index structure for subsequent use.
82485 ** sqliteDeleteIndex() when the Index structure itself is cleaned
82509 ** for each column indexed by the index, according to the affinity of the
82569 Index *pIndex;
82614 int iDb, /* Index of the database holding pTab */
82792 ** foreach index on <table>
82793 ** open a write cursor on the <table> index
82794 ** open a read cursor on the corresponding <table2> index
82866 Index *pIdx; /* For looping over indices of the table */
82878 int iDb; /* Index of database holding TABLE */
82891 int *aRegIdx = 0; /* One register allocated to each index */
83126 ** the index into IDLIST of the primary key column. keyColumn is
83127 ** the index of the primary key as it appears in IDLIST, not as
83128 ** is appears in the original table. (The index of the primary
83159 ** key, the set the keyColumn variable to the primary key column index
83385 /* Generate code to check constraints and generate index keys and
83496 ** The regRowid parameter is the index of the register containing (1).
83507 ** The code generated by this routine store new index entries into
83508 ** registers identified by aRegIdx[]. No index entry is created for
83561 int baseCur, /* Index of a read/write cursor pointing at pTab */
83562 int regRowid, /* Index of the range of input registers */
83563 int *aRegIdx, /* Register used by each index. 0 for unused indices */
83578 Index *pIdx; /* Pointer to one of the indices */
83683 ** the triggers and remove both the table and index b-tree entries.
83687 ** GenerateRowIndexDelete(). This removes the index b-tree entries
83731 ** index and making sure that duplicate entries do not already exist.
83740 /* Create a key for accessing the index entry */
83759 continue; /* pIdx is not a UNIQUE index */
83771 /* Check to see if the new index entry will be unique */
83779 /* Generate code that executes if the new index entry is not unique */
83847 int baseCur, /* Index of a read/write cursor pointing at pTab */
83849 int *aRegIdx, /* Register used by each index. 0 for unused indices */
83857 Index *pIdx;
83912 Index *pIdx;
83961 ** Check to see if index pSrc is compatible as a source of data
83962 ** for index pDest in an insert transfer optimization. The rules
83963 ** for a compatible index:
83965 ** * The index is over the same set of columns
83970 static int xferCompatibleIndex(Index *pDest, Index *pSrc){
84036 Index *pSrcIdx, *pDestIdx; /* Source and destination indices */
84045 KeyInfo *pKey; /* Key information for an index */
84047 int destHasUniqueIdx = 0; /* True if pDest has a UNIQUE index */
84150 return 0; /* pDestIdx has no corresponding index in pSrc */
84183 ** Or if the destination has a UNIQUE index and is not empty,
85781 int iDb; /* Database index for <database> */
85790 ** index of the database this pragma is being applied to in db.aDb[]. */
86371 Index *pIdx;
86395 Index *pIdx;
86587 Index *pIdx;
86617 Index *pIdx;
86648 sqlite3VdbeChangeP4(v, addr+3, " missing from index ", P4_STATIC);
86678 "wrong # of entries in index ", P4_STATIC);
86778 ** creating or dropping a table or index). The schema version is used by
86793 int iCookie; /* Cookie index. 1 for schema-cookie, 6 for user-cookie. */
87026 ** argv[1] = root page number for table or index. 0 for trigger or view.
87049 /* Call the parser to process a CREATE TABLE, INDEX or VIEW.
87052 ** structures that describe the table, index, or view.
87082 /* If the SQL column is blank it means this is an index that
87084 ** constraint for a CREATE TABLE. The index should have already
87086 ** to do here is record the root page number for that index.
87088 Index *pIndex;
87091 /* This can occur if there exists an index on a TEMP table which
87092 ** has the same name as another index on a permanent index. Since
87094 ** safely ignore the index on the permanent table.
87106 ** data structures for a single database file. The index of the
87464 ** Convert a schema pointer into the iDb index that indicates
87479 ** -1000000 as the incorrect index into db->aDb[] is much
88021 ** Return the index of a column in a table. Return -1 if the column
88036 ** When found, set *piTab and *piCol to the table index and column index
88045 int *piTab, /* Write index of pSrc->a[] here */
88046 int *piCol /* Write index of pSrc->a[*piTab].pTab->aCol[] here */
88049 int iCol; /* Index of column matching zCol */
88079 int iLeft, /* Index of first table to join in pSrc */
88080 int iColLeft, /* Index of column in first table */
88081 int iRight, /* Index of second table in pSrc */
88082 int iColRight, /* Index of column in second table */
88308 ** form a distinct entry. iTab is a sorting index that holds previously
88317 int iTab, /* A sorting index
88577 ** KeyInfo structure is appropriate for initializing a virtual index to
88580 ** index to implement a DISTINCT test.
88835 int iCol = pExpr->iColumn; /* Index of column in pTab */
89064 int cnt; /* Index added to make the name unique */
90508 int iFrom, /* Index in p->pSrc->a[] of the inner subquery */
90941 ** INDEXED BY clause, then try to locate the specified index. If there
90942 ** was such a clause and the named index cannot be found, return
90950 Index *pIdx;
90956 sqlite3ErrorMsg(pParse, "no such index: %s", zIndex, 0);
91059 /* Locate the index named by the INDEXED BY clause, if any. */
91655 ** GROUP BY might use an index, DISTINCT never does.
91677 ** index might end up being unused if the data can be
91680 ** we figure out that the sorting index is not needed. The addrSortIndex
91707 /* Open a virtual index to use for the distinct set.
91730 /* If sorting index that was created by a prior OP_OpenEphemeral
91814 int addrSortingIdx; /* The OP_OpenEphemeral for the sorting index */
91818 /* If there is a GROUP BY clause we might need a sorting index to
91819 ** implement it. Allocate that sorting index now. If it turns out
91848 ** it might be a single loop that uses an index to extract information
91863 ** each row into a sorting index, terminate the first loop,
91864 ** then loop over the sorting index in order to get the output
92025 ** is better to execute the op on an index, as indexes are almost
92030 Index *pIdx; /* Iterator variable */
92031 KeyInfo *pKeyInfo = 0; /* Keyinfo for scanned index */
92032 Index *pBest = 0; /* Best index found so far */
92038 /* Search for the index that has the least amount of columns. If
92039 ** there is such an index, and it has less columns than the table
92042 ** In this case set iRoot to the root page number of the index b-tree
92044 ** index.
92090 ** index or indices to use) should place a different priority on
92119 VdbeComment((v, "%s() by index",
92565 int iTabDb; /* Index of the database holding pTab */
93122 int iDb; /* Index of the database to use */
93519 ** with an index greater than 32 may be accessed, 0xffffffff is returned.
93664 Index *pIdx; /* For looping over indices */
93668 int *aRegIdx = 0; /* One register assigned to each index to be updated */
93669 int *aXRef = 0; /* aXRef[i] is the index in pChanges->a[] of the
93738 ** The index cursors might not be used, but if they are used they
93753 ** of the UPDATE statement. Also find the column index
93800 ** array for each index associated with table being updated. Fill in
93806 aRegIdx = sqlite3DbMallocRaw(db, sizeof(Index*) * nIdx );
93904 ** Open every index that needs updating. Note that if any
93905 ** index could potentially invoke a REPLACE conflict resolution
93976 ** table and index records, and as the values for any new.* references
94053 /* Delete the index entries associated with the current record. */
94067 /* Insert the new index entries and the new record. */
94448 "SELECT 'CREATE INDEX vacuum_db.' || substr(sql,14)"
94449 " FROM sqlite_master WHERE sql LIKE 'CREATE INDEX %' ");
94452 "SELECT 'CREATE UNIQUE INDEX vacuum_db.' || substr(sql,21) "
94453 " FROM sqlite_master WHERE sql LIKE 'CREATE UNIQUE INDEX %'");
95754 #define WHERE_INDEXED 0x000f0000 /* Anything that uses an index */
95760 #define WHERE_IDX_ONLY 0x00800000 /* Use index only - omit table */
95766 #define WHERE_TEMP_INDEX 0x20000000 /* Uses an ephemeral index */
95829 ** The index in pWC->a[] of the new WhereTerm is returned on success.
95995 ** IMPLEMENTATION-OF: R-59926-26393 To be usable by an index a term must be
96083 Index *pIdx /* Must be compatible with this index, if not NULL */
96105 /* Figure out the collation sequence required from an index for
96331 ** potentially be used with an index if an appropriate index exists.
96332 ** This analysis does not consider whether or not the index exists; that
96357 int idxTerm /* Index of the OR-term to be analyzed */
96472 int iColumn = -1; /* Column index on lhs of IN operator */
96604 ** and the copy has idxParent set to the index of the original term.
96609 int idxTerm /* Index of the term to be analyzed */
96612 WhereMaskSet *pMaskSet; /* Set of table index masks */
96648 extraRight = x-1; /* ON clause terms may not be used with an index
96708 ** skipped. Or, if the children are satisfied by an index, the original
96846 ** an index for tables to the left of the join.
96878 ** the table has a cursor number of "base". pIdx is an index on pTab.
96884 ** All terms of the ORDER BY that match against the index must be either
96886 ** index do not need to satisfy this constraint.) The *pbRev value is
96893 Index *pIdx, /* The index we are testing */
96896 int nEqCol, /* Number of index columns with == constraints */
96900 int sortOrder = 0; /* XOR of index and ORDER BY sort direction */
96909 /* Argument pIdx must either point to a 'real' named index structure,
96910 ** or an index structure allocated on the stack by bestBtreeIndex() to
96911 ** represent the rowid index that is part of every table. */
96915 ** the index.
96919 ** of the index is also allowed to match against the ORDER BY
96926 int iColumn; /* The i-th column of the index. -1 for rowid */
96927 int iSortOrder; /* 1 for DESC, 0 for ASC on the i-th index term */
96928 const char *zColl; /* Name of the collating sequence for i-th index term */
96932 /* Can not use an index sort on anything that is not a column in the
96953 /* Term j of the ORDER BY clause does not match column i of the index */
96955 /* If an index column that is constrained by == fails to match an
96956 ** ORDER BY term, that is OK. Just ignore that column of the index
96960 /* Index column i is the rowid. All other terms match. */
96963 /* If an index column fails to match and is not constrained by ==
96964 ** then the index cannot satisfy the ORDER BY constraint.
96987 ** tables in the join, then we are assured that the index can be used
96997 /* All terms of the ORDER BY clause are covered by this index so
96998 ** this index can be used for sorting. */
97003 /* All terms of this index match some prefix of the ORDER BY clause
97004 ** and the index is UNIQUE and no terms on the tail of the ORDER BY
97124 WHERETRACE(("... Multi-index OR testing for term %d of %d....\n",
97158 WHERETRACE(("... multi-index OR cost=%.9g nrow=%.9g\n", rTotal, nRow));
97174 ** could be used with an index to access pSrc, assuming an appropriate
97175 ** index existed.
97196 ** possible to construct a transient index that would perform better
97197 ** than a full table scan even when the cost of constructing the index
97199 ** transient index.
97210 double costTempIdx; /* per-query cost of the transient index */
97220 /* We already have some kind of index in use for this query. */
97243 WHERETRACE(("auto-index reduces cost from %.2f to %.2f\n",
97260 ** Generate code to construct the Index object for an automatic index
97262 ** makes use of the automatic index.
97267 struct SrcList_item *pSrc, /* The FROM clause term to get the next index */
97269 WhereLevel *pLevel /* Write new index here */
97271 int nColumn; /* Number of columns in the constructed index */
97275 Index *pIdx; /* Object describing the transient index */
97280 KeyInfo *pKeyinfo; /* Key information for the index */
97281 int addrTop; /* Top of the index fill loop */
97282 int regRecord; /* Register holding an index record */
97291 ** transient index on 2nd and subsequent iterations of the loop. */
97298 /* Count the number of columns that will be added to the index
97320 ** covering index. A "covering index" is an index that contains all
97321 ** columns that are needed by the query. With a covering index, the
97323 ** be a covering index because the index will not be updated if the
97324 ** original table changes and the index and table cannot both be used
97339 /* Construct the Index object to describe this index */
97340 nByte = sizeof(Index);
97341 nByte += nColumn*sizeof(int); /* Index.aiColumn */
97342 nByte += nColumn*sizeof(char*); /* Index.azColl */
97343 nByte += nColumn; /* Index.aSortOrder */
97350 pIdx->zName = "auto-index";
97371 /* Add additional columns needed to make the automatic index into
97372 ** a covering index */
97389 /* Create the automatic index */
97396 /* Fill the automatic index with content */
97433 WHERETRACE(("Recomputing index info for %s...\n", pSrc->pTab->zName));
97565 ** Compute the best index for a virtual table.
97567 ** The best index is computed by the xBestIndex method of the virtual
97584 Bitmask notReady, /* Mask of cursors not available for index */
97588 sqlite3_index_info **ppIdxInfo /* Index information passed to xBestIndex */
97646 ** even though we might try to pick the best index multiple times.
97647 ** For each attempt at picking an index, the order of tables in the
97684 /* If there is an ORDER BY clause, and the selected virtual table index
97720 ** Argument pIdx is a pointer to an index structure that has an array of
97722 ** stored in Index.aSample. The domain of values stored in said column
97729 ** pVal lies in, sets *piRegion to the region index (a value between 0
97737 Index *pIdx, /* Index to consider domain of */
97850 ** by scanning an index for a range of values. The range may have an upper
97853 ** example, assuming that index p is on t1(a):
97863 ** The nEq parameter is passed the index of the index column subject to the
97865 ** optimized by the proposed index scan. For example, assuming index p is
97871 ** b, is the second left-most column of the index). Or, if the query is:
97891 Index *p, /* The index containing the range-compared column; "x" */
97892 int nEq, /* index into p->aCol[] of the range-compared column */
97978 ** index and in the main table.
97982 ** named index. If no such plan is found, then the returned cost is
97983 ** SQLITE_BIG_DBL. If a plan is found that uses the named index,
97989 ** index.
98001 Index *pProbe; /* An index we are evaluating */
98002 Index *pIdx; /* Copy of pProbe, or zero for IPK index */
98004 int idxEqTermMask; /* Index mask of valid equality operators */
98005 Index sPk; /* A fake index object for the primary key */
98006 unsigned int aiRowEstPk[2]; /* The aiRowEst[] value for the sPk index */
98007 int aiColumnPk = -1; /* The aColumn[] value for the sPk index */
98015 ** use an index to satisfy IS NULL constraints on that table. This is
98017 ** a circumstance which the index cannot help us discover. Ticket #2177.
98026 /* An INDEXED BY clause specifies a particular index to use */
98031 /* There is no INDEXED BY clause. Create a fake Index object to
98033 Index *pFirst; /* Any other index on the table */
98034 memset(&sPk, 0, sizeof(Index));
98069 ** Number of equality terms that can be implemented using the index.
98073 ** SQLite must perform on the index in question. For example, if the
98078 ** SQLite must perform 9 lookups on an index on (a, b), so nInMul is
98106 ** external sort (i.e. scanning the index being evaluated will not
98110 ** Boolean. True if for each index entry visited a lookup on the
98112 ** for the rowid index. For other indexes, it is true unless all the
98114 ** the index (such an index is sometimes described as a covering index).
98115 ** For example, given the index on (a, b), the second of the following
98178 /* If there is an ORDER BY clause and the index being considered will
98180 ** in wsFlags. Otherwise, if there is an ORDER BY clause but the index
98193 /* If currently calculating the cost of using an index (not the IPK
98194 ** index), determine if all required column data may be obtained without
98195 ** using the main table (i.e. if the index is a covering
98196 ** index for this query). If it is, set the WHERE_IDX_ONLY flag in
98242 /* If all information can be taken directly from the index, we avoid
98249 /**** Cost of using this index has now been computed ****/
98252 ** be used with the current index, but which might lower the number
98254 ** matters if the current index is the least costly, so do not bother
98255 ** with this step if we already know this index will not be chosen.
98259 ** the notReady mask. When computing an "optimal" index, the notReady
98263 ** of notValid, then a optimal index that depends on inner joins loops
98264 ** might be selected even when there exists an optimal index that has
98279 /* Ignore the first nEq equality matches since the index
98289 /* Ignore the first nBound range constraints since the index
98314 /* If this index is the best we have seen so far, then record this
98315 ** index and its cost in the pCost structure.
98328 /* If there was an INDEXED BY clause, then only that one index is
98332 /* Reset masks for the next index in the loop */
98338 ** is set, then reverse the order that the index will be scanned
98353 WHERETRACE(("best index is: %s\n",
98541 ** index.
98543 ** For example, consider table t1(a,b,c,d,e,f) with index i1(a,b,c).
98545 ** The index has as many as three equality constraints, but in this
98549 ** in consecutive registers and the index of the first register is returned.
98557 ** the index of that memory cell. The code that
98564 ** copy of the column affinity string of the index allocated using
98572 ** In the example above, the index on t1(a) has TEXT affinity. But since
98575 ** a key to search the index. Hence the first byte in the returned affinity
98588 Index *pIdx; /* The index being used for this loop */
98596 /* This module is only called on query plans that use an index. */
98620 ** Ex: CREATE INDEX i1 ON t1(a,b,a); SELECT * FROM t1 WHERE a=0 AND b=0; */
98662 int iTerm, /* Index of this term. First is zero */
98682 ** is run and there is an index on (a, b), then this function returns a
98693 Index *pIndex = pPlan->u.pIdx;
98787 zMsg = sqlite3MAppendf(db, zMsg, "%s VIRTUAL TABLE INDEX %d:%s", zMsg,
98819 int omitTable; /* True if we use the index only */
99007 /* Case 3: A scan using an index.
99011 ** left-most columns of the index. It may also contain
99016 ** index is on (x,y,z), then the following clauses are all
99035 ** constraints but an index is selected anyway, in order
99063 Index *pIdx; /* The index we will be using */
99064 int iIdxCur; /* The VDBE cursor for the index */
99079 ** the first one after the nEq equality constraints in the index,
99114 /* If we are doing a reverse order scan on an ascending index, or
99115 ** a forward order scan on a descending index, interchange the
99130 /* Seek the index cursor to the start of the range. */
99196 /* Check if the index cursor is past the end of the range. */
99230 ** WHERE clause terms made redundant by the index range scan.
99243 ** CREATE INDEX i1 ON t1(a);
99244 ** CREATE INDEX i2 ON t1(b);
99245 ** CREATE INDEX i3 ON t1(c);
99382 /* Case 5: There is no usable index. We must do a complete
99480 Index *pIdx = pWInfo->a[i].plan.u.pIdx;
99572 ** If an index can be used so that the natural output order of the table
99573 ** scan is correct for the ORDER BY clause, then that index is used and
99575 ** unnecessary sort of the result set if an index appropriate for the
99713 /* Chose the best index to use for each table in the FROM clause.
99717 ** pWInfo->a[].pIdx The index to use for this level of the loop.
99722 ** pWInfo->a[].iIdxCur The VDBE cursor for the index
99735 Index *pIdx; /* Index for FROM table at pTabItem */
99741 Bitmask notIndexed; /* Mask of tables that cannot use an index */
99796 WhereCost sCost; /* Cost information from best[Virtual]Index() */
99797 ExprList *pOrderBy; /* ORDER BY clause for index to optimize */
99827 ** index if it uses any index at all */
99846 ** index specified by its INDEXED BY clause. This rule ensures
99898 ** INDEXED BY clause attached to it, that the named index is being
99905 sqlite3ErrorMsg(pParse, "cannot use index: %s", pIdx->zName);
99909 ** guaranteed to find the index specified in the INDEXED BY clause
99910 ** if it find an index at all. */
99946 int iDb; /* Index of database containing table/index */
99986 Index *pIx = pLevel->plan.u.pIdx;
100015 ** and the index used to access it (if any). If the table itself
100016 ** is not used, its name is just '{}'. If no index is used
100017 ** the index is listed as "{}". If the primary key is used the
100018 ** index name is '*'.
100155 /* If this scan uses an index, make code substitutions to read data
100156 ** from the index in preference to the table. Sometimes, this means
100160 ** position in the index.
100166 ** reference the index.
100171 Index *pIdx = pLevel->plan.u.pIdx;
100463 ** If the index value yy_shift_ofst[S]+X is out of range or if the value
101060 int yyidx; /* Index of top element in stack */
101144 "THEN", "ELSE", "INDEX", "ALTER",
101423 /* 243 */ "cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP",
101432 /* 252 */ "cmd ::= DROP INDEX ifexists fullname",
103092 case 243: /* cmd ::= createkw uniqueflag INDEX ifnotexists nm dbnm ON nm LP idxlist RP */
103115 sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
103128 sqlite3ExprListCheckLength(pParse, yygotominor.yy322, "index");
103135 case 252: /* cmd ::= DROP INDEX ifexists fullname */
103840 testcase( i==2 ); /* INDEX */
105639 /* SQLITE_RANGE */ "bind or column index out of range",
106161 int iDb = SQLITE_MAX_ATTACHED; /* sqlite3.aDb[] index of db to checkpoint */
106479 ** If an invalid limit index is supplied, report -1.
107762 /* The full-text index is stored in a series of b+tree (-like)
107800 ** A position is the index of a word within the document. The first
107815 ** varint column; (index of new column)
107824 ** memory. A "position" is an index of a token in the token stream
107955 ** idx - index within level
108017 ** index into the term index, we clearly cannot simply update the term
108018 ** index when a document is deleted or updated. For deletions, we
108176 ** *piEndOffset. *piStartOffset should be set to the index of the first
108178 ** to the index of the first byte just past the end of the token in
108421 ** A connection to a fulltext index is an instance of the following
108448 /* The following hash table is used to buffer pending index updates during
108495 ** FTS3_FULLTEXT_SEARCH. If so, then Fts3Cursor.eSearch - 2 is the index
108509 #define FTS3_FULLTEXT_SEARCH 2 /* Full-text index search */
108518 ** matchinfo() function. They are populated when the full-text index is
108527 int bFulltext; /* True if full-text index was used */
108535 int iColumn; /* Index of column this phrase must match */
108752 int iIn = 1; /* Index of next byte to read from input */
108753 int iOut = 0; /* Index of next byte to write to output */
109053 int iCol; /* Column index */
109255 int iCons = -1; /* Index of constraint to use */
109353 ** table is missing a row that is present in the full-text index.
109717 int iCol1; /* The current column index in pp1 */
109718 int iCol2; /* The current column index in pp2 */
109737 ** for the same column (the column with index iCol1 and iCol2).
110197 ** querying the full-text index for a doclist associated with a term or
110570 ** then no tokens in the phrase were looked up in the full-text index. This
110649 ** be loaded from the full-text index for this phrase.
110936 ** data read from the full-text index.
110947 ** reading the data for each token from the full-text index, the data is
111222 ** If idxNum>=FTS3_FULLTEXT_SEARCH then use the full text index. The
111229 int idxNum, /* Strategy index */
111327 ** (not using the full-text index). In this case grab the rowid from the
111343 int iCol /* Index of column to read value from */
111625 sqlite3_result_text(pContext, "Index optimized", -1, SQLITE_STATIC);
111628 sqlite3_result_text(pContext, "Index already optimal", -1, SQLITE_STATIC);
112571 ** The iDefaultCol parameter should be passed the index of the table column
113239 int iToken; /* index of next token to be returned */
114368 int iToken; /* index of next token to be returned */
114583 ** When full-text index nodes are loaded from disk, the buffer that they
114585 ** of it. i.e. if a full-text index node is 900 bytes in size, then a buffer
114628 ** terms when querying the full-text index. See functions:
114642 int iIdx; /* Index within level, or 0x7FFFFFFF for PT */
114897 int eStmt, /* Index of statement to evaluate */
115296 ** full-text index.
115337 ** This function allocates a new level iLevel index in the segdir table.
115339 ** with 0, so the allocated index is one greater than the value returned
115346 ** allocated index is 0.
115348 ** If successful, *piIdx is set to the allocated index slot and SQLITE_OK
115356 /* Set variable iNext to the next available segdir index at level iLevel. */
115369 ** segment and allocate (newly freed) index 0 at level iLevel. Otherwise,
115370 ** if iNext is less than FTS3_MERGE_COUNT, allocate index iNext.
116665 ** stored in the full-text index. It merges data contained in one or
116826 ** term (if such a term exists in the index) has already been made.
116858 int iIdx; /* Index of new segment */
116870 ** greatest segment level currently present in the database. The index
116884 ** available segment index at level iLevel+1. The call to
116959 int idx; /* Index of new segment created */
116972 /* Determine the next index at level 0. If level 0 is already full, this
117522 int iPos; /* Index of first token in snippet */
117917 int iCol, /* Index of column to create snippet from */
118283 ** file system. This is done because the full-text index doclist is required
118284 ** to calculate these values properly, and the full-text index doclist is
118315 int iCol; /* Column index */
119298 int iCell; /* Index of current cell in pNode */
119324 int iCoord; /* Index of constrained coordinate */
119653 ** Remove cell the cell with index iCell from node pNode.
120134 ** integer value equal to iRowid. Return the index of this cell.
120154 ** Return the index of the cell containing a pointer to node pNode
121527 ** Delete the cell at index iCell of node pNode. After removing the
121765 int iCell; /* Index of iDelete cell in pLeaf */
122428 int iPattern = 0; /* Current byte index in zPattern */
122429 int iString = 0; /* Current byte index in zString */