When should "'target' => 'slave'" be used in a query? Looking at Drupal code, I notice that sometimes a query is being executed using array('target' =&gt; 'slave') as options, and I don't understand in which case that should be done.

I thought it was done when query where executed in parallel to others, but then I thought that could be said for almost any query executed by Drupal, when more than one user is looking at the pages of a site.
In which cases should array('target' =&gt; 'slave') be used?

  // node_update_index()
  $result = db_query_range("SELECT n.nid FROM {node} n LEFT JOIN {search_dataset} d ON d.type = 'node' AND d.sid = n.nid WHERE d.sid IS NULL OR d.reindex &lt;&gt; 0 ORDER BY d.reindex ASC, n.nid ASC", 0, $limit, array(), array('target' =&gt; 'slave'));




// search_index()
$node = db_query('SELECT title, nid, vid FROM {node} WHERE nid = :nid', array(':nid' =&gt; $linknid), array('target' =&gt; 'slave'))-&gt;fetchObject();


Also, looking at Drupal core code, why is array('target' =&gt; 'slave') sometimes used, and sometimes no?
SELECT (read) queries can go to the slave, other such as UPDATE and DELETE (write) queries should go to master then propagate across to the slave database.


  Also, looking at Drupal core code, why is array('target' =&gt; 'slave') sometimes used, and sometimes no?


That's probably just historical / legacy reasons due to the nature of how the Drupal code base is gradually committed. Potentially any SELECT queries could target the slave database.