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 (
    5764, 5765, 5766, 5767, 5768, 5769, 5770, 
    5771, 5772, 5773, 5774, 5775, 5776, 
    5777, 5778, 5779, 5780, 5781, 5782, 
    5783, 5784, 1986, 1987, 1988, 1989, 
    1990, 1991, 1992, 1993, 1994, 1995, 
    1996, 1997, 1998, 1999, 2000, 2001, 
    2002, 2003, 2004, 2005, 2006, 2007, 
    2008, 2009, 2010, 2011, 2012, 2013, 
    2014, 2015, 2016, 2017, 2018, 2019, 
    2020, 2021, 2022, 2023, 2024, 2025, 
    2026, 2027, 2028, 2029, 2030, 2031, 
    2032, 2033, 2034, 2035, 2036, 2037, 
    2038, 5668, 5669, 5670, 5671, 5672, 
    5673, 5674, 5675, 5676, 5677, 5678, 
    5679, 5680, 5681, 5682, 5683, 5684, 
    5685, 5686, 5687, 5688, 5689
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00297

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "68.48"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.61"
      },
      "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.92",
            "index_condition": "(`gaseus`.`cscart_products_categories`.`product_id` in (5764,5765,5766,5767,5768,5769,5770,5771,5772,5773,5774,5775,5776,5777,5778,5779,5780,5781,5782,5783,5784,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016,2017,2018,2019,2020,2021,2022,2023,2024,2025,2026,2027,2028,2029,2030,2031,2032,2033,2034,2035,2036,2037,2038,5668,5669,5670,5671,5672,5673,5674,5675,5676,5677,5678,5679,5680,5681,5682,5683,5684,5685,5686,5687,5688,5689))",
            "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.87",
              "data_read_per_join": "25"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
1986 308M 0
1987 308M 0
1988 308M 0
1989 308M 0
1990 308M 0
1991 308M 0
1992 308M 0
1993 308M 0
1994 308M 0
1995 308M 0
1996 308M 0
1997 308M 0
1998 308M 0
1999 308M 0
2000 308M 0
2001 308M 0
2002 308M 0
2003 308M 0
2004 308M 0
2005 308M 0
2006 308M 0
2007 308M 0
2008 308M 0
2009 308M 0
2010 308M 0
2011 308M 0
2012 308M 0
2013 308M 0
2014 308M 0
2015 308M 0
2016 308M 0
2017 308M 0
2018 308M 0
2019 308M 0
2020 308M 0
2021 308M 0
2022 308M 0
2023 308M 0
2024 308M 0
2025 308M 0
2026 308M 0
2027 308M 0
2028 308M 0
2029 308M 0
2030 308M 0
2031 308M 0
2032 308M 0
2033 308M 0
2034 308M 0
2035 308M 0
2036 308M 0
2037 308M 0
2038 308M 0
5668 308M 0
5669 308M 0
5670 308M 0
5671 308M 0
5672 308M 0
5673 308M 0
5674 308M 0
5675 308M 0
5676 308M 0
5677 308M 0
5678 308M 0
5679 308M 0
5680 308M 0
5681 308M 0
5682 308M 0
5683 308M 0
5684 308M 0
5685 308M 0
5686 308M 0
5687 308M 0
5688 308M 0
5689 308M 0
5764 308M 0
5765 308M 0
5766 308M 0
5767 308M 0
5768 308M 0
5769 308M 0
5770 308M 0
5771 308M 0
5772 308M 0
5773 308M 0
5774 308M 0
5775 308M 0
5776 308M 0
5777 308M 0
5778 308M 0
5779 308M 0
5780 308M 0
5781 308M 0
5782 308M 0
5783 308M 0
5784 308M 0