# Does Aerospike delete the secondary index on a bin if I delete the bin?

**URL:** <https://discuss.aerospike.com/t/does-aerospike-delete-the-secondary-index-on-a-bin-if-i-delete-the-bin/4906>\
**Category:** Operations\
**Tags:** deletion, index\
**Created:** [February 2, 2018, 6:35am UTC](https://discuss.aerospike.com/t/does-aerospike-delete-the-secondary-index-on-a-bin-if-i-delete-the-bin/4906 "2018-02-02T06:35:01Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![HimanshuKumarSingh](https://avatars.discourse-cdn.com/v4/letter/h/ee59a6/32.png) [@HimanshuKumarSingh](https://discuss.aerospike.com/u/HimanshuKumarSingh)\
**Post date:** [February 2, 2018, 6:35am UTC](https://discuss.aerospike.com/t/does-aerospike-delete-the-secondary-index-on-a-bin-if-i-delete-the-bin/4906/1 "2018-02-02T06:35:01Z")

</div>

I have a bin that I no longer require. My application gradually moves all data from the bin to another bin.

1. Once the bin is empty, does Aerospike remove the bin from its metadata?
2. If the answer to 1 is yes, does it also delete any secondary index on it?

---

<div class="post-metadata">

**Author:** ![pgupta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pgupta/32/2351_2.png) [@pgupta](https://discuss.aerospike.com/u/pgupta)\
**Post date:** [February 2, 2018, 8:15pm UTC](https://discuss.aerospike.com/t/does-aerospike-delete-the-secondary-index-on-a-bin-if-i-delete-the-bin/4906/2 "2018-02-02T20:15:25Z")

</div>

Bin metadata is stored on each record - so if you delete a bin in a record, metadata on the bin for that record is absent in the new version of the record. You must explicitly delete the secondary index. BTW, you can delete secondary index on existing bins, before deleting the bins.

---

<div class="post-metadata">

**Author:** ![HimanshuKumarSingh](https://avatars.discourse-cdn.com/v4/letter/h/ee59a6/32.png) [@HimanshuKumarSingh](https://discuss.aerospike.com/u/HimanshuKumarSingh)\
**Post date:** [February 3, 2018, 7:22am UTC](https://discuss.aerospike.com/t/does-aerospike-delete-the-secondary-index-on-a-bin-if-i-delete-the-bin/4906/3 "2018-02-03T07:22:41Z")

</div>

Okay. I understand that - Deleting a bin from a record removes bin metadata only from that record. But I guess when the bin has been deleted from all the records, the bin-name is still present in the list of 32k bin names until a cold restart. Am i right?

On secondary indexes:

1. If i delete a bin from a record, its entry from the secondary index is removed automatically?
2. If the bin has been deleted from all the records its secondary index would still exist but would be empty?
3. Deleting a secondary index itself (irrespective of weather the bin has been removed from all the records or not) is possible?

---

<div class="post-metadata">

**Author:** ![pgupta](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/pgupta/32/2351_2.png) [@pgupta](https://discuss.aerospike.com/u/pgupta)\
**Post date:** [February 4, 2018, 12:11am UTC](https://discuss.aerospike.com/t/does-aerospike-delete-the-secondary-index-on-a-bin-if-i-delete-the-bin/4906/4 "2018-02-04T00:11:27Z")

</div>

I will answer to the best of my understanding… but you can easily test this on a single node instance. Specifically: "I guess when the bin has been deleted from all the records, the bin-name is still present in the list of 32k bin names until a cold restart. Am i right? "- Not quite - AQL\> show bins … the bin name will still be present as used if you had declared a secondary index on that bin and did not delete the secondary index before cold starting the node. So delete the secondary index - AQL\> drop index … before cold starting the node.

If i delete a bin from a record, its entry from the secondary index is removed automatically? ==\> Yes

If the bin has been deleted from all the records its secondary index would still exist but would be empty? ==\> yes, but I would reword as: the secondary index tied to the bin name and data type is still defined with no entries in it

Deleting a secondary index itself (irrespective of weather the bin has been removed from all the records or not) is possible? – Yes, frees up the RAM used by the secondary index tree.

---

<div class="post-metadata">

**Author:** ![HimanshuKumarSingh](https://avatars.discourse-cdn.com/v4/letter/h/ee59a6/32.png) [@HimanshuKumarSingh](https://discuss.aerospike.com/u/HimanshuKumarSingh)\
**Post date:** [February 4, 2018, 2:19pm UTC](https://discuss.aerospike.com/t/does-aerospike-delete-the-secondary-index-on-a-bin-if-i-delete-the-bin/4906/5 "2018-02-04T14:19:19Z")

</div>

Thanks, I have sufficient info now!

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.aerospike.com/system/32/2274_2.png) [@system](https://discuss.aerospike.com/u/system)\
**Post date:** [February 10, 2018, 2:19pm UTC](https://discuss.aerospike.com/t/does-aerospike-delete-the-secondary-index-on-a-bin-if-i-delete-the-bin/4906/6 "2018-02-10T14:19:26Z")

</div>

This topic was automatically closed 6 days after the last reply. New replies are no longer allowed.
