MySql 性能问题:MD5(值)
出于安全目的,我以这种方式进行一些查询:
SELECT avatar_data FROM users WHERE MD5(ID) ='md5value'
因此,例如我有以下条目:
-TABLE.users-
ID | avatar_data
39 | some-data
我执行此查询:
SELECT avatar_data FROM users WHERE MD5(ID) ='d67d8ab4f4c10bf22aa353e27879133c'
'd67d8ab4f4c10bf22aa353e27879133c'
是通过过滤的 '39'
值MD5。
我有一个非常大的数据库,有很多条目。我想知道这种方法是否会损害数据库性能?
for security purpose I do some queries in this way:
SELECT avatar_data FROM users WHERE MD5(ID) ='md5value'
So, for example I have this entries:
-TABLE.users-
ID | avatar_data
39 | some-data
I do this query:
SELECT avatar_data FROM users WHERE MD5(ID) ='d67d8ab4f4c10bf22aa353e27879133c'
'd67d8ab4f4c10bf22aa353e27879133c'
is the '39'
value filtered by MD5.
I have a VERY large database with a lot of entries. I wonder if this approach might compromise the DB performance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
因为您正在要搜索的列上使用函数( MD5(ID)= ),所以 MySQL 将必须执行全表扫描。
虽然我不确定您进行此类搜索的原因,但为了加快速度,我建议您添加另一列,其中包含已处理的 ID 数据并为其建立索引。
所以你应该这样做:
Because you are using a function on the column you want to search ( MD5(ID)= ), MySQL will have to do a full table scan.
While I am not sure your reason for doing a search like that, to speed things up, I can suggest you add another column with the processed ID data and index it.
So you should do:
使用该查询并且没有功能索引,是的,您将对整个事物进行表扫描。如果您经常这样做,您可能需要将摘要预先计算到代理表或另一列中,直接索引和查找。
With that query and without functional indexes, yes you would table-scan the whole thing. If you do that often, you may want to pre-compute the digest into a surrogate table or in another column, index and lookup directly.
是的,这可能会变得非常慢,而且它确实不会增加任何安全性。 “39”的 MD5 很容易算出来。为了使单向哈希成功,它需要包含攻击者未知的值。否则,攻击者只会对值进行哈希处理,而您并没有真正完成任何事情。
您可以考虑发布更多有关您正在做的事情的信息。例如:这是一个网络管理工具吗?有密码保护吗? ETC。
Yes that would probably get very slow and it really doesn't add any security. MD5 of '39' is pretty easy to figure out. For a one way hash to be successful it needs to contain values that would be unknown to an attacker. Otherwise the attacker is just going to hash the value and you've not really accomplished anything.
You might consider posting more about what you're doing. For example: is this a web administration tool? Is it password protected? Etc.
如果您想要这种安全性,那么将密码保存为 md5 哈希值可能会更好。编码 id 并不能真正提供安全性
if you want this kind of security you probably be better out if you save the passwords as a md5 hash. encoding id's dont realy give security