请问一下php mysql查询效率有关问题

WBOY
Release: 2016-06-13 13:29:48
Original
974 people have browsed it

请教一下php mysql查询效率问题
我需要上传一个excel文档里的数据到mysql数据库中,并且要对excel文件中的身份证这一列进行查询,如果数据库中已经存在了相同的身份证,则这一条记录不会导入。
目前我使用这条语句来查询的:
SELECT id FROM information WHERE idcard = '$sfz' LIMIT 1
如果返回的结果条数大于0,那么就存在了。
可是这样一条一条进行查询并判断后再插入数据库,5000多条数据需要近1分钟的时间才能完成。
请问大家有没有更好的办法呢?

------解决方案--------------------
那就你那样没什么不妥了。或你给idcard 加个索引。

不过像你这样一次select 一次INSERT,更新索引也耗时。
要么设置延时mysql更新索引的时间,
要不全部一次select判断后给记录加个tag标记下再insert。
------解决方案--------------------
楼主还没解决。。。…… 

上面的基本都说了,你测试了那个优就选择那个啊。


又没具体数据跟代码。
解决还是要靠你自己多调试测试拉。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!