On the other hand, it looks appealing to make index_set_state_flags() transactional. This would solve the consistency problem, and looking at the code scanning pg_index, I don't see a reason why we could not do that. What do you think?
TBH, I am not sure. I think it is a reasonable change. It is even indicated in the
comment above index_set_state_flags() that it can be made transactional.
At the same time, probably we can just go ahead with current
inconsistent update of relisreplident and indisvalid flags. Can't see what