SELECT 
  ushop_products_categories.product_id, 
  GROUP_CONCAT(
    IF(
      ushop_products_categories.link_type = "M", 
      CONCAT(
        ushop_products_categories.category_id, 
        "M"
      ), 
      ushop_products_categories.category_id
    )
  ) AS category_ids, 
  product_position_source.position AS position 
FROM 
  ushop_products_categories 
  INNER JOIN ushop_categories ON ushop_categories.category_id = ushop_products_categories.category_id 
  AND ushop_categories.storefront_id IN (0, 1) 
  AND (
    ushop_categories.usergroup_ids = '' 
    OR FIND_IN_SET(
      0, ushop_categories.usergroup_ids
    ) 
    OR FIND_IN_SET(
      1, ushop_categories.usergroup_ids
    )
  ) 
  AND ushop_categories.status IN ('A', 'H') 
  LEFT JOIN ushop_products_categories AS product_position_source ON ushop_products_categories.product_id = product_position_source.product_id 
  AND product_position_source.category_id = 318 
WHERE 
  ushop_products_categories.product_id IN (
    345, 346, 337, 321, 347, 323, 317, 326, 
    314, 327, 313, 324, 332, 316, 341, 333, 
    335, 339, 334, 336, 340, 343, 338, 342, 
    348, 344, 349
  ) 
GROUP BY 
  ushop_products_categories.product_id

Query time 0.00180

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "37.81"
    },
    "grouping_operation": {
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "ushop_products_categories",
            "access_type": "range",
            "possible_keys": [
              "PRIMARY",
              "pt"
            ],
            "key": "pt",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "rows_examined_per_scan": 27,
            "rows_produced_per_join": 27,
            "filtered": "100.00",
            "index_condition": "(`marketplace`.`ushop_products_categories`.`product_id` in (345,346,337,321,347,323,317,326,314,327,313,324,332,316,341,333,335,339,334,336,340,343,338,342,348,344,349))",
            "cost_info": {
              "read_cost": "16.21",
              "eval_cost": "2.70",
              "prefix_cost": "18.91",
              "data_read_per_join": "432"
            },
            "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",
              "marketplace.ushop_products_categories.product_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 27,
            "filtered": "100.00",
            "cost_info": {
              "read_cost": "6.75",
              "eval_cost": "2.70",
              "prefix_cost": "28.36",
              "data_read_per_join": "432"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        },
        {
          "table": {
            "table_name": "ushop_categories",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "c_status",
              "p_category_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "category_id"
            ],
            "key_length": "3",
            "ref": [
              "marketplace.ushop_products_categories.category_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 1,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "6.75",
              "eval_cost": "0.14",
              "prefix_cost": "37.81",
              "data_read_per_join": "4K"
            },
            "used_columns": [
              "category_id",
              "storefront_id",
              "usergroup_ids",
              "status"
            ],
            "attached_condition": "((`marketplace`.`ushop_categories`.`storefront_id` in (0,1)) and ((`marketplace`.`ushop_categories`.`usergroup_ids` = '') or (0 <> find_in_set(0,`marketplace`.`ushop_categories`.`usergroup_ids`)) or (0 <> find_in_set(1,`marketplace`.`ushop_categories`.`usergroup_ids`))) and (`marketplace`.`ushop_categories`.`status` in ('A','H')))"
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
313 354M
314 354M
316 354M
317 354M
321 355M
323 355M
324 355M
326 355M
327 355M
332 355M
333 355M
334 355M
335 355M
336 355M
337 355M
338 355M
339 355M
340 355M
341 355M
342 355M
343 355M
344 354M
345 357M
346 357M
347 357M
348 357M
349 357M