[MDEV-18850] Optimizer should not choose semi-join conversion with ORDER BY + LIMIT supported by an index Created: 2019-03-07  Updated: 2020-03-11

Status: Open
Project: MariaDB Server
Component/s: Optimizer
Affects Version/s: 10.3
Fix Version/s: 10.3

Type: Bug Priority: Major
Reporter: jocelyn fournier Assignee: Igor Babaev
Resolution: Unresolved Votes: 1
Labels: None


 Description   

I'm opening the issue as requested by Igor in MDEV-17795

In 10.3 semi-join optimisation could be make queries much slower:

SELECT `news`.* FROM `news` WHERE (news.publier = 1) AND (news.date_publication < "2019-03-07 19:20:08") AND (news.date_fin > "2019-03-07 19:20:08" OR news.date_fin IS NULL) AND (news.sponsored = 0) AND (news.idnews in ([about 1600 ids]) ) GROUP BY `news`.`idnews` ORDER BY `date_publication` desc LIMIT 5

Execution plan:

*************************** 1. row ***************************
           id: 1
  select_type: PRIMARY
        table: <derived3>
         type: ALL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: 8949
        Extra: Start temporary; Using temporary; Using filesort
*************************** 2. row ***************************
           id: 1
  select_type: PRIMARY
        table: news
         type: eq_ref
possible_keys: PRIMARY,date_publication
          key: PRIMARY
      key_len: 4
          ref: tvc_0._col_1
         rows: 1
        Extra: Using where; End temporary
*************************** 3. row ***************************
           id: 3
  select_type: DERIVED
        table: NULL
         type: NULL
possible_keys: NULL
          key: NULL
      key_len: NULL
          ref: NULL
         rows: NULL
        Extra: No tables used
3 rows in set (0.006 sec)

Table struct:

CREATE TABLE `news` (
  `idnews` int(11) NOT NULL AUTO_INCREMENT,
  `titre` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  `contenu` text CHARACTER SET latin1 DEFAULT NULL,
  `date_publication` timestamp NULL DEFAULT '0000-00-00 00:00:00',
  `date_modification` timestamp NULL DEFAULT '0000-00-00 00:00:00',
  `image` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  `image_mini` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
  `publier` tinyint(1) DEFAULT NULL,
  `categorie` int(11) DEFAULT NULL,
  `likes` int(11) NOT NULL DEFAULT 0,
  `visites` int(11) NOT NULL DEFAULT 0,
  `retweet` int(11) NOT NULL DEFAULT 0,
  `gplus` int(11) NOT NULL DEFAULT 0,
  `maj_social` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
  `date_fin` timestamp NULL DEFAULT NULL,
  `chapo` text DEFAULT NULL,
  `star_news` tinyint(1) DEFAULT 0,
  `auteur` varchar(255) DEFAULT NULL,
  `newsimport` int(10) NOT NULL,
  `old` varchar(200) NOT NULL,
  `site_origine` varchar(25) NOT NULL,
  `id_origine` int(6) NOT NULL,
  `credits_photo` varchar(255) DEFAULT NULL,
  `iframe_videos` text DEFAULT NULL,
  `zones` varchar(200) DEFAULT NULL,
  `date_affichage` tinyint(3) unsigned DEFAULT 1,
  `partage_affichage` tinyint(3) unsigned DEFAULT 1,
  `sponsored` tinyint(3) unsigned DEFAULT 0,
  `legende_photo` varchar(255) DEFAULT NULL,
  `ordre` int(11) DEFAULT NULL,
  `contenu_amp` text DEFAULT NULL,
  `iframe_videos_amp` text DEFAULT NULL,
  PRIMARY KEY (`idnews`),
  KEY `newsimport` (`newsimport`,`idnews`),
  KEY `date_publication` (`date_publication`)
) ENGINE=InnoDB AUTO_INCREMENT=41981 DEFAULT CHARSET=utf8

Rewriting by the optimiser:

/* select#1 */ select `voltage`.`news`.`idnews` AS `idnews`,`voltage`.`news`.`titre` AS `titre`,`voltage`.`news`.`contenu` AS `contenu`,`voltage`.`news`.`date_publication` AS `date_publication`,`voltage`.`news`.`date_modification` AS `date_modification`,`voltage`.`news`.`image` AS `image`,`voltage`.`news`.`image_mini` AS `image_mini`,`voltage`.`news`.`publier` AS `publier`,`voltage`.`news`.`categorie` AS `categorie`,`voltage`.`news`.`likes` AS `likes`,`voltage`.`news`.`visites` AS `visites`,`voltage`.`news`.`retweet` AS `retweet`,`voltage`.`news`.`gplus` AS `gplus`,`voltage`.`news`.`maj_social` AS `maj_social`,`voltage`.`news`.`date_fin` AS `date_fin`,`voltage`.`news`.`chapo` AS `chapo`,`voltage`.`news`.`star_news` AS `star_news`,`voltage`.`news`.`auteur` AS `auteur`,`voltage`.`news`.`newsimport` AS `newsimport`,`voltage`.`news`.`old` AS `old`,`voltage`.`news`.`site_origine` AS `site_origine`,`voltage`.`news`.`id_origine` AS `id_origine`,`voltage`.`news`.`credits_photo` AS `credits_photo`,`voltage`.`news`.`iframe_videos` AS `iframe_videos`,`voltage`.`news`.`zones` AS `zones`,`voltage`.`news`.`date_affichage` AS `date_affichage`,`voltage`.`news`.`partage_affichage` AS `partage_affichage`,`voltage`.`news`.`sponsored` AS `sponsored`,`voltage`.`news`.`legende_photo` AS `legende_photo`,`voltage`.`news`.`ordre` AS `ordre`,`voltage`.`news`.`contenu_amp` AS `contenu_amp`,`voltage`.`news`.`iframe_videos_amp` AS `iframe_videos_amp` from `voltage`.`news` semi join ((values [...] `tvc_0`) where `voltage`.`news`.`publier` = 1 and `voltage`.`news`.`sponsored` = 0 and `voltage`.`news`.`date_publication` < '2019-03-07 19:20:08' and (`voltage`.`news`.`date_fin` > '2019-03-07 19:20:08' or `voltage`.`news`.`date_fin` is null) and `voltage`.`news`.`idnews` = `tvc_0`.`_col_1` group by `voltage`.`news`.`idnews` order by `voltage`.`news`.`date_publication` desc limit 5

The associated profiling:

SHOW PROFILE FOR QUERY 1;
+--------------------------------+----------+
| Status                         | Duration |
+--------------------------------+----------+
| Starting                       | 0.000194 |
| Waiting for query cache lock   | 0.000032 |
| Init                           | 0.000022 |
| Checking query cache for query | 0.003343 |
| Checking permissions           | 0.000030 |
| Opening tables                 | 0.000044 |
| After opening tables           | 0.000027 |
| System lock                    | 0.000024 |
| Table lock                     | 0.000027 |
| Waiting for query cache lock   | 0.000431 |
| Init                           | 0.001572 |
| Optimizing                     | 0.000904 |
| Statistics                     | 0.000100 |
| Preparing                      | 0.000069 |
| Creating tmp table             | 0.000072 |
| Sorting result                 | 0.000047 |
| Executing                      | 0.000024 |
| Sending data                   | 0.001152 |
| Removing tmp table             | 0.000029 |
| Sending data                   | 0.107823 |
| Creating sort index            | 0.012458 |
| Removing tmp table             | 0.006703 |
| Creating sort index            | 0.000047 |
| End of update loop             | 0.000027 |
| Removing tmp table             | 0.000027 |
| End of update loop             | 0.000031 |
| Query end                      | 0.000023 |
| Commit                         | 0.000022 |
| Closing tables                 | 0.000021 |
| Removing tmp table             | 0.000023 |
| Closing tables                 | 0.000021 |
| Unlocking tables               | 0.000020 |
| Closing tables                 | 0.000030 |
| Starting cleanup               | 0.000021 |
| Freeing items                  | 0.000256 |
| Updating status                | 0.000030 |
| Waiting for query cache lock   | 0.000020 |
| Updating status                | 0.000071 |
| Waiting for query cache lock   | 0.000026 |
| Updating status                | 0.000026 |
| Storing result in query cache  | 0.000035 |
| Reset for next command         | 0.000030 |
+--------------------------------+----------+
42 rows in set (0.000 sec)

Output of the Analyze format:

{
  "query_block": {
    "select_id": 1,
    "r_loops": 1,
    "r_total_time_ms": 125.17,
    "filesort": {
      "sort_key": "news.date_publication desc",
      "r_loops": 1,
      "r_total_time_ms": 11.992,
      "r_limit": 5,
      "r_used_priority_queue": true,
      "r_output_rows": 6,
      "temporary_table": {
        "duplicates_removal": {
          "table": {
            "table_name": "<derived3>",
            "access_type": "ALL",
            "r_loops": 1,
            "rows": 8949,
            "r_rows": 8949,
            "r_total_time_ms": 0.5357,
            "filtered": 100,
            "r_filtered": 100,
            "materialized": {
              "query_block": {
                "union_result": {
                  "table_name": "<unit3>",
                  "access_type": "ALL",
                  "r_loops": 0,
                  "r_rows": null,
                  "query_specifications": [
                    {
                      "query_block": {
                        "select_id": 3,
                        "table": {
                          "message": "No tables used"
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "table": {
            "table_name": "news",
            "access_type": "eq_ref",
            "possible_keys": ["PRIMARY", "date_publication"],
            "key": "PRIMARY",
            "key_length": "4",
            "used_key_parts": ["idnews"],
            "ref": ["tvc_0._col_1"],
            "r_loops": 8949,
            "rows": 1,
            "r_rows": 1,
            "r_total_time_ms": 28.308,
            "filtered": 100,
            "r_filtered": 99.497,
            "attached_condition": "news.publier = 1 and news.sponsored = 0 and news.date_publication < '2019-03-07 19:20:08' and (news.date_fin > '2019-03-07 19:20:08' or news.date_fin is null) and news.idnews = tvc_0._col_1"
          }
        }
      }
    }
  }
}

In 10.2 :

 {
  "query_block": {
    "select_id": 1,
    "r_loops": 1,
    "r_total_time_ms": 0.1169,
    "table": {
      "table_name": "news",
      "access_type": "index",
      "possible_keys": ["PRIMARY", "date_publication"],
      "key": "date_publication",
      "key_length": "5",
      "used_key_parts": ["date_publication"],
      "r_loops": 1,
      "rows": 6626,
      "r_rows": 5,
      "r_total_time_ms": 0.0761,
      "filtered": 100,
      "r_filtered": 100,
      "attached_condition": "news.publier = 1 and news.sponsored = 0 and news.date_publication < '2019-03-07 19:20:08' and (news.date_fin > '2019-03-07 19:20:08' or news.date_fin is null) and news.idnews in ([...])"
    }
  }
}

Explain is trivial:

+------+-------------+-------+-------+--------------------------+------------------+---------+------+------+-------------+
| id   | select_type | table | type  | possible_keys            | key              | key_len | ref  | rows | Extra       |
+------+-------------+-------+-------+--------------------------+------------------+---------+------+------+-------------+
|    1 | SIMPLE      | news  | index | PRIMARY,date_publication | date_publication | 5       | NULL |    5 | Using where |
+------+-------------+-------+-------+--------------------------+------------------+---------+------+------+-------------+

In 10.3, the query execution takes about 0.18sec vs 0.06 sec in 10.2



 Comments   
Comment by jocelyn fournier [ 2019-10-30 ]

FYI, I've just hit a similar case in production where I had to kill a query after 1580s vs 0.053s with semijoin=off
So it's a really bad regression in 10.3.

Query:

SELECT                     
SQL_CALC_FOUND_ROWS                     
si.id_product, SUM(si.weight) position, GROUP_CONCAT(sw.word SEPARATOR ' ') as terms,                     IFNULL(stock.quantity, 0) as quantity                     
FROM ps_search_word sw                     
LEFT JOIN ps_search_index si ON sw.id_word = si.id_word                     
LEFT JOIN ps_product p ON p.id_product=si.id_product                      
LEFT JOIN ps_product_shop product_shop ON (product_shop.id_product = si.id_product AND product_shop.id_shop = 1)   
LEFT JOIN ps_stock_available stock ON (stock.id_product = p.id_product AND stock.id_product_attribute = 0 AND stock.id_shop = 1  AND stock.id_shop_group = 0  )         
LEFT JOIN `ps_manufacturer` m ON m.`id_manufacturer` = p.`id_manufacturer`         
WHERE sw.id_lang = 1 AND sw.id_shop = 1 AND ((sw.id_word 
IN(70753384,70513881,71090789,71038048,70528020,70444280,70514106,71091008,71038217,70753558,70514165,71091100,71038307)) OR (sw.word LIKE "%fase1%"))                         
AND si.id_product IN(                 
SELECT                 
DISTINCT cp.`id_product`                 
FROM `ps_category_group` cg                 
INNER JOIN `ps_category_product` cp ON cp.`id_category` = cg.`id_category`                 
INNER JOIN `ps_category` c ON cp.`id_category` = c.`id_category`                 
INNER JOIN `ps_product` p ON cp.`id_product` = p.`id_product`                  
LEFT JOIN ps_product_shop product_shop ON (product_shop.id_product = p.id_product AND product_shop.id_shop = 1)                                  
WHERE c.`active` = 1                     
AND product_shop.`active` = 1                     
AND product_shop.`visibility` IN ("both", "search")                     
AND product_shop.indexed = 1                                                                                    
AND cg.`id_group` IN (                        
SELECT id_group FROM ps_customer_group                         
WHERE id_customer = 51952)                    
)                     
GROUP BY si.id_product  HAVING (terms LIKE "%fase%")
ORDER BY  position desc,p.id_product;

ANALYZE output with semijoin:

{
  "query_block": {
    "select_id": 1,
    "r_loops": 1,
    "r_total_time_ms": 2.01e6,
    "having_condition": "terms like '%fase%'",
    "filesort": {
      "sort_key": "sum(si.weight) desc, p.id_product",
      "r_loops": 1,
      "r_total_time_ms": 0.061,
      "r_used_priority_queue": false,
      "r_output_rows": 151,
      "r_buffer_size": "5Kb",
      "temporary_table": {
        "filesort": {
          "sort_key": "si.id_product",   
          "r_loops": 1,
          "r_total_time_ms": 0.0319,
          "r_used_priority_queue": false,
          "r_output_rows": 151,
          "r_buffer_size": "3Kb",
          "temporary_table": {
            "duplicates_removal": {
              "table": {
                "table_name": "ps_customer_group",
                "access_type": "ref",
                "possible_keys": ["PRIMARY", "customer_login", "id_customer"],
                "key": "PRIMARY",
                "key_length": "4",
                "used_key_parts": ["id_customer"],
                "ref": ["const"],
                "r_loops": 1,
                "rows": 1,
                "r_rows": 1,
                "r_total_time_ms": 0.0248,
                "filtered": 100,
                "r_filtered": 100,
                "using_index": true
              },
              "table": {
                "table_name": "cg",
                "access_type": "ref",
                "possible_keys": ["PRIMARY", "id_category", "id_group"],
                "key": "id_group",
                "key_length": "4",
                "used_key_parts": ["id_group"],
                "ref": ["outletsaludcom.ps_customer_group.id_group"],
                "r_loops": 1,
                "rows": 115,
                "r_rows": 249,
                "r_total_time_ms": 0.1637,
                "filtered": 100,
                "r_filtered": 100,
                "using_index": true
              },
              "table": {
                "table_name": "c",
                "access_type": "eq_ref", 
                "possible_keys": ["PRIMARY", "activenleft", "activenright"],
                "key": "PRIMARY",
                "key_length": "4",
                "used_key_parts": ["id_category"],
                "ref": ["outletsaludcom.cg.id_category"],
                "r_loops": 249,
                "rows": 1,
                "r_rows": 1,
                "r_total_time_ms": 0.676,
                "filtered": 100,
                "r_filtered": 85.141,
                "attached_condition": "c.active = 1"
              },
              "table": {
                "table_name": "cp",
                "access_type": "ref",
                "possible_keys": ["PRIMARY", "id_product", "id_category"],
                "key": "PRIMARY",
                "key_length": "4",
                "used_key_parts": ["id_category"],
                "ref": ["outletsaludcom.cg.id_category"],
                "r_loops": 212,
                "rows": 21,
                "r_rows": 42.354,
                "r_total_time_ms": 3.6359,
                "filtered": 100,
                "r_filtered": 100,
                "using_index": true
              },
              "table": {
                "table_name": "p",
                "access_type": "eq_ref", 
                "possible_keys": ["PRIMARY"],
                "key": "PRIMARY",
                "key_length": "4",
                "used_key_parts": ["id_product"],
                "ref": ["outletsaludcom.cp.id_product"],
                "r_loops": 8979,
                "rows": 1,
                "r_rows": 1,
                "r_total_time_ms": 14.591,
                "filtered": 100,
                "r_filtered": 100,
                "using_index": true
              },
              "table": {
                "table_name": "product_shop",
                "access_type": "eq_ref", 
                "possible_keys": ["PRIMARY", "indexed"],
                "key": "PRIMARY",
                "key_length": "8",
                "used_key_parts": ["id_product", "id_shop"],
                "ref": ["outletsaludcom.cp.id_product", "const"],
                "r_loops": 8979,
                "rows": 1,
                "r_rows": 1,
                "r_total_time_ms": 17.941,
                "filtered": 100,
                "r_filtered": 87.983,
                "attached_condition": "product_shop.active = 1 and product_shop.indexed = 1 and product_shop.visibility in ('both','search')"
              },
              "table": {
                "table_name": "si",
                "access_type": "ref",
                "possible_keys": ["PRIMARY", "id_product"],
                "key": "id_product",
                "key_length": "4",
                "used_key_parts": ["id_product"],
                "ref": ["outletsaludcom.cp.id_product"],
                "r_loops": 7900,
                "rows": 217,
                "r_rows": 430.45,
                "r_total_time_ms": 620.98,
                "filtered": 100,
                "r_filtered": 100,
                "using_index": true
              }
            },
            "table": {
              "table_name": "p",
              "access_type": "eq_ref",   
              "possible_keys": ["PRIMARY"],
              "key": "PRIMARY",
              "key_length": "4",
              "used_key_parts": ["id_product"],
              "ref": ["outletsaludcom.cp.id_product"],
              "r_loops": 765047,
              "rows": 1,
              "r_rows": 1,
              "r_total_time_ms": 2.6409, 
              "filtered": 100,
              "r_filtered": 100
            },
            "table": {
              "table_name": "stock",
              "access_type": "ref",
              "possible_keys": [
                "product_sqlstock",
                "id_shop",
                "id_shop_group",
                "id_product",
                "id_product_attribute"   
              ],
              "key": "id_product",
              "key_length": "4",
              "used_key_parts": ["id_product"],
              "ref": ["outletsaludcom.p.id_product"],
              "r_loops": 765047,
              "rows": 1,
              "r_rows": 1.0408,
              "r_total_time_ms": 1123.1, 
              "filtered": 100,
              "r_filtered": 96.077,
              "attached_condition": "trigcond(stock.id_product_attribute = 0 and stock.id_shop = 1 and stock.id_shop_group = 0 and trigcond(p.id_product is not null))"
            },
            "table": {
              "table_name": "sw",
              "access_type": "ref",
              "possible_keys": ["PRIMARY", "id_lang"],
              "key": "id_lang",
              "key_length": "8",
              "used_key_parts": ["id_lang", "id_shop"],
              "ref": ["const", "const"], 
              "r_loops": 765047,
              "rows": 11006,
              "r_rows": 10758,
              "r_total_time_ms": 1.59e6, 
              "filtered": 100,
              "r_filtered": 1.8e-6,
              "attached_condition": "sw.id_word = si.id_word and (sw.id_word in (70753384,70513881,71090789,71038048,70528020,70444280,70514106,71091008,71038217,70753558,70514165,71091100,71038307) or sw.word like '%fase1%')",
              "using_index": true
            }
          }
        }
      }
    }
  }
}

ANALYSE Without semijoin:

{
  "query_block": {
    "select_id": 1,
    "r_loops": 1,
    "r_total_time_ms": 41.687,
    "having_condition": "terms like '%fase%'",
    "filesort": {
      "sort_key": "sum(si.weight) desc, p.id_product",
      "r_loops": 1,
      "r_total_time_ms": 0.0887,
      "r_used_priority_queue": false,
      "r_output_rows": 151,
      "r_buffer_size": "5Kb",
      "temporary_table": {
        "filesort": {
          "sort_key": "si.id_product",
          "r_loops": 1,
          "r_total_time_ms": 0.0317,
          "r_used_priority_queue": false,
          "r_output_rows": 151,
          "r_buffer_size": "3Kb",
          "temporary_table": {
            "table": {
              "table_name": "sw",
              "access_type": "ref",
              "possible_keys": ["PRIMARY", "id_lang"],
              "key": "id_lang",
              "key_length": "8",
              "used_key_parts": ["id_lang", "id_shop"],
              "ref": ["const", "const"],
              "r_loops": 1,
              "rows": 11006,
              "r_rows": 10758,
              "r_total_time_ms": 4.77,
              "filtered": 100,
              "r_filtered": 0.0372,
              "attached_condition": "sw.id_word in (70753384,70513881,71090789,71038048,70528020,70444280,70514106,71091008,71038217,70753558,70514165,71091100,71038307) or sw.word like '%fase1%'",
              "using_index": true
            },
            "table": {
              "table_name": "si",
              "access_type": "ref",
              "possible_keys": ["PRIMARY"],
              "key": "PRIMARY",
              "key_length": "4",
              "used_key_parts": ["id_word"],
              "ref": ["outletsaludcom.sw.id_word"],
              "r_loops": 4,
              "rows": 6,
              "r_rows": 39,
              "r_total_time_ms": 0.1247,
              "filtered": 100,
              "r_filtered": 97.436,
              "attached_condition": "trigcond(<in_optimizer>(si.id_product,si.id_product in (subquery#2)))"
            },
            "table": {
              "table_name": "p",
              "access_type": "eq_ref",
              "possible_keys": ["PRIMARY"],
              "key": "PRIMARY",
              "key_length": "4",
              "used_key_parts": ["id_product"],
              "ref": ["outletsaludcom.si.id_product"],
              "r_loops": 151,
              "rows": 1,
              "r_rows": 1,
              "r_total_time_ms": 0.2148,
              "filtered": 100,
              "r_filtered": 100,
              "attached_condition": "trigcond(trigcond(si.id_product is not null))"
            },
            "table": {
              "table_name": "stock",
              "access_type": "eq_ref",
              "possible_keys": [
                "product_sqlstock",
                "id_shop",
                "id_shop_group",
                "id_product",
                "id_product_attribute"
              ],
              "key": "product_sqlstock",
              "key_length": "16",
              "used_key_parts": [
                "id_product",
                "id_product_attribute",
                "id_shop",
                "id_shop_group"
              ],
              "ref": ["outletsaludcom.p.id_product", "const", "const", "const"],
              "r_loops": 151,
              "rows": 1,
              "r_rows": 1,
              "r_total_time_ms": 0.3796,
              "filtered": 100,
              "r_filtered": 100,
              "attached_condition": "trigcond(trigcond(p.id_product is not null))"
            },
            "subqueries": [
              {
                "query_block": {
                  "select_id": 2,
                  "r_loops": 1,
                  "r_total_time_ms": 30.137,
                  "table": {
                    "table_name": "c",
                    "access_type": "ref",
                    "possible_keys": [
                      "PRIMARY",
                      "category_parent",
                      "nleftrightactive",
                      "level_depth",
                      "nright",
                      "activenleft",
                      "activenright"
                    ],
                    "key": "activenleft",
                    "key_length": "1",
                    "used_key_parts": ["active"],
                    "ref": ["const"],
                    "r_loops": 1,
                    "rows": 213,
                    "r_rows": 213,
                    "r_total_time_ms": 0.0726,
                    "filtered": 100,
                    "r_filtered": 100,
                    "using_index": true
                  },
                  "table": {
                    "table_name": "cg",
                    "access_type": "ref",
                    "possible_keys": ["PRIMARY", "id_category", "id_group"],
                    "key": "PRIMARY",
                    "key_length": "4",
                    "used_key_parts": ["id_category"],
                    "ref": ["outletsaludcom.c.id_category"],
                    "r_loops": 213,
                    "rows": 1,
                    "r_rows": 3.7793,
                    "r_total_time_ms": 0.551,
                    "filtered": 100,
                    "r_filtered": 26.335,
                    "attached_condition": "<in_optimizer>(cg.id_group,cg.id_group in (subquery#3))",
                    "using_index": true
                  },
                  "table": {
                    "table_name": "cp",
                    "access_type": "ref",
                    "possible_keys": ["PRIMARY", "id_product", "id_category"],
                    "key": "PRIMARY",
                    "key_length": "4",
                    "used_key_parts": ["id_category"],
                    "ref": ["outletsaludcom.c.id_category"],
                    "r_loops": 212,
                    "rows": 21,
                    "r_rows": 42.354,
                    "r_total_time_ms": 3.0359,
                    "filtered": 100,
                    "r_filtered": 100,
                    "using_index": true
                  },
                  "table": {
                    "table_name": "product_shop",
                    "access_type": "eq_ref",
                    "possible_keys": [
                      "PRIMARY",
                      "id_category_default",
                      "date_add",
                      "indexed"
                    ],
                    "key": "PRIMARY",
                    "key_length": "8",
                    "used_key_parts": ["id_product", "id_shop"],
                    "ref": ["outletsaludcom.cp.id_product", "const"],
                    "r_loops": 8979,
                    "rows": 1,
                    "r_rows": 1,
                    "r_total_time_ms": 8.312,
                    "filtered": 100,
                    "r_filtered": 87.983,
                    "attached_condition": "product_shop.active = 1 and product_shop.indexed = 1 and product_shop.visibility in ('both','search')"
                  },
                  "table": {
                    "table_name": "p",
                    "access_type": "eq_ref",
                    "possible_keys": [
                      "PRIMARY",
                      "product_supplier",
                      "product_manufacturer",
                      "id_category_default",
                      "indexed",
                      "date_add"
                    ],
                    "key": "PRIMARY",
                    "key_length": "4",
                    "used_key_parts": ["id_product"],
                    "ref": ["outletsaludcom.cp.id_product"],
                    "r_loops": 7900,
                    "rows": 1,
                    "r_rows": 1,
                    "r_total_time_ms": 10.726,
                    "filtered": 100,
                    "r_filtered": 100,
                    "using_index": true
                  },
                  "subqueries": [
                    {
                      "query_block": {
                        "select_id": 3,
                        "r_loops": 1,
                        "r_total_time_ms": 0.0188,
                        "table": {
                          "table_name": "ps_customer_group",
                          "access_type": "ref",
                          "possible_keys": [
                            "PRIMARY",
                            "customer_login",
                            "id_customer"
                          ],
                          "key": "PRIMARY",
                          "key_length": "4",
                          "used_key_parts": ["id_customer"],
                          "ref": ["const"],
                          "r_loops": 1,
                          "rows": 1,
                          "r_rows": 1,
                          "r_total_time_ms": 0.0085,
                          "filtered": 100,
                          "r_filtered": 100,
                          "using_index": true
                        }
                      }
                    }
                  ]
                }
              }
            ]
          }
        }
      }
    }
  }
}

I'll post the ANALYZE for the first query once it finishes its execution, can take a while

Comment by jocelyn fournier [ 2019-11-27 ]

@sergei @igor any feedback on this one ?

Comment by Igor Babaev [ 2020-03-11 ]

Jocelyn,
We can only suggest you to set @@in_predicate_conversion_threshold to 2000.

Generated at Thu Feb 08 08:47:12 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.