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

Overview
Comment: Fix an off-by-one error in the WhereCost to integer conversion. Tarball | ZIP archive | SQL archive family | ancestors | descendants | both | files | file ages | folders b5ca80d924f8c6d31f036247ba6e20d234f4482e drh 2013-06-13 14:51:53
Context
 2013-06-13 15:16 Make the MIN() and MAX() macros available in sqliteInt.h. Add TUNING comments to the NGQP and adjust costs slightly. check-in: 3a72af2a user: drh tags: nextgen-query-plan-exp 14:51 Fix an off-by-one error in the WhereCost to integer conversion. check-in: b5ca80d9 user: drh tags: nextgen-query-plan-exp 2013-06-12 20:18 Activate the one-pass optimization. Update comments, especially the descriptions of the various objects. check-in: e120c558 user: drh tags: nextgen-query-plan-exp
Changes

Changes to src/where.c.

 ```445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 ``` ``` /* Convert a WhereCost value (10 times log2(X)) into its integer value X. ** A rough approximation is used. The value returned is not exact. */ static u64 whereCostToInt(WhereCost x){ u64 n; if( x<=10 ) return 1; n = x%10; x /= 10; if( n>=5 ) n -= 2; else if( n>=1 ) n -= 1; if( x>=3 ) return (n+8)<<(x-3); return (n+8)>>(3-x); } ``` ``` | ``` ```445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 ``` ``` /* Convert a WhereCost value (10 times log2(X)) into its integer value X. ** A rough approximation is used. The value returned is not exact. */ static u64 whereCostToInt(WhereCost x){ u64 n; if( x<10 ) return 1; n = x%10; x /= 10; if( n>=5 ) n -= 2; else if( n>=1 ) n -= 1; if( x>=3 ) return (n+8)<<(x-3); return (n+8)>>(3-x); } ```

Changes to tool/wherecosttest.c.

 ```69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 ``` ``` while( x>255 ){ y += 40; x >>= 4; } while( x>15 ){ y += 10; x >>= 1; } } return a[x&7] + y - 10; } static unsigned long int whereCostToInt(WhereCost x){ unsigned long int n; if( x<=10 ) return 1; n = x%10; x /= 10; if( n>=5 ) n -= 2; else if( n>=1 ) n -= 1; if( x>=3 ) return (n+8)<<(x-3); return (n+8)>>(3-x); } ``` ``` | ``` ```69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 ``` ``` while( x>255 ){ y += 40; x >>= 4; } while( x>15 ){ y += 10; x >>= 1; } } return a[x&7] + y - 10; } static unsigned long int whereCostToInt(WhereCost x){ unsigned long int n; if( x<10 ) return 1; n = x%10; x /= 10; if( n>=5 ) n -= 2; else if( n>=1 ) n -= 1; if( x>=3 ) return (n+8)<<(x-3); return (n+8)>>(3-x); } ```