How to add new STORING column to index

98 views Asked by At

How can I change a secondary index? For example: I want to add a new column to the STORING specification.

1

There are 1 answers

0
Mike Curtiss On BEST ANSWER

If you want to update an index to store a new column in its STORING clause, it takes a few steps. Cloud Spanner does not support updating index schemas directly, so you'll need to create a new index and drop your old index. For example, if you have an old index, "myindex", that you're trying to update:

  1. Create a new index, "myindex2" (or whatever name you wish), that has your desired STORING specification.
  2. Note that backfilling a new index can take hours or days. You will know when the index is created once the long-running operation for the schema change is complete.
  3. Update your application code to start using myindex2.
  4. Drop your old index.

Note that, if you want your new index to have the same name as the old index, you could repeat the same steps as above to re-create myindex. However, there will still be a temporary period where you won't have an index called "myindex" (this could last hours to days), so your application code would need to be resilient to this. It's typically easiest just to update your application code to point at the new index name.