-C Update\sthe\sspeed\scomparison\spage.\s(CVS\s840)
-D 2003-01-18T22:01:07
+C Update\scomments.\s\sNo\schanges\sto\scode.\s(CVS\s841)
+D 2003-01-19T03:59:46
F Makefile.in 6606854b1512f185b8e8c779b8d7fc2750463d64
F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
F src/btree.h 17710339f7a8f46e3c7d6d0d4648ef19c584ffda
F src/build.c 0454fd02e163865c82106dd52dec4a4caf908ebf
F src/delete.c cbd499f3f9297504c42e328af89bef1a2113d04c
-F src/encode.c 09d1fe8a2e97ff94cce496e2909e2ebc8947960b
+F src/encode.c faf03741efe921755ec371cf4a6984536de00042
F src/expr.c 382839b92cb66a34cfa71cf1d2bc8fb818226c90
F src/func.c 90c583f0b91220f7cd411a2407deaf9327245d63
F src/hash.c 4fc39feb7b7711f6495ee9f2159559bedb043e1f
F src/hash.h cd0433998bc1a3759d244e1637fe5a3c13b53bf8
F src/insert.c db954e955970795819145a3649fd2ad116a58890
-F src/main.c a05db522f8182f47e0cc6902327a7c205735d808
+F src/main.c ad3193c56da5acd31bc6cd48aa50dae1962d7c78
F src/md5.c fe4f9c9c6f71dfc26af8da63e4d04489b1430565
F src/os.c 3a652608c296cf639ce63bd31d255db862e45685
F src/os.h afa3e096213bad86845f8bdca81a9e917505e401
F src/pager.c 081155624cff7bec54590133b69906a23f9b3659
F src/pager.h 540833e8cb826b80ce2e39aa917deee5e12db626
F src/parse.y a4fbfbe3c4254c96dae8c33264fb54af755a3770
-F src/printf.c 5c50fc1da75c8f5bf432b1ad17d91d6653acd167
+F src/printf.c e8e9a0605602cb1a3a2dc754e0978fa9064ecee7
F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe
-F src/select.c 65373244633151884ea83daffb34ef98382ac3b3
+F src/select.c c3c0b8263587d290592dca8b4371b5c1162ca684
F src/shell.c cbb29252f0bd7b144d1e3126e64e17e5a314f2fd
F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
F src/sqlite.h.in 90657185cff387069d17c5b876a87a6a7a3b6f10
F src/trigger.c da142decd2808bc39e801f3bb1f161dbc2bd4005
F src/update.c f06afa9bf1f777d17702e0f6e33cf44c44bc4f75
F src/util.c e23f8ffc654923e18f8db2d8e0de97c166fca20f
-F src/vdbe.c dc0a9c1b815c95b14ffe62765cfd528d974c6c1b
+F src/vdbe.c 7796485aa510c89aa378a11d3fbeb6fcf3893433
F src/vdbe.h 754eba497cfe0c3e352b9c101ab2f811f10d0a55
F src/where.c 5bf7f1e1d756ab3d25a18b24bb42106cb8e14d18
F test/all.test 873d30e25a41b3aa48fec5633a7ec1816e107029
F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 71cc292dce59cf8224b205d1cdbff59ad12f1043
-R 843340c3fef7e6ee0ac6b3187554a951
+P 424cb2edb0c51b911791422ce7a9f5284a57f9ce
+R c412fddde0211bcedc2c913718bf3cae
U drh
-Z 66212ef777c3998af30d067a457e17bb
+Z 08ec0c344754362c114e2ab7933a5823
** 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"
/*
** 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
/*
** 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 */
**
** 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;
** 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 */
** 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:
**
** 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.
** 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 */
*/
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;
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);
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);
** successful coding of the SELECT.
*/
select_end:
- /* pParse->nTab = base; */
sqliteAggregateInfoReset(pParse);
return rc;
}