views_query_alter change to operator OR for contextual filters and normal filters My question is rather simple and I have searched quite a bit for the answer with no result.
My view produces below SQL (simplified):

SELECT stuff
FROM 
tableA
LEFT JOIN tableB
LEFT JOIN tableC ON stuff
WHERE (( (MY_CONTEXTUAL_FILTER = '5' ) )AND(( (MY_NORMAL_FILTER IS NULL ) )))


All I want to do is to change that AND between the contextual filter and normal filter. I have tried to change all ANDs (including set_group_operator()) to OR and it does not change my AND. 

Also need to mention it is an 'Entity Reference' display which I am trying to achieve the above on. Views version 7.x-3.7.

UPDATE

In order to achieve the above, I also tried hook_views_pre_execute() as below:

 $old_query = (string)$view-&gt;query-&gt;query();
 $new_query = str_replace('AND', 'OR', $old_query);
 $view-&gt;build_info['query']=$new_query;


But that doesn't work and throws and error. I know they are different approaches with different issues but both are trying to solve one problem.
As a simple try to help, did you implement hook_views_query_alter(&amp;$view, &amp;$query) as following ?

First, call Views API in YOUR_MODULE.module :

/**
 * Implementation of hook_views_api().
 */
function YOUR_MODULE_views_api() { 
  return array(
    'api' =&gt; 3,
    'path' =&gt; drupal_get_path('module', 'YOUR_MODULE_NAME'),
  );
}


Create a file YOUR_MODULE.views.inc. It seems that with Views, you don't need to put files[] = YOUR_MODULE.views.inc in your module's .info file, as you usually would. 

Then implement hook_views_query_alter() in views.inc.

function YOUR_MODULE_views_query_alter(&amp;$view, &amp;$query) {

  if($view-&gt;name == 'VIEW_NAME') {

    dpm($query);
    //at this point find the right part to alter and adapt following line
    $query-&gt;where[0]['type'] = 'OR';

  }
}


EDIT: If for any reason, you can't override the View with hook_views_query_alter(), Views Filter Harmonizer might fit your need.


  Views Filter Harmonizer solves an operational foible with the Views
  module regarding filtering. This small module allows you to have a contextual filter argument apply only when there is no corresponding regular (exposed) filter value present.


Last, check also Views arguments in filters sandbox, or test this patch. Both rely on the same logic, setting a "Global: Null" contextual filters and using it in regular filters. Many people report using it to solve the same And/Or contextual filters issue. Good luck !