]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Add missing comments and fix other issues with routines used by new EQP features.
authordan <dan@noemail.net>
Tue, 9 Nov 2010 17:35:19 +0000 (17:35 +0000)
committerdan <dan@noemail.net>
Tue, 9 Nov 2010 17:35:19 +0000 (17:35 +0000)
FossilOrigin-Name: 925f35c535396603e13bb12e9a361072e2c2c223

manifest
manifest.uuid
src/select.c
src/where.c

index c86c9737cf5fb903204364651e84a378e4667429..c6c2d39540988f1c2af19139acddce4f1ef72bfa 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Further\senhancements\sand\sfixes\sfor\sexplain\squery\splan.
-D 2010-11-09T14:49:00
+C Add\smissing\scomments\sand\sfix\sother\sissues\swith\sroutines\sused\sby\snew\sEQP\sfeatures.
+D 2010-11-09T17:35:20
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in e7a59672eaeb04408d1fa8501618d7501a3c5e39
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -174,7 +174,7 @@ F src/printf.c 8ae5082dd38a1b5456030c3755ec3a392cd51506
 F src/random.c cd4a67b3953b88019f8cd4ccd81394a8ddfaba50
 F src/resolve.c 1c0f32b64f8e3f555fe1f732f9d6f501a7f05706
 F src/rowset.c 69afa95a97c524ba6faf3805e717b5b7ae85a697
-F src/select.c 7c92d9d06037065f4a01634d94a4e4cfc4bccf62
+F src/select.c 3d5086dfccb245af4801234d42b6d2888a30e2b1
 F src/shell.c 8517fc1f9c59ae4007e6cc8b9af91ab231ea2056
 F src/sqlite.h.in f47e09412fc9a129f759fa4d96ef21f4b3d529eb
 F src/sqlite3ext.h c90bd5507099f62043832d73f6425d8d5c5da754
@@ -239,7 +239,7 @@ F src/vtab.c b297e8fa656ab5e66244ab15680d68db0adbec30
 F src/wal.c f26b8d297bd11cb792e609917f9d4c6718ac8e0e
 F src/wal.h c1aac6593a0b02b15dc625987e619edeab39292e
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
-F src/where.c 8aded05b9845c1ed6849f0bda4e7c5723ef11624
+F src/where.c 2b69056fb5a9c271af4cf3d24112e9413b43d6ad
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
 F test/all.test 6745008c144bd2956d58864d21f7b304689c1cce
@@ -886,7 +886,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P f4747eb83dacce6430ad6e5eb20155ffad975514
-R 7fc20a21ba3c9c313a6e02ede2df35d9
+P 73c93f5a2a32ee8c5d07c9ba33b2641e72626627
+R 8f6e7c70fce424ee9ca0153ffe26200c
 U dan
-Z 5072ca13b6a16309d03aca048a4f29a7
+Z fb47697d5a40be4039059baaad8146eb
index d5953f1611903c5095098bc4f3061785a0745141..a93db8e13bb6baf3f3bb81eecff4d1203f39bda7 100644 (file)
@@ -1 +1 @@
-73c93f5a2a32ee8c5d07c9ba33b2641e72626627
\ No newline at end of file
+925f35c535396603e13bb12e9a361072e2c2c223
\ No newline at end of file
index 70200616f5c36d7e1a78205925eb2ec939ecd292..9e0cba59f710d7d4d99de8c1bddaf218791a93f8 100644 (file)
@@ -772,6 +772,16 @@ static KeyInfo *keyInfoFromExprList(Parse *pParse, ExprList *pList){
 }
 
 #ifndef SQLITE_OMIT_EXPLAIN
+/*
+** Unless an "EXPLAIN QUERY PLAN" command is being processed, this function
+** is a no-op. Otherwise, it adds a single row of output to the EQP result,
+** where the caption is of the form:
+**
+**   "USE TEMP B-TREE FOR xxx"
+**
+** where xxx is one of "DISTINCT", "ORDER BY" or "GROUP BY". Exactly which
+** is determined by the zUsage argument.
+*/
 static void explainTempTable(Parse *pParse, const char *zUsage){
   if( pParse->explain==2 ){
     Vdbe *v = pParse->pVdbe;
@@ -779,12 +789,20 @@ static void explainTempTable(Parse *pParse, const char *zUsage){
     sqlite3VdbeAddOp4(v, OP_Explain, pParse->iSelectId, 0, 0, zMsg, P4_DYNAMIC);
   }
 }
-# define explainRestoreSelectId() pParse->iSelectId = iRestoreSelectId
-# define explainAssignSelectId(pItem, id) pItem->iSelectId = id
+
+/*
+** Assign expression b to lvalue a. A second, no-op, version of this macro
+** is provided when SQLITE_OMIT_EXPLAIN is defined. This allows the code
+** in sqlite3Select() to assign values to structure member variables that
+** only exist if SQLITE_OMIT_EXPLAIN is not defined without polluting the
+** code with #ifndef directives.
+*/
+# define explainSetInteger(a, b) a = b
+
 #else
-# define explainRestoreSelectId()
+/* No-op versions of the explainXXX() functions and macros. */
 # define explainTempTable(y,z)
-# define explainAssignSelectId(y,z)
+# define explainSetInteger(y,z)
 #endif
 
 /*
@@ -3681,7 +3699,7 @@ int sqlite3Select(
     }else{
       sqlite3SelectDestInit(&dest, SRT_EphemTab, pItem->iCursor);
       assert( pItem->isPopulated==0 );
-      explainAssignSelectId(pItem, pParse->iNextSelectId);
+      explainSetInteger(pItem->iSelectId, pParse->iNextSelectId);
       sqlite3Select(pParse, pSub, &dest);
       pItem->isPopulated = 1;
     }
@@ -3720,7 +3738,7 @@ int sqlite3Select(
         goto select_end;
       }
     }
-    explainRestoreSelectId();
+    explainSetInteger(pParse->iSelectId, iRestoreSelectId);
     return multiSelect(pParse, p, pDest);
   }
 #endif
@@ -4227,7 +4245,7 @@ int sqlite3Select(
   ** successful coding of the SELECT.
   */
 select_end:
-  explainRestoreSelectId();
+  explainSetInteger(pParse->iSelectId, iRestoreSelectId);
 
   /* Identify column names if results of the SELECT are to be output.
   */
index 443df8cefd6bc7aa02dbed9dbc19f6c37394680f..48c3f6488b768681a32983b235c06842ba9a89cd 100644 (file)
@@ -3131,7 +3131,26 @@ static int codeAllEqualityTerms(
 }
 
 #ifndef SQLITE_OMIT_EXPLAIN
-static char *indexRangeText(sqlite3 *db, WhereLevel *pLevel, Table *pTab){
+/*
+** Argument pLevel describes a strategy for scanning table pTab. This 
+** function returns a pointer to a string buffer containing a description
+** of the subset of table rows scanned by the strategy in the form of an
+** SQL expression. Or, if all rows are scanned, NULL is returned.
+**
+** For example, if the query:
+**
+**   SELECT * FROM t1 WHERE a=1 AND b>2;
+**
+** is run and there is an index on (a, b), then this function returns a
+** string similar to:
+**
+**   "a=? AND b>?"
+**
+** The returned pointer points to memory obtained from sqlite3DbMalloc().
+** It is the responsibility of the caller to free the buffer when it is
+** no longer required.
+*/
+static char *explainIndexRange(sqlite3 *db, WhereLevel *pLevel, Table *pTab){
   WherePlan *pPlan = &pLevel->plan;
   Index *pIndex = pPlan->u.pIdx;
   int nEq = pPlan->nEq;
@@ -3160,7 +3179,13 @@ static char *indexRangeText(sqlite3 *db, WhereLevel *pLevel, Table *pTab){
   return zRet;
 }
 
-static void codeOneLoopExplain(
+/*
+** This function is a no-op unless currently processing an EXPLAIN QUERY PLAN
+** command. If the query being compiled is an EXPLAIN QUERY PLAN, a single
+** record is added to the output to describe the table scan strategy in 
+** pLevel.
+*/
+static void explainOneScan(
   Parse *pParse,                  /* Parse context */
   SrcList *pTabList,              /* Table list this loop refers to */
   WhereLevel *pLevel,             /* Scan to write OP_Explain opcode for */
@@ -3171,9 +3196,9 @@ static void codeOneLoopExplain(
   if( pParse->explain==2 ){
     u32 flags = pLevel->plan.wsFlags;
     struct SrcList_item *pItem = &pTabList->a[pLevel->iFrom];
-    Vdbe *v = pParse->pVdbe;
-    sqlite3 *db = pParse->db;
-    char *zMsg;
+    Vdbe *v = pParse->pVdbe;      /* VM being constructed */
+    sqlite3 *db = pParse->db;     /* Database handle */
+    char *zMsg;                   /* Text to add to EQP output */
     sqlite3_int64 nRow;           /* Expected number of rows visited by scan */
     int iId = pParse->iSelectId;  /* Select id (left-most output column) */
 
@@ -3189,7 +3214,7 @@ static void codeOneLoopExplain(
       zMsg = sqlite3MAppendf(db, zMsg, "%s AS %s", zMsg, pItem->zAlias);
     }
     if( (flags & WHERE_INDEXED)!=0 ){
-      char *zWhere = indexRangeText(db, pLevel, pItem->pTab);
+      char *zWhere = explainIndexRange(db, pLevel, pItem->pTab);
       zMsg = sqlite3MAppendf(db, zMsg, "%s BY %s%sINDEX%s%s%s", zMsg, 
           ((flags & WHERE_TEMP_INDEX)?"AUTOMATIC ":""),
           ((flags & WHERE_IDX_ONLY)?"COVERING ":""),
@@ -3228,7 +3253,7 @@ static void codeOneLoopExplain(
   }
 }
 #else
-# define codeOneLoopExplain(u,v,w,x,y,z)
+# define explainOneScan(u,v,w,x,y,z)
 #endif /* SQLITE_OMIT_EXPLAIN */
 
 
@@ -3773,7 +3798,7 @@ static Bitmask codeOneLoopStart(
                         WHERE_OMIT_OPEN | WHERE_OMIT_CLOSE |
                         WHERE_FORCE_TABLE | WHERE_ONETABLE_ONLY);
         if( pSubWInfo ){
-          codeOneLoopExplain(
+          explainOneScan(
               pParse, pOrTab, &pSubWInfo->a[0], iLevel, pLevel->iFrom, 0
           );
           if( (wctrlFlags & WHERE_DUPLICATES_OK)==0 ){
@@ -4432,7 +4457,7 @@ WhereInfo *sqlite3WhereBegin(
   notReady = ~(Bitmask)0;
   for(i=0; i<nTabList; i++){
     WhereLevel *pLevel = &pWInfo->a[i];
-    codeOneLoopExplain(pParse, pTabList, pLevel, i, pLevel->iFrom, wctrlFlags);
+    explainOneScan(pParse, pTabList, pLevel, i, pLevel->iFrom, wctrlFlags);
     notReady = codeOneLoopStart(pWInfo, i, wctrlFlags, notReady);
     pWInfo->iContinue = pLevel->addrCont;
   }