SELECT 
  cscart_products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      cscart_products_categories.link_type = "M", 
      CONCAT(
        cscart_products_categories.category_id, 
        "M"
      ), 
      cscart_products_categories.category_id
    )
  ) AS category_ids, 
  product_position_source.position AS position 
FROM 
  cscart_products_categories 
  INNER JOIN cscart_categories ON cscart_categories.category_id = cscart_products_categories.category_id 
  AND cscart_categories.storefront_id IN (0, 1) 
  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') 
  LEFT JOIN cscart_products_categories AS product_position_source ON cscart_products_categories.product_id = product_position_source.product_id 
  AND product_position_source.category_id = 308 
WHERE 
  cscart_products_categories.product_id IN (
    5134, 5135, 1452, 5161, 1442, 5151, 6734, 
    6733, 6729, 6710, 1721, 1722, 1723, 
    1724, 1725, 1726, 1727, 1728, 1729, 
    1730, 1731, 1732, 1733, 1734, 1735, 
    1736, 1737, 1738, 1739, 1740, 1741, 
    1742, 1743, 1744, 1745, 1746, 1747, 
    1748, 1749, 1750, 1751, 1752, 1753, 
    1754, 1755, 1756, 1757, 1758, 1759, 
    1760, 1761, 1762, 1763, 1764, 1766, 
    1767, 1768, 1769, 3739, 3740, 3741, 
    3742, 5415, 5416, 5417, 5418, 5419, 
    5420, 5421, 5422, 5423, 5424, 5425, 
    5426, 5427, 5428, 5429, 5430, 5431, 
    5432, 5433, 5434, 5435, 5436, 5437, 
    5438, 5439, 5440, 5441, 5442, 5443, 
    5444, 5445, 5446, 5447, 5448
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00333

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "68.46"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.60"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "ALL",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "rows_examined_per_scan": 40,
            "rows_produced_per_join": 1,
            "filtered": "4.00",
            "cost_info": {
              "read_cost": "4.54",
              "eval_cost": "0.16",
              "prefix_cost": "4.70",
              "data_read_per_join": "6K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`gaseus`.`cscart_categories`.`storefront_id` in (0,1)) and ((`gaseus`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`gaseus`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`gaseus`.`cscart_categories`.`usergroup_ids`))) and (`gaseus`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "gaseus.cscart_categories.category_id"
            ],
            "rows_examined_per_scan": 110,
            "rows_produced_per_join": 1,
            "filtered": "0.91",
            "index_condition": "(`gaseus`.`cscart_products_categories`.`product_id` in (5134,5135,1452,5161,1442,5151,6734,6733,6729,6710,1721,1722,1723,1724,1725,1726,1727,1728,1729,1730,1731,1732,1733,1734,1735,1736,1737,1738,1739,1740,1741,1742,1743,1744,1745,1746,1747,1748,1749,1750,1751,1752,1753,1754,1755,1756,1757,1758,1759,1760,1761,1762,1763,1764,1766,1767,1768,1769,3739,3740,3741,3742,5415,5416,5417,5418,5419,5420,5421,5422,5423,5424,5425,5426,5427,5428,5429,5430,5431,5432,5433,5434,5435,5436,5437,5438,5439,5440,5441,5442,5443,5444,5445,5446,5447,5448))",
            "cost_info": {
              "read_cost": "44.00",
              "eval_cost": "0.16",
              "prefix_cost": "66.30",
              "data_read_per_join": "25"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "table": {
            "table_name": "product_position_source",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id",
              "product_id"
            ],
            "key_length": "6",
            "ref": [
              "const",
              "gaseus.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 1,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "0.40",
              "eval_cost": "0.16",
              "prefix_cost": "66.86",
              "data_read_per_join": "25"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
1442 308M 0
1452 308M 0
1721 308M 0
1722 308M 0
1723 308M 0
1724 308M 0
1725 308M 0
1726 308M 0
1727 308M 0
1728 308M 0
1729 308M 0
1730 308M 0
1731 308M 0
1732 308M 0
1733 308M 0
1734 308M 0
1735 308M 0
1736 308M 0
1737 308M 0
1738 308M 0
1739 308M 0
1740 308M 0
1741 308M 0
1742 308M 0
1743 308M 0
1744 308M 0
1745 308M 0
1746 308M 0
1747 308M 0
1748 308M 0
1749 308M 0
1750 308M 0
1751 308M 0
1752 308M 0
1753 308M 0
1754 308M 0
1755 308M 0
1756 308M 0
1757 308M 0
1758 308M 0
1759 308M 0
1760 308M 0
1761 308M 0
1762 308M 0
1763 308M 0
1764 308M 0
1766 308M 0
1767 308M 0
1768 308M 0
1769 308M 0
3739 308M 0
3740 308M 0
3741 308M 0
3742 308M 0
5134 308M 0
5135 308M 0
5151 308M 0
5161 308M 0
5415 308M 0
5416 308M 0
5417 308M 0
5418 308M 0
5419 308M 0
5420 308M 0
5421 308M 0
5422 308M 0
5423 308M 0
5424 308M 0
5425 308M 0
5426 308M 0
5427 308M 0
5428 308M 0
5429 308M 0
5430 308M 0
5431 308M 0
5432 308M 0
5433 308M 0
5434 308M 0
5435 308M 0
5436 308M 0
5437 308M 0
5438 308M 0
5439 308M 0
5440 308M 0
5441 308M 0
5442 308M 0
5443 308M 0
5444 308M 0
5445 308M 0
5446 308M 0
5447 308M 0
5448 308M 0
6710 308M 0
6729 308M 0
6733 308M 0
6734 308M 0