我的应用程序如何从临时表中受益? [英] How can my application benefit from temporary tables?

查看:23
本文介绍了我的应用程序如何从临时表中受益?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了一些有关MySQL中的临时表的信息,但是当涉及到一般的数据库,尤其是MySQL时,我是一个公认的新手.我已经看过有关如何创建临时表的一些示例和MySQL文档,但是我试图确定临时表如何使我的应用程序受益,我想第二是我会遇到什么样的问题.当然,每种情况都是不同的,但是我想我正在寻找的是关于该主题的一些一般性建议.

I've been reading a little about temporary tables in MySQL but I'm an admitted newbie when it comes to databases in general and MySQL in particular. I've looked at some examples and the MySQL documentation on how to create a temporary table, but I'm trying to determine just how temporary tables might benefit my applications and I guess secondly what sorts of issues I can run into. Granted, each situation is different, but I guess what I'm looking for is some general advice on the topic.

我做了一些谷歌搜索,但没有找到我真正想要的主题.如果您有任何经验,我很想听听.

I did a little googling but didn't find exactly what I was looking for on the topic. If you have any experience with this, I'd love to hear about it.

谢谢, 马特

推荐答案

当您要执行相当复杂的SELECT并在该表上执行一堆查询时,临时表通常很有价值.

Temporary tables are often valuable when you have a fairly complicated SELECT you want to perform and then perform a bunch of queries on that...

您可以执行以下操作:


CREATE TEMPORARY TABLE myTopCustomers
   SELECT customers.*,count(*) num from customers join purchases using(customerID)
   join items using(itemID) GROUP BY customers.ID HAVING num > 10;

然后对myTopCustomers进行一堆查询,而不必对每个查询进行购买和商品的联接.然后,当您的应用程序不再需要数据库句柄时,就无需进行清理.

And then do a bunch of queries against myTopCustomers without having to do the joins to purchases and items on each query. Then when your application no longer needs the database handle, no cleanup needs to be done.

几乎总是会看到临时表用于创建昂贵的派生表.

Almost always you'll see temporary tables used for derived tables that were expensive to create.

这篇关于我的应用程序如何从临时表中受益?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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