explorer-backend icon indicating copy to clipboard operation
explorer-backend copied to clipboard

DB Index is created over ergoTreeTemplate which is being created for all ergoTrees instead of just P2PK

Open pragmaxim opened this issue 1 year ago • 1 comments

Hi,

This might improve performance a lot in both query time and indexing time.

Problem :

  • ErgoTreeTemplate is created here for ALL ErgoTrees instead of just P2SH. The Template is always the same for P2PK which creates a SuperNode containing extreme amount of boxes https://github.com/ergoplatform/explorer-backend/blob/master/modules/chain-grabber/src/main/scala/org/ergoplatform/explorer/indexer/extractors/package.scala#L139
  • creating db Index over this column with supernodes is quite inefficient https://github.com/ergoplatform/explorer-backend/blob/master/modules/explorer-core/src/main/resources/db/V9__Schema.sql#L153

pragmaxim avatar Jun 25 '23 16:06 pragmaxim

I overlooked that the index is already skipping the FeeContract https://github.com/ergoplatform/explorer-backend/blob/master/modules/explorer-core/src/main/resources/db/V9__Schema.sql#L153 WHERE NOT ergo_tree_template_hash = 'd19683030193a38cc7b2a57300000193c2b2a57301007473027303830108cdeeac93b1a57304'; This should be done even for any P2PK as they all have the same template

Ideally storing NULL in these cases and then do :

CREATE INDEX "node_outputs__ergo_tree_template_hash" ON node_outputs (ergo_tree_template_hash)
    WHERE ergo_tree_template_hash IS NOT NULL;

pragmaxim avatar Jun 26 '23 06:06 pragmaxim