diff --git a/pathauto.pathauto.inc b/pathauto.pathauto.inc
index 28d3ce0..f94ded7 100644
--- a/pathauto.pathauto.inc
+++ b/pathauto.pathauto.inc
@@ -89,10 +89,11 @@ function node_pathauto_bulk_update_batch_process(&$context) {
     $context['sandbox']['current'] = 0;
   }
 
+  $tmp_id_table = _pathauto_create_temp_id_table('node/');
   $query = db_select('node', 'n');
-  $query->leftJoin('url_alias', 'ua', "CONCAT('node/', n.nid) = ua.source");
+  $query->leftJoin($tmp_id_table, 'ti', "n.nid = ti.id");
   $query->addField('n', 'nid');
-  $query->isNull('ua.source');
+  $query->isNull('ti.id');
   $query->condition('n.nid', $context['sandbox']['current'], '>');
   $query->orderBy('n.nid');
   $query->addTag('pathauto_bulk_update');
@@ -113,6 +114,10 @@ function node_pathauto_bulk_update_batch_process(&$context) {
   $nids = $query->execute()->fetchCol();
 
   pathauto_node_update_alias_multiple($nids, 'bulkupdate');
+
+  // Clean up.
+  db_drop_table($tmp_nid_table);
+
   $context['sandbox']['count'] += count($nids);
   $context['sandbox']['current'] = max($nids);
   $context['message'] = t('Updated alias for node @nid.', array('@nid' => end($nids)));
@@ -390,3 +395,24 @@ function blog_pathauto_bulk_update_batch_process(&$context) {
     $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
   }
 }
+
+/**
+ * Create a temporary table of ids of already aliased entities.
+ * The name of the field should be set, it should be an integer, and it 
+ * should be indexed, so we create the table explicitly.
+ *
+ * @param $prefix
+ *   The part of the source path before the id (e.g. node/, user/, etc.).
+ * @return
+ *   The name of the temporary table.
+ */
+function _pathauto_create_temp_id_table($prefix) {
+  $tmp_tablename = uniqid('pathauto_tmp_');
+  db_query('CREATE TEMPORARY TABLE '. $tmp_tablename .' (id int PRIMARY KEY)');
+  // Cut the id from the source field.
+  $idposition = strlen($prefix) + 1;
+  db_query('INSERT INTO '. $tmp_tablename .' (id) SELECT SUBSTRING(source, '. $idposition .') FROM url_alias WHERE SUBSTRING(source, 1, '. strlen($prefix) .') = :prefix',
+    array(':prefix' => $prefix)
+  );
+  return $tmp_tablename;
+}
