/ Check-in [f6a87068]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Update comments. No changes to code. (CVS 841)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f6a8706872c43cee3003b48bb427c7b74b1f89e7
User & Date: drh 2003-01-19 03:59:46
Context
2003-01-21
02:39
In the pager, cache a pointer to the first page on the freelist that does not need to be synced. This makes a fetch of a page that is not in cache go a lot faster when the cache is full. This check-in also adds some performance instrumentation to the OS layer. (CVS 842) check-in: 00f08fc0 user: drh tags: trunk
2003-01-19
03:59
Update comments. No changes to code. (CVS 841) check-in: f6a87068 user: drh tags: trunk
2003-01-18
22:01
Update the speed comparison page. (CVS 840) check-in: 424cb2ed user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/encode.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains helper routines used to translate binary data into
    13     13   ** a null-terminated string (suitable for use in SQLite) and back again.
    14     14   ** These are convenience routines for use by people who want to store binary
    15         -** data in an SQLite database.  The code in this file is used by any other
           15  +** data in an SQLite database.  The code in this file is not used by any other
    16     16   ** part of the SQLite library.
    17     17   **
    18         -** $Id: encode.c,v 1.4 2003/01/11 14:25:40 drh Exp $
           18  +** $Id: encode.c,v 1.5 2003/01/19 03:59:46 drh Exp $
    19     19   */
    20     20   #include <string.h>
    21     21   
    22     22   /*
    23     23   ** Encode a binary buffer "in" of size n bytes so that it contains
    24     24   ** no instances of characters '\'' or '\000'.  The output is 
    25     25   ** null-terminated and can be used as a string value in an INSERT

Changes to src/main.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Main file for the SQLite library.  The routines in this file
    13     13   ** implement the programmer interface to the library.  Routines in
    14     14   ** other files are for internal use by SQLite and should not be
    15     15   ** accessed by users of the library.
    16     16   **
    17         -** $Id: main.c,v 1.108 2003/01/18 17:04:09 drh Exp $
           17  +** $Id: main.c,v 1.109 2003/01/19 03:59:47 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include "os.h"
    21     21   #include <ctype.h>
    22     22   
    23     23   /*
    24     24   ** A pointer to this structure is used to communicate information
................................................................................
    35     35   ** database.  See sqliteInit() below for additional information.
    36     36   **
    37     37   ** Each callback contains the following information:
    38     38   **
    39     39   **     argv[0] = "file-format" or "schema-cookie" or "table" or "index"
    40     40   **     argv[1] = table or index name or meta statement type.
    41     41   **     argv[2] = root page number for table or index.  NULL for meta.
    42         -**     argv[3] = SQL create statement for the table or index
           42  +**     argv[3] = SQL text for a CREATE TABLE or CREATE INDEX statement.
    43     43   **     argv[4] = "1" for temporary files, "0" for main database
    44     44   **
    45     45   */
    46     46   static
    47     47   int sqliteInitCallback(void *pInit, int argc, char **argv, char **azColName){
    48     48     InitData *pData = (InitData*)pInit;
    49     49     Parse sParse;
................................................................................
   387    387       sqliteFree(*pzErrMsg);
   388    388       *pzErrMsg = 0;
   389    389     }
   390    390   
   391    391     /* If the database is in formats 1 or 2, then upgrade it to
   392    392     ** version 3.  This will reconstruct all indices.  If the
   393    393     ** upgrade fails for any reason (ex: out of disk space, database
   394         -  ** is read only, interrupt receive, etc.) then refuse to open.
          394  +  ** is read only, interrupt received, etc.) then refuse to open.
   395    395     */
   396    396     if( rc==SQLITE_OK && db->file_format<3 ){
   397    397       char *zErr = 0;
   398    398       InitData initData;
   399    399       int meta[SQLITE_N_BTREE_META];
   400    400   
   401    401       initData.db = db;
................................................................................
   782    782   ** string that is exported from SQLite should have already passed through
   783    783   ** sqliteStrRealloc().
   784    784   */
   785    785   void sqlite_freemem(void *p){ free(p); }
   786    786   
   787    787   /*
   788    788   ** Windows systems need functions to call to return the sqlite_version
   789         -** and sqlite_encoding strings.
          789  +** and sqlite_encoding strings since they are unable to access constants
          790  +** within DLLs.
   790    791   */
   791    792   const char *sqlite_libversion(void){ return sqlite_version; }
   792    793   const char *sqlite_libencoding(void){ return sqlite_encoding; }
   793    794   
   794    795   /*
   795    796   ** Create new user-defined functions.  The sqlite_create_function()
   796    797   ** routine creates a regular function and sqlite_create_aggregate()

Changes to src/printf.c.

     1      1   /*
     2      2   ** The "printf" code that follows dates from the 1980's.  It is in
     3      3   ** the public domain.  The original comments are included here for
     4      4   ** completeness.  They are slightly out-of-date.
     5      5   **
     6         -** The following modules is an enhanced replacement for the "printf" programs
     7         -** found in the standard library.  The following enhancements are
            6  +** The following modules is an enhanced replacement for the "printf" subroutines
            7  +** found in the standard C library.  The following enhancements are
     8      8   ** supported:
     9      9   **
    10     10   **      +  Additional functions.  The standard set of "printf" functions
    11     11   **         includes printf, fprintf, sprintf, vprintf, vfprintf, and
    12     12   **         vsprintf.  This module adds the following:
    13     13   **
    14     14   **           *  snprintf -- Works like sprintf, but has an extra argument

Changes to src/select.c.

     8      8   **    May you find forgiveness for yourself and forgive others.
     9      9   **    May you share freely, never taking more than you give.
    10     10   **
    11     11   *************************************************************************
    12     12   ** This file contains C code routines that are called by the parser
    13     13   ** to handle SELECT statements in SQLite.
    14     14   **
    15         -** $Id: select.c,v 1.122 2003/01/18 20:11:07 drh Exp $
           15  +** $Id: select.c,v 1.123 2003/01/19 03:59:47 drh Exp $
    16     16   */
    17     17   #include "sqliteInt.h"
    18     18   
    19     19   
    20     20   /*
    21     21   ** Allocate a new Select structure and return a pointer to that
    22     22   ** structure.
................................................................................
   176    176       *ppExpr = pE;
   177    177     }
   178    178   }
   179    179   
   180    180   /*
   181    181   ** Set the EP_FromJoin property on all terms of the given expression.
   182    182   **
   183         -** The EP_FromJoin property is used at on terms of an expression to tell
          183  +** The EP_FromJoin property is used on terms of an expression to tell
   184    184   ** the LEFT OUTER JOIN processing logic that this term is part of the
   185    185   ** join restriction specified in the ON or USING clause and not a part
   186    186   ** of the more general WHERE clause.  These terms are moved over to the
   187    187   ** WHERE clause during join processing but we need to remember that they
   188    188   ** originated in the ON or USING clause.
   189    189   */
   190    190   static void setJoinExpr(Expr *p){
................................................................................
   673    673     sqliteVdbeResolveLabel(v, end);
   674    674     sqliteVdbeAddOp(v, OP_SortReset, 0, 0);
   675    675   }
   676    676   
   677    677   /*
   678    678   ** Generate code that will tell the VDBE the datatypes of
   679    679   ** columns in the result set.
          680  +**
          681  +** This routine only generates code if the "PRAGMA show_datatypes=on"
          682  +** has been executed.  The datatypes are reported out in the azCol
          683  +** parameter to the callback function.  The first N azCol[] entries
          684  +** are the names of the columns, and the second N entries are the
          685  +** datatypes for the columns.
          686  +**
          687  +** The "datatype" for a result that is a column of a type is the
          688  +** datatype definition extracted from the CREATE TABLE statement.
          689  +** The datatype for an expression is either TEXT or NUMERIC.  The
          690  +** datatype for a ROWID field is INTEGER.
   680    691   */
   681    692   static void generateColumnTypes(
   682    693     Parse *pParse,      /* Parser context */
   683    694     int base,           /* VDBE cursor corresponding to first entry in pTabList */
   684    695     SrcList *pTabList,  /* List of tables */
   685    696     ExprList *pEList    /* Expressions defining the result set */
   686    697   ){
................................................................................
  1183   1194   ** if the corresponding column in p and every SELECT to the left of
  1184   1195   ** p has a datatype of SQLITE_SO_TEXT.  If the cooressponding column
  1185   1196   ** in p or any of the left SELECTs is SQLITE_SO_NUM, then the datatype
  1186   1197   ** of the order-by expression is set to SQLITE_SO_NUM.
  1187   1198   **
  1188   1199   ** Examples:
  1189   1200   **
  1190         -**    SELECT a,b
         1201  +**     CREATE TABLE one(a INTEGER, b TEXT);
         1202  +**     CREATE TABLE two(c VARCHAR(5), d FLOAT);
         1203  +**
         1204  +**     SELECT b, b FROM one UNION SELECT d, c FROM two ORDER BY 1, 2;
         1205  +**
         1206  +** The primary sort key will use SQLITE_SO_NUM because the "d" in
         1207  +** the second SELECT is numeric.  The 1st column of the first SELECT
         1208  +** is text but that does not matter because a numeric always overrides
         1209  +** a text.
         1210  +**
         1211  +** The secondary key will use the SQLITE_SO_TEXT sort order because
         1212  +** both the (second) "b" in the first SELECT and the "c" in the second
         1213  +** SELECT have a datatype of text.
  1191   1214   */ 
  1192   1215   static void multiSelectSortOrder(Select *p, ExprList *pOrderBy){
  1193   1216     int i;
  1194   1217     ExprList *pEList;
  1195   1218     if( pOrderBy==0 ) return;
  1196   1219     if( p==0 ){
  1197   1220       for(i=0; i<pOrderBy->nExpr; i++){
................................................................................
  1211   1234     }
  1212   1235   }
  1213   1236   
  1214   1237   /*
  1215   1238   ** This routine is called to process a query that is really the union
  1216   1239   ** or intersection of two or more separate queries.
  1217   1240   **
  1218         -** "p" points to the right-most of the two queries.  The results should
  1219         -** be stored in eDest with parameter iParm.
         1241  +** "p" points to the right-most of the two queries.  the query on the
         1242  +** left is p->pPrior.  The left query could also be a compound query
         1243  +** in which case this routine will be called recursively. 
         1244  +**
         1245  +** The results of the total query are to be written into a destination
         1246  +** of type eDest with parameter iParm.
         1247  +**
         1248  +** Example 1:  Consider a three-way compound SQL statement.
         1249  +**
         1250  +**     SELECT a FROM t1 UNION SELECT b FROM t2 UNION SELECT c FROM t3
         1251  +**
         1252  +** This statement is parsed up as follows:
         1253  +**
         1254  +**     SELECT c FROM t3
         1255  +**      |
         1256  +**      `----->  SELECT b FROM t2
         1257  +**                |
         1258  +**                `------>  SELECT c FROM t1
         1259  +**
         1260  +** The arrows in the diagram above represent the Select.pPrior pointer.
         1261  +** So if this routine is called with p equal to the t3 query, then
         1262  +** pPrior will be the t2 query.  p->op will be TK_UNION in this case.
         1263  +**
         1264  +** Notice that because of the way SQLite parses compound SELECTs, the
         1265  +** individual selects always group from left to right.
  1220   1266   */
  1221   1267   static int multiSelect(Parse *pParse, Select *p, int eDest, int iParm){
  1222   1268     int rc;             /* Success code from a subroutine */
  1223   1269     Select *pPrior;     /* Another SELECT immediately to our left */
  1224   1270     Vdbe *v;            /* Generate code to this VDBE */
  1225   1271   
  1226   1272     /* Make sure there is no ORDER BY clause on prior SELECTs.  Only the 
................................................................................
  1691   1737     return 1;
  1692   1738   }
  1693   1739   
  1694   1740   /*
  1695   1741   ** Analyze the SELECT statement passed in as an argument to see if it
  1696   1742   ** is a simple min() or max() query.  If it is and this query can be
  1697   1743   ** satisfied using a single seek to the beginning or end of an index,
  1698         -** then generate the code for this SELECT return 1.  If this is not a 
         1744  +** then generate the code for this SELECT and return 1.  If this is not a 
  1699   1745   ** simple min() or max() query, then return 0;
  1700   1746   **
  1701   1747   ** A simply min() or max() query looks like this:
  1702   1748   **
  1703   1749   **    SELECT min(a) FROM table;
  1704   1750   **    SELECT max(a) FROM table;
  1705   1751   **
................................................................................
  1822   1868   **
  1823   1869   **     SRT_Union       Store results as a key in a temporary table iParm
  1824   1870   **
  1825   1871   **     SRT_Except      Remove results form the temporary table iParm.
  1826   1872   **
  1827   1873   **     SRT_Table       Store results in temporary table iParm
  1828   1874   **
         1875  +** The table above is incomplete.  Additional eDist value have be added
         1876  +** since this comment was written.  See the selectInnerLoop() function for
         1877  +** a complete listing of the allowed values of eDest and their meanings.
         1878  +**
  1829   1879   ** This routine returns the number of errors.  If any errors are
  1830   1880   ** encountered, then an appropriate error message is left in
  1831   1881   ** pParse->zErrMsg.
  1832   1882   **
  1833   1883   ** This routine does NOT free the Select structure passed in.  The
  1834   1884   ** calling function needs to do that.
  1835   1885   **
  1836   1886   ** The pParent, parentTab, and *pParentAgg fields are filled in if this
  1837   1887   ** SELECT is a subquery.  This routine may try to combine this SELECT
  1838   1888   ** with its parent to form a single flat query.  In so doing, it might
  1839   1889   ** change the parent query from a non-aggregate to an aggregate query.
  1840   1890   ** For that reason, the pParentAgg flag is passed as a pointer, so it
  1841   1891   ** can be changed.
         1892  +**
         1893  +** Example 1:   The meaning of the pParent parameter.
         1894  +**
         1895  +**    SELECT * FROM t1 JOIN (SELECT x, count(*) FROM t2) JOIN t3;
         1896  +**    \                      \_______ subquery _______/        /
         1897  +**     \                                                      /
         1898  +**      \____________________ outer query ___________________/
         1899  +**
         1900  +** This routine is called for the outer query first.   For that call,
         1901  +** pParent will be NULL.  During the processing of the outer query, this 
         1902  +** routine is called recursively to handle the subquery.  For the recursive
         1903  +** call, pParent will point to the outer query.  Because the subquery is
         1904  +** the second element in a three-way join, the parentTab parameter will
         1905  +** be 1 (the 2nd value of a 0-indexed array.)
  1842   1906   */
  1843   1907   int sqliteSelect(
  1844   1908     Parse *pParse,         /* The parser context */
  1845   1909     Select *p,             /* The SELECT statement being coded. */
  1846         -  int eDest,             /* One of: SRT_Callback Mem Set Union Except */
  1847         -  int iParm,             /* Save result in this memory location, if >=0 */
         1910  +  int eDest,             /* How to dispose of the results */
         1911  +  int iParm,             /* A parameter used by the eDest disposal method */
  1848   1912     Select *pParent,       /* Another SELECT for which this is a sub-query */
  1849   1913     int parentTab,         /* Index in pParent->pSrc of this query */
  1850   1914     int *pParentAgg        /* True if pParent uses aggregate functions */
  1851   1915   ){
  1852   1916     int i;
  1853   1917     WhereInfo *pWInfo;
  1854   1918     Vdbe *v;
................................................................................
  1891   1955   
  1892   1956     /* 
  1893   1957     ** Do not even attempt to generate any code if we have already seen
  1894   1958     ** errors before this routine starts.
  1895   1959     */
  1896   1960     if( pParse->nErr>0 ) goto select_end;
  1897   1961   
  1898         -  /* Look up every table in the table list and create an appropriate
  1899         -  ** columnlist in pEList if there isn't one already.  (The parser leaves
  1900         -  ** a NULL in the p->pEList if the SQL said "SELECT * FROM ...")
         1962  +  /* Expand any "*" terms in the result set.  (For example the "*" in
         1963  +  ** "SELECT * FROM t1")  The fillInColumnlist() routine also does some
         1964  +  ** other housekeeping - see the header comment for details.
  1901   1965     */
  1902   1966     if( fillInColumnList(pParse, p) ){
  1903   1967       goto select_end;
  1904   1968     }
  1905   1969     pWhere = p->pWhere;
  1906   1970     pEList = p->pEList;
  1907   1971     if( pEList==0 ) goto select_end;
................................................................................
  2020   2084     }
  2021   2085   
  2022   2086     /* Begin generating code.
  2023   2087     */
  2024   2088     v = sqliteGetVdbe(pParse);
  2025   2089     if( v==0 ) goto select_end;
  2026   2090   
  2027         -  /* Identify column names if we will be using in the callback.  This
  2028         -  ** step is skipped if the output is going to a table or a memory cell.
         2091  +  /* Identify column names if we will be using them in a callback.  This
         2092  +  ** step is skipped if the output is going to some other destination.
  2029   2093     */
  2030   2094     if( eDest==SRT_Callback ){
  2031   2095       generateColumnNames(pParse, p->base, pTabList, pEList);
  2032   2096     }
  2033   2097   
  2034   2098     /* Set the limiter
  2035   2099     */
................................................................................
  2072   2136     */
  2073   2137     if( pParent && pParentAgg &&
  2074   2138         flattenSubquery(pParse, pParent, parentTab, *pParentAgg, isAgg) ){
  2075   2139       if( isAgg ) *pParentAgg = 1;
  2076   2140       return rc;
  2077   2141     }
  2078   2142   
  2079         -  /* Identify column types if we will be using in the callback.  This
  2080         -  ** step is skipped if the output is going to a table or a memory cell.
         2143  +  /* Identify column types if we will be using a callback.  This
         2144  +  ** step is skipped if the output is going to a destination other
         2145  +  ** than a callback.
  2081   2146     */
  2082   2147     if( eDest==SRT_Callback ){
  2083   2148       generateColumnTypes(pParse, p->base, pTabList, pEList);
  2084   2149     }
  2085   2150   
  2086   2151     /* If the output is destined for a temporary table, open that table.
  2087   2152     */
................................................................................
  2250   2315     */
  2251   2316     rc = 0;
  2252   2317   
  2253   2318     /* Control jumps to here if an error is encountered above, or upon
  2254   2319     ** successful coding of the SELECT.
  2255   2320     */
  2256   2321   select_end:
  2257         -  /* pParse->nTab = base; */
  2258   2322     sqliteAggregateInfoReset(pParse);
  2259   2323     return rc;
  2260   2324   }

Changes to src/vdbe.c.

    32     32   **
    33     33   ** Various scripts scan this source file in order to generate HTML
    34     34   ** documentation, headers files, or other derived files.  The formatting
    35     35   ** of the code in this file is, therefore, important.  See other comments
    36     36   ** in this file for details.  If in doubt, do not deviate from existing
    37     37   ** commenting and indentation practices when changing or adding code.
    38     38   **
    39         -** $Id: vdbe.c,v 1.198 2003/01/16 13:42:43 drh Exp $
           39  +** $Id: vdbe.c,v 1.199 2003/01/19 03:59:47 drh Exp $
    40     40   */
    41     41   #include "sqliteInt.h"
    42     42   #include <ctype.h>
    43     43   
    44     44   /*
    45     45   ** The makefile scans this source file and creates the following
    46     46   ** array of string constants which are the names of all VDBE opcodes.
................................................................................
  1755   1755     break;
  1756   1756   }
  1757   1757   
  1758   1758   /* Opcode: NullCallback P1 * *
  1759   1759   **
  1760   1760   ** Invoke the callback function once with the 2nd argument (the
  1761   1761   ** number of columns) equal to P1 and with the 4th argument (the
  1762         -** names of the columns) set according to prior OP_ColumnName and
  1763         -** OP_ColumnCount instructions.  This is all like the regular
         1762  +** names of the columns) set according to prior OP_ColumnName
         1763  +** instructions.  This is all like the regular
  1764   1764   ** OP_Callback or OP_SortCallback opcodes.  But the 3rd argument
  1765   1765   ** which normally contains a pointer to an array of pointers to
  1766   1766   ** data is NULL.
  1767   1767   **
  1768   1768   ** The callback is only invoked if there have been no prior calls
  1769   1769   ** to OP_Callback or OP_SortCallback.
  1770   1770   **