查询优化 现有一张表customer,其中数据有1百万条,现在要对它进行查询遍历,$customer = new Customer();$customers = $customer->getAll();foreach($customers as $c) { // ...}这样查询很慢,请问应该怎么优化? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 数据有100万 难道你的查询不应该在SQL里执行获取需要的结果吗?非要得到100万条记录然后来foreach? 表结构是这样CREATE TABLE IF NOT EXISTS `bd_customer` ( `customer_id` int(11) NOT NULL AUTO_INCREMENT, `company_id` int(11) DEFAULT '0', `customer_name` varchar(180) DEFAULT NULL, `enterprise_id` int(11) DEFAULT NULL, `customer_type` tinyint(4) NOT NULL DEFAULT '1', `gender` tinyint(1) NOT NULL DEFAULT '1', `mobile` varchar(13) DEFAULT NULL, `telephone` varchar(20) DEFAULT NULL, `telephone_ext` varchar(10) DEFAULT NULL, `birthday` int(11) DEFAULT NULL, `email` varchar(160) DEFAULT NULL, `fax` varchar(20) DEFAULT NULL, `post_code` varchar(6) DEFAULT NULL, `identify_type` tinyint(1) DEFAULT '0', `identify_code` varchar(50) DEFAULT NULL, `in_time` int(11) NOT NULL, `province_id` tinyint(11) NOT NULL, `city` varchar(20) NOT NULL, `address` varchar(255) DEFAULT NULL, `delete_status` tinyint(1) NOT NULL DEFAULT '0', `capital_word` varchar(1) DEFAULT NULL, `call_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL, `t_cusomter_id` varchar(50) DEFAULT NULL, PRIMARY KEY (`customer_id`), KEY `Index_1` (`enterprise_id`,`telephone`), KEY `Index_2` (`company_id`)) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1105537 ; google mysql 内存表 既然是放到 redis 里, 那也就是一次性的工作。依然不存在优化问题 如何结合checkbox写sql语句 php网站开发文档需要数据流程图吗? 页面A.PHP提交到面面B.PHP时如何让B.PHP页面变量不丢失? mysql存储进程几问——循环流程和变量使用范围、二次使用游标等 linux下php读取excel乱码,服务器不支持iconv函数 共享内存问题 邮件发不出去 这里的js:document.thisform.act.value=1和js:document.thisform.act.value=0是什么意思啊 数据插入的问题 linux gzip压缩页面和图片靠谱么 php 二维数组转一维神奇迷惑 求帮忙看下 php可以写多大的缓存文件,求大家讨论
非要得到100万条记录然后来foreach?
表结构是这样CREATE TABLE IF NOT EXISTS `bd_customer` (
`customer_id` int(11) NOT NULL AUTO_INCREMENT,
`company_id` int(11) DEFAULT '0',
`customer_name` varchar(180) DEFAULT NULL,
`enterprise_id` int(11) DEFAULT NULL,
`customer_type` tinyint(4) NOT NULL DEFAULT '1',
`gender` tinyint(1) NOT NULL DEFAULT '1',
`mobile` varchar(13) DEFAULT NULL,
`telephone` varchar(20) DEFAULT NULL,
`telephone_ext` varchar(10) DEFAULT NULL,
`birthday` int(11) DEFAULT NULL,
`email` varchar(160) DEFAULT NULL,
`fax` varchar(20) DEFAULT NULL,
`post_code` varchar(6) DEFAULT NULL,
`identify_type` tinyint(1) DEFAULT '0',
`identify_code` varchar(50) DEFAULT NULL,
`in_time` int(11) NOT NULL,
`province_id` tinyint(11) NOT NULL,
`city` varchar(20) NOT NULL,
`address` varchar(255) DEFAULT NULL,
`delete_status` tinyint(1) NOT NULL DEFAULT '0',
`capital_word` varchar(1) DEFAULT NULL,
`call_id` varchar(50) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL,
`t_cusomter_id` varchar(50) DEFAULT NULL,
PRIMARY KEY (`customer_id`),
KEY `Index_1` (`enterprise_id`,`telephone`),
KEY `Index_2` (`company_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=1105537 ;