<< previous page   --   table of contents   --   next page >>
| | | | | | | |
  • Return to Table of Contents
  • Table of Contents

    1. General Information
    2. MySQL Installation
    3. Tutorial Introduction
    4. Database Administration
    5. MySQL Optimisation
    6. MySQL Language Reference
    7. MySQL Table Types
    8. MySQL APIs
    9. Extending MySQL

    Chapter 5:  MySQL Optimisation 343 table type possible_keys key key_len ref rows Extra et ALL PRIMARY NULL NULL NULL 74 tt ref AssignedPC, ActualPC 15 et.nfontPLOYID 52 where ClientID, ActualPC et_1   eq_ref PRIMARY PRIMARY   15 tt.AssignedPC 1 do eq_ref PRIMARY PRIMARY   15 tt.ClientID 1 This is almost as good as it can get. The remaining problem is that, by default, MySQL assumes that values in the tt.ActualPC column are evenly distributed, and that isn't the case for the tt table.  Fortunately, it is easy to tell MySQL about this: shell> myisamchk --analyze PATH_TO_MYSQL_DATABASE/tt shell> mysqladmin refresh Now the join is perfect, and EXPLAIN produces this result: table type possible_keys key key_len ref rows Extra tt ALL AssignedPC NULL NULL NULL 3872 where used ClientID, ActualPC et eq_ref PRIMARY PRIMARY 15 tt.ActualPC 1 et_1   eq_ref PRIMARY PRIMARY 15 tt.AssignedPC 1 do eq_ref PRIMARY PRIMARY 15 tt.ClientID 1 Note  that  the  rows  column  in  the  output  from  EXPLAIN  is  an  educated  guess  from  the MySQL  join  optimiser.   To  optimise  a  query,  you  should  check  if  the  numbers  are  even close to the truth.  If not, you may get better performance by using STRAIGHT_JOIN in your SELECT  statement and trying to list the tables in a di erent order in the  FROM  clause. 5.2.2  Estimating Query Performance In most cases you can estimate the performance by counting disk seeks.  For small tables, you can usually nd the row in 1 disk seek (as the index is probably cached).  For bigger tables, you can estimate that (using B++ tree indexes) you will need:  log(row_count) / log(index_block_length / 3 * 2 / (index_length + data_pointer_length)) + 1  seeks to nd a row. In  MySQL  an  index  block  is  usually  1024  bytes  and  the  data  pointer  is  usually  4 bytes.    A  500,000  row  table  with  an  index  length  of  3  (medium  integer)  gives  you: log(500,000)/log(1024/3*2/(3+4)) + 1 = 4 seeks. As  the  above  index  would  require  about  500,000  *  7  *  3/2  =  5.2M,  (assuming  that  the index bu ers are lled to 2/3, which is typical) you will probably have much of the index in memory and you will probably only need 1-2 calls to read data from the OS to nd the row. For writes, however, you will need 4 seek requests (as above) to nd where to place the new index and normally 2 seeks to update the index and write the row. Note that the above doesn't mean that your application will slowly degenerate by N log N! As long as everything is cached by the OS or SQL server things will only go marginally
     

    Customer Support CentreMySQL Reference Manual

    Web Hosting Services
    UNIX WEB HOSTING
    SUPPORT & FAQ's
    TERMS OF USE
    Domain Services
    DOMAIN REGISTRATION
    MANAGE YOUR ACCOUNT
    SUPPORT & FAQ's
    TERMS OF USE
    SITE MAP
    Home
    Hosting Plans | Domain Registration | About Us | Contact Us | Site Map
    Terms of Use | Privacy Policy | Guarantees
    Merchant Accounts

    SpiritHost - web hosting for spiritual and education sites
    SpiritHit.com - Religious and Spiritual Portal
  • Return to Table of Contents
  • Back to top

  • Web Hosting: Manuals & FAQ's

    1. Unix-Based Web Hosting
    2. Unix Dedicated Servers
    3. Windows Dedicated Servers
    4. CuteFTP User’s Guide
    5. CuteHTML User’s Guide
    6. WS_FTP Pro User's Guide
    7. Miva Order User's Guide
    8. Miva Merchant User's Guide