3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ridgepoleにおけるintとbigintでのlimitの違い

Posted at

結論

  • intではmysqlの型が変わる
    • ただし有効はものは1から5まで
  • bigintではlimitは意味を持たない

詳細

schemaファイル

create_table :limit_schema do |t|
  t.integer     :int_limit_1,        limit: 1, null: false, default: 0
  t.integer     :int_limit_2,        limit: 2, null: false, default: 0
  t.integer     :int_limit_3,        limit: 3, null: false, default: 0
  t.integer     :int_limit_4,        limit: 4, null: false, default: 0
  t.integer     :int_limit_5,        limit: 5, null: false, default: 0
  t.integer     :int_limit_6,        limit: 6, null: false, default: 0
  t.integer     :int_limit_7,        limit: 7, null: false, default: 0
  t.integer     :int_limit_8,        limit: 8, null: false, default: 0
  t.bigint      :bigint_limit_1,     limit: 1, null: false, default: 0
  t.bigint      :bigint_limit_2,     limit: 2, null: false, default: 0
  t.bigint      :bigint_limit_3,     limit: 3, null: false, default: 0
  t.bigint      :bigint_limit_4,     limit: 4, null: false, default: 0
  t.bigint      :bigint_limit_5,     limit: 5, null: false, default: 0
  t.bigint      :bigint_limit_6,     limit: 6, null: false, default: 0
  t.bigint      :bigint_limit_7,     limit: 7, null: false, default: 0
  t.bigint      :bigint_limit_8,     limit: 8, null: false, default: 0
end

limitの値を変えていくとintの型が変わる

  `int_limit_1` tinyint(4) NOT NULL DEFAULT '0',
  `int_limit_2` smallint(6) NOT NULL DEFAULT '0',
  `int_limit_3` mediumint(9) NOT NULL DEFAULT '0',
  `int_limit_4` int(11) NOT NULL DEFAULT '0',
  `int_limit_5` bigint(20) NOT NULL DEFAULT '0',
  `int_limit_6` bigint(20) NOT NULL DEFAULT '0',
  `int_limit_7` bigint(20) NOT NULL DEFAULT '0',
  `int_limit_8` bigint(20) NOT NULL DEFAULT '0',
  `bigint_limit_1` bigint(20) NOT NULL DEFAULT '0',
  `bigint_limit_2` bigint(20) NOT NULL DEFAULT '0',
  `bigint_limit_3` bigint(20) NOT NULL DEFAULT '0',
  `bigint_limit_4` bigint(20) NOT NULL DEFAULT '0',
  `bigint_limit_5` bigint(20) NOT NULL DEFAULT '0',
  `bigint_limit_6` bigint(20) NOT NULL DEFAULT '0',
  `bigint_limit_7` bigint(20) NOT NULL DEFAULT '0',
  `bigint_limit_8` bigint(20) NOT NULL DEFAULT '0',
  • intはlimitによって型が変わる
    • limit: 1: tinyint
    • limit: 2: smallint
    • limit: 3: mediumint
    • limit: 4: int
    • limit: 5: bigint
  • bigintに関してはlimitは必要ない

ちなみにmysql5.6でのストレージ要件

TINYINT 1 バイト
SMALLINT 2 バイト
MEDIUMINT 3 バイト
INT、INTEGER 4 バイト
BIGINT 8 バイト

参考リンク

http://qiita.com/Yinaura/items/cede8324d08993d2065c
https://dev.mysql.com/doc/refman/5.6/ja/storage-requirements.html

3
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?