Say a contract factory is used to spawn multiple child contracts, each with associated data within them. The contract factor stores all addresses of the derived contracts along with a unique name of each contract. Is there an easy, efficient way to query information across all the child contracts?
For example, say the child contracts represent people; is it possible to write a query to return all child contracts that have a particular age, name and location of birth (where these properties are member variables on the child contracts). This is in effect running a SQL query over all the child contracts.
Clearly, the naive solution is to iterate over all child contracts from the map within the factory. This is not ideal in any way. Alternatively, an offchain solution could be built where a linking table is made offchain with the associated contract addresses. This solution really is not ideal as I'd like to keep to an on-chain solution. This also results in duplication of data on chain, making the blockchain redundant.
In simple terms: is there a way to build an efficient query structure in order to search for contracts, if the contract addresses are known. This sounds very much like a relational database but running on-chain. IPFS wont help in this context as you are effectively stuck with the same query problem; how to search effectively through all records for particular sub information within entries.