This is a backport of core#19521 [5/17]
https://github.com/bitcoin/bitcoin/pull/19521/commits/3c914d58ff323255b32e717d0ce28209ec0abdaa
partial https://github.com/bitcoin/bitcoin/pull/19521/commits/6a4c0c09ab4d073a26c3c4a02783d5dcd88f6eef
The functional test only checks that "-coinstatsindex" argument does not break anything. The rest of the functional test from commit 6a4c0c09ab is not yet applicable and will be added in the next commit.
Depends on D11598