Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 89 lines (70 sloc) 1.803 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
# -*- coding: utf-8 -*-

$: << File.dirname(__FILE__) + '/../lib'
require 'testdata_generater_for_mysql'

require 'benchmark'
require 'json'

#
# hogehogableってテーブルを作ります
# その際、タイプを指定するカラムを文字列or数値でどれぐらいの開きがあるのか?
# の検証です
#

include TestdataGeneraterForMysql
setup_mysql_client(
  :host => "127.0.0.1",
  :username => "root",
  :database=>'testdata_generater_for_mysql_test')

insert_per_rows 200
#hide_progress_bar

TABLE = 'load_table_test'

# 100万レコード保持
#CNT_PARENT = 100_000
#CHANGE_POINT = 50_000

CNT_PARENT = 400
CHANGE_POINT = 200

def varchar_col_value(i)
  i.to_s.rjust(10,'0')
end

def create_data
  return if load_table(TABLE)
  query "DROP TABLE IF EXISTS #{TABLE};"
  query "
CREATE TABLE #{TABLE} (
`id` bigint(11) UNSIGNED NOT NULL AUTO_INCREMENT,
`json` text NOT NULL,
`created_at` datetime ,
PRIMARY KEY (`id`),
INDEX `idx01` (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
"

  # ループランダムで回す(メモリを食います(100万レコードで500M〜))
  #random_loop
  loops = [
    [:parent_id, (1..CNT_PARENT)],
  ]

  st1 = 'a' * 60
  st2 = 'b' * 60
  st3 = 'あ' * 60

  today = Time.now
  yesterday = (Time.now - 24 * 60 * 60)

  procs = {
    :json => proc{|v|
        hash = {}
        (1..20).each do |i|
          hash[i] = rand(100)
        end
        hash[1] = v[:parent_id]
        hash['st1'] = st1
        hash['st2'] = st2
        hash['st3'] = st3

        hash.to_json
      },
    :created_at => proc{|v| v[:parent_id] < CHANGE_POINT ? 'date_sub(now() , interval 1 day)'.to_func : 'NOW()'.to_func},
  }

  create_rows(
    "#{TABLE}",
    loops,
    procs
  )

  save_table(TABLE)
end

create_data
Something went wrong with that request. Please try again.