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 (
    13951, 13952, 13953, 13954, 13955, 13956, 
    13957, 13958, 13959, 13960, 13961, 
    13962, 13963, 13964, 13965, 13966, 
    13967, 13968, 13969, 13970, 13971, 
    13972, 13973, 13974, 13975, 13976, 
    13977, 13978, 13979, 13980, 13981, 
    13982, 13983, 13984, 13985, 13986, 
    13987, 13988, 13989, 13990, 13991, 
    13992, 13993, 13994, 13995, 13996, 
    13997, 13998, 13999, 14000, 14001, 
    14002, 14003, 14004, 14005, 14006, 
    14007, 14008, 14009, 14010, 14011, 
    14012, 14013, 14014, 14015, 14016, 
    14017, 14018
  ) 
GROUP BY 
  p.product_id

Query time 0.00078

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost": 0.015057387,
    "filesort": {
      "sort_key": "p.product_id",
      "temporary_table": {
        "nested_loop": [
          {
            "table": {
              "table_name": "dp",
              "access_type": "index",
              "possible_keys": ["thread_id", "thread_id_2"],
              "key": "thread_id_2",
              "key_length": "6",
              "used_key_parts": ["thread_id", "status"],
              "loops": 1,
              "rows": 2,
              "cost": 0.00693929,
              "filtered": 100,
              "attached_condition": "dp.`status` = 'A'",
              "using_index": true
            }
          },
          {
            "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": ["u508912950_dev_2025.dp.thread_id"],
              "loops": 2,
              "rows": 1,
              "cost": 0.00342728,
              "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": ["u508912950_dev_2025.cscart_discussion.object_id"],
              "loops": 2,
              "rows": 1,
              "cost": 0.00342728,
              "filtered": 100,
              "attached_condition": "p.product_id in (13951,13952,13953,13954,13955,13956,13957,13958,13959,13960,13961,13962,13963,13964,13965,13966,13967,13968,13969,13970,13971,13972,13973,13974,13975,13976,13977,13978,13979,13980,13981,13982,13983,13984,13985,13986,13987,13988,13989,13990,13991,13992,13993,13994,13995,13996,13997,13998,13999,14000,14001,14002,14003,14004,14005,14006,14007,14008,14009,14010,14011,14012,14013,14014,14015,14016,14017,14018)"
            }
          }
        ]
      }
    }
  }
}