/ Check-in [9b091527]
Login

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

Overview
Comment:Disable the optimization where a REAL value with no fractional part is stored as an INTEGER when the integer uses as much space as the real value it proposes to stand in for (8 bytes). This avoids corner cases of comparing integers against real values that are beyond the resolution of an IEEE 754 double. Fix for ticket [6c1d3febc00b22d457c78c2]
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 9b0915272f4d4052aa31e9297424a7db9a0234b676e8e2a44c3f2dc54236705a
User & Date: drh 2019-05-09 17:10:30
Context
2019-05-09
17:54
Fix a crash in the sqlite_dbdata module that could occur if a pointer within an overflow chain in a corrupt database pointed past the end of the db. check-in: 3eae4e30 user: dan tags: trunk
17:10
Disable the optimization where a REAL value with no fractional part is stored as an INTEGER when the integer uses as much space as the real value it proposes to stand in for (8 bytes). This avoids corner cases of comparing integers against real values that are beyond the resolution of an IEEE 754 double. Fix for ticket [6c1d3febc00b22d457c78c2] check-in: 9b091527 user: drh tags: trunk
16:57
Avoid long delays that can occur when ".recover"ing data from a database with a corrupt freelist. check-in: 20f06bf2 user: dan tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/vdbeaux.c.

  3418   3418   **
  3419   3419   ** The 8 and 9 types were added in 3.3.0, file format 4.  Prior versions
  3420   3420   ** of SQLite will not understand those serial types.
  3421   3421   */
  3422   3422   
  3423   3423   /*
  3424   3424   ** Return the serial-type for the value stored in pMem.
         3425  +**
         3426  +** This routine might convert a large MEM_IntReal value into MEM_Real.
  3425   3427   */
  3426   3428   u32 sqlite3VdbeSerialType(Mem *pMem, int file_format, u32 *pLen){
  3427   3429     int flags = pMem->flags;
  3428   3430     u32 n;
  3429   3431   
  3430   3432     assert( pLen!=0 );
  3431   3433     if( flags&MEM_Null ){
................................................................................
  3454   3456         }
  3455   3457       }
  3456   3458       if( u<=32767 ){ *pLen = 2; return 2; }
  3457   3459       if( u<=8388607 ){ *pLen = 3; return 3; }
  3458   3460       if( u<=2147483647 ){ *pLen = 4; return 4; }
  3459   3461       if( u<=MAX_6BYTE ){ *pLen = 6; return 5; }
  3460   3462       *pLen = 8;
         3463  +    if( flags&MEM_IntReal ){
         3464  +      /* If the value is IntReal and is going to take up 8 bytes to store
         3465  +      ** as an integer, then we might as well make it an 8-byte floating
         3466  +      ** point value */
         3467  +      pMem->u.r = (double)pMem->u.i;
         3468  +      pMem->flags &= ~MEM_IntReal;
         3469  +      pMem->flags |= MEM_Real;
         3470  +      return 7;
         3471  +    }
  3461   3472       return 6;
  3462   3473     }
  3463   3474     if( flags&MEM_Real ){
  3464   3475       *pLen = 8;
  3465   3476       return 7;
  3466   3477     }
  3467   3478     assert( pMem->db->mallocFailed || flags&(MEM_Str|MEM_Blob) );

Changes to test/select3.test.

   256    256     }
   257    257   } {real}
   258    258   do_test select3-8.2 {
   259    259     execsql {
   260    260       SELECT typeof(sum(a3)) FROM a GROUP BY a1;
   261    261     }
   262    262   } {real}
          263  +
          264  +# 2019-05-09 ticket https://www.sqlite.org/src/tktview/6c1d3febc00b22d457c7
          265  +#
          266  +unset -nocomplain x
          267  +foreach {id x} {
          268  +  100 127
          269  +  101 128
          270  +  102 -127
          271  +  103 -128
          272  +  104 -129
          273  +  110 32767
          274  +  111 32768
          275  +  112 -32767
          276  +  113 -32768
          277  +  114 -32769
          278  +  120 2147483647
          279  +  121 2147483648
          280  +  122 -2147483647
          281  +  123 -2147483648
          282  +  124 -2147483649
          283  +  130 140737488355327
          284  +  131 140737488355328
          285  +  132 -140737488355327
          286  +  133 -140737488355328
          287  +  134 -140737488355329
          288  +  140 9223372036854775807
          289  +  141 -9223372036854775807
          290  +  142 -9223372036854775808
          291  +  143 9223372036854775806
          292  +  144 9223372036854775805
          293  +  145 -9223372036854775806
          294  +  146 -9223372036854775805
          295  +
          296  +} {
          297  +  set x [expr {$x+0}]
          298  +  do_execsql_test select3-8.$id {
          299  +     DROP TABLE IF EXISTS t1;
          300  +     CREATE TABLE t1 (c0, c1 REAL PRIMARY KEY);
          301  +     INSERT INTO t1(c0, c1) VALUES (0, $x), (0, 0);
          302  +     UPDATE t1 SET c0 = NULL;
          303  +     UPDATE OR REPLACE t1 SET c1 = 1;
          304  +     SELECT DISTINCT * FROM t1 WHERE (t1.c0 IS NULL);
          305  +     PRAGMA integrity_check;
          306  +  } {{} 1.0 ok}
          307  +}
   263    308   
   264    309   finish_test