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 (
    5549, 5550, 5551, 5552, 5553, 5554, 5555, 
    5556, 5557, 5558, 5559, 1457, 5166, 
    1447, 5156, 5169, 3162, 1450, 5159, 
    1440, 5149, 1451, 5160, 1441, 5150, 
    1453, 5162, 1443, 5152, 1770, 1771, 
    1772, 1773, 1774, 1775, 1776, 1777, 
    1778, 1779, 1780, 1781, 1782, 1783, 
    1784, 1785, 1786, 1787, 1788, 1789, 
    1790, 1791, 1792, 1793, 1794, 1795, 
    1796, 1797, 1798, 1799, 1800, 1801, 
    1802, 1803, 1804, 1805, 1806, 1807, 
    1808, 1809, 1810, 1811, 1812, 1813, 
    1814, 1815, 1816, 1817, 1818, 1819, 
    3744, 3745, 3746, 3747, 5461, 5462, 
    5463, 5464, 5465, 5466, 5467, 5468, 
    5469, 5470, 5471, 5472, 5473
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00410

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "68.50"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.63"
      },
      "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.93",
            "index_condition": "(`gaseus`.`cscart_products_categories`.`product_id` in (5549,5550,5551,5552,5553,5554,5555,5556,5557,5558,5559,1457,5166,1447,5156,5169,3162,1450,5159,1440,5149,1451,5160,1441,5150,1453,5162,1443,5152,1770,1771,1772,1773,1774,1775,1776,1777,1778,1779,1780,1781,1782,1783,1784,1785,1786,1787,1788,1789,1790,1791,1792,1793,1794,1795,1796,1797,1798,1799,1800,1801,1802,1803,1804,1805,1806,1807,1808,1809,1810,1811,1812,1813,1814,1815,1816,1817,1818,1819,3744,3745,3746,3747,5461,5462,5463,5464,5465,5466,5467,5468,5469,5470,5471,5472,5473))",
            "cost_info": {
              "read_cost": "44.00",
              "eval_cost": "0.16",
              "prefix_cost": "66.30",
              "data_read_per_join": "26"
            },
            "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.41",
              "eval_cost": "0.16",
              "prefix_cost": "66.87",
              "data_read_per_join": "26"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
1440 308M
1441 308M
1443 308M
1447 308M
1450 308M
1451 308M
1453 308M
1457 308M
1770 308M
1771 308M
1772 308M
1773 308M
1774 308M
1775 308M
1776 308M
1777 308M
1778 308M
1779 308M
1780 308M
1781 308M
1782 308M
1783 308M
1784 308M
1785 308M
1786 308M
1787 308M
1788 308M
1789 308M
1790 308M
1791 308M
1792 308M
1793 308M
1794 308M
1795 308M
1796 308M
1797 308M
1798 308M
1799 308M
1800 308M
1801 308M
1802 308M
1803 308M
1804 308M
1805 308M
1806 308M
1807 308M
1808 308M
1809 308M
1810 308M
1811 308M
1812 308M
1813 308M
1814 308M
1815 308M
1816 308M
1817 308M
1818 308M
1819 308M
3162 308M
3744 308M
3745 308M
3746 308M
3747 308M
5149 308M
5150 308M
5152 308M
5156 308M
5159 308M
5160 308M
5162 308M
5166 308M
5169 308M
5461 308M
5462 308M
5463 308M
5464 308M
5465 308M
5466 308M
5467 308M
5468 308M
5469 308M
5470 308M
5471 308M
5472 308M
5473 308M
5549 308M
5550 308M
5551 308M
5552 308M
5553 308M
5554 308M
5555 308M
5556 308M
5557 308M
5558 308M
5559 308M