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'
  ) 
WHERE 
  dp.status = 'A' 
  and p.product_id in (
    291, 292, 293, 294, 295, 296, 297, 298, 
    300, 302, 303, 304, 305, 306, 307, 308, 
    309, 310, 311, 312, 313, 314, 315, 316, 
    317, 318, 319, 320, 321, 330, 331, 332, 
    333, 334, 335, 338, 339, 340, 341, 342, 
    344, 345, 346, 347, 348, 349, 350, 351, 
    352, 353, 354, 355, 356, 357, 358, 359, 
    360, 361, 362, 363, 364, 365, 366, 367, 
    368, 369, 370, 371
  ) 
GROUP BY 
  p.product_id

Query time 0.00047

JSON explain

{
  "query_block": {
    "select_id": 1,
    "filesort": {
      "sort_key": "p.product_id",
      "temporary_table": {
        "nested_loop": [
          {
            "table": {
              "table_name": "dp",
              "access_type": "ALL",
              "possible_keys": ["thread_id", "thread_id_2"],
              "rows": 6,
              "filtered": 100,
              "attached_condition": "dp.`status` = 'A'"
            }
          },
          {
            "table": {
              "table_name": "cscart_discussion",
              "access_type": "eq_ref",
              "possible_keys": ["PRIMARY", "object_id"],
              "key": "PRIMARY",
              "key_length": "3",
              "used_key_parts": ["thread_id"],
              "ref": ["demov2026.dp.thread_id"],
              "rows": 1,
              "filtered": 100,
              "attached_condition": "cscart_discussion.object_type = 'P'"
            }
          },
          {
            "table": {
              "table_name": "p",
              "access_type": "eq_ref",
              "possible_keys": ["PRIMARY"],
              "key": "PRIMARY",
              "key_length": "3",
              "used_key_parts": ["product_id"],
              "ref": ["demov2026.cscart_discussion.object_id"],
              "rows": 1,
              "filtered": 100,
              "attached_condition": "p.product_id in (291,292,293,294,295,296,297,298,300,302,303,304,305,306,307,308,309,310,311,312,313,314,315,316,317,318,319,320,321,330,331,332,333,334,335,338,339,340,341,342,344,345,346,347,348,349,350,351,352,353,354,355,356,357,358,359,360,361,362,363,364,365,366,367,368,369,370,371)",
              "using_index": true
            }
          }
        ]
      }
    }
  }
}