title: set enable_seqscan = off, through jdbc | Postgres
body: <p>I have two queries, insert and update. I did a benchmark through postgres console with a large dataset and found that postgres was not picking up the index. To solve this - I disabled seqscan for those two queries and got a huge performance boost; Postgres was able to pick up the indexes for scanning through the table.</p>
  
  <p>Problem:
  I am doing the same thing through jdbc</p>
  
  <pre><code>statement.executeUpdate("set enable_seqscan = off");
  statement.executeUpdate("My_Insert_Query");
  statement.executeUpdate("My_Update_Query");
  statement.executeUpdate("set enable_seqscan = on");
  </code></pre>
  
  <p>But seems like postgres is not turning seq_scan off for and the queries are taking way too long to execute.</p>
  
  <p>Master Table</p>
  
  <pre><code>Master_Id   auto-generated
  child_unique     integer
  
  
  Child Table
  child_unique integer
  Master_id integer
  
  Insert into Master (child_unique) from Child as i WHERE NOT EXISTS ( SELECT * from Master where Master.child_unique = i.child_unique);
  
  Update Child set Master_id = Master.Master_id from Master where Master.child_unique = Child.child_unique;
  </code></pre>
  
  <p>For every unique row in Child which is not present in Master-  I insert that into my Master table and get the auto generated Master_ID and insert it back into the Child table.</p>
  
  <p>Both tables have index on child_unique.</p>
  
  <p>Index is picked up on the Master table where as it is not in the case of Child table.
  How did I find out? Using Postgres's pg_stat_all_indexes table.</p>