Views 3 query altering with hook_views_query_alter

You can alter views, alter queries and much more. Problem with documentation online is that is lacking some crucial information.

First, you should put your alter function in separate file, your_module.views.inc
as it is said here
https://api.drupal.org/api/views/views.api.php/function/hook_views_quer…

What you also need to do is implement hook_views_api, it is said above that you don't have to but with lates views 3.0 it won't work if you don't do it, so you add this little line

function your_module_views_api() {
  return array('api' => 3.0);
}

and you can also add path if file is in some other directory

function mymodule_views_api() {
  return array(
    'api' => 2.0,
    'path' => drupal_get_path('module', 'mymodule') . '/includes/views',
  );
}

then you just refresh caches and it should work. Alter away with

function mymodule_views_query_alter(&$view, &$query) {
  dpm($view, __FUNCTION__);
  dpm($query, __FUNCTION__);
  ... some code
}

Just a note, this should all work until you hit a " [field] => DatabaseCondition Object" in your query then you have another beast to tame. I can't really tell you much how at this point, but maybe whole different approach with http://www.metachunk.com/blog/altering-queries-drupal-7 would help.