官术网_书友最值得收藏!

Controlling MariaDB optimizer strategies

Starting with MariaDB 5.3 and continuing with all major releases since, various optimizations have been introduced that improve the core performance of MariaDB. To keep upgrades as compatible and as trouble-free as possible or because it is only useful in certain limited instances, many of these optimizations are turned off by default. This recipe is about enabling optimizations which are turned off by default.

In this recipe, we will enable the Multi-Range Read optimizations, but the basic concepts apply to control any of the optimizer_switch flags.

How to do it...

  1. Launch the mysql command-line client application and connect to our MariaDB server as the root user or as a user with the SUPER privilege.
  2. Show the current status of all optimizer_switch flags with the following command:
    SELECT @@optimizer_switch\G
    
  3. The output of the previous command will be similar to the following screenshot. There may be some differences depending on our local server settings.
    How to do it...
  4. In the output, the mrr, mrr_cost_based, and mrr_sort_keys flags are all set to off. Enable them with the following command:
    SET optimizer_switch="mrr=on";
    SET optimizer_switch="mrr_cost_based=on";
    SET optimizer_switch="mrr_sort_keys=on";
    
  5. Run the SELECT command from step 2 and confirm that the three mrr flags are now set to on.

How it works...

The optimizer_switch variable is basically a list of flags, which shows the status of the various available optimization strategies. When we use the SET command, we can turn various individual flags off and on. Any flags that we do not name in the SET command remain as they are.

There's more...

By default, the SET command only sets the variables for our current session. If we quit the client or we are disconnected for some reason and then we reconnect, the flags will be set to what they were before the changes were made.

To make our changes until MariaDB is shut down or restarted, add GLOBAL to the command as follows:

SET GLOBAL optimizer_switch="mrr=on";

If we want to make the change permanent, so that an optimization is either on or off permanently, we need to add it to our my.cnf or my.ini file. For example, to turn on all the mrr optimizations, add the following lines of code to the end of the file (or to an existing [mysqld] section):

[mysqld]
optimizer_switch = "mrr=on, mrr_cost_based=on,mrr_sort_keys=on"

Restart MariaDB to activate the changes.

See also

主站蜘蛛池模板: 本溪市| 东山县| 宜都市| 福州市| 应用必备| 台南市| 巴林左旗| 新龙县| 德清县| 高陵县| 邯郸县| 嘉禾县| 定襄县| 鹰潭市| 府谷县| 潜山县| 东兰县| 安新县| 桦甸市| 通山县| 西吉县| 普格县| 明星| 长岭县| 淮南市| 蒙城县| 达拉特旗| 平泉县| 镇原县| 临沧市| 洞口县| 当阳市| 慈溪市| 玉环县| 乳源| 汉中市| 策勒县| 衡山县| 凉城县| 若羌县| 宜黄县|