MySQL 中的 BIT(1) 与 ENUM(“未知”、“男性”、“女性”)
就性能而言,使用 BIT(1) NULL
(null = 未知,0 = 男性,1 = 女性)或 ENUM('unknown', 'male', 'female') NOT NULL DEFAULT 'unknown'
in MySQL MyISAM?
或者这被认为是微优化?
[编辑]
我想我会使用 ENUM('male', 'female') DEFAULT NULL
In performance terms, what will be faster, use a BIT(1) NULL
(null = unknown, 0 = male, 1 = female) or ENUM('unknown', 'male', 'female') NOT NULL DEFAULT 'unknown'
in MySQL MyISAM?
Or this is considered micro-optimization?
[EDIT]
I think I'm going to use ENUM('male', 'female') DEFAULT NULL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,这就是微优化。性能将由其他因素决定,并且无论如何,可空字段会占用更多空间(对于空标志),因此请使用有意义的枚举。
Yes, this is microoptimization. Performance will be dominated by other things, and anyway nullable fields take more space (for a null flag) so use the meaningful enumeration.
我认为这是微观优化。
我会选择 ENUM 选项,因为所有值的含义都完全清楚,无需阅读文档。位选项有点模糊。
关于性能,我似乎记得 NULL 通常很糟糕,但现在找不到参考。
I consider this micro-optimization.
I would go for the ENUM option, because the meaning of all values is completely clear without reading documentation. The bit option is a bit vague.
Regarding performance, I seem to remember NULL is usually bad, but can't find references right now.