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 (
    1462, 1463, 1464, 1465, 5170, 5171, 5172, 
    5173, 5174, 5175, 1878, 1879, 1880, 
    1881, 1882, 1883, 1884, 1885, 1886, 
    1887, 1888, 1889, 1890, 1891, 1892, 
    1893, 1894, 1895, 1896, 1897, 1898, 
    1899, 1900, 1901, 1902, 1903, 1904, 
    1905, 1906, 1907, 1908, 1909, 1910, 
    1911, 1912, 1913, 1914, 1915, 1916, 
    1917, 1918, 1919, 1920, 1921, 1922, 
    1923, 1924, 1925, 1926, 1927, 1928, 
    1929, 1930, 1931, 5560, 5561, 5562, 
    5563, 5564, 5565, 5566, 5567, 5568, 
    5569, 5570, 5571, 5572, 5573, 5574, 
    5575, 5576, 5577, 5578, 5579, 5580, 
    5581, 5582, 5583, 5584, 5585, 5586, 
    5587, 5588, 5589, 5590, 5591
  ) 
GROUP BY 
  cscart_products_categories.product_id

Query time 0.00273

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "68.44"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "1.58"
      },
      "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.90",
            "index_condition": "(`gaseus`.`cscart_products_categories`.`product_id` in (1462,1463,1464,1465,5170,5171,5172,5173,5174,5175,1878,1879,1880,1881,1882,1883,1884,1885,1886,1887,1888,1889,1890,1891,1892,1893,1894,1895,1896,1897,1898,1899,1900,1901,1902,1903,1904,1905,1906,1907,1908,1909,1910,1911,1912,1913,1914,1915,1916,1917,1918,1919,1920,1921,1922,1923,1924,1925,1926,1927,1928,1929,1930,1931,5560,5561,5562,5563,5564,5565,5566,5567,5568,5569,5570,5571,5572,5573,5574,5575,5576,5577,5578,5579,5580,5581,5582,5583,5584,5585,5586,5587,5588,5589,5590,5591))",
            "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.86",
              "data_read_per_join": "25"
            },
            "used_columns": [
              "product_id",
              "category_id",
              "position"
            ]
          }
        }
      ]
    }
  }
}

Result

product_id category_ids position
1462 308M 0
1463 308M 0
1464 308M 0
1465 308M 0
1878 308M 0
1879 308M 0
1880 308M 0
1881 308M 0
1882 308M 0
1883 308M 0
1884 308M 0
1885 308M 0
1886 308M 0
1887 308M 0
1888 308M 0
1889 308M 0
1890 308M 0
1891 308M 0
1892 308M 0
1893 308M 0
1894 308M 0
1895 308M 0
1896 308M 0
1897 308M 0
1898 308M 0
1899 308M 0
1900 308M 0
1901 308M 0
1902 308M 0
1903 308M 0
1904 308M 0
1905 308M 0
1906 308M 0
1907 308M 0
1908 308M 0
1909 308M 0
1910 308M 0
1911 308M 0
1912 308M 0
1913 308M 0
1914 308M 0
1915 308M 0
1916 308M 0
1917 308M 0
1918 308M 0
1919 308M 0
1920 308M 0
1921 308M 0
1922 308M 0
1923 308M 0
1924 308M 0
1925 308M 0
1926 308M 0
1927 308M 0
1928 308M 0
1929 308M 0
1930 308M 0
1931 308M 0
5170 308M 0
5171 308M 0
5172 308M 0
5173 308M 0
5174 308M 0
5175 308M 0
5560 308M 0
5561 308M 0
5562 308M 0
5563 308M 0
5564 308M 0
5565 308M 0
5566 308M 0
5567 308M 0
5568 308M 0
5569 308M 0
5570 308M 0
5571 308M 0
5572 308M 0
5573 308M 0
5574 308M 0
5575 308M 0
5576 308M 0
5577 308M 0
5578 308M 0
5579 308M 0
5580 308M 0
5581 308M 0
5582 308M 0
5583 308M 0
5584 308M 0
5585 308M 0
5586 308M 0
5587 308M 0
5588 308M 0
5589 308M 0
5590 308M 0
5591 308M 0