doudong4532 2010-01-21 13:44
浏览 43
已采纳

PHP与MySQL的数据操作速度

Apologies in advance if this is a silly question but I'm wondering which might be faster/better in the following simplified scenario...

I've got registered users (in a users table) and I've got countries (in a countries table) roughly as follows:

USERS TABLE: user_id (PK, INT) | country_id (FK, TINYINT) | other user-related fields...

COUNTRIES TABLE: country_id (PK, TINYINT) | country_name (VARCHAR) | other country-related fields...

Now, every time I need to display a user's country, I need to do a MySQL join. However, I often need to do lots of other joins with regard to the users and the big picture seems quite "join-heavy".

I'm wondering what the pros & cons might be of taking the countries out of the database and sticking them into a class as an array, from which I could easily retrieve them with public method calls using country_id? Would there be a speed advantage/disadvantage?

Thanks a lot.

EDIT: Thanks for the all the views, very useful. I'll pick the first answer as the accepted solution although all contributions are valued.

  • 写回答

5条回答 默认 最新

  • dpf71390 2010-01-21 13:49
    关注

    It would ease stress on your MySQL server to have less JOIN statements, but not significantly so (there aren't that many countries in the world). However, you'll make up that time in the fact that you'll have to implement the JOIN yourself in PHP. And since you're writing it yourself, you will probably write it less efficiently than the SQL statement, which means that it will take more time. I would recommend keeping it in the SQL server, since the advantages of moving it out are so few (and if the PHP instance and the MySQL instance are on the same box, there are not real advantages).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 Revit2020下载问题
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 单片机无法进入HAL_TIM_PWM_PulseFinishedCallback回调函数
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线