Skip to content

Instantly share code, notes, and snippets.

@esafwan
Last active December 30, 2015 08:19
Show Gist options
  • Save esafwan/7802034 to your computer and use it in GitHub Desktop.
Save esafwan/7802034 to your computer and use it in GitHub Desktop.
View Query Alter in Drupal to dramatically increase the query performance. This converts left joins to inner join and disables distinct query.
<?php
/**
* Implements hook_views_query_alter().
*
* This disables distinct and turns LEFT joins into INNER joins. This increases
* performance.
*/
function my_module_views_query_alter(&$view, &$query) {
if ($view->name == "my_view") {
$query->table_queue['content_type_article']['join']->type = 'INNER';
$query->distinct = 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment