开发者

Does MySQL slow down with really high primary key values?

开发者 https://www.devze.com 2023-04-12 18:19 出处:网络
If the values of the primary key in my table range from 200,000,000 to 200,000,100 Will queries be much slower than if the values were 1000 to 1100?开发者_开发百科No. Unless you\'re using char/varcha

If the values of the primary key in my table range from 200,000,000 to 200,000,100

Will queries be much slower than if the values were 1000 to 1100?开发者_开发百科


No. Unless you're using char/varchar fields for those numbers, a number is stored in a fixed-sized raw binary format, and the "size" of a number has no bearing on search speeds - 1 will occupy as much space inside the database as 999999999999.


The answer to your specific question is no, they will not be much slower.

Maybe a few nanoseconds as the extra bits get sent down the wire and processed, but nothing significant.

However, if your question was "will having 200,000,100 rows be slower than 1,100?" then yes, it would be a bit slower.


No, but as others have noted, a larger number of records in your table will generally require more IO to retrieve records, although it can be mitigated through indexes.

The data type for your primary key will make a slight difference (200M still fits into a 4 byte INT, but an 8 byte BIGINT will be slightly larger, and a CHAR(100) would be more wasteful etc). This choice will result in slightly larger storage requirements, for this table, its indexes, and other tables with foreign keys to this table.


Well, define much slower.....

The values 1000-1100 can fit in a SMALLINT (2 bytes) and 200,000,000 will have to be put into an INT (4 bytes). So there can be twice as many records in memory for a SMALLINT as for an INT. So 1000-11000 will be faster


Nope, otherwise the algorithm would be very stupid... Your values perfectly fit into 32 bit integer.


The queries will be exactly the same.

They will be slower, however, when you have between 200,000,000 to 200,000,100 rows in your table when compared to 1000 to 1100 rows.


Not at all. It wouldn't at all. The mysql developers are very particular about high value - speed interoperability.

0

精彩评论

暂无评论...
验证码 换一张
取 消