Last active
August 29, 2015 14:27
-
-
Save sifue/db30a7b4179543d21f9e to your computer and use it in GitHub Desktop.
MySQL InnoDBの介在する大規模サービスにおけるID生成戦略について ref: http://qiita.com/sifue/items/c9192726bdce4b4a6dd7
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create table `user_relations` ( | |
| `from_user_id` int NOT NULL, | |
| `to_user_id` int NOT NULL, | |
| `from_user_id_dummy` VARCHAR(124) NOT NULL, | |
| `to_user_id_dummy` VARCHAR(124) NOT NULL, | |
| `created_time` DATETIME NOT NULL, | |
| PRIMARY KEY (`from_user_id`, `to_user_id`), | |
| INDEX `relation_index_created_time` (`from_user_id`, `to_user_id`, `created_time` ) | |
| ) ENGINE=InnoDB DEFAULT CHARACTER SET=latin1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create table `user_relations` ( | |
| `from_user_id` bigint NOT NULL, | |
| `to_user_id` bigint NOT NULL, | |
| `from_user_id_dummy` VARCHAR(120) NOT NULL, | |
| `to_user_id_dummy` VARCHAR(120) NOT NULL, | |
| `created_time` DATETIME NOT NULL, | |
| PRIMARY KEY (`from_user_id`, `to_user_id`), | |
| INDEX `relation_index_created_time` (`from_user_id`, `to_user_id`, `created_time` ) | |
| ) ENGINE=InnoDB DEFAULT CHARACTER SET=latin1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'securerandom' | |
| require "date" | |
| (1..5000000).each { |i| | |
| from_user_id = SecureRandom.random_number(2147483647) | |
| to_user_id = SecureRandom.random_number(2147483647) | |
| from_user_id_dummy = SecureRandom.hex(62) | |
| to_user_id_dummy = SecureRandom.hex(62) | |
| s1 = Date.parse("2015/07/28") | |
| s2 = Date.parse("2025/07/28") | |
| s = Random.rand(s1 .. s2) | |
| date = s.strftime("%Y/%m/%d %H:%M:%S") | |
| # より現実に即すようにわざとバルクインサートにしない | |
| puts "insert into user_relations values(#{from_user_id}, #{to_user_id},'#{from_user_id_dummy}', '#{to_user_id_dummy}', '#{date}');" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'securerandom' | |
| require "date" | |
| (1..5000000).each { |i| | |
| from_user_id = SecureRandom.random_number(9223372036854775807) | |
| to_user_id = SecureRandom.random_number(9223372036854775807) | |
| from_user_id_dummy = SecureRandom.hex(60) | |
| to_user_id_dummy = SecureRandom.hex(60) | |
| s1 = Date.parse("2015/07/28") | |
| s2 = Date.parse("2025/07/28") | |
| s = Random.rand(s1 .. s2) | |
| date = s.strftime("%Y/%m/%d %H:%M:%S") | |
| # より現実に即すようにわざとバルクインサートにしない | |
| puts "insert into user_relations values(#{from_user_id}, #{to_user_id},'#{from_user_id_dummy}', '#{to_user_id_dummy}', '#{date}');" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'securerandom' | |
| require "date" | |
| (1..5000000).each { |i| | |
| from_user_id = i * 4294967296 | |
| to_user_id = i * 4294967296 + 2147483648 | |
| from_user_id_dummy = SecureRandom.hex(60) | |
| to_user_id_dummy = SecureRandom.hex(60) | |
| s1 = Date.parse("2015/07/28") | |
| s2 = Date.parse("2025/07/28") | |
| s = Random.rand(s1 .. s2) | |
| date = s.strftime("%Y/%m/%d %H:%M:%S") | |
| # より現実に即すようにわざとバルクインサートにしない | |
| puts "insert into user_relations values(#{from_user_id}, #{to_user_id},'#{from_user_id_dummy}', '#{to_user_id_dummy}', '#{date}');" | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| create table `user_relations` ( | |
| `from_user_id` binary(18) NOT NULL, | |
| `to_user_id` binary(18) NOT NULL, | |
| `from_user_id_dummy` VARCHAR(110) NOT NULL, | |
| `to_user_id_dummy` VARCHAR(110) NOT NULL, | |
| `created_time` DATETIME NOT NULL, | |
| PRIMARY KEY (`from_user_id`, `to_user_id`), | |
| INDEX `relation_index_created_time` (`from_user_id`, `to_user_id`, `created_time` ) | |
| ) ENGINE=InnoDB DEFAULT CHARACTER SET=latin1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'securerandom' | |
| require 'date' | |
| require 'uuid' | |
| uuid = UUID.new # gem install uuid | |
| (1..5000000).each { |i| | |
| from_user_id = '0x' + uuid.generate.gsub(/-/, "") + SecureRandom.hex(2) | |
| to_user_id = '0x' + uuid.generate.gsub(/-/, "") + SecureRandom.hex(2) | |
| from_user_id_dummy = SecureRandom.hex(55) | |
| to_user_id_dummy = SecureRandom.hex(55) | |
| s1 = Date.parse("2015/07/28") | |
| s2 = Date.parse("2025/07/28") | |
| s = Random.rand(s1 .. s2) | |
| date = s.strftime("%Y/%m/%d %H:%M:%S") | |
| # より現実に即すようにわざとバルクインサートにしない | |
| puts "insert into user_relations values(#{from_user_id}, #{to_user_id},'#{from_user_id_dummy}', '#{to_user_id_dummy}', '#{date}');" | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require 'securerandom' | |
| require 'date' | |
| require 'uuid' | |
| uuid = UUID.new # gem install uuid | |
| (1..5000000).each { |i| | |
| from_user_id = '0x'+ SecureRandom.hex(2) + uuid.generate.gsub(/-/, "") | |
| to_user_id = '0x'+ SecureRandom.hex(2) + uuid.generate.gsub(/-/, "") | |
| from_user_id_dummy = SecureRandom.hex(55) | |
| to_user_id_dummy = SecureRandom.hex(55) | |
| s1 = Date.parse("2015/07/28") | |
| s2 = Date.parse("2025/07/28") | |
| s = Random.rand(s1 .. s2) | |
| date = s.strftime("%Y/%m/%d %H:%M:%S") | |
| # より現実に即すようにわざとバルクインサートにしない | |
| puts "insert into user_relations values(#{from_user_id}, #{to_user_id},'#{from_user_id_dummy}', '#{to_user_id_dummy}', '#{date}');" | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment