Very slow query with meta_query on large database

It is recommended to stick with WP_query for grabbing WordPress posts; but, you can build your own queries directly from the postmeta table, then iterate through the results.

Depending on the query, this may be faster (Not often; WordPress works hard to make their database queries as fast as they can be).

global $wpdb;
$table = $wpdb->prefix . 'the_table_you_want';
$sql = $wpdb->prepare( 'SELECT id FROM ' . $table . ' WHERE some_field = %s AND another_field = %d;', 'some_value', 42 );
$results = $wpdb->get_results( $sql );

foreach( $results as $result ):

    //do stuff with $result ( it is an object, not an array )       

endforeach;

ALWAYS use prepare when constructing your own queries.