douba6361 2012-06-05 12:01
浏览 93
已采纳

PHP mysql_query嵌套循环或重复引用

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.

  • 写回答

1条回答 默认 最新

  • duanchuang3182 2012-06-05 12:03
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?