网站首页  汉语字词  英语词汇  考试资料  写作素材  旧版资料

请输入您要查询的考试资料:

 

标题 mysql使用临时表加速查询的方法
内容
    本文实例讲述了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
    临时表中的行要比主表中的行少,而且物理顺序就是所要求的顺序,减少了磁盘i/o,所以查询工作量可以得到大幅减少。
    注意:临时表创建后不会反映主表的修改。在主表中数据频繁修改的情况下,注意不要丢失数据。
    希望本文所述对大家的mysql数据库程序设计有所帮助。
随便看

 

在线学习网考试资料包含高考、自考、专升本考试、人事考试、公务员考试、大学生村官考试、特岗教师招聘考试、事业单位招聘考试、企业人才招聘、银行招聘、教师招聘、农村信用社招聘、各类资格证书考试等各类考试资料。

 

Copyright © 2002-2024 cuapp.net All Rights Reserved
更新时间:2025/5/19 21:51:27