why filters are not working in view query alter?
I solved it by myself ,i have added condition for operator where i was doing mistake ,on first page load "IN" operator will work then "=" on selection of select list :

  function get_purchased_product_id() {
  //Get current user id 
  $user_id = \Drupal::currentUser()-&gt;id();

  $uid = ($user_id ==1)? 267 :$user_id;

  $query_get_product_name =  db_select('commerce_order', 'c');
  $query_get_product_name-&gt;join('commerce_order_item', 'ci', 'c.order_id = ci.order_id');
  $query_get_product_name-&gt;join('commerce_product_variation_field_data', 'cf', 'ci.purchased_entity = cf.variation_id');
  $query_get_product_name-&gt;fields('c', ['uid']);
  $query_get_product_name-&gt;fields('ci', ['purchased_entity']);
  $query_get_product_name-&gt;fields('cf', ['product_id','title']);
  $query_get_product_name-&gt;condition('c.uid', $uid,'=');
  $query_get_product_name-&gt;condition('c.state', 'completed','=');
  $result = $query_get_product_name-&gt;execute();

  $arr_var=array();

  foreach ($result as $value ){
  $arr_var[]= $value-&gt;product_id;
   }
  return $arr_var;

 } 


 function classroom_common_views_query_alter(ViewExecutable $view, QueryPluginBase $query) {

if ($view-&gt;id() == 'answer_key_form_management' &amp;&amp; $view-&gt;getDisplay()-&gt;display['id'] == 'page_2') {
  //function call to get product id of purchased item by current user
  $arr_product_id = get_purchased_product_id();

  $product_target_id = Drupal::request()-&gt;query-&gt;get('field_akfp_select_product_target_id');
  if(!empty($product_target_id)){
     $arr_product_id = $product_target_id;
  }
  $operator = !empty($product_target_id) ? '=' : 'IN';

foreach ($query-&gt;where as &amp;$condition_group) {
      foreach ($condition_group['conditions'] as &amp;$condition) {
        if ($condition['field'] == 'node__field_akfp_select_product.field_akfp_select_product_target_id') {

          $condition = array(
            'field' =&gt; 'node__field_akfp_select_product.field_akfp_select_product_target_id',
            'value' =&gt;  $arr_product_id,
            'operator' =&gt; $operator,
          );

        }
      }
    }
}