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 (
    20221, 20222, 20223, 21286, 21287, 21288, 
    21289, 21290, 21291, 22177, 21514, 
    22151, 21292, 21293, 21342, 21294, 
    21295, 21343, 21296, 21297, 21344, 
    22152, 22153, 21345, 21346, 21347, 
    21348, 22154, 22155, 22156, 22159, 
    21349, 21350, 22157, 22158, 21552, 
    21553, 21351, 21488, 21352, 21353, 
    21354, 21298, 21355, 21299, 21300, 
    21301, 21302, 22160, 21303, 22175, 
    21356, 21357, 22161, 21304, 21305, 
    21306, 21307
  ) 
GROUP BY 
  p.product_id

Query time 0.00077

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 (20221,20222,20223,21286,21287,21288,21289,21290,21291,22177,21514,22151,21292,21293,21342,21294,21295,21343,21296,21297,21344,22152,22153,21345,21346,21347,21348,22154,22155,22156,22159,21349,21350,22157,22158,21552,21553,21351,21488,21352,21353,21354,21298,21355,21299,21300,21301,21302,22160,21303,22175,21356,21357,22161,21304,21305,21306,21307)",
          "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'"
        }
      }
    ]
  }
}