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 = 250 
WHERE 
  cscart_products_categories.product_id IN (
    4651, 5190, 1580, 3324, 3495, 5253, 5387, 
    3321, 3327, 1667, 3932, 2090, 2277, 
    5843, 2278, 5969, 3338, 2400, 5814, 
    5251, 5831, 4239, 5751, 5740, 4191, 
    5839, 2179, 5813, 1629, 5205, 5266, 
    1666, 5024, 5262, 5282, 5565, 3332, 
    5275, 5264, 5825, 5924, 5283, 5838, 
    5268, 5738, 1630, 3494, 5274, 2183, 
    2237, 5273, 5291, 2087, 3491, 3930, 
    4233, 5927, 2239, 8813, 1843, 5182, 
    2092, 5267, 5279, 2176, 2238, 5269, 
    5280, 5017, 1671, 3801, 2091, 1845, 
    2089, 3498, 5286, 2276, 4475, 3506, 
    5211
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00670

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "328.21"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "cscart_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 377,
            "rows_produced_per_join": 377,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (4651,5190,1580,3324,3495,5253,5387,3321,3327,1667,3932,2090,2277,5843,2278,5969,3338,2400,5814,5251,5831,4239,5751,5740,4191,5839,2179,5813,1629,5205,5266,1666,5024,5262,5282,5565,3332,5275,5264,5825,5924,5283,5838,5268,5738,1630,3494,5274,2183,2237,5273,5291,2087,3491,3930,4233,5927,2239,8813,1843,5182,2092,5267,5279,2176,2238,5269,5280,5017,1671,3801,2091,1845,2089,3498,5286,2276,4475,3506,5211))",
            "cost_info": {
              "read_cost": "151.96",
              "eval_cost": "37.70",
              "prefix_cost": "189.66",
              "data_read_per_join": "5K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "link_type"
            ]
          }
        },
        {
          "table": {
            "table_name": "cscart_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 18,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "94.25",
              "eval_cost": "1.89",
              "prefix_cost": "321.61",
              "data_read_per_join": "59K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`storefront_id` in (0,1)) and ((`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`usergroup_ids`))) and (`softwarepirmam_hewadelivard_cscart_4`.`cscart_categories`.`status` in ('A','H')))"
          }
        },
        {
          "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",
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 18,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "4.71",
              "eval_cost": "1.89",
              "prefix_cost": "328.21",
              "data_read_per_join": "301"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
1580 404,402,328,166,341M
1629 380,250M 0
1630 380,250M 0
1666 250,380M 0
1667 380,250M 0
1671 250,399,329,166,523M 0
1843 371,250,394M 0
1845 371,250,394M 0
2087 371,250,393M 0
2089 371,250,397M 0
2090 371,250,398M 0
2091 371,250,398M 0
2092 371,398,250M 0
2176 386,350,308,250,166,382M 0
2179 250,166,386,350,308,382M 0
2183 386,350,308,250,166,382M 0
2237 401,166,250,351,429M 0
2238 401,166,429M
2239 401,166,429M
2276 250,336,441M 0
2277 341,328,402,250,166,404M 0
2278 250,336,441M 0
2400 308,350,386,250,166,382M 0
3321 371,250,393M 0
3324 371,250,395M 0
3327 371,250,394M 0
3332 371,250,393M 0
3338 568,546,521,402,328,250,166,406,543,545,343M 0
3491 250,371,393M 0
3494 250,371,393M 0
3495 250,371,393M 0
3498 458,250,488M 0
3506 166,174,453,372,380,250,487,486M 0
3801 166,250,328,565,402,564M 0
3930 341,328,402,250,166,404M 0
3932 250,166,401,351,446M 0
4191 386,308,250,350,166,382M 0
4233 386,308,250,350,166,382M 0
4239 386,308,250,350,166,382M 0
4475 250,399,329,166,400M 0
4651 250,371,393,395M 0
5017 561,555,557,552,553,372,250,563M 0
5024 563,555,557,552,553,372,250,561M 0
5182 563,557,555,250,372,553,552,561M 0
5190 166,250,402,328,565,564M 0
5205 555,250,372,553,552,557,563,561M 0
5211 328,402,359,407,412,166,250,360M 0
5251 328,402,405,342,410,166,250,362M 0
5253 402,328,405,410,342,166,250,362M 0
5262 372,557,555,553,552,250,563,561M 0
5264 250,372,553,552,563,557,555,561M 0
5266 250,372,563,557,555,553,552,561M 0
5267 372,250,563,557,555,553,552,561M 0
5268 250,372,563,557,555,553,552,561M 0
5269 250,372,563,557,555,553,552,561M 0
5273 372,250,563,557,555,553,552,561M 0
5274 250,372,563,557,555,553,552,561M 0
5275 250,372,563,557,555,553,552,561M 0
5279 250,372,563,557,555,553,552,561M 0
5280 250,372,563,557,555,553,552,561M 0
5282 250,372,563,557,555,553,552,561M 0
5283 250,372,563,557,555,553,552,561M 0
5286 372,250,553,552,563,557,555,561M 0
5291 250,372,563,557,555,553,552,561M 0
5387 554,553,250,552,372,556M 0
5565 554,553,250,552,372,556M 0
5738 410,405,402,250,342,328,166,362M 0
5740 410,405,402,250,342,328,166,362M 0
5751 410,405,342,402,250,328,166,362M 0
5813 405,402,250,342,328,166,410,362M 0
5814 410,405,402,250,342,328,166,362M 0
5825 410,405,402,250,342,328,166,362M 0
5831 410,405,342,250,166,362M 0
5838 410,405,402,250,342,328,166,362M 0
5839 410,405,402,250,342,328,166,362M 0
5843 412,407,402,250,359,328,166,360M 0
5924 565,402,250,328,166,564M 0
5927 308,250,350,423,166,387,383M 0
5969 561,555,557,552,553,372,250,563M 0
8813 546,568,343M