/ Check-in [03725ce5]
Login

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

Overview
Comment::-) (CVS 19)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 03725ce5ae871247789ece0f2c3426f74ba575e7
User & Date: drh 2000-05-30 20:17:49
Context
2000-05-31
02:27
:-) (CVS 20) check-in: 01d85b35 user: drh tags: trunk
2000-05-30
20:17
:-) (CVS 19) check-in: 03725ce5 user: drh tags: trunk
19:22
:-) (CVS 18) check-in: 2d41caec user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/where.c.

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
...
251
252
253
254
255
256
257

258
259
260
261
262
263
264
**   http://www.hwaci.com/drh/
**
*************************************************************************
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements.  Also found here are subroutines
** to generate VDBE code to evaluate expressions.
**
** $Id: where.c,v 1.2 2000/05/30 03:28:36 drh Exp $
*/
#include "sqliteInt.h"

/*
** The query generator uses an array of instances of this structure to
** help it analyze the subexpressions of the WHERE clause.  Each WHERE
** clause subexpression is separated from the others by an AND operator.
................................................................................
  }

  /* Figure out a good nesting order for the tables.  aOrder[0] will
  ** be the index in pTabList of the outermost table.  aOrder[1] will
  ** be the first nested loop and so on.  aOrder[pTabList->nId-1] will
  ** be the innermost loop.
  **
  ** Someday will put in a good algorithm here to reorder to the loops
  ** for an effiecient query.  But for now, just use whatever order the
  ** tables appear in in the pTabList.
  */
  for(i=0; i<pTabList->nId; i++){
    aOrder[i] = i;
  }

................................................................................
  for(i=0; i<pTabList->nId && i<ARRAYSIZE(aIdx); i++){
    int idx = aOrder[i];
    Table *pTab = pTabList->a[idx].pTab;
    Index *pIdx;
    Index *pBestIdx = 0;

    /* Do a search for usable indices.  Leave pBestIdx pointing to
    ** most specific usable index.
    **
    ** "Most specific" means that pBestIdx is the usable index that
    ** has the largest value for nField.  A usable index is one for
    ** which there are subexpressions to compute every field of the
    ** index.
    */
    for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
................................................................................
      if( fieldMask + 1 == (1<<pIdx->nField) ){
        if( pBestIdx==0 || pBestIdx->nField<pIdx->nField ){
          pBestIdx = pIdx;
        }
      }
    }
    aIdx[i] = pBestIdx;

  }

  /* Open all tables in the pTabList and all indices in aIdx[].
  */
  for(i=0; i<pTabList->nId; i++){
    sqliteVdbeAddOp(v, OP_Open, i, 0, pTabList->a[i].pTab->zName, 0);
    if( i<ARRAYSIZE(aIdx) && aIdx[i]!=0 ){







|







 







|







 







|







 







>







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
...
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
...
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
**   http://www.hwaci.com/drh/
**
*************************************************************************
** This module contains C code that generates VDBE code used to process
** the WHERE clause of SQL statements.  Also found here are subroutines
** to generate VDBE code to evaluate expressions.
**
** $Id: where.c,v 1.3 2000/05/30 20:17:49 drh Exp $
*/
#include "sqliteInt.h"

/*
** The query generator uses an array of instances of this structure to
** help it analyze the subexpressions of the WHERE clause.  Each WHERE
** clause subexpression is separated from the others by an AND operator.
................................................................................
  }

  /* Figure out a good nesting order for the tables.  aOrder[0] will
  ** be the index in pTabList of the outermost table.  aOrder[1] will
  ** be the first nested loop and so on.  aOrder[pTabList->nId-1] will
  ** be the innermost loop.
  **
  ** Someday will put in a good algorithm here to reorder the loops
  ** for an effiecient query.  But for now, just use whatever order the
  ** tables appear in in the pTabList.
  */
  for(i=0; i<pTabList->nId; i++){
    aOrder[i] = i;
  }

................................................................................
  for(i=0; i<pTabList->nId && i<ARRAYSIZE(aIdx); i++){
    int idx = aOrder[i];
    Table *pTab = pTabList->a[idx].pTab;
    Index *pIdx;
    Index *pBestIdx = 0;

    /* Do a search for usable indices.  Leave pBestIdx pointing to
    ** the most specific usable index.
    **
    ** "Most specific" means that pBestIdx is the usable index that
    ** has the largest value for nField.  A usable index is one for
    ** which there are subexpressions to compute every field of the
    ** index.
    */
    for(pIdx=pTab->pIndex; pIdx; pIdx=pIdx->pNext){
................................................................................
      if( fieldMask + 1 == (1<<pIdx->nField) ){
        if( pBestIdx==0 || pBestIdx->nField<pIdx->nField ){
          pBestIdx = pIdx;
        }
      }
    }
    aIdx[i] = pBestIdx;
    loopMask |= 1<<idx;
  }

  /* Open all tables in the pTabList and all indices in aIdx[].
  */
  for(i=0; i<pTabList->nId; i++){
    sqliteVdbeAddOp(v, OP_Open, i, 0, pTabList->a[i].pTab->zName, 0);
    if( i<ARRAYSIZE(aIdx) && aIdx[i]!=0 ){