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 = 630 
WHERE 
  cscart_products_categories.product_id IN (
    6903, 7817, 7805, 7819, 7803, 7824, 7905, 
    8336, 7815, 6941, 7121, 7086, 7714, 
    7176, 6938, 6911, 6994, 7084, 6993, 
    6991, 7027, 6939, 7054, 6940, 7169, 
    7120, 7712, 7138, 7095, 7167, 7141, 
    7695, 7031, 7089, 6992, 6892, 7125, 
    6880, 6996, 7173, 7210, 7711, 7715, 
    7792, 7170, 7174, 7087, 7177, 6989, 
    6995, 6997, 7142, 7171, 7172, 7132, 
    7795, 7709, 7806, 7918, 7119, 7696, 
    7793, 7903, 7929, 7931, 7791, 7814, 
    7818, 7822, 7902, 7925, 7928, 7672, 
    7697, 7713, 7790, 7808, 7820, 7821, 
    7831
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00256

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "113.16"
    },
    "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": 81,
            "rows_produced_per_join": 81,
            "filtered": "100.00",
            "index_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`cscart_products_categories`.`product_id` in (6903,7817,7805,7819,7803,7824,7905,8336,7815,6941,7121,7086,7714,7176,6938,6911,6994,7084,6993,6991,7027,6939,7054,6940,7169,7120,7712,7138,7095,7167,7141,7695,7031,7089,6992,6892,7125,6880,6996,7173,7210,7711,7715,7792,7170,7174,7087,7177,6989,6995,6997,7142,7171,7172,7132,7795,7709,7806,7918,7119,7696,7793,7903,7929,7931,7791,7814,7818,7822,7902,7925,7928,7672,7697,7713,7790,7808,7820,7821,7831))",
            "cost_info": {
              "read_cost": "48.36",
              "eval_cost": "8.10",
              "prefix_cost": "56.46",
              "data_read_per_join": "1K"
            },
            "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",
              "softwarepirmam_hewadelivard_cscart_4.cscart_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 81,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "20.25",
              "eval_cost": "8.10",
              "prefix_cost": "84.81",
              "data_read_per_join": "1K"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        },
        {
          "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": 4,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "20.25",
              "eval_cost": "0.41",
              "prefix_cost": "113.16",
              "data_read_per_join": "12K"
            },
            "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')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
6880 630M 0
6892 630M 0
6903 630M 0
6911 630M 0
6938 630M 0
6939 630M 0
6940 630M 0
6941 630M 0
6989 630M 0
6991 641,630M 0
6992 641,630M 0
6993 630M 0
6994 630M 0
6995 630M 0
6996 630M 0
6997 630M 0
7027 630M 0
7031 630M 0
7054 630M 0
7084 630M 0
7086 630M 0
7087 630M 0
7089 630M 0
7095 630M 0
7119 630M 0
7120 630M 0
7121 630M 0
7125 630M 0
7132 630M 0
7138 630M 0
7141 630M 0
7142 630M 0
7167 630M 0
7169 630M 0
7170 630M 0
7171 630M 0
7172 630M 0
7173 630M 0
7174 630M 0
7176 630M 0
7177 630M 0
7210 630M 0
7672 630M 0
7695 630M 0
7696 630M 0
7697 630M 0
7709 630M 0
7711 630M 0
7712 630M 0
7713 630M 0
7714 630M 0
7715 630M 0
7790 630M 0
7791 630M 0
7792 630M 0
7793 630M 0
7795 630M 0
7803 630M 0
7805 630M 0
7806 630M 0
7808 630M 0
7814 630M 0
7815 630M 0
7817 630M 0
7818 630M 0
7819 630M 0
7820 630M 0
7821 630M 0
7822 630M 0
7824 630M 0
7831 630M 0
7902 630M 0
7903 630M 0
7905 630M 0
7918 630M 0
7925 630M 0
7928 630M 0
7929 630M 0
7931 630M 0
8336 630M 0