I have 2 models - Question
and Tag
- which have a HABTM between them, and they share a join table questions_tags
.
Feast your eyes on this badboy:
1.9.3p392 :011 > Question.count
(852.1ms) SELECT COUNT(*) FROM "questions"
=> 417
1.9.3p392 :012 > Tag.count
(197.8ms) SELECT COUNT(*) FROM "tags"
=> 601
1.9.3p392 :013 > Question.connection.execute("select count(*) from questions_tags").first["count"].to_i
(648978.7ms) select count(*) from questions_tags
=> 39919778
I am assuming that the questions_tags
join table contains a bunch of duplicate records - otherwise, I have no idea why it would be so large.
How do I clean up that join table so that it only has uniq
content? Or how do I even check to see if there are duplicate records in there?
Edit 1
I am using PostgreSQL, this is the schema for the join_table questions_tags
create_table "questions_tags", :id => false, :force => true do |t|
t.integer "question_id"
t.integer "tag_id"
end
add_index "questions_tags", ["question_id"], :name => "index_questions_tags_on_question_id"
add_index "questions_tags", ["tag_id"], :name => "index_questions_tags_on_tag_id"