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 = 271 
WHERE 
  cscart_products_categories.product_id IN (
    5503, 5504, 5163, 5153, 1419, 1420, 1421, 
    3157, 5132, 5133, 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
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00269

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "68.44"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.58"
      },
      "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.90",
            "index_condition": "(`gaseus`.`cscart_products_categories`.`product_id` in (5503,5504,5163,5153,1419,1420,1421,3157,5132,5133,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))",
            "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
1419 308M
1420 308M
1421 308M
1442 308M
1452 308M
1721 308M
1722 308M
1723 308M
1724 308M
1725 308M
1726 308M
1727 308M
1728 308M
1729 308M
1730 308M
1731 308M
1732 308M
1733 308M
1734 308M
1735 308M
1736 308M
1737 308M
1738 308M
1739 308M
1740 308M
1741 308M
1742 308M
1743 308M
1744 308M
1745 308M
1746 308M
1747 308M
1748 308M
1749 308M
1750 308M
1751 308M
1752 308M
1753 308M
1754 308M
1755 308M
1756 308M
1757 308M
1758 308M
1759 308M
1760 308M
1761 308M
1762 308M
1763 308M
1764 308M
1766 308M
1767 308M
1768 308M
1769 308M
3157 308M
3739 308M
3740 308M
3741 308M
3742 308M
5132 308M
5133 308M
5134 308M
5135 308M
5151 308M
5153 308M
5161 308M
5163 308M
5415 308M
5416 308M
5417 308M
5418 308M
5419 308M
5420 308M
5421 308M
5422 308M
5423 308M
5424 308M
5425 308M
5426 308M
5427 308M
5428 308M
5429 308M
5430 308M
5431 308M
5432 308M
5433 308M
5434 308M
5435 308M
5436 308M
5437 308M
5438 308M
5503 308M
5504 308M
6710 308M
6729 308M
6733 308M
6734 308M