From 5189d47d91794bd5674fe6799e67be2939c4dc81 Mon Sep 17 00:00:00 2001 From: AntonioTerceiro Date: Sat, 12 Jul 2008 12:06:42 +0000 Subject: [PATCH] ActionItem514: adding indexes for common columns --- db/migrate/046_aggressive_indexing_strategy1.rb | 32 ++++++++++++++++++++++++++++++++ db/schema.rb | 20 +++++++++++++++++--- 2 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 db/migrate/046_aggressive_indexing_strategy1.rb diff --git a/db/migrate/046_aggressive_indexing_strategy1.rb b/db/migrate/046_aggressive_indexing_strategy1.rb new file mode 100644 index 0000000..3a31e40 --- /dev/null +++ b/db/migrate/046_aggressive_indexing_strategy1.rb @@ -0,0 +1,32 @@ +class AggressiveIndexingStrategy1 < ActiveRecord::Migration + def self.up + # profile categorizations + add_index(:categories_profiles, :profile_id) + add_index(:categories_profiles, :category_id) + + # product categorizations + add_index(:product_categorizations, :product_id) + add_index(:product_categorizations, :category_id) + + # finding products by the enterprises that own them + add_index(:products, :enterprise_id) + + # finding profiles by their environment + add_index(:profiles, :environment_id) + + # finding blocks by their box, and boxes by their owner + add_index(:blocks, :box_id) + add_index(:boxes, [:owner_type, :owner_id]) + end + + def self.down + add_index(:categories_profiles, :column => :profile_id) + add_index(:categories_profiles, :column => :category_id) + add_index(:product_categorizations, :column => :product_id) + add_index(:product_categorizations, :column => :category_id) + add_index(:products, :column => :enterprise_id) + add_index(:profiles, :column => :environment_id) + add_index(:blocks, :column => :box_id) + add_index(:box, :column => [:owner_type, :owner_id]) + end +end diff --git a/db/schema.rb b/db/schema.rb index 5c11da1..b14cb82 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -9,7 +9,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 45) do +ActiveRecord::Schema.define(:version => 46) do create_table "article_versions", :force => true do |t| t.integer "article_id" @@ -71,8 +71,8 @@ ActiveRecord::Schema.define(:version => 45) do t.boolean "virtual", :default => false end - add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" add_index "articles_categories", ["article_id"], :name => "index_articles_categories_on_article_id" + add_index "articles_categories", ["category_id"], :name => "index_articles_categories_on_category_id" create_table "blocks", :force => true do |t| t.string "title" @@ -82,12 +82,16 @@ ActiveRecord::Schema.define(:version => 45) do t.integer "position" end + add_index "blocks", ["box_id"], :name => "index_blocks_on_box_id" + create_table "boxes", :force => true do |t| t.string "owner_type" t.integer "owner_id" t.integer "position" end + add_index "boxes", ["owner_type", "owner_id"], :name => "index_boxes_on_owner_type_and_owner_id" + create_table "categories", :force => true do |t| t.string "name" t.string "slug" @@ -108,6 +112,9 @@ ActiveRecord::Schema.define(:version => 45) do t.boolean "virtual", :default => false end + add_index "categories_profiles", ["category_id"], :name => "index_categories_profiles_on_category_id" + add_index "categories_profiles", ["profile_id"], :name => "index_categories_profiles_on_profile_id" + create_table "comments", :force => true do |t| t.string "title" t.text "body" @@ -170,6 +177,9 @@ ActiveRecord::Schema.define(:version => 45) do t.datetime "updated_at" end + add_index "product_categorizations", ["category_id"], :name => "index_product_categorizations_on_category_id" + add_index "product_categorizations", ["product_id"], :name => "index_product_categorizations_on_product_id" + create_table "products", :force => true do |t| t.integer "enterprise_id" t.integer "product_category_id" @@ -183,6 +193,8 @@ ActiveRecord::Schema.define(:version => 45) do t.float "lng" end + add_index "products", ["enterprise_id"], :name => "index_products_on_enterprise_id" + create_table "profiles", :force => true do |t| t.string "name" t.string "type" @@ -202,6 +214,8 @@ ActiveRecord::Schema.define(:version => 45) do t.boolean "enabled", :default => true end + add_index "profiles", ["environment_id"], :name => "index_profiles_on_environment_id" + create_table "region_validators", :id => false, :force => true do |t| t.integer "region_id" t.integer "organization_id" @@ -230,8 +244,8 @@ ActiveRecord::Schema.define(:version => 45) do t.datetime "created_at" end - add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" add_index "taggings", ["tag_id"], :name => "index_taggings_on_tag_id" + add_index "taggings", ["taggable_id", "taggable_type"], :name => "index_taggings_on_taggable_id_and_taggable_type" create_table "tags", :force => true do |t| t.string "name" -- libgit2 0.21.2