MariaDB Inner join is slow

execution-planmariadb-10.3performanceperformance-tuning

Here is my SQL (with explain):

EXPLAIN
SELECT * FROM
GBI gbi
INNER JOIN VF_KRED kred ON
    gbi.vendor = kred.vendor;

Giving below the outcome:

enter image description here

Now, the select SQL takes ~10 seconds to produce the outcome.

Below are the indexes on tables:

  • VF_KRED table:

enter image description here

  • GBI table:

enter image description here

Any clues?

Best Answer

Our solution: Set the variable optimizer_search_depth to zero. The same query now needs 0.3 instead of 13 seconds.

To test it, call before your statement:

set SESSION optimizer_search_depth=0;

To make it permanent put it in the my.conf file and restart the db.