SELECT 
  p.product_id, 
  ifnull(
    count(dp.post_id), 
    0
  ) as discussion_amount_posts 
FROM 
  cscart_discussion 
  INNER JOIN cscart_products as p ON (
    cscart_discussion.object_id = p.product_id
  ) 
  INNER JOIN cscart_discussion_posts as dp ON (
    cscart_discussion.thread_id = dp.thread_id 
    AND cscart_discussion.object_type = 'P' 
    AND cscart_discussion.company_id = 1
  ) 
WHERE 
  dp.status = 'A' 
  and p.product_id in (
    21351, 21291, 22158, 21296, 21307, 21352, 
    21287, 22159, 21297, 21342, 21353, 
    21288, 22175, 21298, 21343, 21354, 
    21289, 22177, 21299, 22152, 21344, 
    21355, 22151, 22160, 21300, 21345, 
    20221, 21356, 21488, 22161, 21301, 
    21346, 20222, 21357, 22153, 21552, 
    21302, 21347, 20223, 22154, 21292, 
    21553, 21303, 21348, 21514, 22155, 
    21293, 21304, 21349, 21286, 22156, 
    21294, 21305, 21350, 21290, 22157, 
    21295, 21306
  ) 
GROUP BY 
  p.product_id

Query time 0.00089

JSON explain

{
  "query_block": {
    "select_id": 1,
    "nested_loop": [
      {
        "table": {
          "table_name": "p",
          "access_type": "range",
          "possible_keys": ["PRIMARY"],
          "key": "PRIMARY",
          "key_length": "3",
          "used_key_parts": ["product_id"],
          "rows": 58,
          "filtered": 100,
          "attached_condition": "p.product_id in (21351,21291,22158,21296,21307,21352,21287,22159,21297,21342,21353,21288,22175,21298,21343,21354,21289,22177,21299,22152,21344,21355,22151,22160,21300,21345,20221,21356,21488,22161,21301,21346,20222,21357,22153,21552,21302,21347,20223,22154,21292,21553,21303,21348,21514,22155,21293,21304,21349,21286,22156,21294,21305,21350,21290,22157,21295,21306)",
          "using_index": true
        }
      },
      {
        "table": {
          "table_name": "cscart_discussion",
          "access_type": "eq_ref",
          "possible_keys": ["PRIMARY", "object_id", "idx_company_id"],
          "key": "object_id",
          "key_length": "10",
          "used_key_parts": ["object_id", "object_type", "company_id"],
          "ref": ["lillyshop_lillyshop.p.product_id", "const", "const"],
          "rows": 1,
          "filtered": 100,
          "index_condition": "cscart_discussion.object_type = 'P'"
        }
      },
      {
        "table": {
          "table_name": "dp",
          "access_type": "ref",
          "possible_keys": ["thread_id", "thread_id_2"],
          "key": "thread_id_2",
          "key_length": "6",
          "used_key_parts": ["thread_id", "status"],
          "ref": ["lillyshop_lillyshop.cscart_discussion.thread_id", "const"],
          "rows": 2,
          "filtered": 100,
          "index_condition": "dp.`status` = 'A'"
        }
      }
    ]
  }
}