سؤال

Quick question I had a table with 1.7 million records and performed a delete which left me with 400k records which is fine.

I have several indexes on this table, I am just wondering does a normal

delete * from my_table where value = 1

also make the index size smaller by removing the indexes which are no longer needed because of the records deleted ?

هل كانت مفيدة؟

المحلول

Data is removed from the indexes on delete, as well as maintained on update and inserts, in Sql Server

However, the table and index statistics aren't automatically updated unless you affect enough of the rows in the table with your query.
That threshold is as I recall 20% of the table by default, so if your delete affect less it might be worth it to update statistics yourself.

This is usually where the confusion around the indexes are coming from because statistics are a part of index usage (the engine is using statistics to calculate when to use various indexes) and the can be 'old' even while the actual data is removed from the physical index.

نصائح أخرى

technically the indices are supposed to maintain themselves, but the DB will have it's own way of doing it.

MySQL does it automatically, but Postgres sometimes needs a vacuum command run manually. not sure about other DBs.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top