Question about storing/retrieving data for a complex page


  1. My stack is php and mysql.
  2. I am trying to design a page to display details of a mutual fund.
  3. Data for a single fund is distributed over 15-20 different tables.
  4. Currently, my front-end is a brute-force php page that queries/joins these tables using 8 different queries for a single scheme. It’s messy and poor performing.

I am considering alternatives. Good thing is that the data changes only once a day, so I can do some preprocessing.

An option that I am considering is to create run these queries for every fund (about 2000 funds) and create a complex json object for each of them, store it in mysql indexed for the fund code, retrieve the json at run time and show the data. I am thinking of using the simple json_object() mysql function to create the json, and json_decode in php to get the values for display. Is this a good approach?

I was tempted to store them in a separate MongoDB store – would that be an overkill for this?

Any other suggestion?

Thanks much!


To meet your objective of quick pageviews, your overnight-run approach is very good. You could generate JSON objects with your distilled data, or even prerendered HTML pages, and store them.

You can certainly store JSON objects in MySQL columns. If you don’t need the database server to search the objects, simply use TEXT (or LONGTEXT) data types to store them.

To my way of thinking, adding a new type of server (mongodb) to your operations to store a few thousand JSON objects does not seem worth the the trouble. If you find it necessary to search the contents of your JSON objects, another type of server might be useful, however.

Other things to consider:

  1. Optimize your SQL queries. Read up: and other sources of good info. Consider your queries one-by-one starting with the slowest one. Use the EXPLAIN or even the EXPLAIN ANALYZE command to get your MySQL server to tell you how it plans each query. And judiciously add indexes. Using the tag here on StackOverflow, you can get help. Many queries can be optimized by adding indexes to MySQL without changing anything in your php code or your data. So this can be an ongoing project rather than a big new software release.

  2. Consider measuring your query times. You can do this with MySQL’s slow query log. The point of this is to identify your "dirty dozen" slowest queries in a particular time period. Then, see step one.

  3. Make your pages fill up progressively, to keep your users busy reading while you get the data they need. Put the toplevel stuff (fund name, etc) in server-side HTML so search engines can see it. Use some sort of front-end tech (React, maybe, or Datatables that fetch data via AJAX) to render your pages client-side, and provide REST endpoints on your server to get the data, in JSON format, for each data block in the page.

  4. In your overnight run create a sitemap file along with your JSON data rows. That lets you control exactly how you want search engines to present your data.

Answered By – O. Jones

This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply

(*) Required, Your email will not be published