Mysql Query Optimization


  1. Which system variable tells the optimizer to skip certain plans based on estimates of the number of rows accessed for each table?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    The optimizer_prune_level variable tells the optimizer to skip certain plans based on estimates of the number of rows accessed for each table. This option is kept on by default.


  1. Which of the following WHERE clauses is faster?
    1. WHERE col * 3 < 9
    2. WHERE col < 9 / 3











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    For the first variation, MySQL would retrieve the value of ‘col’ for each row, multiply by three, and then compare the result to nine. In this case, no index can be used and hence it is slower.



  1. What are the results of the following queries if col is an integer column?
    1. SELECT * FROM student WHERE id = '6';
    2. SELECT * FROM student WHERE id = 6;











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    The first query invokes a type conversion. The conversion operation involves some performance penalty for converting the integer and string to double to perform the comparison.


  1. Which of these comparisons is slowest?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    On comparing indexed columns, identical data types will give better performance than dissimilar types. So an INT/INT or BIGINT/BIGINT comparison is faster than an INT/BIGINT comparison.



  1. Which system variable tells how far into the rest of each incomplete plan the optimizer should look to evaluate whether it should be expanded further?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    In MySQL, the optimizer_search_depth system variable tells how far into the “future” of each incomplete plan the optimizer should look to evaluate whether it should be expanded further.