操纵 15+用php在mysql中存储百万条记录?

发布于 2024-10-10 08:51:16 字数 286 浏览 0 评论 0原文

我有一个包含 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

愛上了 2024-10-17 08:51:16

如果您只想检查它是否存在,请尝试不使用count。只需简单地从用户中选择用户名,其中 username='webdev' LIMIT 1 可能会更快。

另外,将列类型更改为 varchar(如果尚未更改)。不要使用文本类型。它要慢得多。

If you just want to check that it exists or not, try not using the count. Just a simple select 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 user text type. It's much much slower.

画中仙 2024-10-17 08:51:16

这可能是一个没有实际意义的问题,但为了测试并查看用户名是否已经存在,我将发出以下查询(对 shamittomar 的查询稍加修改):

SELECT DISTINCT `username` FROM `users` WHERE `username` = 'webdev';

默认情况下,这将返回“用户名”栏;但是,如果添加更多参数,可能会改变结果。一个例子是,如果您运行

SELECT DISTINCT `user_id`, `username` FROM `users` WHERE `username` = 'webdev';

它将返回“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):

SELECT DISTINCT `username` FROM `users` WHERE `username` = 'webdev';

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

SELECT DISTINCT `user_id`, `username` FROM `users` WHERE `username` = 'webdev';

it would return all unique combinations of "user_id" and "username".

风透绣罗衣 2024-10-17 08:51:16

您可以做的一件事是将用户名的索引从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 a limit 1 at the end even though it will only help if the value already exists.

这个俗人 2024-10-17 08:51:16

您的用户名是唯一的,因此您必须在查询中将限制设置为 1,这样会更快

select count(uid) from users where username='webdev' limit 1

your user name is unique so you must set limit of 1 in your query it will be more faster

select count(uid) from users where username='webdev' limit 1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文