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 (
    339432, 
    339433, 
    339438, 
    339434, 
    339439, 
    339445, 
    339440, 
    339511, 
    339515, 
    339441, 
    339527, 
    339513, 
    339519, 
    339510, 
    339518, 
    339508, 
    339713, 
    339525, 
    339505, 
    339530, 
    339446, 
    339514, 
    339521, 
    339551, 
    339501, 
    339499, 
    339721, 
    339495, 
    339494, 
    339503, 
    339531, 
    339516, 
    339447, 
    339637, 
    339539, 
    339509, 
    339636, 
    339538, 
    339492, 
    339506, 
    339724, 
    339635, 
    339502, 
    339537, 
    339491, 
    339540, 
    339524, 
    339493, 
    339536, 
    339520, 
    339517, 
    339522, 
    339526, 
    339741, 
    339490, 
    339498, 
    339449, 
    339689, 
    339528, 
    339497, 
    339448, 
    339622, 
    339450, 
    339435, 
    339616, 
    339442, 
    339507, 
    339574, 
    339443, 
    339436, 
    339512, 
    339523, 
    339504, 
    339451, 
    339437, 
    339740, 
    339692, 
    339609, 
    339737, 
    339500, 
    339532, 
    339573, 
    339535, 
    339621, 
    339534, 
    339620, 
    339496, 
    339617, 
    339587, 
    339611, 
    339742, 
    339444, 
    339533, 
    339710, 
    339683, 
    339722, 
    339610, 
    339584, 
    339706, 
    339570, 
    339625, 
    339638, 
    339771, 
    339751, 
    339529, 
    339736, 
    339770, 
    339615, 
    339618, 
    339569, 
    339581, 
    339705, 
    339619, 
    339608, 
    339693, 
    339779, 
    339607, 
    339759, 
    339783, 
    339732, 
    339572, 
    339775, 
    339476, 
    339571, 
    339589, 
    339652, 
    339456, 
    339778, 
    339738, 
    339550, 
    339686, 
    339461, 
    339586, 
    339739, 
    339667, 
    339630, 
    339644, 
    339780, 
    339747, 
    339645, 
    339744, 
    339684, 
    339676, 
    339748, 
    339580, 
    339576, 
    339556, 
    339777, 
    339633, 
    339591, 
    339588, 
    339583, 
    339553, 
    339454, 
    339547, 
    339471, 
    339711, 
    339614, 
    339708, 
    339657, 
    339719, 
    339545, 
    339632, 
    339716, 
    339745, 
    339548, 
    339776, 
    339552, 
    339474, 
    339649, 
    339826, 
    339743, 
    339665, 
    339756, 
    339647, 
    339470, 
    339773, 
    339703, 
    339577, 
    339848, 
    339789, 
    339749, 
    339544, 
    339651, 
    339669, 
    339455, 
    339666, 
    339565, 
    339784, 
    339626, 
    339670, 
    339824, 
    339646, 
    339543, 
    339575, 
    339662, 
    339834, 
    339833, 
    339567, 
    339549, 
    339698, 
    339631, 
    339830, 
    339628, 
    339595, 
    339557, 
    339767, 
    339673, 
    339823, 
    339717, 
    339658, 
    339653, 
    339542, 
    339853, 
    339852, 
    339472, 
    339763, 
    339822, 
    339682, 
    339818, 
    339487, 
    339555, 
    339613, 
    339639, 
    339480, 
    339560, 
    339854, 
    339579, 
    339788, 
    339680, 
    339559, 
    339475, 
    339772, 
    339850, 
    339785, 
    339815, 
    339568, 
    339558, 
    339561, 
    339566, 
    339766, 
    339688, 
    339563, 
    339819, 
    339661, 
    339837, 
    339640, 
    339790, 
    339585, 
    339598, 
    339634, 
    339578, 
    339546, 
    339629, 
    339672, 
    339844, 
    339641, 
    339840, 
    339624, 
    339627, 
    339832, 
    339687, 
    339842, 
    339800, 
    339612, 
    339642, 
    339827, 
    339764, 
    339605, 
    339564, 
    339690, 
    339462, 
    339793, 
    339562, 
    339663, 
    339554, 
    339700, 
    339792, 
    339811, 
    339801, 
    339459, 
    339592, 
    339679, 
    339590, 
    339473, 
    339799, 
    339791, 
    339795, 
    339660, 
    339803, 
    339623, 
    339813, 
    339659, 
    339678, 
    339465, 
    339457, 
    339786, 
    339477, 
    339541, 
    339796, 
    339643, 
    339489, 
    339699, 
    339797, 
    339469, 
    339798, 
    339458, 
    339606, 
    339482, 
    339685, 
    339468, 
    339453, 
    339730, 
    339731, 
    339478, 
    339794, 
    339463, 
    339709, 
    339467, 
    339753, 
    339460, 
    339808, 
    339696, 
    339757, 
    339787, 
    339464, 
    339805, 
    339806, 
    339810, 
    339704, 
    339701, 
    339707, 
    339677, 
    339769, 
    339814, 
    339758, 
    339750, 
    339714, 
    339829, 
    339695, 
    339735, 
    339807, 
    339479, 
    339752, 
    339746, 
    339654, 
    339452, 
    339755, 
    339847, 
    339656, 
    339712, 
    339715, 
    339851, 
    339729, 
    339760, 
    339648, 
    339668, 
    339681, 
    339664, 
    339485, 
    339671, 
    339809, 
    339694, 
    339655, 
    339828, 
    339812, 
    339761, 
    339817, 
    339720, 
    339697, 
    339650, 
    339835, 
    339702, 
    339593, 
    339849, 
    339484, 
    339820, 
    339483, 
    339734, 
    339596, 
    339725, 
    339466, 
    339774, 
    339728, 
    339674, 
    339754, 
    339836, 
    339821, 
    339843, 
    339802, 
    339723, 
    339599, 
    339816, 
    339845, 
    339582, 
    339486, 
    339839, 
    339594, 
    339727, 
    339765, 
    339762, 
    339691, 
    339804, 
    339600, 
    339733, 
    339781, 
    339831, 
    339488, 
    339726, 
    339855, 
    339825, 
    339718, 
    339675, 
    339597, 
    339782, 
    339481, 
    339838, 
    339846, 
    339841, 
    339604, 
    339768
  ) 
GROUP BY 
  p.product_id

Query time 0.00428

JSON explain

{
  "query_block": {
    "select_id": 1,
    "cost_info": {
      "query_cost": "7.29"
    },
    "grouping_operation": {
      "using_temporary_table": true,
      "using_filesort": true,
      "cost_info": {
        "sort_cost": "0.10"
      },
      "nested_loop": [
        {
          "table": {
            "table_name": "dp",
            "access_type": "index",
            "possible_keys": [
              "thread_id",
              "thread_id_2"
            ],
            "key": "thread_id_2",
            "used_key_parts": [
              "thread_id",
              "status"
            ],
            "key_length": "6",
            "rows_examined_per_scan": 19,
            "rows_produced_per_join": 1,
            "filtered": "10.00",
            "using_index": true,
            "cost_info": {
              "read_cost": "4.42",
              "eval_cost": "0.38",
              "prefix_cost": "4.80",
              "data_read_per_join": "851"
            },
            "used_columns": [
              "post_id",
              "thread_id",
              "status"
            ],
            "attached_condition": "(`webmarco`.`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": [
              "webmarco.dp.thread_id"
            ],
            "rows_examined_per_scan": 1,
            "rows_produced_per_join": 0,
            "filtered": "5.00",
            "cost_info": {
              "read_cost": "1.90",
              "eval_cost": "0.02",
              "prefix_cost": "7.08",
              "data_read_per_join": "2"
            },
            "used_columns": [
              "thread_id",
              "object_id",
              "object_type"
            ],
            "attached_condition": "((`webmarco`.`cscart_discussion`.`object_id` in (339432,339433,339438,339434,339439,339445,339440,339511,339515,339441,339527,339513,339519,339510,339518,339508,339713,339525,339505,339530,339446,339514,339521,339551,339501,339499,339721,339495,339494,339503,339531,339516,339447,339637,339539,339509,339636,339538,339492,339506,339724,339635,339502,339537,339491,339540,339524,339493,339536,339520,339517,339522,339526,339741,339490,339498,339449,339689,339528,339497,339448,339622,339450,339435,339616,339442,339507,339574,339443,339436,339512,339523,339504,339451,339437,339740,339692,339609,339737,339500,339532,339573,339535,339621,339534,339620,339496,339617,339587,339611,339742,339444,339533,339710,339683,339722,339610,339584,339706,339570,339625,339638,339771,339751,339529,339736,339770,339615,339618,339569,339581,339705,339619,339608,339693,339779,339607,339759,339783,339732,339572,339775,339476,339571,339589,339652,339456,339778,339738,339550,339686,339461,339586,339739,339667,339630,339644,339780,339747,339645,339744,339684,339676,339748,339580,339576,339556,339777,339633,339591,339588,339583,339553,339454,339547,339471,339711,339614,339708,339657,339719,339545,339632,339716,339745,339548,339776,339552,339474,339649,339826,339743,339665,339756,339647,339470,339773,339703,339577,339848,339789,339749,339544,339651,339669,339455,339666,339565,339784,339626,339670,339824,339646,339543,339575,339662,339834,339833,339567,339549,339698,339631,339830,339628,339595,339557,339767,339673,339823,339717,339658,339653,339542,339853,339852,339472,339763,339822,339682,339818,339487,339555,339613,339639,339480,339560,339854,339579,339788,339680,339559,339475,339772,339850,339785,339815,339568,339558,339561,339566,339766,339688,339563,339819,339661,339837,339640,339790,339585,339598,339634,339578,339546,339629,339672,339844,339641,339840,339624,339627,339832,339687,339842,339800,339612,339642,339827,339764,339605,339564,339690,339462,339793,339562,339663,339554,339700,339792,339811,339801,339459,339592,339679,339590,339473,339799,339791,339795,339660,339803,339623,339813,339659,339678,339465,339457,339786,339477,339541,339796,339643,339489,339699,339797,339469,339798,339458,339606,339482,339685,339468,339453,339730,339731,339478,339794,339463,339709,339467,339753,339460,339808,339696,339757,339787,339464,339805,339806,339810,339704,339701,339707,339677,339769,339814,339758,339750,339714,339829,339695,339735,339807,339479,339752,339746,339654,339452,339755,339847,339656,339712,339715,339851,339729,339760,339648,339668,339681,339664,339485,339671,339809,339694,339655,339828,339812,339761,339817,339720,339697,339650,339835,339702,339593,339849,339484,339820,339483,339734,339596,339725,339466,339774,339728,339674,339754,339836,339821,339843,339802,339723,339599,339816,339845,339582,339486,339839,339594,339727,339765,339762,339691,339804,339600,339733,339781,339831,339488,339726,339855,339825,339718,339675,339597,339782,339481,339838,339846,339841,339604,339768)) and (`webmarco`.`cscart_discussion`.`object_type` = 'P'))"
          }
        },
        {
          "table": {
            "table_name": "p",
            "access_type": "eq_ref",
            "possible_keys": [
              "PRIMARY",
              "age_verification",
              "status",
              "idx_parent_product_id",
              "idx_master_product_id"
            ],
            "key": "PRIMARY",
            "used_key_parts": [
              "product_id"
            ],
            "key_length": "3",
            "ref": [
              "webmarco.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.10",
              "eval_cost": "0.02",
              "prefix_cost": "7.19",
              "data_read_per_join": "760"
            },
            "used_columns": [
              "product_id"
            ]
          }
        }
      ]
    }
  }
}