Last active
November 29, 2016 02:16
-
-
Save yn-misaki/374242bad0843fddc4c9b9bb6bddb5c6 to your computer and use it in GitHub Desktop.
【MySQL5.6以上】Webエンジニア向け!メンテなしで500万件レコード入りのテーブルにINDEXを張る実行時間の目安 ref: http://qiita.com/yn-misaki/items/018a76d15d1fe96fd9d7
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ALTER TABLE テーブル名 ADD INDEX インデックス名(カラム名); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 自動採番のプライマリーキーは、NULLにしましょう(エラーで怒られなくて済みます) **/ | |
INSERT INTO テーブル名 | |
SELECT NULL(プライマリキー),カラム名1,...,カラムn FROM テーブル名; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bundle exec rake db:migrate RAILS_ENV=development |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ bundle exec rake db:migrate RAILS_ENV=production | |
================================================== | |
== 20161128017930 AddIndexToHoge: migrating | |
-- add_index(:companies, [:foo_number, :bar_id, :bar_status], {:name=>"index_hoge_on_foo_number_and_bar_id_and_bar_status"}) | |
-> 52.6168s | |
== 20161128017930 AddIndexToHoge: migrated (52.6169s) | |
================================================== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AddIndexToHoge < ActiveRecord::Migration | |
def change | |
# テーブル:hoge | |
# カラム: foo_id, bar_id, bar_status | |
# 単体のINDEX | |
# add_index :hoge, :bar_status | |
# 複合INDEXを作成 | |
add_index :hoge, [:foo_number, :bar_id, :bar_status] | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment