Site icon Hip-Hop Website Design and Development

Create a Dozens of indexable pages with dynamic content

I have a website with 5000 of custom posts and need to create a relation pages between all of those.
This 25 000 000 pages should be indexable.
I would like to avoid inflate our database and we don’t need edit functionality as the content would be generated dynamically.

Right now there is only one idea:
With WordPress API add custom rewrite rule, register all this relations in xml sitemap and point to some php file which will generate the content.
Do you have other better proposal and if there any limitation with it?