/ Check-in [a0bdb584]
Login
SQLite training in Houston TX on 2019-11-05 (details)
Part of the 2019 Tcl Conference

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

Overview
Comment:Attempt to fix the SQLite core so that no floating point operations are used anywhere if SQLITE_OMIT_FLOATING_POINT is defined at compile-time. This is useful to people who use SQLite on embedded processors that lack floating point support. (CVS 2749)
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: a0bdb584680ce6400d9e8c57db9d91197cc7b776
User & Date: drh 2005-10-13 02:09:50
Context
2005-10-20
07:28
Changes to prevent various compiler warnings. (CVS 2750) check-in: e261b8b0 user: drh tags: trunk
2005-10-13
02:09
Attempt to fix the SQLite core so that no floating point operations are used anywhere if SQLITE_OMIT_FLOATING_POINT is defined at compile-time. This is useful to people who use SQLite on embedded processors that lack floating point support. (CVS 2749) check-in: a0bdb584 user: drh tags: trunk
2005-10-10
00:05
Make the default TEMP_STORE=1 (TEMP tables stored on disk) in the configure script. (CVS 2748) check-in: 9753af53 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/func.c.

    12     12   ** This file contains the C functions that implement various SQL
    13     13   ** functions of SQLite.  
    14     14   **
    15     15   ** There is only one exported symbol in this file - the function
    16     16   ** sqliteRegisterBuildinFunctions() found at the bottom of the file.
    17     17   ** All other code has file scope.
    18     18   **
    19         -** $Id: func.c,v 1.110 2005/09/08 20:37:43 drh Exp $
           19  +** $Id: func.c,v 1.111 2005/10/13 02:09:50 drh Exp $
    20     20   */
    21     21   #include "sqliteInt.h"
    22     22   #include <ctype.h>
    23         -#include <math.h>
           23  +/* #include <math.h> */
    24     24   #include <stdlib.h>
    25     25   #include <assert.h>
    26     26   #include "vdbeInt.h"
    27     27   #include "os.h"
    28     28   
    29     29   /*
    30     30   ** Return the collating function associated with a function.

Changes to src/printf.c.

   116    116     {  'q',  0, 4, etSQLESCAPE,  0,  0 },
   117    117     {  'Q',  0, 4, etSQLESCAPE2, 0,  0 },
   118    118     {  'c',  0, 0, etCHARX,      0,  0 },
   119    119     {  'o',  8, 0, etRADIX,      0,  2 },
   120    120     {  'u', 10, 0, etRADIX,      0,  0 },
   121    121     {  'x', 16, 0, etRADIX,      16, 1 },
   122    122     {  'X', 16, 0, etRADIX,      0,  4 },
          123  +#ifndef SQLITE_OMIT_FLOATING_POINT
   123    124     {  'f',  0, 1, etFLOAT,      0,  0 },
   124    125     {  'e',  0, 1, etEXP,        30, 0 },
   125    126     {  'E',  0, 1, etEXP,        14, 0 },
   126    127     {  'G',  0, 1, etGENERIC,    14, 0 },
          128  +#endif
   127    129     {  'i', 10, 1, etRADIX,      0,  0 },
   128    130     {  'n',  0, 0, etSIZE,       0,  0 },
   129    131     {  '%',  0, 0, etPERCENT,    0,  0 },
   130    132     {  'p', 16, 0, etPOINTER,    0,  1 },
   131    133     {  'T',  0, 2, etTOKEN,      0,  0 },
   132    134     {  'S',  0, 2, etSRCLIST,    0,  0 },
   133    135   };
   134    136   #define etNINFO  (sizeof(fmtinfo)/sizeof(fmtinfo[0]))
   135    137   
   136    138   /*
   137         -** If NOFLOATINGPOINT is defined, then none of the floating point
          139  +** If SQLITE_OMIT_FLOATING_POINT is defined, then none of the floating point
   138    140   ** conversions will work.
   139    141   */
   140         -#ifndef etNOFLOATINGPOINT
          142  +#ifndef SQLITE_OMIT_FLOATING_POINT
   141    143   /*
   142    144   ** "*val" is a double such that 0.1 <= *val < 10.0
   143    145   ** Return the ascii code for the leading digit of *val, then
   144    146   ** multiply "*val" by 10.0 to renormalize.
   145    147   **
   146    148   ** Example:
   147    149   **     input:     *val = 3.14159
................................................................................
   157    159     if( (*cnt)++ >= 16 ) return '0';
   158    160     digit = (int)*val;
   159    161     d = digit;
   160    162     digit += '0';
   161    163     *val = (*val - d)*10.0;
   162    164     return digit;
   163    165   }
   164         -#endif
          166  +#endif /* SQLITE_OMIT_FLOATING_POINT */
   165    167   
   166    168   /*
   167    169   ** On machines with a small stack size, you can redefine the
   168    170   ** SQLITE_PRINT_BUF_SIZE to be less than 350.  But beware - for
   169    171   ** smaller values some %f conversions may go into an infinite loop.
   170    172   */
   171    173   #ifndef SQLITE_PRINT_BUF_SIZE
................................................................................
   230    232     char prefix;               /* Prefix character.  "+" or "-" or " " or '\0'. */
   231    233     etByte errorflag = 0;      /* True if an error is encountered */
   232    234     etByte xtype;              /* Conversion paradigm */
   233    235     char *zExtra;              /* Extra memory used for etTCLESCAPE conversions */
   234    236     static const char spaces[] =
   235    237      "                                                                         ";
   236    238   #define etSPACESIZE (sizeof(spaces)-1)
   237         -#ifndef etNOFLOATINGPOINT
          239  +#ifndef SQLITE_OMIT_FLOATING_POINT
   238    240     int  exp, e2;              /* exponent of real numbers */
   239    241     double rounder;            /* Used for rounding floating point values */
   240    242     etByte flag_dp;            /* True if decimal point should be shown */
   241    243     etByte flag_rtz;           /* True if trailing zeros should be removed */
   242    244     etByte flag_exp;           /* True to force display of the exponent */
   243    245     int nsd;                   /* Number of significant digits returned */
   244    246   #endif
................................................................................
   421    423           }
   422    424           length = &buf[etBUFSIZE-1]-bufpt;
   423    425           break;
   424    426         case etFLOAT:
   425    427         case etEXP:
   426    428         case etGENERIC:
   427    429           realvalue = va_arg(ap,double);
   428         -#ifndef etNOFLOATINGPOINT
          430  +#ifndef SQLITE_OMIT_FLOATING_POINT
   429    431           if( precision<0 ) precision = 6;         /* Set default precision */
   430    432           if( precision>etBUFSIZE/2-10 ) precision = etBUFSIZE/2-10;
   431    433           if( realvalue<0.0 ){
   432    434             realvalue = -realvalue;
   433    435             prefix = '-';
   434    436           }else{
   435    437             if( flag_plussign )          prefix = '+';

Changes to src/sqlite.h.in.

     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 header file defines the interface that the SQLite library
    13     13   ** presents to client programs.
    14     14   **
    15         -** @(#) $Id: sqlite.h.in,v 1.141 2005/09/08 10:58:52 drh Exp $
           15  +** @(#) $Id: sqlite.h.in,v 1.142 2005/10/13 02:09:50 drh Exp $
    16     16   */
    17     17   #ifndef _SQLITE3_H_
    18     18   #define _SQLITE3_H_
    19     19   #include <stdarg.h>     /* Needed for the definition of va_list */
    20     20   
    21     21   /*
    22     22   ** Make sure we can call this stuff from C++.
................................................................................
    82     82     typedef __int64 sqlite_int64;
    83     83     typedef unsigned __int64 sqlite_uint64;
    84     84   #else
    85     85     typedef long long int sqlite_int64;
    86     86     typedef unsigned long long int sqlite_uint64;
    87     87   #endif
    88     88   
           89  +/*
           90  +** If compiling for a processor that lacks floating point support,
           91  +** substitute integer for floating-point
           92  +*/
           93  +#ifdef SQLITE_OMIT_FLOATING_POINT
           94  +# define double sqlite_int64
           95  +#endif
    89     96   
    90     97   /*
    91     98   ** A function to close the database.
    92     99   **
    93    100   ** Call this function with a pointer to a structure that was previously
    94    101   ** returned from sqlite3_open() and the corresponding database will by closed.
    95    102   **
................................................................................
  1265   1272   ** Return the sqlite3* database handle to which the prepared statement given
  1266   1273   ** in the argument belongs.  This is the same database handle that was
  1267   1274   ** the first argument to the sqlite3_prepare() that was used to create
  1268   1275   ** the statement in the first place.
  1269   1276   */
  1270   1277   sqlite3 *sqlite3_db_handle(sqlite3_stmt*);
  1271   1278   
         1279  +/*
         1280  +** Undo the hack that converts floating point types to integer for
         1281  +** builds on processors without floating point support.
         1282  +*/
         1283  +#ifdef SQLITE_OMIT_FLOATING_POINT
         1284  +# undef double
         1285  +#endif
         1286  +
  1272   1287   #ifdef __cplusplus
  1273   1288   }  /* End of the 'extern "C"' block */
  1274   1289   #endif
  1275   1290   #endif

Changes to src/sqliteInt.h.

     7      7   **    May you do good and not evil.
     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   ** Internal interface definitions for SQLite.
    13     13   **
    14         -** @(#) $Id: sqliteInt.h,v 1.422 2005/10/06 16:53:15 drh Exp $
           14  +** @(#) $Id: sqliteInt.h,v 1.423 2005/10/13 02:09:50 drh Exp $
    15     15   */
    16     16   #ifndef _SQLITEINT_H_
    17     17   #define _SQLITEINT_H_
    18     18   
    19     19   /*
    20     20   ** Many people are failing to set -DNDEBUG=1 when compiling SQLite.
    21     21   ** Setting NDEBUG makes the code smaller and run faster.  So the following
................................................................................
    55     55   #include "parse.h"
    56     56   #include <stdio.h>
    57     57   #include <stdlib.h>
    58     58   #include <string.h>
    59     59   #include <assert.h>
    60     60   #include <stddef.h>
    61     61   
           62  +/*
           63  +** If compiling for a processor that lacks floating point support,
           64  +** substitute integer for floating-point
           65  +*/
           66  +#ifdef SQLITE_OMIT_FLOATING_POINT
           67  +# define double sqlite_int64
           68  +# define LONGDOUBLE_TYPE sqlite_int64
           69  +# define SQLITE_BIG_DBL (0x7fffffffffffffff)
           70  +# define SQLITE_OMIT_DATETIME_FUNCS 1
           71  +# define SQLITE_OMIT_TRACE 1
           72  +#endif
           73  +
    62     74   /*
    63     75   ** The maximum number of in-memory pages to use for the main database
    64     76   ** table and for temporary tables. Internally, the MAX_PAGES and 
    65     77   ** TEMP_PAGES macros are used. To override the default values at
    66     78   ** compilation time, the SQLITE_DEFAULT_CACHE_SIZE and 
    67     79   ** SQLITE_DEFAULT_TEMP_CACHE_SIZE macros should be set.
    68     80   */
................................................................................
   124    136   #define MAX_ATTACHED 10
   125    137   
   126    138   /*
   127    139   ** The maximum value of a ?nnn wildcard that the parser will accept.
   128    140   */
   129    141   #define SQLITE_MAX_VARIABLE_NUMBER 999
   130    142   
   131         -/*
   132         -** When building SQLite for embedded systems where memory is scarce,
   133         -** you can define one or more of the following macros to omit extra
   134         -** features of the library and thus keep the size of the library to
   135         -** a minimum.
   136         -*/
   137         -/* #define SQLITE_OMIT_AUTHORIZATION  1 */
   138         -/* #define SQLITE_OMIT_MEMORYDB     1 */
   139         -/* #define SQLITE_OMIT_VACUUM         1 */
   140         -/* #define SQLITE_OMIT_DATETIME_FUNCS 1 */
   141         -/* #define SQLITE_OMIT_PROGRESS_CALLBACK 1 */
   142         -/* #define SQLITE_OMIT_AUTOVACUUM */
   143         -/* #define SQLITE_OMIT_ALTERTABLE */
   144         -
   145    143   /*
   146    144   ** Provide a default value for TEMP_STORE in case it is not specified
   147    145   ** on the command-line
   148    146   */
   149    147   #ifndef TEMP_STORE
   150    148   # define TEMP_STORE 1
   151    149   #endif

Changes to src/util.c.

    10     10   **
    11     11   *************************************************************************
    12     12   ** Utility functions used throughout sqlite.
    13     13   **
    14     14   ** This file contains functions for allocating memory, comparing
    15     15   ** strings, and stuff like that.
    16     16   **
    17         -** $Id: util.c,v 1.146 2005/09/17 18:34:11 drh Exp $
           17  +** $Id: util.c,v 1.147 2005/10/13 02:09:50 drh Exp $
    18     18   */
    19     19   #include "sqliteInt.h"
    20     20   #include <stdarg.h>
    21     21   #include <ctype.h>
    22     22   
    23     23   #if SQLITE_MEMDEBUG>2 && defined(__GLIBC__)
    24     24   #include <execinfo.h>
................................................................................
   602    602   **
   603    603   ** This routine is used instead of the library atof() function because
   604    604   ** the library atof() might want to use "," as the decimal point instead
   605    605   ** of "." depending on how locale is set.  But that would cause problems
   606    606   ** for SQL.  So this routine always uses "." regardless of locale.
   607    607   */
   608    608   int sqlite3AtoF(const char *z, double *pResult){
          609  +#ifndef SQLITE_OMIT_FLOATING_POINT
   609    610     int sign = 1;
   610    611     const char *zBegin = z;
   611    612     LONGDOUBLE_TYPE v1 = 0.0;
   612    613     if( *z=='-' ){
   613    614       sign = -1;
   614    615       z++;
   615    616     }else if( *z=='+' ){
................................................................................
   652    653         v1 /= scale;
   653    654       }else{
   654    655         v1 *= scale;
   655    656       }
   656    657     }
   657    658     *pResult = sign<0 ? -v1 : v1;
   658    659     return z - zBegin;
          660  +#else
          661  +  return sqlite3atoi64(z, pResult);
          662  +#endif /* SQLITE_OMIT_FLOATING_POINT */
   659    663   }
   660    664   
   661    665   /*
   662    666   ** Return TRUE if zNum is a 64-bit signed integer and write
   663    667   ** the value of the integer into *pNum.  If zNum is not an integer
   664    668   ** or is an integer that is too large to be expressed with 64 bits,
   665    669   ** then return false.  If n>0 and the integer is string is not

Changes to src/where.c.

    12     12   ** This module contains C code that generates VDBE code used to process
    13     13   ** the WHERE clause of SQL statements.  This module is reponsible for
    14     14   ** generating the code that loops through a table looking for applicable
    15     15   ** rows.  Indices are selected and used to speed the search when doing
    16     16   ** so is applicable.  Because this module is responsible for selecting
    17     17   ** indices, you might also think of this module as the "query optimizer".
    18     18   **
    19         -** $Id: where.c,v 1.179 2005/09/20 17:42:23 drh Exp $
           19  +** $Id: where.c,v 1.180 2005/10/13 02:09:50 drh Exp $
    20     20   */
    21     21   #include "sqliteInt.h"
    22     22   
    23     23   /*
    24     24   ** The number of bits in a Bitmask.  "BMS" means "BitMask Size".
    25     25   */
    26     26   #define BMS  (sizeof(Bitmask)*8)
................................................................................
    36     36   #if defined(SQLITE_TEST) || defined(SQLITE_DEBUG)
    37     37   int sqlite3_where_trace = 0;
    38     38   # define TRACE(X)  if(sqlite3_where_trace) sqlite3DebugPrintf X
    39     39   #else
    40     40   # define TRACE(X)
    41     41   #endif
    42     42   
           43  +/*
           44  +** A large value which is the maximum cost of using an index.
           45  +** By default this is a large floating point value.  When compiling
           46  +** SQLite for a processor that lacks floating point support, simply
           47  +** redefine this constant to a large integer.
           48  +*/
           49  +#ifndef SQLITE_BIG_DBL
           50  +# define SQLITE_BIG_DBL (1.0e+99)
           51  +#endif
           52  +
    43     53   /* Forward reference
    44     54   */
    45     55   typedef struct WhereClause WhereClause;
    46     56   
    47     57   /*
    48     58   ** The query generator uses an array of instances of this structure to
    49     59   ** help it analyze the subexpressions of the WHERE clause.  Each WHERE
................................................................................
   850    860   ** Prepare a crude estimate of the logarithm of the input value.
   851    861   ** The results need not be exact.  This is only used for estimating
   852    862   ** the total cost of performing operatings with O(logN) or O(NlogN)
   853    863   ** complexity.  Because N is just a guess, it is no great tragedy if
   854    864   ** logN is a little off.
   855    865   */
   856    866   static double estLog(double N){
   857         -  double logN = 1.0;
   858         -  double x = 10.0;
          867  +  double logN = 1;
          868  +  double x = 10;
   859    869     while( N>x ){
   860         -    logN += 1.0;
          870  +    logN += 1;
   861    871       x *= 10;
   862    872     }
   863    873     return logN;
   864    874   }
   865    875   
   866    876   /*
   867    877   ** Find the best index for accessing a particular table.  Return a pointer
................................................................................
   889    899     ExprList *pOrderBy,         /* The order by clause */
   890    900     Index **ppIndex,            /* Make *ppIndex point to the best index */
   891    901     int *pFlags,                /* Put flags describing this choice in *pFlags */
   892    902     int *pnEq                   /* Put the number of == or IN constraints here */
   893    903   ){
   894    904     WhereTerm *pTerm;
   895    905     Index *bestIdx = 0;         /* Index that gives the lowest cost */
   896         -  double lowestCost = 1.0e99; /* The cost of using bestIdx */
          906  +  double lowestCost;          /* The cost of using bestIdx */
   897    907     int bestFlags = 0;          /* Flags associated with bestIdx */
   898    908     int bestNEq = 0;            /* Best value for nEq */
   899    909     int iCur = pSrc->iCursor;   /* The cursor of the table to be accessed */
   900    910     Index *pProbe;              /* An index we are evaluating */
   901    911     int rev;                    /* True to scan in reverse order */
   902    912     int flags;                  /* Flags associated with pProbe */
   903    913     int nEq;                    /* Number of == or IN constraints */
   904    914     double cost;                /* Cost of using pProbe */
   905    915   
   906    916     TRACE(("bestIndex: tbl=%s notReady=%x\n", pSrc->pTab->zName, notReady));
          917  +  lowestCost = SQLITE_BIG_DBL;
   907    918   
   908    919     /* Check for a rowid=EXPR or rowid IN (...) constraints
   909    920     */
   910    921     pTerm = findTerm(pWC, iCur, -1, notReady, WO_EQ|WO_IN, 0);
   911    922     if( pTerm ){
   912    923       Expr *pExpr;
   913    924       *ppIndex = 0;
................................................................................
   924    935         ** elements.  */
   925    936         lowestCost = pExpr->pList->nExpr;
   926    937         lowestCost *= estLog(lowestCost);
   927    938       }else{
   928    939         /* Rowid IN (SELECT): cost is NlogN where N is the number of rows
   929    940         ** in the result of the inner select.  We have no way to estimate
   930    941         ** that value so make a wild guess. */
   931         -      lowestCost = 200.0;
          942  +      lowestCost = 200;
   932    943       }
   933    944       TRACE(("... rowid IN cost: %.9g\n", lowestCost));
   934    945     }
   935    946   
   936    947     /* Estimate the cost of a table scan.  If we do not know how many
   937    948     ** entries are in the table, use 1 million as a guess.
   938    949     */
   939    950     pProbe = pSrc->pTab->pIndex;
   940         -  cost = pProbe ? pProbe->aiRowEst[0] : 1000000.0;
          951  +  cost = pProbe ? pProbe->aiRowEst[0] : 1000000;
   941    952     TRACE(("... table scan base cost: %.9g\n", cost));
   942    953     flags = WHERE_ROWID_RANGE;
   943    954   
   944    955     /* Check for constraints on a range of rowids in a table scan.
   945    956     */
   946    957     pTerm = findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE|WO_GT|WO_GE, 0);
   947    958     if( pTerm ){
   948    959       if( findTerm(pWC, iCur, -1, notReady, WO_LT|WO_LE, 0) ){
   949    960         flags |= WHERE_TOP_LIMIT;
   950         -      cost *= 0.333;  /* Guess that rowid<EXPR eliminates two-thirds or rows */
          961  +      cost /= 3;  /* Guess that rowid<EXPR eliminates two-thirds or rows */
   951    962       }
   952    963       if( findTerm(pWC, iCur, -1, notReady, WO_GT|WO_GE, 0) ){
   953    964         flags |= WHERE_BTM_LIMIT;
   954         -      cost *= 0.333;  /* Guess that rowid>EXPR eliminates two-thirds of rows */
          965  +      cost /= 3;  /* Guess that rowid>EXPR eliminates two-thirds of rows */
   955    966       }
   956    967       TRACE(("... rowid range reduces cost to %.9g\n", cost));
   957    968     }else{
   958    969       flags = 0;
   959    970     }
   960    971   
   961    972     /* If the table scan does not satisfy the ORDER BY clause, increase
................................................................................
   976    987       bestFlags = flags;
   977    988     }
   978    989   
   979    990     /* Look at each index.
   980    991     */
   981    992     for(; pProbe; pProbe=pProbe->pNext){
   982    993       int i;                       /* Loop counter */
   983         -    double inMultiplier = 1.0;
          994  +    double inMultiplier = 1;
   984    995   
   985    996       TRACE(("... index %s:\n", pProbe->zName));
   986    997   
   987    998       /* Count the number of columns in the index that are satisfied
   988    999       ** by x=EXPR constraints or x IN (...) constraints.
   989   1000       */
   990   1001       flags = 0;
................................................................................
   993   1004         pTerm = findTerm(pWC, iCur, j, notReady, WO_EQ|WO_IN, pProbe);
   994   1005         if( pTerm==0 ) break;
   995   1006         flags |= WHERE_COLUMN_EQ;
   996   1007         if( pTerm->operator & WO_IN ){
   997   1008           Expr *pExpr = pTerm->pExpr;
   998   1009           flags |= WHERE_COLUMN_IN;
   999   1010           if( pExpr->pSelect!=0 ){
  1000         -          inMultiplier *= 100.0;
         1011  +          inMultiplier *= 100;
  1001   1012           }else if( pExpr->pList!=0 ){
  1002         -          inMultiplier *= pExpr->pList->nExpr + 1.0;
         1013  +          inMultiplier *= pExpr->pList->nExpr + 1;
  1003   1014           }
  1004   1015         }
  1005   1016       }
  1006   1017       cost = pProbe->aiRowEst[i] * inMultiplier * estLog(inMultiplier);
  1007   1018       nEq = i;
  1008   1019       if( pProbe->onError!=OE_None && (flags & WHERE_COLUMN_IN)==0
  1009   1020            && nEq==pProbe->nColumn ){
................................................................................
  1016   1027       if( nEq<pProbe->nColumn ){
  1017   1028         int j = pProbe->aiColumn[nEq];
  1018   1029         pTerm = findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE|WO_GT|WO_GE, pProbe);
  1019   1030         if( pTerm ){
  1020   1031           flags |= WHERE_COLUMN_RANGE;
  1021   1032           if( findTerm(pWC, iCur, j, notReady, WO_LT|WO_LE, pProbe) ){
  1022   1033             flags |= WHERE_TOP_LIMIT;
  1023         -          cost *= 0.333;
         1034  +          cost /= 3;
  1024   1035           }
  1025   1036           if( findTerm(pWC, iCur, j, notReady, WO_GT|WO_GE, pProbe) ){
  1026   1037             flags |= WHERE_BTM_LIMIT;
  1027         -          cost *= 0.333;
         1038  +          cost /= 3;
  1028   1039           }
  1029   1040           TRACE(("...... range reduces cost to %.9g\n", cost));
  1030   1041         }
  1031   1042       }
  1032   1043   
  1033   1044       /* Add the additional cost of sorting if that is a factor.
  1034   1045       */
................................................................................
  1059   1070           int x = pProbe->aiColumn[j];
  1060   1071           if( x<BMS-1 ){
  1061   1072             m &= ~(((Bitmask)1)<<x);
  1062   1073           }
  1063   1074         }
  1064   1075         if( m==0 ){
  1065   1076           flags |= WHERE_IDX_ONLY;
  1066         -        cost *= 0.5;
         1077  +        cost /= 2;
  1067   1078           TRACE(("...... idx-only reduces cost to %.9g\n", cost));
  1068   1079         }
  1069   1080       }
  1070   1081   
  1071   1082       /* If this index has achieved the lowest cost so far, then use it.
  1072   1083       */
  1073   1084       if( cost < lowestCost ){
................................................................................
  1460   1471       int flags;                  /* Flags asssociated with pIdx */
  1461   1472       int nEq;                    /* Number of == or IN constraints */
  1462   1473       double cost;                /* The cost for pIdx */
  1463   1474       int j;                      /* For looping over FROM tables */
  1464   1475       Index *pBest = 0;           /* The best index seen so far */
  1465   1476       int bestFlags = 0;          /* Flags associated with pBest */
  1466   1477       int bestNEq = 0;            /* nEq associated with pBest */
  1467         -    double lowestCost = 1.0e99; /* Cost of the pBest */
         1478  +    double lowestCost;          /* Cost of the pBest */
  1468   1479       int bestJ;                  /* The value of j */
  1469   1480       Bitmask m;                  /* Bitmask value for j or bestJ */
  1470   1481   
         1482  +    lowestCost = SQLITE_BIG_DBL;
  1471   1483       for(j=iFrom, pTabItem=&pTabList->a[j]; j<pTabList->nSrc; j++, pTabItem++){
  1472   1484         m = getMask(&maskSet, pTabItem->iCursor);
  1473   1485         if( (m & notReady)==0 ){
  1474   1486           if( j==iFrom ) iFrom++;
  1475   1487           continue;
  1476   1488         }
  1477   1489         cost = bestIndex(pParse, &wc, pTabItem, notReady,