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 = 266 
WHERE 
  cscart_products_categories.product_id IN (
    5474, 5475, 5476, 5477, 5478, 5479, 5480, 
    5481, 5482, 5483, 5484, 5485, 5486, 
    5487, 5488, 5489, 5490, 5491, 5492, 
    5493, 5494, 5495, 5496, 5497, 5498, 
    5499, 5500, 5501, 5502, 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
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00247

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 (5474,5475,5476,5477,5478,5479,5480,5481,5482,5483,5484,5485,5486,5487,5488,5489,5490,5491,5492,5493,5494,5495,5496,5497,5498,5499,5500,5501,5502,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))",
            "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
3157 308M
5132 308M
5133 308M
5134 308M
5135 308M
5151 308M
5153 308M
5161 308M
5163 308M
5474 308M
5475 308M
5476 308M
5477 308M
5478 308M
5479 308M
5480 308M
5481 308M
5482 308M
5483 308M
5484 308M
5485 308M
5486 308M
5487 308M
5488 308M
5489 308M
5490 308M
5491 308M
5492 308M
5493 308M
5494 308M
5495 308M
5496 308M
5497 308M
5498 308M
5499 308M
5500 308M
5501 308M
5502 308M
5503 308M
5504 308M
6710 308M
6729 308M
6733 308M
6734 308M