简体   繁体   English

mysql性能问题

[英]mysql performance question

Is a search through numbers (INT) faster than characters in an mySQL database? 通过数字(INT)搜索比使用MySQL数据库中的字符快吗? Regards, Thijs 此致Thijs

Yes, it should be. 是的,应该如此。 An int is only 4 bytes, while in a text ( varchar ) might be considerably bigger. 一个int只有4个字节,而文本( varchar )可能更大。

Besides, if you have an index on the field you are searching, it will be smaller in size. 此外,如果您要搜索的字段上有索引,则索引的大小会较小。 Hence, you might need fewer disk accesses to do an index scan . 因此,执行index scan可能需要较少的磁盘访问index scan

In practice the difference will be small - it will increase depending on the relative length of the 2 fields. 实际上,差异将很小-它将根据2个字段的相对长度而增加。 The question pre-supposes that 2 are interchangeable - which is a very bad assumption given that MySQL natively supports an ENUM data-type. 该问题预先假设2是可互换的-考虑到MySQL本机支持ENUM数据类型,这是一个非常糟糕的假设。

If it's that important to you, why not measure it? 如果这对您很重要,为什么不测量它呢?

If the INT and VARCHAR consumes the same amount of space the difference should be negligible, even though INT probably will come out on top. 如果INT和VARCHAR占用相同的空间量,则即使INT可能会排在首位,差异也可以忽略不计。

Databases don't use black magic. 数据库不使用黑魔法。 They need to physically access data like everyone else. 他们需要像其他所有人一样物理访问数据。 Table rows consume disk space. 表行占用磁盘空间。 Reading 100 mb is faster than reading 200 mb. 读取100 mb比读取200 mb快。 Always. 总是。

Therefore. 因此。 this affects everything. 这影响到一切。 Smaller rows means more rows per "block". 较小的行意味着每个“块”有更多的行。 More rows per block means more rows fetched per disk access. 每个块更多的行意味着每个磁盘访问获取更多的行。 Fewer blocks in total means that a larger percentage of the rows will fit in various buffer caches. 总共更少的块意味着较大的行百分比将适合各种缓冲区高速缓存。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM