If I truncate the table, should I add indexes

I am developing a rails application with MYSQL, and I created a migration to add indexes to tables. I also have a rake task that trims some of the tables and writes data.

ActiveRecord::Base.connection.execute("TRUNCATE #{Model.table_name}")

Do I need to add indexes after truncation? Thanks in advance:)

+3
source share
1 answer

No. The table is discarded and then recreated again (including any indexes and constraints).

+5
source

Source: https://habr.com/ru/post/1774394/


All Articles