$query = db_select('taxonomy_term_data', 'td');
$query->fields('td', array('tid', 'name'));
$query->condition('td.vid', 3);
$query->addExpression("(SELECT COUNT(*) FROM {taxonomy_index} ti LEFT JOIN {node} n ON ti.nid = n.nid WHERE ti.tid = td.tid AND n.status = 1)", 'node_count');
$terms = $query->execute()->fetchAll();