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 (
    6151, 
    5696, 
    2698, 
    5721, 
    5621, 
    5724, 
    3605, 
    5944, 
    4951, 
    5830, 
    2340, 
    5887, 
    3354, 
    3155, 
    3834, 
    2737, 
    3308, 
    5892, 
    3306, 
    5848, 
    3397, 
    2352, 
    2431, 
    5934, 
    3841, 
    5114, 
    2339, 
    3212, 
    3389, 
    2924, 
    1626, 
    3350, 
    4163, 
    3392, 
    6098, 
    5811, 
    3390, 
    4934, 
    2862, 
    5719, 
    4960, 
    5706, 
    5720, 
    4933, 
    5850, 
    5821, 
    2922, 
    5849, 
    5828, 
    5703, 
    5832, 
    5824, 
    5798, 
    3603, 
    2693, 
    3928, 
    2338, 
    5826, 
    5801, 
    5864, 
    5829, 
    3301, 
    5852, 
    4894, 
    3660, 
    5928, 
    5822, 
    5847, 
    5854, 
    5896, 
    2341, 
    5794, 
    2702, 
    3147, 
    6099, 
    3828, 
    5898, 
    5788, 
    5932, 
    3649, 
    3520, 
    3529, 
    4962, 
    1668, 
    3146, 
    4958, 
    4942, 
    3809, 
    8586, 
    3518, 
    3148, 
    3918, 
    8372, 
    3215, 
    3213, 
    2222, 
    3400, 
    5691, 
    5687, 
    3733, 
    3552, 
    2805, 
    3232, 
    4915, 
    6025, 
    3149, 
    3416, 
    3157, 
    3589, 
    5791, 
    3845, 
    3150, 
    2481, 
    3822, 
    4976, 
    3115, 
    3740, 
    3123, 
    2228, 
    3743, 
    3112, 
    3944, 
    3664, 
    3126, 
    2230, 
    2655, 
    3741, 
    5683, 
    3440, 
    5890, 
    2226, 
    5859, 
    3843, 
    3840, 
    3130, 
    3811, 
    3441, 
    6054, 
    2221, 
    5891, 
    3153, 
    3924, 
    3377, 
    2522, 
    2719, 
    6041, 
    5111, 
    3385, 
    5948, 
    8240, 
    3551, 
    3831, 
    5927, 
    3289, 
    10078, 
    3382, 
    3519, 
    3356, 
    6093, 
    6194
  ) 
GROUP BY 
  p.product_id

Query time 0.00130

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 (6151,5696,2698,5721,5621,5724,3605,5944,4951,5830,2340,5887,3354,3155,3834,2737,3308,5892,3306,5848,3397,2352,2431,5934,3841,5114,2339,3212,3389,2924,1626,3350,4163,3392,6098,5811,3390,4934,2862,5719,4960,5706,5720,4933,5850,5821,2922,5849,5828,5703,5832,5824,5798,3603,2693,3928,2338,5826,5801,5864,5829,3301,5852,4894,3660,5928,5822,5847,5854,5896,2341,5794,2702,3147,6099,3828,5898,5788,5932,3649,3520,3529,4962,1668,3146,4958,4942,3809,8586,3518,3148,3918,8372,3215,3213,2222,3400,5691,5687,3733,3552,2805,3232,4915,6025,3149,3416,3157,3589,5791,3845,3150,2481,3822,4976,3115,3740,3123,2228,3743,3112,3944,3664,3126,2230,2655,3741,5683,3440,5890,2226,5859,3843,3840,3130,3811,3441,6054,2221,5891,3153,3924,3377,2522,2719,6041,5111,3385,5948,8240,3551,3831,5927,3289,10078,3382,3519,3356,6093,6194)) 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"
            ]
          }
        }
      ]
    }
  }
}