SQLite

Check-in [3fa177c54a]
Login

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

Overview
Comment:Speed improvements as described by tickets #1257 and #1258. These changes help some but are nowhere near the 23% claimed in the tickets. (CVS 2469)
Downloads: Tarball | ZIP archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 3fa177c54a8589dcfa0bfad0ca124cb73b363f18
User & Date: drh 2005-05-21 18:32:19.000
Context
2005-05-22
06:49
Allow schema objects beginning with sqlite_ to be created if the SQLITE_WriteSchema flag is set. (CVS 2470) (check-in: afc8ce42b6 user: danielk1977 tags: trunk)
2005-05-21
18:32
Speed improvements as described by tickets #1257 and #1258. These changes help some but are nowhere near the 23% claimed in the tickets. (CVS 2469) (check-in: 3fa177c54a user: drh tags: trunk)
02:48
More structure rearrangements for additional size reductions. Ticket #1253. (CVS 2468) (check-in: 6b6e525b29 user: drh tags: trunk)
Changes
Unified Diff Ignore Whitespace Patch
Changes to src/vdbeaux.c.
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693




1694
1695





1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709

1710


1711


1712
1713
1714
1715
1716
1717
1718

1719

1720



1721
1722


1723
1724


1725

1726
1727
1728

1729
1730
1731

1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743

1744

1745
1746
1747
1748
1749
1750
1751
1752
** and store the result in pMem.  Return the number of bytes read.
*/ 
int sqlite3VdbeSerialGet(
  const unsigned char *buf,     /* Buffer to deserialize from */
  u32 serial_type,              /* Serial type to deserialize */
  Mem *pMem                     /* Memory cell to write value into */
){
  int len;

  if( serial_type==0 ){




    /* NULL */
    pMem->flags = MEM_Null;





    return 0;
  }
  len = sqlite3VdbeSerialTypeLen(serial_type);
  if( serial_type<=7 ){
    /* Integer and Real */
    if( serial_type<=4 ){
      /* 32-bit integer type.  This is handled by a special case for
      ** performance reasons. */
      int v = buf[0];
      int n;
      if( v&0x80 ){
        v |= -256;
      }
      for(n=1; n<len; n++){

        v = (v<<8) | buf[n];


      }


      pMem->flags = MEM_Int;
      pMem->i = v;
      return n;
    }else{
      u64 v = 0;
      int n;


      if( buf[0]&0x80 ){

        v = -1;



      }
      for(n=0; n<len; n++){


        v = (v<<8) | buf[n];
      }


      if( serial_type==7 ){

        pMem->flags = MEM_Real;
        pMem->r = *(double*)&v;
      }else{

        pMem->flags = MEM_Int;
        pMem->i = *(i64*)&v;
      }

    }
  }else{
    /* String or blob */
    assert( serial_type>=12 );
    pMem->z = (char *)buf;
    pMem->n = len;
    pMem->xDel = 0;
    if( serial_type&0x01 ){
      pMem->flags = MEM_Str | MEM_Ephem;
    }else{
      pMem->flags = MEM_Blob | MEM_Ephem;
    }

  }

  return len;
}

/*
** This function compares the two table rows or index records specified by 
** {nKey1, pKey1} and {nKey2, pKey2}, returning a negative, zero
** or positive integer if {nKey1, pKey1} is less than, equal to or 
** greater than {nKey2, pKey2}.  Both Key1 and Key2 must be byte strings







<
<
|
>
>
>
>
|
|
>
>
>
>
>
|
|
<
<
|
<
<
<
|
|
<
|
|
<
>
|
>
>
|
>
>

<
|
<
<
<
|
>
|
>
|
>
>
>
|
<
>
>
|
<
>
>
|
>
|
<

>
|
<

>

|
<
|
|
|
|
|
|
|
|
|
>
|
>
|







1684
1685
1686
1687
1688
1689
1690


1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704


1705



1706
1707

1708
1709

1710
1711
1712
1713
1714
1715
1716
1717

1718



1719
1720
1721
1722
1723
1724
1725
1726
1727

1728
1729
1730

1731
1732
1733
1734
1735

1736
1737
1738

1739
1740
1741
1742

1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
** and store the result in pMem.  Return the number of bytes read.
*/ 
int sqlite3VdbeSerialGet(
  const unsigned char *buf,     /* Buffer to deserialize from */
  u32 serial_type,              /* Serial type to deserialize */
  Mem *pMem                     /* Memory cell to write value into */
){


  switch( serial_type ){
    case 8:    /* Reserved for future use */
    case 9:    /* Reserved for future use */
    case 10:   /* Reserved for future use */
    case 11:   /* Reserved for future use */
    case 0: {  /* NULL */
      pMem->flags = MEM_Null;
      break;
    }
    case 1: { /* 1-byte signed integer */
      pMem->i = (signed char)buf[0];
      pMem->flags = MEM_Int;
      return 1;
    }


    case 2: { /* 2-byte signed integer */



      pMem->i = (((signed char)buf[0])<<8) | buf[1];
      pMem->flags = MEM_Int;

      return 2;
    }

    case 3: { /* 3-byte signed integer */
      pMem->i = (((signed char)buf[0])<<16) | (buf[1]<<8) | buf[2];
      pMem->flags = MEM_Int;
      return 3;
    }
    case 4: { /* 4-byte signed integer */
      pMem->i = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];
      pMem->flags = MEM_Int;

      return 4;



    }
    case 5: { /* 6-byte signed integer */
      u64 x = (((signed char)buf[0])<<8) | buf[1];
      u32 y = (buf[2]<<24) | (buf[3]<<16) | (buf[4]<<8) | buf[5];
      x = (x<<32) | y;
      pMem->i = *(i64*)&x;
      pMem->flags = MEM_Int;
      return 6;
    }

    case 6:   /* 6-byte signed integer */
    case 7: { /* IEEE floating point */
      u64 x = (buf[0]<<24) | (buf[1]<<16) | (buf[2]<<8) | buf[3];

      u32 y = (buf[4]<<24) | (buf[5]<<16) | (buf[6]<<8) | buf[7];
      x = (x<<32) | y;
      if( serial_type==6 ){
        pMem->i = *(i64*)&x;
        pMem->flags = MEM_Int;

      }else{
        pMem->r = *(double*)&x;
        pMem->flags = MEM_Real;

      }
      return 8;
    }
    default: {

      int len = (serial_type-12)/2;
      pMem->z = (char *)buf;
      pMem->n = len;
      pMem->xDel = 0;
      if( serial_type&0x01 ){
        pMem->flags = MEM_Str | MEM_Ephem;
      }else{
        pMem->flags = MEM_Blob | MEM_Ephem;
      }
      return len;
    }
  }
  return 0;
}

/*
** This function compares the two table rows or index records specified by 
** {nKey1, pKey1} and {nKey2, pKey2}, returning a negative, zero
** or positive integer if {nKey1, pKey1} is less than, equal to or 
** greater than {nKey2, pKey2}.  Both Key1 and Key2 must be byte strings
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
    ** the file is corrupted.  Then read the value from each key into mem1
    ** and mem2 respectively.
    */
    d1 += sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1);
    d2 += sqlite3VdbeSerialGet(&aKey2[d2], serial_type2, &mem2);

    rc = sqlite3MemCompare(&mem1, &mem2, i<nField ? pKeyInfo->aColl[i] : 0);
    sqlite3VdbeMemRelease(&mem1);
    sqlite3VdbeMemRelease(&mem2);
    if( rc!=0 ){
      break;
    }
    i++;
  }

  /* One of the keys ran out of fields, but all the fields up to that point







|
|







1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
    ** the file is corrupted.  Then read the value from each key into mem1
    ** and mem2 respectively.
    */
    d1 += sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1);
    d2 += sqlite3VdbeSerialGet(&aKey2[d2], serial_type2, &mem2);

    rc = sqlite3MemCompare(&mem1, &mem2, i<nField ? pKeyInfo->aColl[i] : 0);
    if( mem1.flags & MEM_Dyn ) sqlite3VdbeMemRelease(&mem1);
    if( mem2.flags & MEM_Dyn ) sqlite3VdbeMemRelease(&mem2);
    if( rc!=0 ){
      break;
    }
    i++;
  }

  /* One of the keys ran out of fields, but all the fields up to that point