Mysql VIEWS 与 PHP 查询 [英] Mysql VIEWS vs. PHP query

查看:21
本文介绍了Mysql VIEWS 与 PHP 查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个 Web 应用程序,该应用程序涉及在各种列表中创建餐厅列表,例如Joe 必须访问的地方".现在对于每个餐厅和列表,我在网站上显示了计算

I am working on a web application which involves create list of Restaurants in various lists like "Joe's must visit places". Now for each Restaurant and list, I have display on website which calculates

  • 计算餐厅的受欢迎程度
  • 列表的受欢迎程度
  • 餐厅所在的列表数量

目前我正在 PHP 中使用 MySQL 语句,但计划切换到 MySQL VIEWS 并在 PHP 中执行一个简单的选择语句...

Currently I am using MySQL statements in PHP for this but planning to switch to MySQL VIEWS and do a simple select statement in PHP...

我的问题是,在 PHP 中使用 VIEWS 编写 sql 查询的优点/缺点是什么?

推荐答案

使用视图增加了抽象级别:您以后可以更改表的结构,而不必更改显示有关列表信息的代码,因为您仍将查询视图(尽管视图定义可能会更改).

Using views adds a level of abstraction : you may later change the structure of your tables, and you will not have to change the code that displays the information about the lists, because you will still be querying the view (the view definition may change, though).

主要区别在于每次插入后都会更新视图,这样每当您查询视图时数据就准备好",而使用自定义查询将使 MySQL 每次都计算所有内容(当然有一些缓存).

The main difference is that views are updated after each insertion, such that the data is "ready" whenever you query the view, whereas using your custom query will have MySQL compute everything each time (there is some caching, of course).

最重要的是,如果您的列表更新频率低于查看频率,您会发现使用视图的性能有所提升.

The bottom line is that if your lists are updated less frenquently than they are viewed, you will see some gains in performance in using views.

这篇关于Mysql VIEWS 与 PHP 查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆