From what I understand, blockchains are not optimised for searching for past transactions. Does Etherscan download the data into another database for more performant querying? If so, how can it download the data and what does it use the query it?
Etherscan – Understanding How Etherscan Works
etherscango-ethereum
Best Answer
If you want to do analytics, the trick is scrapping the whole blockchain into an indexed database. My advice is that you get a SQL database, and write a program that queries a node for its blocks, one by one, then you get the transactions and the transactions receipts, which you can query again for more data. Is up to you which fields interest you the most, to which you want to apply the right indexing.
Here is the structure of a block
From https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_getblockbyhash
Then you get hashes for transactions, which you can perform for each, two queries
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionbyhash
https://github.com/ethereum/wiki/wiki/JSON-RPC#eth_gettransactionreceipt