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 (
    2587, 2588, 2589, 2590, 2593, 2594, 2595, 
    2603, 2609, 2610, 2611, 2613, 2614, 
    2617, 2618, 2619, 2622, 2696, 2697, 
    2695, 2694, 2704, 2705, 2706, 2723, 
    2724, 2725, 2726, 2739, 2740, 2741, 
    2742, 2743, 2744, 2745, 2761, 2762, 
    2763, 2764, 2828, 2830, 2841, 2865, 
    2872, 2873, 2874, 2875, 3096, 3097, 
    3098, 3104, 3105, 3106, 3136, 3137, 
    3138, 3423, 3422, 3610, 3556, 3557, 
    3593, 3594, 3812, 3813, 3876, 3877, 
    4888, 4891, 4892, 5122, 5121, 5124, 
    5125, 5155, 5156, 5157, 5158, 5979, 
    5980, 5981, 5982, 5984, 6221, 5999, 
    5997, 5998, 6000, 6001, 6002, 6003, 
    6004, 6005, 6007, 6008, 6009, 6010, 
    6011, 6012, 6013, 6014, 6015, 6019, 
    6020, 6021, 6022, 6023, 6271, 6272, 
    10022, 10028
  ) 
GROUP BY 
  p.product_id

Query time 0.00105

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "2.31"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": false,
      "nested_loop": [
        {
          "table": {
            "table_name": "dp",
            "access_type": "ALL",
            "possible_keys": [
              "thread_id",
              "thread_id_2"
            ],
            "rows_examined_per_scan": 13,
            "rows_produced_per_join": 1,
            "filtered": "10.00",
            "cost_info": {
              "read_cost": "1.70",
              "eval_cost": "0.13",
              "prefix_cost": "1.83",
              "data_read_per_join": "582"
            },
            "used_columns": [
              "post_id",
              "thread_id",
              "status"
            ],
            "attached_condition": "(`softwarepirmam_hewadelivard_cscart_4`.`dp`.`status` = 'A')"
          }
        },
        {
          "table": {
            "table_name": "cscart_discussion",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "object_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "thread_id"
            ],
            "key_length": "3",
            "ref": [
              "softwarepirmam_hewadelivard_cscart_4.dp.thread_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 0,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "0.33",
              "eval_cost": "0.01",
              "prefix_cost": "2.28",
              "data_read_per_join": "1"
            },
            "used_columns": [
              "thread_id",
              "object_id",
              "object_type"
            ],
            "attached_condition": "((`softwarepirmam_hewadelivard_cscart_4`.`cscart_discussion`.`object_id` in (2587,2588,2589,2590,2593,2594,2595,2603,2609,2610,2611,2613,2614,2617,2618,2619,2622,2696,2697,2695,2694,2704,2705,2706,2723,2724,2725,2726,2739,2740,2741,2742,2743,2744,2745,2761,2762,2763,2764,2828,2830,2841,2865,2872,2873,2874,2875,3096,3097,3098,3104,3105,3106,3136,3137,3138,3423,3422,3610,3556,3557,3593,3594,3812,3813,3876,3877,4888,4891,4892,5122,5121,5124,5125,5155,5156,5157,5158,5979,5980,5981,5982,5984,6221,5999,5997,5998,6000,6001,6002,6003,6004,6005,6007,6008,6009,6010,6011,6012,6013,6014,6015,6019,6020,6021,6022,6023,6271,6272,10022,10028)) and (`softwarepirmam_hewadelivard_cscart_4`.`cscart_discussion`.`object_type` = 'P'))"
          }
        },
        {
          "table": {
            "table_name": "p",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "ref": [
              "softwarepirmam_hewadelivard_cscart_4.cscart_discussion.object_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 0,
            "filtered": "100.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "0.02",
              "eval_cost": "0.01",
              "prefix_cost": "2.31",
              "data_read_per_join": "294"
            },
            "used_columns": [
              "product_id"
            ]
          }
        }
      ]
    }
  }
}