無料PHPプログラム

MySQL 5.1 リファレンスマニュアル :: B Errors, Error Codes, and Common Problems :: B.1 Problems and Common Errors :: B.1.6 Optimizer-Related Issues
« B.1.5.8 Problems with Floating-Point Comparisons

B.1.7 Table Definition-Related Issues »
Section Navigation      [Toggle]
  • B.1 Problems and Common Errors
  • B.1.1 How to Determine What Is Causing a Problem
  • B.1.2 Common Errors When Using MySQL Programs
  • B.1.3 Installation-Related Issues
  • B.1.4 Administration-Related Issues
  • B.1.5 Query-Related Issues
  • B.1.6 Optimizer-Related Issues
  • B.1.7 Table Definition-Related Issues
  • B.1.8 Known Issues in MySQL

B.1.6. Optimizer-Related Issues

MySQL uses a cost-based optimizer to determine the best way to resolve a query. In many cases, MySQL can calculate the best possible query plan, but sometimes MySQL doesn't have enough information about the data at hand and has to make 「educated」 guesses about the data.

For the cases when MySQL does not do the "right" thing, tools that you have available to help MySQL are:

  • Use the EXPLAIN statement to get information about how MySQL processes a query. To use it, just add the keyword EXPLAIN to the front of your SELECT statement:

    mysql> EXPLAIN SELECT * FROM t1, t2 WHERE t1.i = t2.i;
    

    EXPLAIN is discussed in more detail in 項6.2.1. 「EXPLAINを使用して、クエリを最適化する」.

  • Use ANALYZE TABLE tbl_name to update the key distributions for the scanned table. See 項12.5.2.1. 「ANALYZE TABLE 構文」.

  • Use FORCE INDEX for the scanned table to tell MySQL that table scans are very expensive compared to using the given index. See 項12.2.7. 「SELECT 構文」.

    SELECT * FROM t1, t2 FORCE INDEX (index_for_column)
    WHERE t1.col_name=t2.col_name;
    

    USE INDEX and IGNORE INDEX may also be useful.

  • Global and table-level STRAIGHT_JOIN. See 項12.2.7. 「SELECT 構文」.

  • You can tune global or thread-specific system variables. For example, Start mysqld with the --max-seeks-for-key=1000 option or use SET max_seeks_for_key=1000 to tell the optimizer to assume that no key scan causes more than 1,000 key seeks. See 項4.2.3. 「システム変数」.

Copyright c 1997, 2010, Oracle and/or its affiliates. All rights reserved. Legal Notices
Top / Previous / Next / Up / Table of Contents
© 2010, Oracle Corporation and/or its affiliates

無料CGI PHPスクリプト | 新着情報スクリプト | 営業日カレンダー | PHPマニュアル | MySQLマニュアル | PEARマニュアル

Copyright (c) 2010 jmcodex.com All rights reserved.