Very Slow Query on large postmeta tables
-
Hey,
I’ve been debugging slow querys on my wordpress site and i’ve noticed that calling$dynamic_featured_image->get_featured_images()
is really slow.It comes down to this query:
SELECT post_id FROM ' . $this->db->postmeta . ' WHERE meta_key = %s AND meta_value = %s
Called from:get_image_id();
this query on my site takes 12 seconds… But by adding a simple condition on a keyed field solves this down to basically nothingI suggest changing the code to the following:
$row = $this->execute_query( $this->db->prepare( 'SELECT post_id FROM ' . $this->db->postmeta . ' WHERE meta_key = %s AND meta_value = %s', '_wp_attached_file', $image_url ) );
- The topic ‘Very Slow Query on large postmeta tables’ is closed to new replies.