操纵 15+用php在mysql中存储百万条记录?
我有一个包含 15+ 百万条记录的用户表,在执行注册功能时,我希望检查用户名是否已存在。我为用户名列建立了索引,当我运行查询“select count(uid) from users where username='webdev'”
时,。嗯,一直在加载黑屏,最后挂断了。我在本地主机中使用 php 5 & 执行此操作mysql 5。所以建议我一些技术来处理这种情况。
mongodb 是在我们的本地计算机上处理此过程的良好替代方案吗?
谢谢, 尼西什。
I got a user table containing 15+ million records and while doing the registration function i wish to check whether the username already exist. I did indexing for username column and when i run the query "select count(uid) from users where username='webdev'"
,. hmmm, its keep on loading blank screen finally hanged up. I'm doing this in my localhost with php 5 & mysql 5. So suggest me some technique to handle this situation.
Is that mongodb is good alternative for handling this process in our local machine?
Thanks,
Nithish.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您只想检查它是否存在,请尝试不使用
count
。只需简单地从用户中选择用户名,其中 username='webdev' LIMIT 1
可能会更快。另外,将列类型更改为
varchar
(如果尚未更改)。不要使用文本
类型。它要慢得多。If you just want to check that it exists or not, try not using the
count
. Just a simpleselect username from users where username='webdev' LIMIT 1
may be faster.ALSO, change the column type to
varchar
, if it's not already so. Don't usertext
type. It's much much slower.这可能是一个没有实际意义的问题,但为了测试并查看用户名是否已经存在,我将发出以下查询(对 shamittomar 的查询稍加修改):
默认情况下,这将返回“用户名”栏;但是,如果添加更多参数,可能会改变结果。一个例子是,如果您运行
它将返回“user_id”和“username”的所有唯一组合。
This might be a moot point, but to test and see if the user name already exists, I would issue the following query (a slight modification on shamittomar's query):
This will, by default, return the only instance of "webdev" in the "username" column; if you add more parameters, though, it could change your results. An example being, if you run
it would return all unique combinations of "user_id" and "username".
您可以做的一件事是将用户名的索引从
index更改为unique
,这将使搜索速度更快,就像shamittomar所说,甚至在最后添加一个limit 1
尽管只有当该值已经存在时它才会有帮助。One thing you can do is change the indexing of the username from
index to unique
that will make the search much much faster and like shamittomar said add alimit 1
at the end even though it will only help if the value already exists.您的用户名是唯一的,因此您必须在查询中将限制设置为 1,这样会更快
your user name is unique so you must set limit of 1 in your query it will be more faster