]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Work toward combining the OP_MakeKey, OP_MakeIdxKey, and OP_MakeRecord
authordrh <drh@noemail.net>
Wed, 2 Jun 2004 01:22:02 +0000 (01:22 +0000)
committerdrh <drh@noemail.net>
Wed, 2 Jun 2004 01:22:02 +0000 (01:22 +0000)
opcodes into one.  The work is incomplete. (CVS 1524)

FossilOrigin-Name: 165d69a04cca719dec2b042117f848f153721a1d

manifest
manifest.uuid
src/btree.c
src/sqlite.h.in
src/vdbe.c
src/vdbeInt.h
src/vdbeaux.c

index d2209fc5fe73d470b96c8c8680650b14e272dea7..19a88387c79661a72838e4b853e7445b2ba45c39 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\sthe\ssqlite3_libencoding()\sapi\sand\sthe\sISO8859\sencoding\soption.\s(CVS\s1523)
-D 2004-06-02T00:41:09
+C Work\stoward\scombining\sthe\sOP_MakeKey,\sOP_MakeIdxKey,\sand\sOP_MakeRecord\nopcodes\sinto\sone.\s\sThe\swork\sis\sincomplete.\s(CVS\s1524)
+D 2004-06-02T01:22:02
 F Makefile.in ab7b0d5118e2da97bac66be8684a1034e3500f5a
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -25,7 +25,7 @@ F sqlite.def fc4f5734786fe4743cfe2aa98eb2da4b089edb5f
 F sqlite.pc.in 30552343140c53304c2a658c080fbe810cd09ca2
 F src/attach.c c315c58cb16fd6e913b3bfa6412aedecb4567fa5
 F src/auth.c 5c2f0bea4729c98c2be3b69d6b466fc51448fe79
-F src/btree.c 652efb14a17ba26759f73ca167f7d1e5d6651eb3
+F src/btree.c bf725408c6ac656327b0f5546c7c5d1eb065d181
 F src/btree.h 1e2beb41b4b4a4fc41da67cb4692614938066f2f
 F src/build.c 13985630bf6b3db4c7e7d4c9476bb94495b7d5fa
 F src/date.c 8e6fa3173386fb29fdef012ee08a853c1e9908b2
@@ -55,7 +55,7 @@ F src/printf.c ef750e8e2398ca7e8b58be991075f08c6a7f0e53
 F src/random.c eff68e3f257e05e81eae6c4d50a51eb88beb4ff3
 F src/select.c 0297717eb7331604687c2e29c147d3a311359df1
 F src/shell.c a9e2ad8f6c1d39b04bad61a0ec655e9a3a360b50
-F src/sqlite.h.in 021965a94f5799c8308003cb6e3b01e3b36a8b88
+F src/sqlite.h.in 8236db65bc6d8f5f47dc5a5e86c4a9bce42f2adf
 F src/sqliteInt.h 1aa9f7d5f88d13442d39c1bc9216c73e9b6c5191
 F src/table.c af14284fa36c8d41f6829e3f2819dce07d3e2de2
 F src/tclsqlite.c 3db6b868bd844bfb71720c8e573f4c9b0d536bd5
@@ -70,11 +70,11 @@ F src/update.c 259f06e7b22c684b2d3dda54a18185892d6e9573
 F src/utf.c c8be20ecdcb10659e23c43e35d835460e964d248
 F src/util.c d3d2f62ec94160db3cb2b092267405ba99122152
 F src/vacuum.c c91acc316127411980982938d050b299d42b81ef
-F src/vdbe.c cc754eddc0d2e741e57c4557c77754d8bbd93eeb
+F src/vdbe.c 4ce596ee57b663d4c428bee5c40f51094525acd9
 F src/vdbe.h e73f890e0f2a6c42b183d7d6937947930fe4fdeb
-F src/vdbeInt.h 5d357541db688b21ce05a88b3ea4d9a1fb09f232
+F src/vdbeInt.h f19df2246cf61f4dc27b13c0f9c278a379a935ee
 F src/vdbeapi.c 77d2e681a992ef189032cd9c1b7bf922f01ebe3e
-F src/vdbeaux.c 17b99f8d5fb6ec097e38b793c282ddc8a301a5a3
+F src/vdbeaux.c 5842109cc9fa76bd454305861c5936b370b9458a
 F src/vdbemem.c 5d029d83bc60eaf9c45837fcbc0b03348ec95d7a
 F src/where.c 444a7c3a8b1eb7bba072e489af628555d21d92a4
 F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
@@ -214,7 +214,7 @@ F www/support.tcl 1801397edd271cc39a2aadd54e701184b5181248
 F www/tclsqlite.tcl 19191cf2a1010eaeff74c51d83fd5f5a4d899075
 F www/vdbe.tcl 59288db1ac5c0616296b26dce071c36cb611dfe9
 F www/whentouse.tcl a8335bce47cc2fddb07f19052cb0cb4d9129a8e4
-P c17b864103fe5e6def0f650eadb7b2cc6e87144f
-R f4cae94848dada7ca979780be2518e9d
+P b53640ed2232aaf173a71636073477d80407d11f
+R 65e9a4b0c9422591cc77c047015d1b85
 U drh
-Z 839a132eb4ffa52deddad34237e579b7
+Z f635685494f9f4de060c8aaaeeb301d1
index ae3d18f7656b516982638eaf70a11c32a242c388..2e0dc154614772d8538605ab54705f06b827322d 100644 (file)
@@ -1 +1 @@
-b53640ed2232aaf173a71636073477d80407d11f
\ No newline at end of file
+165d69a04cca719dec2b042117f848f153721a1d
\ No newline at end of file
index ac526ef2ddf6d69c38fa4ac062c928740de485b5..6059899c376730905f2e7a9b8ba809956e90479e 100644 (file)
@@ -9,7 +9,7 @@
 **    May you share freely, never taking more than you give.
 **
 *************************************************************************
-** $Id: btree.c,v 1.154 2004/05/31 10:01:35 danielk1977 Exp $
+** $Id: btree.c,v 1.155 2004/06/02 01:22:02 drh Exp $
 **
 ** This file implements a external (disk-based) database using BTrees.
 ** For a detailed discussion of BTrees, refer to
@@ -1504,6 +1504,7 @@ create_cursor_exception:
   return rc;
 }
 
+#if 0  /* Not Used */
 /*
 ** Change the value of the comparison function used by a cursor.
 */
@@ -1515,6 +1516,7 @@ void sqlite3BtreeSetCompare(
   pCur->xCompare = xCmp ? xCmp : dfltCompare;
   pCur->pArg = pArg;
 }
+#endif
 
 /*
 ** Close a cursor.  The read lock on the database file is released
index 85821e14b0fc13badf66db3fca7cbe4e3fa7f40d..5243e94a069aec02fc2910b50e1e5c6f07ea2e6e 100644 (file)
@@ -12,7 +12,7 @@
 ** This header file defines the interface that the SQLite library
 ** presents to client programs.
 **
-** @(#) $Id: sqlite.h.in,v 1.90 2004/06/02 00:41:09 drh Exp $
+** @(#) $Id: sqlite.h.in,v 1.91 2004/06/02 01:22:02 drh Exp $
 */
 #ifndef _SQLITE_H_
 #define _SQLITE_H_
@@ -37,21 +37,6 @@ extern "C" {
 */
 extern const char sqlite3_version[];
 
-/*
-** The SQLITE_UTF8 macro is defined if the library expects to see
-** UTF-8 encoded data.  The SQLITE_ISO8859 macro is defined if the
-** iso8859 encoded should be used.
-*/
-#define SQLITE_--ENCODING-- 1
-
-/*
-** The following constant holds one of two strings, "UTF-8" or "iso8859",
-** depending on which character encoding the SQLite library expects to
-** see.  The character encoding makes a difference for the LIKE and GLOB
-** operators and for the LENGTH() and SUBSTR() functions.
-*/
-extern const char sqlite3_encoding[];
-
 /*
 ** Each open sqlite database is represented by an instance of the
 ** following opaque structure.
index 80d5d96b3917ef07f14987ce65d5ccbc8b1b4bb4..bff8480e8316cbdaacbfc08a97be9bcc75613b19 100644 (file)
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.354 2004/05/31 23:56:43 danielk1977 Exp $
+** $Id: vdbe.c,v 1.355 2004/06/02 01:22:02 drh Exp $
 */
 #include "sqliteInt.h"
 #include "os.h"
@@ -222,9 +222,8 @@ static Sorter *Merge(Sorter *pLeft, Sorter *pRight, KeyInfo *pKeyInfo){
   pTail = &sHead;
   pTail->pNext = 0;
   while( pLeft && pRight ){
-    int c = sqlite3VdbeKeyCompare(pKeyInfo, pLeft->nKey, pLeft->zKey,
-                                  pRight->nKey, pRight->zKey);
-    /* int c = sqlite3SortCompare(pLeft->zKey, pRight->zKey); */
+    int c = sqlite3VdbeRecordCompare(pKeyInfo, pLeft->nKey, pLeft->zKey,
+                                     pRight->nKey, pRight->zKey);
     if( c<=0 ){
       pTail->pNext = pLeft;
       pLeft = pLeft->pNext;
@@ -2043,25 +2042,53 @@ case OP_Column: {
 **
 ** If P3 is NULL then all index fields have the affinity NONE.
 */
+/* Opcode MakeRecord P1 P2 P3
+**
+** Convert the top abs(P1) entries of the stack into a single entry
+** suitable for use as a data record in a database table or as a key
+** in an index.  The details of the format are irrelavant as long as
+** the OP_Column opcode can decode the record later and as long as the
+** sqlite3VdbeRecordCompare function will correctly compare two encoded
+** records.  Refer to source code comments for the details of the record
+** format.
+**
+** The original stack entries are popped from the stack if P1>0 but
+** remain on the stack if P1<0.
+**
+** If P2 is not zero and one or more of the entries are NULL, then jump
+** to P2.  This feature can be used to skip a uniqueness test on indices.
+**
+** P3 may be a string that is P1 characters long.  The nth character of the
+** string indicates the column affinity that should be used for the nth
+** field of the index key (i.e. the first character of P3 corresponds to the
+** lowest element on the stack).
+**
+**  Character      Column affinity
+**  ------------------------------
+**  'n'            NUMERIC
+**  'i'            INTEGER
+**  't'            TEXT
+**  'o'            NONE
+**
+** If P3 is NULL then all index fields have the affinity NONE.
+*/
 case OP_MakeKey:
 case OP_MakeIdxKey:
 case OP_MakeRecord: {
   /* Assuming the record contains N fields, the record format looks
   ** like this:
   **
-  ** --------------------------------------------------------------------------
-  ** | header-siz | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | 
-  ** --------------------------------------------------------------------------
+  ** ------------------------------------------------------------------------
+  ** | hdr-size | type 0 | type 1 | ... | type N-1 | data0 | ... | data N-1 | 
+  ** ------------------------------------------------------------------------
   **
   ** Data(0) is taken from the lowest element of the stack and data(N-1) is
   ** the top of the stack.
   **
   ** Each type field is a varint representing the serial type of the 
   ** corresponding data element (see sqlite3VdbeSerialType()). The
-  ** num-fields field is also a varint storing N.
-  ** 
-  ** TODO: Even when the record is short enough for Mem::zShort, this opcode
-  **   allocates it dynamically.
+  ** hdr-size field is also a varint which is the offset from the beginning
+  ** of the record to data0.
   */
   int nField = pOp->p1;
   unsigned char *zNewRecord;
@@ -2451,12 +2478,10 @@ case OP_OpenWrite: {
   pCur->nullRow = 1;
   if( pX==0 ) break;
   do{
-    /* When opening cursors, always supply the comparison function
-    ** sqlite3VdbeKeyCompare(). If the table being opened is of type
-    ** INTKEY, the btree layer won't call the comparison function anyway.
-    */
+    /* We always provide a key comparison function.  If the table being
+    ** opened is of type INTKEY, the comparision function will be ignored. */
     rc = sqlite3BtreeCursor(pX, p2, wrFlag,
-             sqlite3VdbeKeyCompare, pOp->p3,
+             sqlite3VdbeRecordCompare, pOp->p3,
              &pCur->pCursor);
     pCur->pKeyInfo = (KeyInfo*)pOp->p3;
     if( pCur->pKeyInfo ){
@@ -2542,7 +2567,7 @@ case OP_OpenTemp: {
       rc = sqlite3BtreeCreateTable(pCx->pBt, &pgno, BTREE_ZERODATA); 
       if( rc==SQLITE_OK ){
         assert( pgno==MASTER_ROOT+1 );
-        rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, sqlite3VdbeKeyCompare,
+        rc = sqlite3BtreeCursor(pCx->pBt, pgno, 1, sqlite3VdbeRecordCompare,
             pOp->p3, &pCx->pCursor);
         pCx->pKeyInfo = (KeyInfo*)pOp->p3;
         pCx->pKeyInfo->enc = p->db->enc;
@@ -3162,10 +3187,6 @@ case OP_SetCounts: {
 ** off (if P2==0).  In key-as-data mode, the OP_Column opcode pulls
 ** data off of the key rather than the data.  This is used for
 ** processing compound selects.
-**
-** This opcode also instructs the cursor that the keys used will be
-** serialized in the record format usually used for table data, not
-** the usual index key format.
 */
 case OP_KeyAsData: {
   int i = pOp->p1;
@@ -3173,7 +3194,6 @@ case OP_KeyAsData: {
   assert( i>=0 && i<p->nCursor );
   pC = p->apCsr[i];
   pC->keyAsData = pOp->p2;
-  sqlite3BtreeSetCompare(pC->pCursor, sqlite3VdbeRowCompare, pC->pKeyInfo);
   break;
 }
 
index a0a57dcc2b5e3472c2ead6e95a1f3fc35c3a01ab..e52dc51e635a7c7d361ed8d0b3ce547f74b28a2d 100644 (file)
@@ -347,8 +347,7 @@ int sqlite2BtreeKeyCompare(BtCursor *, const void *, int, int, int *);
 int sqlite3VdbeIdxKeyCompare(Cursor*, int , const unsigned char*, int*);
 int sqlite3VdbeIdxRowid(BtCursor *, i64 *);
 int sqlite3MemCompare(const Mem*, const Mem*, const CollSeq*);
-int sqlite3VdbeKeyCompare(void*,int,const void*,int, const void*);
-int sqlite3VdbeRowCompare(void*,int,const void*,int, const void*);
+int sqlite3VdbeRecordCompare(void*,int,const void*,int, const void*);
 int sqlite3VdbeIdxRowidLen(int,const u8*);
 int sqlite3VdbeExec(Vdbe*);
 int sqlite3VdbeList(Vdbe*);
index acf4f8291fc1c41dadc8f82fa6792cec9801b20a..0920ae28bed703887e5f857884c232516a2a638b 100644 (file)
@@ -1323,38 +1323,13 @@ int sqlite3VdbeSerialGet(
 }
 
 /*
-** The following is the comparison function for (non-integer)
-** keys in the btrees.  This function returns negative, zero, or
-** positive if the first key is less than, equal to, or greater than
-** the second.
-**
-** This function assumes that each key consists of one or more type/blob
-** pairs, encoded using the sqlite3VdbeSerialXXX() functions above. 
-**
-** Following the type/blob pairs, each key may have a single 0x00 byte
-** followed by a varint. A key may only have this traling 0x00/varint
-** pair if it has at least as many type/blob pairs as the key it is being
-** compared to.
-*/
-int sqlite3VdbeKeyCompare(
-  void *userData,
-  int nKey1, const void *pKey1, 
-  int nKey2, const void *pKey2
-){
-  return sqlite3VdbeRowCompare(userData,nKey1,pKey1,nKey2,pKey2);
-}
-
-/*
-** This function compares the two table row records specified by 
+** This function compares the two table rows or index records specified by 
 ** {nKey1, pKey1} and {nKey2, pKey2}, returning a negative, zero
 ** or positive integer if {nKey1, pKey1} is less than, equal to or 
-** greater than {nKey2, pKey2}.
-**
-** This function is pretty inefficient and will probably be replaced
-** by something else in the near future. It is currently required
-** by compound SELECT operators. 
+** greater than {nKey2, pKey2}.  Both Key1 and Key2 must be byte strings
+** composed by the OP_MakeRecord opcode of the VDBE.
 */
-int sqlite3VdbeRowCompare(
+int sqlite3VdbeRecordCompare(
   void *userData,
   int nKey1, const void *pKey1, 
   int nKey2, const void *pKey2
@@ -1429,8 +1404,10 @@ int sqlite3VdbeRowCompare(
 }
 
 /*
-** The argument is an index key that contains the ROWID at the end.
-** Return the length of the rowid.
+** The argument is an index entry composed using the OP_MakeRecord opcode.
+** The last entry in this record should be an integer (specifically
+** an integer rowid).  This routine returns the number of bytes in
+** that integer.
 */
 int sqlite3VdbeIdxRowidLen(int nKey, const u8 *aKey){
   u32 szHdr;        /* Size of the header */
@@ -1443,9 +1420,9 @@ int sqlite3VdbeIdxRowidLen(int nKey, const u8 *aKey){
   
 
 /*
-** pCur points at an index entry. Read the rowid (varint occuring at
-** the end of the entry and store it in *rowid. Return SQLITE_OK if
-** everything works, or an error code otherwise.
+** pCur points at an index entry created using the OP_MakeRecord opcode.
+** Read the rowid (the last field in the record) and store it in *rowid.
+** Return SQLITE_OK if everything works, or an error code otherwise.
 */
 int sqlite3VdbeIdxRowid(BtCursor *pCur, i64 *rowid){
   u64 nCellKey;
@@ -1505,7 +1482,7 @@ int sqlite3VdbeIdxKeyCompare(
     return rc;
   }
   lenRowid = sqlite3VdbeIdxRowidLen(m.n, m.z);
-  *res = sqlite3VdbeKeyCompare(pC->pKeyInfo, m.n-lenRowid, m.z, nKey, pKey);
+  *res = sqlite3VdbeRecordCompare(pC->pKeyInfo, m.n-lenRowid, m.z, nKey, pKey);
   if( m.flags & MEM_Dyn ){
     sqliteFree(m.z);
   }