db: Add index on utxoset.spendheight to speed up blockchain reorgs

Otherwise we would be doing a table scan per block being reorged/rescanned.

Signed-off-by: Christian Decker <decker.christian@gmail.com>
This commit is contained in:
Christian Decker 2018-03-04 02:23:41 +01:00
parent e44ea0b363
commit 50a8e32e3f

View File

@ -227,6 +227,9 @@ char *dbmigrations[] = {
" satoshis BIGINT,"
" PRIMARY KEY(txid, outnum));",
"CREATE INDEX short_channel_id ON utxoset (blockheight, txindex, outnum)",
/* Necessary index for long rollbacks of the blockchain, otherwise we're
* doing table scans for every block removed. */
"CREATE INDEX utxoset_spend ON utxoset (spendheight)",
NULL,
};