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 = 372 
WHERE 
  cscart_products_categories.product_id IN (
    6778, 6793, 7698, 8960, 9014, 10148, 
    10325, 10420, 10128, 6494, 6575, 6579, 
    6674, 6718, 6816, 7540, 7543, 10122, 
    10217, 6496, 6548, 6775, 6809, 10387, 
    6715, 6758, 6766, 6768, 6717, 6771, 
    6813, 6716, 6772, 6669, 6671, 6812, 
    7522, 6761, 6672, 7516, 11046, 11255, 
    11277, 10428, 6760, 7699, 10956, 11067, 
    10312, 10453, 6767, 6815, 7704, 7729, 
    10226, 10471, 10196, 7751, 10219, 10365, 
    10398, 10463, 11280, 6759, 10315, 7753, 
    6668, 6762, 6765, 6810, 7750, 10406, 
    10436, 10480, 10486, 10545, 11155, 
    11456, 6404, 6757
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00350

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "137.73"
    },
    "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": 144,
            "rows_produced_per_join": 144,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (6778,6793,7698,8960,9014,10148,10325,10420,10128,6494,6575,6579,6674,6718,6816,7540,7543,10122,10217,6496,6548,6775,6809,10387,6715,6758,6766,6768,6717,6771,6813,6716,6772,6669,6671,6812,7522,6761,6672,7516,11046,11255,11277,10428,6760,7699,10956,11067,10312,10453,6767,6815,7704,7729,10226,10471,10196,7751,10219,10365,10398,10463,11280,6759,10315,7753,6668,6762,6765,6810,7750,10406,10436,10480,10486,10545,11155,11456,6404,6757))",
            "cost_info": {
              "read_cost": "70.41",
              "eval_cost": "14.40",
              "prefix_cost": "84.81",
              "data_read_per_join": "2K"
            },
            "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": 7,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "36.00",
              "eval_cost": "0.72",
              "prefix_cost": "135.21",
              "data_read_per_join": "22K"
            },
            "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": 7,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "1.80",
              "eval_cost": "0.72",
              "prefix_cost": "137.73",
              "data_read_per_join": "115"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
6404 572,372,582M 0
6494 372,583M 0
6496 572,372,582M 0
6548 466,574M
6575 466,574M
6579 572,372,582M 0
6668 466,574M
6669 466,574M
6671 466,574M
6672 466,575M
6674 466,575M
6715 466,574M
6716 466,574M
6717 466,574M
6718 466,574M
6757 466,573M
6758 466,579M
6759 466M
6760 466M
6761 466M
6762 466M
6765 466,573M
6766 372,384M 0
6767 372,384M 0
6768 372,384M 0
6771 372,384M 0
6772 372,384M 0
6775 372,573M 0
6778 372,574M 0
6793 466,574M
6809 466,574M
6810 466,574M
6812 466,574M
6813 466,574M
6815 466,574M
6816 466,574M
7516 556,554M
7522 460M
7540 465M
7543 465M
7698 655M
7699 575M
7704 467M
7729 574M
7750 574M
7751 574M
7753 573M
8960 583M
9014 584M
10122 372,454,453,190,174,166M 0
10128 372,454,453,190,174,166M 0
10148 372M 0
10196 372,454,453,190,174,166M 0
10217 174,453,454,372,190,166M 0
10219 459M
10226 459M
10312 372,454,453,190,174,166M 0
10315 372,454,453,190,174,166M 0
10325 372,166M 0
10365 372M 0
10387 372,587M 0
10398 598M
10406 574M
10420 574M
10428 466,467M
10436 587M
10453 597M
10463 566,597M
10471 384M
10480 573M
10486 574M
10545 579M
10956 667,666M
11046 587M
11067 587M
11155 581M
11255 556,554M
11277 556,554M
11280 556,554M
11456 599M