We want to generate a report with 10,000 records by querying 12 million records from the database and show in an user interface, it's a REST API call. We have two approaches right now to achieve this.
Here is the little background about our database tables design:
Design#1: We uses SQL database and we have a big legacy database table(Single) where it has more than 12 million records in a given time, we always keeps one year data in this table. Every month we have a backup policy, which moves data to a history table, even with this backup policy we end up more than 12 million records.
Design#2: As part of the above big table redesign, we created 12 tables based on certain criteria and we are persisting the above 12 million records into these 12 tables more or less equally, a million records per each table.
Approach#1: Query 12 tables simultaneously using java executor API with callable tasks and send the result to the caller.
Approach#2: Query the single big legacy table and send the result to the caller.
Please suggest me which approach better suits with optimal performance.
Let me know if anything unclear.