1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-11-14 00:22:38 +03:00

Update comments. No changes to code. (CVS 841)

FossilOrigin-Name: f6a8706872c43cee3003b48bb427c7b74b1f89e7
This commit is contained in:
drh
2003-01-19 03:59:45 +00:00
parent 79104c9d2a
commit e78e8284ad
7 changed files with 103 additions and 38 deletions

View File

@@ -12,7 +12,7 @@
** This file contains C code routines that are called by the parser
** to handle SELECT statements in SQLite.
**
** $Id: select.c,v 1.122 2003/01/18 20:11:07 drh Exp $
** $Id: select.c,v 1.123 2003/01/19 03:59:47 drh Exp $
*/
#include "sqliteInt.h"
@@ -180,7 +180,7 @@ static void addWhereTerm(
/*
** Set the EP_FromJoin property on all terms of the given expression.
**
** The EP_FromJoin property is used at on terms of an expression to tell
** The EP_FromJoin property is used on terms of an expression to tell
** the LEFT OUTER JOIN processing logic that this term is part of the
** join restriction specified in the ON or USING clause and not a part
** of the more general WHERE clause. These terms are moved over to the
@@ -677,6 +677,17 @@ static void generateSortTail(
/*
** Generate code that will tell the VDBE the datatypes of
** columns in the result set.
**
** This routine only generates code if the "PRAGMA show_datatypes=on"
** has been executed. The datatypes are reported out in the azCol
** parameter to the callback function. The first N azCol[] entries
** are the names of the columns, and the second N entries are the
** datatypes for the columns.
**
** The "datatype" for a result that is a column of a type is the
** datatype definition extracted from the CREATE TABLE statement.
** The datatype for an expression is either TEXT or NUMERIC. The
** datatype for a ROWID field is INTEGER.
*/
static void generateColumnTypes(
Parse *pParse, /* Parser context */
@@ -1187,7 +1198,19 @@ Vdbe *sqliteGetVdbe(Parse *pParse){
**
** Examples:
**
** SELECT a,b
** CREATE TABLE one(a INTEGER, b TEXT);
** CREATE TABLE two(c VARCHAR(5), d FLOAT);
**
** SELECT b, b FROM one UNION SELECT d, c FROM two ORDER BY 1, 2;
**
** The primary sort key will use SQLITE_SO_NUM because the "d" in
** the second SELECT is numeric. The 1st column of the first SELECT
** is text but that does not matter because a numeric always overrides
** a text.
**
** The secondary key will use the SQLITE_SO_TEXT sort order because
** both the (second) "b" in the first SELECT and the "c" in the second
** SELECT have a datatype of text.
*/
static void multiSelectSortOrder(Select *p, ExprList *pOrderBy){
int i;
@@ -1215,8 +1238,31 @@ static void multiSelectSortOrder(Select *p, ExprList *pOrderBy){
** This routine is called to process a query that is really the union
** or intersection of two or more separate queries.
**
** "p" points to the right-most of the two queries. The results should
** be stored in eDest with parameter iParm.
** "p" points to the right-most of the two queries. the query on the
** left is p->pPrior. The left query could also be a compound query
** in which case this routine will be called recursively.
**
** The results of the total query are to be written into a destination
** of type eDest with parameter iParm.
**
** Example 1: Consider a three-way compound SQL statement.
**
** SELECT a FROM t1 UNION SELECT b FROM t2 UNION SELECT c FROM t3
**
** This statement is parsed up as follows:
**
** SELECT c FROM t3
** |
** `-----> SELECT b FROM t2
** |
** `------> SELECT c FROM t1
**
** The arrows in the diagram above represent the Select.pPrior pointer.
** So if this routine is called with p equal to the t3 query, then
** pPrior will be the t2 query. p->op will be TK_UNION in this case.
**
** Notice that because of the way SQLite parses compound SELECTs, the
** individual selects always group from left to right.
*/
static int multiSelect(Parse *pParse, Select *p, int eDest, int iParm){
int rc; /* Success code from a subroutine */
@@ -1695,7 +1741,7 @@ static int flattenSubquery(
** Analyze the SELECT statement passed in as an argument to see if it
** is a simple min() or max() query. If it is and this query can be
** satisfied using a single seek to the beginning or end of an index,
** then generate the code for this SELECT return 1. If this is not a
** then generate the code for this SELECT and return 1. If this is not a
** simple min() or max() query, then return 0;
**
** A simply min() or max() query looks like this:
@@ -1826,6 +1872,10 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
**
** SRT_Table Store results in temporary table iParm
**
** The table above is incomplete. Additional eDist value have be added
** since this comment was written. See the selectInnerLoop() function for
** a complete listing of the allowed values of eDest and their meanings.
**
** This routine returns the number of errors. If any errors are
** encountered, then an appropriate error message is left in
** pParse->zErrMsg.
@@ -1839,12 +1889,26 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
** change the parent query from a non-aggregate to an aggregate query.
** For that reason, the pParentAgg flag is passed as a pointer, so it
** can be changed.
**
** Example 1: The meaning of the pParent parameter.
**
** SELECT * FROM t1 JOIN (SELECT x, count(*) FROM t2) JOIN t3;
** \ \_______ subquery _______/ /
** \ /
** \____________________ outer query ___________________/
**
** This routine is called for the outer query first. For that call,
** pParent will be NULL. During the processing of the outer query, this
** routine is called recursively to handle the subquery. For the recursive
** call, pParent will point to the outer query. Because the subquery is
** the second element in a three-way join, the parentTab parameter will
** be 1 (the 2nd value of a 0-indexed array.)
*/
int sqliteSelect(
Parse *pParse, /* The parser context */
Select *p, /* The SELECT statement being coded. */
int eDest, /* One of: SRT_Callback Mem Set Union Except */
int iParm, /* Save result in this memory location, if >=0 */
int eDest, /* How to dispose of the results */
int iParm, /* A parameter used by the eDest disposal method */
Select *pParent, /* Another SELECT for which this is a sub-query */
int parentTab, /* Index in pParent->pSrc of this query */
int *pParentAgg /* True if pParent uses aggregate functions */
@@ -1895,9 +1959,9 @@ int sqliteSelect(
*/
if( pParse->nErr>0 ) goto select_end;
/* Look up every table in the table list and create an appropriate
** columnlist in pEList if there isn't one already. (The parser leaves
** a NULL in the p->pEList if the SQL said "SELECT * FROM ...")
/* Expand any "*" terms in the result set. (For example the "*" in
** "SELECT * FROM t1") The fillInColumnlist() routine also does some
** other housekeeping - see the header comment for details.
*/
if( fillInColumnList(pParse, p) ){
goto select_end;
@@ -2024,8 +2088,8 @@ int sqliteSelect(
v = sqliteGetVdbe(pParse);
if( v==0 ) goto select_end;
/* Identify column names if we will be using in the callback. This
** step is skipped if the output is going to a table or a memory cell.
/* Identify column names if we will be using them in a callback. This
** step is skipped if the output is going to some other destination.
*/
if( eDest==SRT_Callback ){
generateColumnNames(pParse, p->base, pTabList, pEList);
@@ -2076,8 +2140,9 @@ int sqliteSelect(
return rc;
}
/* Identify column types if we will be using in the callback. This
** step is skipped if the output is going to a table or a memory cell.
/* Identify column types if we will be using a callback. This
** step is skipped if the output is going to a destination other
** than a callback.
*/
if( eDest==SRT_Callback ){
generateColumnTypes(pParse, p->base, pTabList, pEList);
@@ -2254,7 +2319,6 @@ int sqliteSelect(
** successful coding of the SELECT.
*/
select_end:
/* pParse->nTab = base; */
sqliteAggregateInfoReset(pParse);
return rc;
}