我如何在 32 位操作系统中存储 BIGINT 数字
我在带有 32 位 PIXEL OS(Raspbian 版本)的 raspberry pi 3(64 位 SoC)上运行 LAMP 堆栈.我在 MySQL 中创建了一个新表,并将主键设置为 unsigned BIGINT(20).最初我认为数据库只会截断溢出的数字或其他东西,但它实际上可以存储大于约 40 亿的数字.更准确地说,我存储了数字 5201702020.这怎么可能?
I am running a LAMP stack on a raspberry pi 3 (64-bit SoC) with 32-bit PIXEL OS (a Raspbian version). I created a new table in MySQL and I set the Primary Key as unsigned BIGINT(20). Initially I thought that the database will just truncate the overflowing digits or something but it can actually store bigger numbers than ~4 billion. To be more precise I stored the number 5201702020. How is that possible?
推荐答案
查看 MySQL 源码,发现至少有 4 处对 BIGINT 的引用:
Looking in the MySQL source code, I found at least 4 references to BIGINT:
1) "BIGINT":
1) "BIGINT":
- https://github.com/mysql/mysql-server/blob/5.7/storage/innobase/pars/pars0lex.l#L560
回复PARS_BIGINT_TOKEN":
que retorna "PARS_BIGINT_TOKEN":
- https://github.com/mysql/mysql-server/blob/5.7/storage/innobase/include/pars0grm.h#L247
2) 作为结构体:
- https://github.com/mysql/mysql-server/blob/5.7/strings/dtoa.c#L627
3) 在很多地方作为 int64_t 或 uint64_t
3) As int64_t or uint64_t in many places
4) Java 语言类型,在所有 java 文件中.
4) Java language type, in all java files.
并且,回答您的问题:
情况 (1) 和 (2) 将由源代码实现/逻辑处理.
The situations (1) and (2) will be handled by source code implementation/logics.
情况 (3) 将由编译器处理,而不是操作系统.编译器将对 BigInt 变量和值进行所有必要的转换以完成工作.
The situation (3) will be handled by the compiler, not the OS. The compiler will make all the necessary transformations to BigInt variables and values to accomplish the job.
情况 (4) 将由 JVM 处理,而不是像编译器那样由 OS 处理.
The situation (4) will be handled by JVM, not the OS, as the compiler does.
相关文章