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 
FROM 
  q_products as products 
  LEFT JOIN q_product_features_values as var_val_2 ON var_val_2.product_id = products.product_id 
  AND var_val_2.lang_code = 'en' 
  AND var_val_2.feature_id = 2 
  LEFT JOIN q_product_options_inventory as inventory ON inventory.product_id = products.product_id 
  LEFT JOIN q_product_descriptions as descr1 ON descr1.product_id = products.product_id 
  AND descr1.lang_code = 'en' 
  LEFT JOIN q_product_prices as prices ON prices.product_id = products.product_id 
  AND prices.lower_limit = 1 
  LEFT JOIN q_companies AS companies ON companies.company_id = products.company_id 
  INNER JOIN q_products_categories as products_categories ON products_categories.product_id = products.product_id 
  INNER JOIN q_categories ON q_categories.category_id = products_categories.category_id 
  AND (
    q_categories.usergroup_ids = '' 
    OR FIND_IN_SET(0, q_categories.usergroup_ids) 
    OR FIND_IN_SET(1, q_categories.usergroup_ids)
  ) 
  AND q_categories.status IN ('A', 'H') 
WHERE 
  1 
  AND (
    var_val_2.variant_id IN (8188)
  ) 
  AND q_categories.category_id IN (39) 
  AND companies.status = 'A' 
  AND (
    CASE products.tracking WHEN 'O' THEN inventory.amount > 0 WHEN 'B' THEN products.amount > 0 ELSE 1 END
  ) 
  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) 
GROUP BY 
  product_id 
ORDER BY 
  products.timestamp desc, 
  products.product_id ASC 
LIMIT 
  0, 30

Query time 0.00136

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "2.82"
    },
    "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": "inventory",
                "access_type": "system",
                "possible_keys": [
                  "pc"
                ],
                "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.20",
                  "prefix_cost": "0.00",
                  "data_read_per_join": "976"
                },
                "used_columns": [
                  "product_id",
                  "amount"
                ]
              }
            },
            {
              "table": {
                "table_name": "q_categories",
                "access_type": "const",
                "possible_keys": [
                  "PRIMARY",
                  "c_status",
                  "p_category_id"
                ],
                "key": "PRIMARY",
                "used_key_parts": [
                  "category_id"
                ],
                "key_length": "3",
                "ref": [
                  "const"
                ],
                "rows_examined_per_scan": 1,
                "rows_produced_per_join": 1,
                "filtered": "100.00",
                "cost_info": {
                  "read_cost": "0.00",
                  "eval_cost": "0.20",
                  "prefix_cost": "0.00",
                  "data_read_per_join": "2K"
                },
                "used_columns": [
                  "category_id",
                  "usergroup_ids",
                  "status"
                ]
              }
            },
            {
              "table": {
                "table_name": "var_val_2",
                "access_type": "ref",
                "possible_keys": [
                  "PRIMARY",
                  "fl",
                  "variant_id",
                  "lang_code",
                  "product_id",
                  "fpl"
                ],
                "key": "fl",
                "used_key_parts": [
                  "feature_id",
                  "lang_code",
                  "variant_id"
                ],
                "key_length": "12",
                "ref": [
                  "const",
                  "const",
                  "const"
                ],
                "rows_examined_per_scan": 1,
                "rows_produced_per_join": 1,
                "filtered": "100.00",
                "cost_info": {
                  "read_cost": "1.00",
                  "eval_cost": "0.20",
                  "prefix_cost": "1.20",
                  "data_read_per_join": "792"
                },
                "used_columns": [
                  "feature_id",
                  "product_id",
                  "variant_id",
                  "lang_code"
                ],
                "attached_condition": "(`portal`.`var_val_2`.`product_id` is not null)"
              }
            },
            {
              "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": [
                  "portal.var_val_2.product_id"
                ],
                "rows_examined_per_scan": 1,
                "rows_produced_per_join": 0,
                "filtered": "99.95",
                "using_index": true,
                "cost_info": {
                  "read_cost": "1.00",
                  "eval_cost": "0.20",
                  "prefix_cost": "2.40",
                  "data_read_per_join": "23"
                },
                "used_columns": [
                  "product_id",
                  "lower_limit",
                  "usergroup_id"
                ],
                "attached_condition": "((`portal`.`prices`.`lower_limit` = 1) and (`portal`.`prices`.`usergroup_id` in (0,0,1)))"
              }
            },
            {
              "table": {
                "table_name": "products",
                "access_type": "eq_ref",
                "possible_keys": [
                  "PRIMARY",
                  "status"
                ],
                "key": "PRIMARY",
                "used_key_parts": [
                  "product_id"
                ],
                "key_length": "3",
                "ref": [
                  "portal.var_val_2.product_id"
                ],
                "rows_examined_per_scan": 1,
                "rows_produced_per_join": 0,
                "filtered": "93.11",
                "cost_info": {
                  "read_cost": "0.00",
                  "eval_cost": "0.19",
                  "prefix_cost": "2.60",
                  "data_read_per_join": "5K"
                },
                "used_columns": [
                  "product_id",
                  "product_type",
                  "status",
                  "company_id",
                  "amount",
                  "timestamp",
                  "usergroup_ids",
                  "tracking",
                  "parent_product_id"
                ],
                "attached_condition": "((case `portal`.`products`.`tracking` when 'O' then <cache>((NULL > 0)) when 'B' then (`portal`.`products`.`amount` > 0) else 1 end) and ((`portal`.`products`.`usergroup_ids` = '') or find_in_set(0,`portal`.`products`.`usergroup_ids`) or find_in_set(1,`portal`.`products`.`usergroup_ids`)) and (`portal`.`products`.`status` = 'A'))"
              }
            },
            {
              "table": {
                "table_name": "companies",
                "access_type": "eq_ref",
                "possible_keys": [
                  "PRIMARY"
                ],
                "key": "PRIMARY",
                "used_key_parts": [
                  "company_id"
                ],
                "key_length": "4",
                "ref": [
                  "portal.products.company_id"
                ],
                "rows_examined_per_scan": 1,
                "rows_produced_per_join": 0,
                "filtered": "10.00",
                "cost_info": {
                  "read_cost": "0.00",
                  "eval_cost": "0.02",
                  "prefix_cost": "2.79",
                  "data_read_per_join": "527"
                },
                "used_columns": [
                  "company_id",
                  "status",
                  "company"
                ],
                "attached_condition": "(`portal`.`companies`.`status` = 'A')"
              }
            },
            {
              "table": {
                "table_name": "products_categories",
                "access_type": "eq_ref",
                "possible_keys": [
                  "PRIMARY",
                  "pt"
                ],
                "key": "PRIMARY",
                "used_key_parts": [
                  "category_id",
                  "product_id"
                ],
                "key_length": "6",
                "ref": [
                  "const",
                  "portal.var_val_2.product_id"
                ],
                "rows_examined_per_scan": 1,
                "rows_produced_per_join": 0,
                "filtered": "100.00",
                "using_index": true,
                "cost_info": {
                  "read_cost": "0.00",
                  "eval_cost": "0.02",
                  "prefix_cost": "2.80",
                  "data_read_per_join": "1"
                },
                "used_columns": [
                  "product_id",
                  "category_id"
                ]
              }
            },
            {
              "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": [
                  "portal.var_val_2.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.02",
                  "prefix_cost": "2.82",
                  "data_read_per_join": "363"
                },
                "used_columns": [
                  "product_id",
                  "lang_code",
                  "product"
                ]
              }
            }
          ]
        }
      }
    }
  }
}

Result

product_id product company_name product_ids product_types parent_product_ids product_type parent_product_id
35548 Lorenzo Villoresi Teint De Neige EDP 50ml Smell Attractive Perfumes 35548 P 0 P 0