Optimization on Nested Loop |
I would say that sometimes I have reverted to a loop through one results doing more database queries on one of the values. Although only when I know the loop will only have a few items in it.
Generally it is a bad idea. If the first query returns 50 results you are now doing 50 database queries in your loop. What if it returns 5000 results at some point in the future? The answer is to do a more complex SQL query, where one of your selects has a sub query in it. Personally I find these very difficult to get the format right, so I cannot give an example. Here are some examples from a quick google search: http://beginner-sql-tutorial.com/sql-subquery.htm May not be an example in there for what you are looking for but the point is not to do looped database queries, but to do better sql queries in the first place. Hope that helps, Paul PS Disclaimer - I am no expert on this stuff at all. PSS Narf posted above while I was writing. It seems it is right that you should avoid looped queries. |
Messages In This Thread |
Optimization on Nested Loop - by codeigniter_guru - 11-10-2017, 01:55 AM
RE: Optimization on Nested Loop - by Narf - 11-10-2017, 04:31 AM
RE: Optimization on Nested Loop - by PaulD - 11-10-2017, 04:36 AM
RE: Optimization on Nested Loop - by Narf - 11-10-2017, 06:19 AM
RE: Optimization on Nested Loop - by averroez - 11-14-2017, 12:23 AM
RE: Optimization on Nested Loop - by codeigniter_guru - 12-18-2017, 01:13 AM
RE: Optimization on Nested Loop - by Shawn - 12-22-2017, 03:04 PM
RE: Optimization on Nested Loop - by rolly - 12-24-2017, 02:45 PM
|