I have a relatively simple program which displays information and activity of users which – due to the architecture of the program requires referencing lots of different data in different ways.
For example I have a users who can have different levels of status within different or multiple groups and these groups can have their own statuses. My question is about best practices for referencing lots of data and the speed/logic of the code.
- Option A – have several instances data within the data base and reference this and update this individually over several tables using simple statements and queries.
- Option B – use many nested queries and if statements to retrieve multiple bits of data
Simply put: is it best to use lots of nested queries within loops and if statements, or break the different sets of data up with in a database and reference them individually? I’m after reliability and speed rather than technical wizardry.
I know this may be very specific to my program, but I would like to know the general opinion of developers out there and their experience without getting too deep in to examples.
Joins can be expensive because of a heavy temp table which is produced in the middle of operation. But an accurate data extraction can be more logical in this case. It is very dependent to your data model, tables, references, insert rate, update rate, query rate on the tables. Maybe some queries should be written using joins, maybe some of them better to be written using procedures.