Does using a smallint datatype in a mysql table over a regular int actually improve memory usage? Wouldn't the hardware just allocate a full 64 bit word size for all data anyway? If it doesn't allocate a full word, then wouldn't we see a performance decrease from having to parse out multiple smallints or tinyints from a 64 bit word allocated in memory?

Basically, is there any design/memory/performance benefit to using the following table over the one after it, assuming we know the range of the values stored in the Status column will never exceed the max/min range of smallint? Any insight would be appreciated:

create table `TestTableWithSmallInt` (

`ID` bigint(20) NOT NULL AUTO_INCREMENT,

`Status` smallint(11) DEFAULT 0,

PRIMARY KEY (`ID`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

create table `TestTableWithInt` (

`ID` bigint(20) NOT NULL AUTO_INCREMENT,

`Status` int(11) DEFAULT 0,

PRIMARY KEY (`ID`)

) ENGINE=InnoDB DEFAULT CHARSET=utf8;

解决方案

You'll theoretically save two bytes per row, a SMALLINT is a 16-bit signed integer versus the INT which is 32-bit signed. The various types have varying storage requirements.

Normally the savings between INT and SMALLINT produces such a slim performance improvement that you'll have a hard time measuring it, especially if there's a small number of fields you're trimming this way.

For the opposite, you'll only want to use a BIGINT when it's conceivable that you might exhaust the number space of an AUTO_INCREMENT flagged field.

You should probably declare them in their bare types, without a length, to get the best fit. INT is preferable to INT(11) and SMALLINT(11) is misleading as it's impossible to get that much precision from a 16-bit value.

mysql的smallint,在MySQL中对int使用smallint数据类型是否确实节省了内存?相关推荐

  1. mysql smallint范围_mysql中的int smallint 取值范围

    tinyint 从 -2^7 (-128) 到 2^7 - 1 (123) 的整型数据.存储大小为 1 个字节. unsigned 是从 0 到 255 的整型数据. 所以建表的时候 只能是tinyi ...

  2. mysql数据库中的int类型_mysql数据类型

    mysql数据类型-int int 的有符号和无符号的区别 有符号的int可以插入负值,无符号的int不可以插入负值 整型的每一种都分无符号(unsigned)和有符号(signed)两种类型(flo ...

  3. mysql 定义年龄属性_sql中定义年龄用什么数据类型,长度为多少?

    展开全部 sql中定义年龄可以用的用数据类型及长度: 1.char(3) :长度为3的字符串.小于10位且62616964757a686964616fe59b9ee7ad943133343137386 ...

  4. 在python中、int表示的数据类型是_python--002--数据类型(int、str)

    1. 整型 int int().bit_length() v = int("a", base=16) #表示以16进制转换a print(v) age= 5r= age.bit_l ...

  5. 复制MySQL实时_自制mysql主从复制(实时)软件——实现

    以下是主要的java实现代码:具体设计参考 1.create table package migrate; import java.util.ArrayList; import java.util.V ...

  6. mysql smallint 长度_mysql中int、bigint、smallint 和 tinyint长度范围和区别

    最近使用mySQL数据库的时候遇到了多种数字的类型,主要有int,bigint,smallint和tinyint.其中比较迷惑的是int和smallint的差别.今天就在网上仔细找了找,找到如下内容, ...

  7. mysql:列类型之整数(tinyint、smallint、mediumint、int、bigint)

    环境: window10 vs2022 .net core 3.1 mysql 8.0.25 DBeaver 参考: <mysql:11.1.2 Integer Types (Exact Val ...

  8. 用通俗易懂的大白话彻底搞明白mysql的数据类型以及mysql中的int(11),这个11到底是啥?

    今天抽时间来讲一下mysql里的知识点,之前有不少人问过我,mysql中的int(11),这个11到底是啥意思?是11位的意思吗?你是否也想过这个问题,是否也有这个疑问? ok,今天就展开来讲一下,用 ...

  9. MYSQL数据类型-整数数据类型(bigInt、int、smallint、tinyint)区别

    整数型数据包括bigint型.int型.smallint型和tinyint型 bigint型数据的存储大小为8个字节,共64位.其中63位用于表示数值的大小,1位用于表示符号.bigint型数据可以存 ...

最新文章

  1. python turtle库有什么用_Python中turtle库的使用
  2. android 常用方法集合
  3. 涨姿势时间:为什么飞机的往返时间会不一样?
  4. Nginx 通过 Lua + Redis 实现动态封禁 IP
  5. qt linux 聊天室,Qt网络聊天室客户端
  6. [翻译] 比较 Node.js,Python,Java,C# 和 Go 的 AWS Lambda 性能
  7. gis 联合 融合_GIS技术进化 | 我们为何需要跨平台GIS技术体系?
  8. Java热搜问题大整理
  9. dell服务器经常自动关机,戴尔电脑老是自动关机的解决方法
  10. [javaSE] 基本类型(String相关)
  11. 面向对象系列(三)-抽象类的特点
  12. 第九篇:稳定性之面向失败设计【可用性架构设计、可用性容灾】
  13. win10用易语言需要C环境,win10系统易语言打开支持库配置就崩溃的具体教程
  14. 蓝牙BR/EDR和Bluetooth Smart的十大重要区别
  15. 更改计算机睡眠时间无法打开,win7怎么设置电脑睡眠时间 win7电脑睡眠后黑屏打不开...
  16. xmind可以画流程图吗_怎样用XMind方便地制作流程图
  17. 【SemiDrive源码分析】【X9芯片启动流程】08 - X9平台 lk 目录源码分析 之 目录介绍
  18. E-mail Marketing 的特点及其利弊
  19. 风电随机性动态经济调度模型(Matlab代码实现)
  20. matlab如何求解sbm模型,非期望产出的SBM模型代码问题

热门文章

  1. STM32F407 读保护,写保护,解锁过程【芯片已设置读保护,无法读取更多信息】...
  2. 软件工程(可行性研究)
  3. (20210223已解决)Grafana经常出现Bad Gateway
  4. AI机器人大规模上岗之后,我们会变得更好吗?
  5. java实现小数转百分数
  6. DSPF28335学习之(3)CCS5.5字体设置、代码颜色设置及快速注释
  7. 计算广告、推荐系统论文以及DSP综述
  8. mybatis错误:Type interface com.sks.dao.UserDao is not known to the MapperRegistry.
  9. 呵呵,您可真牛逼啊!
  10. python traceback_Python 捕捉traceback异常栈信息