本文实例讲述了mysql使用临时表加速查询的方法。分享给大家供大家参考。具体分析如下:
使用MySQL临时表,有时是可以加速查询的,下面就为您详细介绍使用MySQL临时表加速查询的方法。
把表的一个子集进行排序并创建MySQL临时表,有时能加速查询。它有助于避免多重排序操作,而且在其他方面还能简化优化器的工作。例如:
代码如下:
SELECT cust.name,rcVBles.balance,……other columns
SELECT cust.name,rcVBles.balance,……other columns
FROM cust,rcvbles
WHERE cust.customer_id = rcvlbes.customer_id
AND rcvblls.balance>0
AND cust.postcode>"98000"
ORDER BY cust.name
代码如下:
SELECT cust.name,rcvbles.balance,……other columns
SELECT cust.name,rcvbles.balance,……other columns
FROM cust,rcvbles
WHERE cust.customer_id = rcvlbes.customer_id
AND rcvblls.balance>0
ORDER BY cust.name
INTO TEMP cust_with_balance
代码如下:
SELECT * FROM cust_with_balance
WHERE postcode>"98000"
注意:临时表创建后不会反映主表的修改。在主表中数据频繁修改的情况下,注意不要丢失数据。
希望本文所述对大家的MySQL数据库程序设计有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号