I work in a website that sell products. I have a table (sell) with has more than 2.000.000 rows.
I need to improve its performace, so I want to know what is the best way I get the number of "sells" one product has.
a) count(id)
$stmt = $mysqli->prepare("SELECT count(id) as num FROM sell WHERE prod_id=?");
$stmt->bind_param('i', $id);
$stmt->execute();
$result = $stmt->get_result();
$stmt->close();
$num = $result->fetch_assoc();
$total = $num['num'];
b) num_rows
$stmt = $mysqli->prepare("SELECT id FROM sell WHERE prod_id=?");
$stmt->bind_param('i', $id);
$stmt->execute();
$result = $stmt->get_result();
$stmt->close();
$total = $result->num_rows;
a or b? why?