当前位置: 网学 > 编程文档 > MySQL > 正文

提高MySQL 查询效率的三个技巧

来源:Http://myeducs.cn 联系QQ:点击这里给我发消息 作者: 用户投稿 来源: 网络 发布时间: 13/08/02
externalIP;       insertbind.is_null = 0;       insertbind.length = 0;             insertbind.buffer_type = MYSQL_TYPE_SHORT;       insertbind.buffer = (char *)&m_stInsertParam->externalPort;       insertbind.is_null = 0;       insertbind.length = 0;        insertbind.buffer_type = MYSQL_TYPE_LONG;       insertbind.buffer = (char *)&m_stInsertParam->internalIP;       insertbind.is_null = 0;       insertbind.length = 0;        insertbind.buffer_type = MYSQL_TYPE_SHORT;       insertbind.buffer = (char *)&m_stInsertParam->internalPort;       insertbind.is_null = 0;       insertbind.is_null = 0;       //绑定       if (mysql_stmt_bind_param(m_stInsertStmt, insertbind))              return false;       return true;} //2.查询bool CDBManager::InsertHostCache2(MYSQL * connecthandle, char * sessionid, char * channelid, int ISPtype,               unsigned int eIP, unsigned short eport, unsigned int iIP, unsigned short iport){       //填充结构变量m_sInsertParam       strcpy(m_stInsertParam->sessionid, sessionid);       strcpy(m_stInsertParam->channelid, channelid);       m_stInsertParam->ISPtype = ISPtype;       m_stInsertParam->externalIP = eIP;       m_stInsertParam->externalPort = eport;       m_stInsertParam->internalIP = iIP;       m_stInsertParam->internalPort = iport;       //执行statement,性能瓶颈处       if(mysql_stmt_execute(m_stInsertStmt))              return false;       return true;} l         随机的获取记录在某些数据库的应用中, 我们并不是要获取所有的满足条件的记录,而只是要随机挑选出满足条件的记录. 这种情况常见于数据业务的统计分析,从大容量数据库中获取小量的数据的场合.      有两种方法可以做到1.       常规方法,首先查询出所有满足条件的记录,然后随机的挑选出部分记录.这种方法在满足条件的记录数很多时效果不理想.2.       使用limit语法,先获取满足条件的记录条数, 然后在sql查询语句中加入limit来限制只查询满足要求的一段记录. 这种方法虽然要查询两次,但是在数据量大时反而比较高效.示例代码如下: //1.常规的方法//性能瓶颈,10万条记录时,执行查询140ms, 获取结果集500ms,其余可忽略int CDBManager::QueryHostCache(MYSQL* connecthandle, char * channelid, int ISPtype, CDBManager::CHostCacheTable * &hostcache){           char selectSQL[SQL_LENG
  • 上一篇资讯: MySQL中group_concat函数
  • 网学推荐

    免费论文

    原创论文

    设为首页 | 加入收藏 | 论文首页 | 论文专题 | 设计下载 | 网学软件 | 论文模板 | 论文资源 | 程序设计 | 关于网学 | 站内搜索 | 网学留言 | 友情链接 | 资料中心
    版权所有 QQ:3710167 邮箱:3710167@qq.com 网学网 [Myeducs.cn] 您电脑的分辨率是 像素
    Copyright 2008-2015 myeducs.Cn www.myeducs.Cn All Rights Reserved 湘ICP备09003080号