Which Drupal function inserts the data in the history table?
It is node_tag_new(), the function that is part of the Node module (line 299 of that file in Drupal 7).

/**
 * Updates the 'last viewed' timestamp of the specified node for current user.
 *
 * @param $node
 *   A node object.
 */
function node_tag_new($node) {
  global $user;
  if ($user-&gt;uid) {
    db_merge('history')
      -&gt;key(array(
        'uid' =&gt; $user-&gt;uid,
        'nid' =&gt; $node-&gt;nid,
      ))
      -&gt;fields(array('timestamp' =&gt; REQUEST_TIME))
      -&gt;execute();
   }
}


Here's the same function in Drupal 6.

/**
 * Update the 'last viewed' timestamp of the specified node for current user.
 */
function node_tag_new($nid) {
  global $user;

  if ($user-&gt;uid) {
    if (node_last_viewed($nid)) {
      db_query('UPDATE {history} SET timestamp = %d WHERE uid = %d AND nid = %d', time(), $user-&gt;uid, $nid);
    }
    else {
      @db_query('INSERT INTO {history} (uid, nid, timestamp) VALUES (%d, %d, %d)', $user-&gt;uid, $nid, time());
    }
  }
}


The function is called by node_show(), which uses the following code.

// Update the history table, stating that this user viewed this node.
node_tag_new($node);


As said from that comment, the purpose of the function call is updating the history table to record the fact the current user viewed the node.