0
如何在將數據導入到我的數據庫時停止mysql索引。我有一個Rails應用程序,用戶可以從文件導入數據。我添加了一些索引,以加快 搜索電話號碼和電子郵件地址的結果。從CSV或EXCEL文件導入時暫停MySQL索引
我接觸模型有一些關係,我去掉一個簡單的例子其它型號:
create_table "contacts", :force => true do |t|
t.integer "user_id"
t.integer "status"
t.integer "gender", :default => 0, :null => false
t.string "salutation", :null => false
t.string "title"
t.string "first_name", :null => false
t.string "last_name", :null => false
t.binary "phone"
t.binary "email"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
:
:
end
add_index "contacts", ["phone"], :name => "index_contacts_on_phone"
add_index "contacts", ["email"], :name => "index_contacts_on_email"
進口需要很長時間。我可以防止MySQL在導入數千個聯繫人時建立索引嗎?導入後,我將啓用索引。有沒有一種首選的方法來做到這一點?
謝謝,丹尼爾
我使用sidekiq進行導入。用戶應該將文件加載到服務器並開始導入過程。 Sidekiq輸入所有數據。但是這個過程很慢,數據庫(服務器)的負載非常高。我的想法是在sidekiq工作進程中停止索引,以便在導入完成時啓動並啓動並重新索引它。 –
在導入數據的工作人員中,創建一些臨時變量/保存數據的對象,每當創建它們時,只保存這些數據到數據庫。它會減少數據庫負載。 –