SELECT 
  SQL_CALC_FOUND_ROWS (
    CASE WHEN products.parent_product_id <> 0 THEN products.parent_product_id ELSE products.product_id END
  ) AS product_id, 
  descr1.product as product, 
  companies.company as company_name, 
  GROUP_CONCAT(
    products.product_id 
    ORDER BY 
      products.parent_product_id ASC, 
      products.product_id ASC
  ) AS product_ids, 
  GROUP_CONCAT(
    products.product_type 
    ORDER BY 
      products.parent_product_id ASC, 
      products.product_id ASC
  ) AS product_types, 
  GROUP_CONCAT(
    products.parent_product_id 
    ORDER BY 
      products.parent_product_id ASC, 
      products.product_id ASC
  ) AS parent_product_ids, 
  products.product_type, 
  products.parent_product_id, 
  products.master_product_offers_count, 
  products.master_product_id, 
  products.company_id, 
  IFNULL(
    abt_erp_city_descr.city, companies.city
  ) as abt__ut2_mv_company_city, 
  IFNULL(
    abt_erp_country_descr.country, companies.country
  ) as abt__ut2_mv_company_country 
FROM 
  cscart_products as products 
  LEFT JOIN cscart_product_descriptions as descr1 ON descr1.product_id = products.product_id 
  AND descr1.lang_code = 'vn' 
  LEFT JOIN cscart_product_prices as prices ON prices.product_id = products.product_id 
  AND prices.lower_limit = 1 
  LEFT JOIN cscart_companies AS companies ON companies.company_id = products.company_id 
  INNER JOIN cscart_products_categories as products_categories ON products_categories.product_id = products.product_id 
  INNER JOIN cscart_categories ON cscart_categories.category_id = products_categories.category_id 
  AND (
    cscart_categories.usergroup_ids = '' 
    OR FIND_IN_SET(
      0, cscart_categories.usergroup_ids
    ) 
    OR FIND_IN_SET(
      1, cscart_categories.usergroup_ids
    )
  ) 
  AND cscart_categories.status IN ('A', 'H') 
  AND cscart_categories.storefront_id IN (0, 1) 
  LEFT JOIN cscart_master_products_storefront_offers_count AS master_products_storefront_offers_count ON master_products_storefront_offers_count.product_id = products.product_id 
  AND master_products_storefront_offers_count.storefront_id = 1 
  LEFT JOIN cscart_cities AS abt_erp_cities ON abt_erp_cities.code = companies.city 
  AND abt_erp_cities.state_code = companies.state 
  AND abt_erp_cities.country_code = companies.country 
  AND abt_erp_cities.status = 'A' 
  LEFT JOIN cscart_city_descriptions AS abt_erp_city_descr ON abt_erp_city_descr.city_id = abt_erp_cities.city_id 
  AND abt_erp_city_descr.lang_code = 'vn' 
  LEFT JOIN cscart_country_descriptions AS abt_erp_country_descr ON abt_erp_country_descr.code = companies.country 
  AND abt_erp_country_descr.lang_code = 'vn' 
WHERE 
  1 
  AND cscart_categories.category_id IN (302, 311, 312, 313) 
  AND (
    companies.status IN ('A') 
    OR products.company_id = 0
  ) 
  AND (
    products.usergroup_ids = '' 
    OR FIND_IN_SET(0, products.usergroup_ids) 
    OR FIND_IN_SET(1, products.usergroup_ids)
  ) 
  AND products.status IN ('A') 
  AND prices.usergroup_id IN (0, 0, 1) 
  AND products.master_product_status IN ('A', 'H') 
  AND products.master_product_id = 0 
  AND (
    products.company_id > 0 
    OR (
      master_products_storefront_offers_count.count > 0
    )
  ) 
  AND products.product_type != 'D' 
GROUP BY 
  product_id 
ORDER BY 
  products_categories.position asc, 
  products.product_id ASC 
LIMIT 
  0, 20

Query time 0.00421

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "3.00"
    },
    "ordering_operation": {
      "using_filesort": true,
      "grouping_operation": {
        "using_temporary_table": true,
        "using_filesort": true,
        "buffer_result": {
          "using_temporary_table": true,
          "nested_loop": [
            {
              "table": {
                "table_name": "master_products_storefront_offers_count",
                "access_type": "system",
                "possible_keys": [
                  "PRIMARY",
                  "idx_storefront_id"
                ],
                "rows_examined_per_scan": 0,
                "rows_produced_per_join": 1,
                "filtered": "0.00",
                "const_row_not_found": true,
                "cost_info": {
                  "read_cost": "0.00",
                  "eval_cost": "0.10",
                  "prefix_cost": "0.00",
                  "data_read_per_join": "16"
                },
                "used_columns": [
                  "storefront_id",
                  "product_id",
                  "count"
                ]
              }
            },
            {
              "table": {
                "table_name": "cscart_categories",
                "access_type": "range",
                "possible_keys": [
                  "PRIMARY",
                  "c_status",
                  "p_category_id"
                ],
                "key": "PRIMARY",
                "used_key_parts": [
                  "category_id"
                ],
                "key_length": "3",
                "rows_examined_per_scan": 4,
                "rows_produced_per_join": 0,
                "filtered": "4.00",
                "index_condition": "(`kcoffee`.`cscart_categories`.`category_id` in (302,311,312,313))",
                "cost_info": {
                  "read_cost": "2.79",
                  "eval_cost": "0.02",
                  "prefix_cost": "2.81",
                  "data_read_per_join": "512"
                },
                "used_columns": [
                  "category_id",
                  "storefront_id",
                  "usergroup_ids",
                  "status"
                ],
                "attached_condition": "(((`kcoffee`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`kcoffee`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`kcoffee`.`cscart_categories`.`usergroup_ids`))) and (`kcoffee`.`cscart_categories`.`status` in ('A','H')) and (`kcoffee`.`cscart_categories`.`storefront_id` in (0,1)))"
              }
            },
            {
              "table": {
                "table_name": "products_categories",
                "access_type": "ref",
                "possible_keys": [
                  "PRIMARY",
                  "pt"
                ],
                "key": "PRIMARY",
                "used_key_parts": [
                  "category_id"
                ],
                "key_length": "3",
                "ref": [
                  "kcoffee.cscart_categories.category_id"
                ],
                "rows_examined_per_scan": 2,
                "rows_produced_per_join": 0,
                "filtered": "100.00",
                "cost_info": {
                  "read_cost": "0.08",
                  "eval_cost": "0.03",
                  "prefix_cost": "2.92",
                  "data_read_per_join": "5"
                },
                "used_columns": [
                  "product_id",
                  "category_id",
                  "position"
                ]
              }
            },
            {
              "table": {
                "table_name": "products",
                "access_type": "eq_ref",
                "possible_keys": [
                  "PRIMARY",
                  "status",
                  "idx_master_product_id"
                ],
                "key": "PRIMARY",
                "used_key_parts": [
                  "product_id"
                ],
                "key_length": "3",
                "ref": [
                  "kcoffee.products_categories.product_id"
                ],
                "rows_examined_per_scan": 1,
                "rows_produced_per_join": 0,
                "filtered": "17.34",
                "cost_info": {
                  "read_cost": "0.00",
                  "eval_cost": "0.01",
                  "prefix_cost": "2.95",
                  "data_read_per_join": "252"
                },
                "used_columns": [
                  "product_id",
                  "product_type",
                  "status",
                  "company_id",
                  "usergroup_ids",
                  "parent_product_id",
                  "master_product_id",
                  "master_product_status",
                  "master_product_offers_count"
                ],
                "attached_condition": "((`kcoffee`.`products`.`master_product_id` = 0) and ((`kcoffee`.`products`.`usergroup_ids` = '') or (0 <> find_in_set(0,`kcoffee`.`products`.`usergroup_ids`)) or (0 <> find_in_set(1,`kcoffee`.`products`.`usergroup_ids`))) and (`kcoffee`.`products`.`status` = 'A') and (`kcoffee`.`products`.`master_product_status` in ('A','H')) and ((`kcoffee`.`products`.`company_id` > 0) or <cache>((NULL > 0))) and (`kcoffee`.`products`.`product_type` <> 'D'))"
              }
            },
            {
              "table": {
                "table_name": "companies",
                "access_type": "eq_ref",
                "possible_keys": [
                  "PRIMARY"
                ],
                "key": "PRIMARY",
                "used_key_parts": [
                  "company_id"
                ],
                "key_length": "4",
                "ref": [
                  "kcoffee.products.company_id"
                ],
                "rows_examined_per_scan": 1,
                "rows_produced_per_join": 0,
                "filtered": "100.00",
                "cost_info": {
                  "read_cost": "0.00",
                  "eval_cost": "0.01",
                  "prefix_cost": "2.96",
                  "data_read_per_join": "353"
                },
                "used_columns": [
                  "company_id",
                  "status",
                  "company",
                  "city",
                  "state",
                  "country"
                ],
                "attached_condition": "<if>(found_match(companies), ((`kcoffee`.`companies`.`status` = 'A') or (`kcoffee`.`products`.`company_id` = 0)), true)"
              }
            },
            {
              "table": {
                "table_name": "descr1",
                "access_type": "eq_ref",
                "possible_keys": [
                  "PRIMARY",
                  "product_id"
                ],
                "key": "PRIMARY",
                "used_key_parts": [
                  "product_id",
                  "lang_code"
                ],
                "key_length": "9",
                "ref": [
                  "kcoffee.products_categories.product_id",
                  "const"
                ],
                "rows_examined_per_scan": 1,
                "rows_produced_per_join": 0,
                "filtered": "100.00",
                "cost_info": {
                  "read_cost": "0.00",
                  "eval_cost": "0.01",
                  "prefix_cost": "2.97",
                  "data_read_per_join": "259"
                },
                "used_columns": [
                  "product_id",
                  "lang_code",
                  "product"
                ]
              }
            },
            {
              "table": {
                "table_name": "abt_erp_cities",
                "access_type": "eq_ref",
                "possible_keys": [
                  "cs",
                  "state_code",
                  "code",
                  "country_code"
                ],
                "key": "cs",
                "used_key_parts": [
                  "country_code",
                  "state_code",
                  "code"
                ],
                "key_length": "204",
                "ref": [
                  "kcoffee.companies.country",
                  "kcoffee.companies.state",
                  "kcoffee.companies.city"
                ],
                "rows_examined_per_scan": 1,
                "rows_produced_per_join": 0,
                "filtered": "100.00",
                "cost_info": {
                  "read_cost": "0.00",
                  "eval_cost": "0.01",
                  "prefix_cost": "2.97",
                  "data_read_per_join": "12"
                },
                "used_columns": [
                  "city_id",
                  "state_code",
                  "country_code",
                  "code",
                  "status"
                ],
                "attached_condition": "<if>(is_not_null_compl(abt_erp_cities), ((`kcoffee`.`abt_erp_cities`.`code` = `kcoffee`.`companies`.`city`) and (`kcoffee`.`abt_erp_cities`.`country_code` = `kcoffee`.`companies`.`country`) and (`kcoffee`.`abt_erp_cities`.`status` = 'A')), true)"
              }
            },
            {
              "table": {
                "table_name": "abt_erp_city_descr",
                "access_type": "eq_ref",
                "possible_keys": [
                  "PRIMARY"
                ],
                "key": "PRIMARY",
                "used_key_parts": [
                  "city_id",
                  "lang_code"
                ],
                "key_length": "9",
                "ref": [
                  "kcoffee.abt_erp_cities.city_id",
                  "const"
                ],
                "rows_examined_per_scan": 1,
                "rows_produced_per_join": 0,
                "filtered": "100.00",
                "cost_info": {
                  "read_cost": "0.00",
                  "eval_cost": "0.01",
                  "prefix_cost": "2.98",
                  "data_read_per_join": "43"
                },
                "used_columns": [
                  "city_id",
                  "lang_code",
                  "city"
                ]
              }
            },
            {
              "table": {
                "table_name": "abt_erp_country_descr",
                "access_type": "eq_ref",
                "possible_keys": [
                  "PRIMARY"
                ],
                "key": "PRIMARY",
                "used_key_parts": [
                  "code",
                  "lang_code"
                ],
                "key_length": "12",
                "ref": [
                  "kcoffee.companies.country",
                  "const"
                ],
                "rows_examined_per_scan": 1,
                "rows_produced_per_join": 0,
                "filtered": "100.00",
                "cost_info": {
                  "read_cost": "0.00",
                  "eval_cost": "0.01",
                  "prefix_cost": "2.98",
                  "data_read_per_join": "22"
                },
                "used_columns": [
                  "code",
                  "lang_code",
                  "country"
                ]
              }
            },
            {
              "table": {
                "table_name": "prices",
                "access_type": "ref",
                "possible_keys": [
                  "usergroup",
                  "product_id",
                  "lower_limit",
                  "usergroup_id"
                ],
                "key": "usergroup",
                "used_key_parts": [
                  "product_id"
                ],
                "key_length": "3",
                "ref": [
                  "kcoffee.products_categories.product_id"
                ],
                "rows_examined_per_scan": 1,
                "rows_produced_per_join": 0,
                "filtered": "99.26",
                "using_index": true,
                "cost_info": {
                  "read_cost": "0.01",
                  "eval_cost": "0.01",
                  "prefix_cost": "3.00",
                  "data_read_per_join": "1"
                },
                "used_columns": [
                  "product_id",
                  "lower_limit",
                  "usergroup_id"
                ],
                "attached_condition": "((`kcoffee`.`prices`.`lower_limit` = 1) and (`kcoffee`.`prices`.`usergroup_id` in (0,0,1)))"
              }
            }
          ]
        }
      }
    }
  }
}

Result

product_id product company_name product_ids product_types parent_product_ids product_type parent_product_id master_product_offers_count master_product_id company_id abt__ut2_mv_company_city abt__ut2_mv_company_country
363 TIÊU XANH SẤY LẠNH K PEPPER 26 G + CỐI XAY TIÊU K COFFEE 363 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
359 TIÊU ĐEN K PEPPER 50 G + CỐI XAY TIÊU K COFFEE 359 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
361 TIÊU TRẮNG K PEPPER 51 G + CỐI XAY TIÊU K COFFEE 361 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
364 TIÊU BỐN MÙA K PEPPER 50 G + CỐI XAY TIÊU K COFFEE 364 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
360 TIÊU ĐEN K PEPPER 90 G + CỐI XAY TIÊU K COFFEE 360 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
362 TIÊU TRẮNG K PEPPER 90 G + CỐI XAY TIÊU K COFFEE 362 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
365 TIÊU BỐN MÙA K PEPPER 70 G + CỐI XAY TIÊU K COFFEE 365 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
367 TIÊU ĐEN K PEPPER 85 G - TIÊU SẠCH NGUYÊN CHẤT K COFFEE 367 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
366 TIÊU ĐEN K PEPPER 125 G - TIÊU SẠCH NGUYÊN CHẤT K COFFEE 366 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
369 TIÊU TRẮNG K PEPPER 85 G K COFFEE 369 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
368 TIÊU TRẮNG K PEPPER 125 G K COFFEE 368 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
370 TIÊU ĐEN HẠT K PEPPER 35 G K COFFEE 370 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
371 TIÊU ĐEN XAY K PEPPER 35G K COFFEE 371 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
345 Sốt Tiêu Xanh Ngâm Giấm K Pepper 130g – Chua Cay Chuẩn Vị K COFFEE 345 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
346 ​Sốt Tiêu Xanh Ngâm Giấm K Pepper 180g – Chua Cay Chuẩn Vị​ K COFFEE 346 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam
358 BỘ GIA VỊ VUA TIÊU K PEPPER K COFFEE 358 P 0 P 0 0 0 3 Phường Cầu Ông Lãnh Viet Nam