title: Matching values from two different tables efficiently
body: <p>I have two tables </p>
  
  <pre><code> class CreateMasterUrls &lt; ActiveRecord::Migration
    def change
     \create_table :master_urls do |t|
    t.string :url
    t.string :host
  
    t.timestamps
   end
   add_index :master_urls, [:url], :name =&gt; :idx_url
   add_index :master_urls, [:host], :name =&gt; :idx_host
   end
  end
  </code></pre>
  
  <p>and </p>
  
  <pre><code> class CreateUrlLists &lt; ActiveRecord::Migration
    def change
    create_table :url_lists do |t|
    t.string :url
    t.integer :project_id
  
    t.timestamps
   end
   end
  end
  </code></pre>
  
  <p>I want to check whether URL present in url_lists table is present in master_urls, if not than add it in master_urls table. Any clue how to do that?</p>
  
  <p>One way would be to do regex match. But it is not efficient and also not solving problem.</p>