How do I implement hook_views_query_alter()? I try to implement hook_views_query_alter() in Drupal 8.
I found a hint, that it has to be in my_module.views_execution.inc.
I tried it, but the hook never gets called.

function mymodulename_views_query_alter(&amp;$view, &amp;$query)
{
    var_dump('foo');die;
}


Do I have to register the *.inc file anywhere? Do you have a documentation source on this topic?
In Drupal 8, best practice is to use hook_views_query_alter() in MYMODULE.views_execution.inc file. If instead it is placed in MYMODULE.views.inc, it will be executed only when rebuilding the views cache, causing your view to function properly once and then not subsequently.

MYMODULE.views_execution.inc file should have this structure...

use Drupal\views\ViewExecutable;
use Drupal\views\Plugin\views\query\QueryPluginBase;

/**
 * Implements hook_views_query_alter().
 */
function MYMODULE_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {

  // Only for my_view view.
  if ($view-&gt;id() == 'my_view') {
    // some action
  }

}


Ref: views_test_data.views_execution.inc