Title: Slow query  &#8211; Nextgen
Last modified: August 21, 2016

---

# Slow query – Nextgen

 *  Resolved [NielsV_E](https://wordpress.org/support/users/nielsv_e/)
 * (@nielsv_e)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/slow-query-nextgen/)
 * Hi All,
 * Since upgrade to new version, I expect hughe problems with mysql.
    Here’s the
   slow query log.
 * This query is executed when clicking “Add Gallery / Images”.
 * # Time: 140123 13:46:17
    # User@Host: @ localhost [] # Query_time: 33.742712 
   Lock_time: 0.000104 Rows_sent: 1406 Rows_examined: 6492984 use xxxxx; SET timestamp
   =1390481177; SELECT wp_ngg_gallery.* , `wp_options`.`option_value` AS ‘custom_post_id’,
   GROUP_CONCAT(CONCAT_WS(‘@@’, meta_key, meta_value)) AS ‘extras’ FROM `wp_ngg_gallery`
   LEFT OUTER JOIN `wp_options` ON `wp_options`.option_name = CONCAT(‘wp_ngg_gallery_’,
   wp_ngg_gallery.gid) LEFT OUTER JOIN `wp_postmeta` ON `wp_postmeta`.`post_id` 
   = `wp_options`.`option_value` GROUP BY wp_ngg_gallery.gid;
 * How can we avoid this querie is being executed or can we tune the tables?
 * Niels
 * [http://wordpress.org/plugins/nextgen-gallery/](http://wordpress.org/plugins/nextgen-gallery/)

Viewing 3 replies - 1 through 3 (of 3 total)

 *  Thread Starter [NielsV_E](https://wordpress.org/support/users/nielsv_e/)
 * (@nielsv_e)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/slow-query-nextgen/#post-4535149)
 * I made a dirty change in the mixin.netgen_table_extras.php …
 * Line 153, function get_generated_query ()
 * Added some limitations:
    $this->object->limit(20,0); $this->object->order_by(
   $primary_key, “DESC”);
 * We don’t use NextGen function for post_id’s (only use [ngggallery id=]), so I
   changed also the query:
    $sql = str_replace(‘FROM’, “, `{$wpdb->options}`.`option_value`
   AS ‘custom_post_id’, GROUP_CONCAT(CONCAT_WS(‘@@’, meta_key, meta_value)) AS ‘
   extras’ FROM”, $sql);
 * in:
    $sql = str_replace(‘FROM’, “, ” AS ‘custom_post_id’, ” AS ‘extras’ FROM”,
   $sql);
 * And also:
    $sql = str_replace($from, “{$from} LEFT OUTER JOIN `{$wpdb->options}`
   ON `{$wpdb->options}`.option_name = CONCAT(‘{$table_name}_’, {$primary_key}) 
   LEFT OUTER JOIN `{$wpdb->postmeta}` ON `{$wpdb->postmeta}`.`post_id` = `{$wpdb-
   >options}`.`option_value` “, $sql);
 * $sql = str_replace($from, “{$from} LEFT OUTER JOIN `{$wpdb->options}` ON `{$wpdb-
   >options}`.option_name = CONCAT(‘{$table_name}_’, {$primary_key})”, $sql);
 * I only show the last 20 galleries when adding pictues to a gallery.
    Therefore
   also showing only the last 20 galleries in selectbox by Posts.
 *  Plugin Contributor [photocrati](https://wordpress.org/support/users/photocrati/)
 * (@photocrati)
 * [12 years, 4 months ago](https://wordpress.org/support/topic/slow-query-nextgen/#post-4535157)
 * [@nielsv_e](https://wordpress.org/support/users/nielsv_e/) – Thanks for your 
   suggestion … we have also improved this part our our queries with our next (beta)
   release and expect it will have an over-all improvement with speed.
 * – Cais.
 *  Anonymous User 88352
 * (@anonymized-88352)
 * [12 years, 3 months ago](https://wordpress.org/support/topic/slow-query-nextgen/#post-4535212)
 * I have also started to see MySQL slow query log entries lately; I can’t say if
   it started with NextGEN Gallery version 2.0.40. The site has about 800 images
   in 40 galleries. Here’s a sample:
 * # Query_time: 14 Lock_time: 0 Rows_sent: 173 Rows_examined: 4431348
    use s******;
   SELECT galleryid, COUNT(*) as counter , `wp_options`.`option_value` AS ‘custom_post_id’,
   GROUP_CONCAT(CONCAT_WS(‘@@’, meta_key, meta_value)) AS ‘extras’ FROM `wp_ngg_pictures`
   LEFT OUTER JOIN `wp_options` ON `wp_options`.option_name = CONCAT(‘wp_ngg_pictures_’,
   wp_ngg_pictures.pid) LEFT OUTER JOIN `wp_postmeta` ON `wp_postmeta`.`post_id`
   = `wp_options`.`option_value` WHERE (`galleryid` IN (35, 38, 15, 16, 41, 17, 
   14, 43)) GROUP BY galleryid, wp_ngg_pictures.pid;

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Slow query – Nextgen’ is closed to new replies.

 * ![](https://ps.w.org/nextgen-gallery/assets/icon-256x256.png?rev=2083961)
 * [Photo Gallery, Sliders, Proofing and Themes - NextGEN Gallery](https://wordpress.org/plugins/nextgen-gallery/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/nextgen-gallery/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/nextgen-gallery/)
 * [Active Topics](https://wordpress.org/support/plugin/nextgen-gallery/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/nextgen-gallery/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/nextgen-gallery/reviews/)

## Tags

 * [MySQL](https://wordpress.org/support/topic-tag/mysql/)
 * [nextgen](https://wordpress.org/support/topic-tag/nextgen/)
 * [query](https://wordpress.org/support/topic-tag/query/)

 * 3 replies
 * 3 participants
 * Last reply from: Anonymous User 88352
 * Last activity: [12 years, 3 months ago](https://wordpress.org/support/topic/slow-query-nextgen/#post-4535212)
 * Status: resolved