you can try some of these extra parameters:
'update_post_term_cache' => false,
'update_post_meta_cache' => false,
'cache_results'=>false,
'no_found_rows' => true,
'posts_per_page'=>1,
'post_status'='publish',
ps: you can measure the speed of your query when you are testing it with microtime()
http://php.net/manual/en/function.microtime.php
Edit:
Here is a another way:
function count_votes($user_id=1, $question_id=1, $post_type="vote", $meta_key='comp_question'){
global $wpdb;
$sql = "SELECT count(*) FROM {$wpdb->posts} INNER JOIN {$wpdb->postmeta} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id) WHERE ({$wpdb->posts}.post_author = %d) AND ({$wpdb->posts}.post_type = %s) AND ({$wpdb->posts}.post_status="publish" ) AND ({$wpdb->postmeta}.meta_key = %s) AND ({$wpdb->postmeta}.meta_value = %d)";
// uncomment if you need to group it
//$sql .= " GROUP BY {$wpdb->posts}.ID";
$count = $wpdb->get_var($wpdb->prepare($sql,$user_id,$post_type,$meta_key,$question_id));
return $count;
}
and you can use it like this:
$user_id=1;
$question_id=1;
$post_type="vote";
$meta_key='comp_question';
echo "votes: " . count_votes($user_id, $question_id, $post_type, $meta_key);
Edit 2:
Here is a function that returns an array of votes ids:
function get_votes($user_id=1, $question_id=1, $post_type="vote", $meta_key='comp_question'){
global $wpdb;
$sql = "SELECT {$wpdb->posts}.ID FROM {$wpdb->posts} INNER JOIN {$wpdb->postmeta} ON ( {$wpdb->posts}.ID = {$wpdb->postmeta}.post_id) WHERE ({$wpdb->posts}.post_author = %d) AND ({$wpdb->posts}.post_type = %s) AND ({$wpdb->posts}.post_status="publish" ) AND ({$wpdb->postmeta}.meta_key = %s) AND ({$wpdb->postmeta}.meta_value = %d)";
// uncomment if you need to group it
//$sql .= " GROUP BY {$wpdb->posts}.ID";
$ids=array();
$ids = $wpdb->get_col($wpdb->prepare($sql,$user_id,$post_type,$meta_key,$question_id));
return $ids;
}
you can use it like this:
$ids=get_votes($user_id, $question_id, $post_type, $meta_key);
print_r($ids);