查询优化 现有一张表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 里, 那也就是一次性的工作。依然不存在优化问题 PHP+AJAX实现无刷新注册(带用户名实时检测) 在网上搜的贴下来不能使用。。。。网上全是这样的没一个能用,请各位帮忙解决下。 寻找截取字符串方案、用于类似新闻标题的列表显示、超过长度则截取 命令行下mail可以发送邮件,但网页的形式不行 html的规范? 终于可以访问了 web方式能否类似资源管理器? 问些php安全的问题 现在比较好的php新闻系统是什么,小弟想学习 急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急急 header的问题 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 ;