ãã¢ãŒãèŠã€ããããšã®é£ããã¯äœã§ãã
ãã¢ãŒãªãã¬ãŒã¿ãŒïŒTezTourãTUIããã¿ãªãŒãã¢ãŒãªã©ïŒã¯ãäžèŠãããšããæããã§ã¯ãªãæ¹æ³ã§èš±å¯ã販売ããŸãã
- ç¹å®ã®æ¥ä»ã®ã»ããã«å¯ŸããŠãç¹å®ã®æ°ã®ããã«ã®å®¢å®€ãäºçŽãããŠããŸãã
- ããã€ãã®èªç©ºæ©ãåéãããŠããŸãã
- å¯èœãªãã¹ãŠã®éšå±ã¿ã€ããæ»åšæéãéœåžãåºçºæ¥ã®çµã¿åãããå«ããã¢ãŒã®æ°ããããã±ãŒãžããªãªãŒã¹ãããŠããŸãã
ãã®åŸããã®ãããªçµã¿åããïŒãã®æ°ã¯æ°åããæ°ååã«ãªãããšããããŸãïŒãæ€çŽ¢ãããŸãã æ€çŽ¢ãã©ãŒã ã®äŸã¯TezTourã§èŠãããšãã§ããŸã-ãŠãŒã¶ãŒã¯åºçºéœåžã宿æ³æœèšã®çš®é¡ãåœãããã³ãŠãŒã¶ãŒãä»»æã«éžæã§ããæ®ãã®ãã©ã¡ãŒã¿ãŒã®ã¿ãéžæã§ããŸãã
ãã¢ãŒïŒçµã¿åããïŒã®åèšæ°ã¯æ°åã«äžããšããäºå®ã«ããããããããã©ã¡ãŒã¿ãŒïŒåºçºéœåžã宿æ³æœèšã®ã¿ã€ããåœïŒã®åºå®ã»ããããšã«ãææªã®å Žåãæ°åäžã®ãªãã·ã§ã³ããããŸãã ãããããã¢ãŒãéåžžã«å€ãå Žåã§ãããŠãŒã¶ãŒãèšå®ããç¡æã®åºæºãæºããã¬ã³ãŒããèŠã€ããå¿ èŠãããã䞊ã¹æ¿ãã¯å€ããå°ãªããä»»æã§ãããããæ€çŽ¢ã¯ããã»ã©ç°¡åã§ã¯ãããŸããïŒååãšããŠãäŸ¡æ Œã«ãã£ãŠäžŠã¹æ¿ããè¡ãããŸããããããå¯äžã®å¯èœãªåºæºã§ã¯ãããŸããïŒ ãã®èšäºã§ã¯ãã¹ããããé€ããMySQLãšClickHouseã«åºã¥ããã¢ãŒã®ãªã¢ã«ã¿ã€ã æ€çŽ¢ã®ç°¡ç¥åãããã¢ãŒããã¯ãã£ãèæ ®ããŸãïŒã¹ã©ã³ã°çšèªãã€ãŸããäžéšã®ãªãã·ã§ã³ã§ã¯é£è¡æ©ã®çªå·ãŸãã¯åº§åžãçµäºããããšãæå³ãããã®ãããªãã¢ãŒã¯åé¡ããé€å€ããå¿ èŠããããŸãïŒã æ€çŽ¢ããã°ããè¡ããä»»æã®ãã£ãŒã«ãã§äžŠã¹æ¿ããŠçµæã衚瀺ã§ããããã«ããæ¹æ³ãåŠç¿ããŸãã
ããŒã¿ãååŸããå Žæ
æåã¯ããã¢ãŒãªãã¬ãŒã¿ãŒã®å®éã®ããŒã¹ãååŸããŠãã·ã¹ãã ã®ãã¹ãããŒã¿ãšããŠã¢ããããŒãããããšèããŠããŸããããã®æ¹æ³ã§ã¯ãçµæãæ¯èŒãããã¢ãŒãªãã¬ãŒã¿ãŒã®ãŠã§ããµã€ãã§æ€çŽ¢ãçºè¡ããããšã§ãæ€çŽ¢ã®åŠ¥åœæ§ã確èªã§ããŸãã ããããæ®å¿µãªããããããªãã¯ãã¡ã€ã³ã§ãã¢ãŒã®ããŒã¿ããŒã¹ãç°¡åã«èŠã€ããããšãã§ããªãã£ããããå®éã®ãã¢ãŒãã·ãã¥ã¬ãŒãããäžé£ã®ç䌌ã©ã³ãã ããŒã¿ã«éå®ããå¿ èŠããããŸãã
ãã£ãŒã«ãã®ã»ãã
éœåžãåœã宿æ³æœèšã®ã¿ã€ããæ€çŽ¢ãããšãã«ãååã«é¢é£ãã©ã¡ãŒã¿ãŒã®IDãå«ãŸããããŒãã«ãäœæã§ãããããããšãã°tours_12_55_1001ã12ã55ã1001ã¯ããããéœåžãåœã宿æ³æœèšã®IDã§ãã ããã«ããã衚瀺ããå¿ èŠãããã¬ã³ãŒãã®æ°ãå€§å¹ ã«åæžãããšåæã«ãããŒãã«ã«éè€ããå€ãæ ŒçŽããªããããã¹ããŒã¹ãç¯çŽã§ããŸãã
ããã§ãããã®ãããªããŒãã«ã®å Žåã§ããæ°åäžã®ãªãã·ã§ã³ãååšããå¯èœæ§ãããããã¹ããµã³ãã«ã§ã¯ãââ次ã®æ§é ãæã€æ£ç¢ºã«1,000äžã®ã¬ã³ãŒããçæããŸãã
- tour_id-uint64-åºæã®ãªãã¡ãŒID
- package_id-uint64-ãã¢ãŒã®å¯Ÿå¿ããããã±ãŒãžã®IDïŒããã±ãŒãžã¯å šäœãšããŠè¿œå ãããåãæ¶ãããŸãïŒ
- date_start-uint8-å°çæ¥-ç¹å®ã®ç¬éããã®æ¥æ°
- stars-uint8-ããã«ã®æã®æ°+ç¹å¥ãªå€ïŒã¢ããŒããªã©ïŒ
- pansion-uint8-é£ã¹ç©ã®ã¿ã€ãïŒBedïŒBreakfastãAll Inclusiveãªã©ïŒ
- æ³-uint8-æ»åšæéïŒæ³æ°ïŒ
- region_id-uint16-ããã«å°åID
- hotel_id-uint32-ããã«ID
- airport_id-uint8-å°ç空枯ID
- äŸ¡æ Œ-uint16-ãªãã¡ãŒäŸ¡æ ŒïŒãã«ïŒ
åœããã¢ãŒãªãã¬ãŒã¿ãŒã«ãã£ãŠããªã¹ãã¯ç°ãªãå ŽåããããŸãïŒããšãã°ãåºçºç©ºæž¯ãããå ŽåããäŸ¡æ Œãç°ãªãé貚ã§ãããuint16ã«åãŸããªãå Žåãªã©ïŒããã ããæãåºæ¬çãªãã®ãšããŠãã®ãªãã·ã§ã³ã«çŠç¹ãåœãŠãŸãã ã
çæã®ããã®ã³ãŒãã¯ãããã°ã©ããŒã«ãã£ãŠ10åã§æžãããŠããŸãã
é衚瀺ã®ããã¹ã
package main import ( "encoding/csv" "flag" "math/rand" "os" "strconv" ) var n = flag.Int("n", 10000000, "How many entries to generate") func main() { wr := csv.NewWriter(os.Stdout) defer wr.Flush() wr.Write([]string{ "tour_id", "package_id", "date_start", "stars", "pansion", "nights", "region_id", "hotel_id", "airport_id", "price", }) for i := 0; i < *n; i++ { wr.Write([]string{ strconv.FormatInt(int64(i), 10), strconv.FormatInt(rand.Int63(), 10), strconv.FormatInt(rand.Int63n(90), 10), strconv.FormatInt(rand.Int63n(10), 10), strconv.FormatInt(rand.Int63n(10), 10), strconv.FormatInt(rand.Int63n(30), 10), strconv.FormatInt(rand.Int63n(1000), 10), strconv.FormatInt(rand.Int63n(1000000), 10), strconv.FormatInt(rand.Int63n(10), 10), strconv.FormatInt(rand.Int63n(10000), 10), }) } }
çµæã®csvãã¡ã€ã«ã¯çŽ500 MBãå æãã1000äžä»¶ã®ã¬ã³ãŒããå«ã¿ãŸãããã®ã¬ã³ãŒãã§ã¯ãtour_idãå調ã«å¢å ããæ®ãã®ãã£ãŒã«ãã¯ã»ãŒçŸå®ã®ç¯å²ã§ã©ã³ãã ãªå€ãæã¡ãŸãã
æ€çŽ¢æ¡ä»¶
åãã£ãŒã«ãã®å€ã®ã»ãããšäžŠã¹æ¿ãã§æ€çŽ¢ã§ããããã«ããå¿ èŠããããŸãããååãšããŠãåºçºæ¥ãšæéã®ç¯å²ã¯ããã»ã©åºãã¯ãããŸãã-ããšãã°ã3æ1æ¥ãã5æ1æ¥ãŸã§ã®åºçºæ¥ç¯å²ã®ãã¢ãŒãæ¢ãããšã¯ã»ãšãã©ãããŸããã åºç¯å²ã®åºçºæ¥ã®æ€çŽ¢ãæ©èœãããšæ³å®ã§ããŸããããã®ç¯å²ãå€§å¹ ã«å¶éãããŠããå Žåãããšãã°å¹³åã§10æ¥ä»¥å ã®å Žåãå¿çæéãšãªãœãŒã¹æ¶è²»ãæé©åããå¿ èŠããããŸãã ãã®ç¥èã¯ãã€ã³ããã¯ã¹ãéžæãããšãã«åœ¹ç«ã¡ãŸãã
MySQLã®å®è£
MySQLãéžæããã®ã¯ããã®ããŒã¿ããŒã¹ã«ç²ŸéããŠããããšãšããã®ã¿ã¹ã¯ã«æ¯èŒçé©ããŠããããã§ãã
å°ãç°ãªã3ã€ã®ã¢ãããŒããè©ŠããŠã¿ãŸãããïŒåçŽãªInnoDBãInnoDB +äž»ããŒïŒdate_startãidïŒããã³MyISAMã ããŒãã«ã®æ§é ã¯3ã€ãã¹ãŠã®ã¢ãããŒãã§åãã§ãããéãã¯ãšã³ãžã³ãšã€ã³ããã¯ã¹ã«èª²ããã®ã®ã¿ã§ãã
CREATE TABLE `tours` ( `tour_id` bigint(20) NOT NULL, `package_id` bigint(20) NOT NULL, `date_start` tinyint(4) NOT NULL, `stars` tinyint(4) NOT NULL, `pansion` tinyint(4) NOT NULL, `nights` tinyint(4) NOT NULL, `region_id` smallint(6) NOT NULL, `hotel_id` int(11) NOT NULL, `airport_id` tinyint(4) NOT NULL, `price` smallint(6) NOT NULL )
Innodb
æåã«ãæšæºã€ã³ããã¯ã¹
PRIMARY KEY (`tour_id`), KEY `date_start` (`date_start`)
ãšãšãã«æšæºInnoDBãšã³ãžã³ã䜿çšããŠã¿ãŠãã ããã date_startã®ããŒã¯ãåºçºæ¥ã®ç¯å²ã«ãã£ãŠéžæãé«éåããprimary KEY tour_idã¯ãtour_idãå調ã«å¢å ããããšãæåŸ ããŠäœæãããæé©ãªæ¿å ¥é床ãæäŸããŸãã
MySQL 5.7.17ã®ããã©ã«ãã®ã€ã³ã¹ããŒã«ã«ããŒã¿ã貌ãä»ããŸãïŒinnodb_buffer_pool_size = 128 MBããã¿ãã¬ã®äžã®æ®ãã®èšå®ãåç §ïŒïŒ
ããã©ã«ãèšå®innodb
innodb_adaptive_flushing ON
innodb_adaptive_flushing_lwm 10
innodb_adaptive_hash_index ON
innodb_adaptive_hash_index_parts 8
innodb_adaptive_max_sleep_delay 150,000
innodb_api_bk_commit_interval 5
innodb_api_disable_rowlock OFF
innodb_api_enable_binlog OFF
innodb_api_enable_mdl OFF
innodb_api_trx_level 0
innodb_autoextend_increment 64
innodb_autoinc_lock_mode 1
innodb_buffer_pool_chunk_size 134217728
innodb_buffer_pool_dump_at_shutdown ON
innodb_buffer_pool_dump_now OFF
innodb_buffer_pool_dump_pct 25
innodb_buffer_pool_filename ib_buffer_pool
innodb_buffer_pool_instances 1
innodb_buffer_pool_load_abort OFF
innodb_buffer_pool_load_at_startup ON
innodb_buffer_pool_load_now OFF
innodb_buffer_pool_size 134217728
innodb_change_buffer_max_size 25
innodb_change_buffering all
innodb_checksum_algorithm crc32
innodb_checksums ON
innodb_cmp_per_index_enabled OFF
innodb_commit_concurrency 0
innodb_compression_failure_threshold_pct 5
innodb_compression_level 6
innodb_compression_pad_pct_max 50
innodb_concurrency_tickets 5000
innodb_data_file_path ibdata1ïŒ12MïŒèªåæ¡åŒµ
innodb_data_home_dir
innodb_deadlock_detect ON
innodb_default_row_formatåç
innodb_disable_sort_file_cache OFF
innodb_doublewrite ON
innodb_fast_shutdown 1
innodb_file_format Barracuda
innodb_file_format_check ON
innodb_file_format_max Barracuda
innodb_file_per_table ON
innodb_fill_factor 100
innodb_flush_log_at_timeout 1
innodb_flush_log_at_trx_commit 1
innodb_flush_method
innodb_flush_neighbors 1
innodb_flush_sync ON
innodb_flushing_avg_loops 30
innodb_force_load_corrupted OFF
innodb_force_recovery 0
innodb_ft_aux_table
innodb_ft_cache_size 8000000
innodb_ft_enable_diag_print OFF
innodb_ft_enable_stopword ON
innodb_ft_max_token_size 84
innodb_ft_min_token_size 3
innodb_ft_num_word_optimize 2000
innodb_ft_result_cache_limit 2,000,000,000
innodb_ft_server_stopword_table
innodb_ft_sort_pll_degree 2
innodb_ft_total_cache_size 640000000
innodb_ft_user_stopword_table
innodb_io_capacity 200
innodb_io_capacity_max 2000
innodb_large_prefix ON
innodb_lock_wait_timeout 50
innodb_locks_unsafe_for_binlog OFF
innodb_log_buffer_size 16777216
innodb_log_checksums ON
innodb_log_compressed_paââges ON
innodb_log_file_size 50331648
innodb_log_files_in_group 2
innodb_log_group_home_dir ./
innodb_log_write_ahead_size 8192
innodb_lru_scan_depth 1024
innodb_max_dirty_pages_pct 75.000000
innodb_max_dirty_pages_pct_lwm 0.000000
innodb_max_purge_lag 0
innodb_max_purge_lag_delay 0
innodb_max_undo_log_size 1073741824
innodb_monitor_disable
innodb_monitor_enable
innodb_monitor_reset
innodb_monitor_reset_all
innodb_old_blocks_pct 37
innodb_old_blocks_time 1000
innodb_online_alter_log_max_size 134217728
innodb_open_files 2000
innodb_optimize_fulltext_only OFF
innodb_page_cleaners 1
innodb_page_size 16384
innodb_print_all_deadlocks OFF
innodb_purge_batch_size 300
innodb_purge_rseg_truncate_frequency 128
innodb_purge_threads 4
innodb_random_read_ahead OFF
innodb_read_ahead_threshold 56
innodb_read_io_threads 4
innodb_read_only OFF
innodb_replication_delay 0
innodb_rollback_on_timeout OFF
innodb_rollback_segments 128
innodb_sort_buffer_size 1048576
innodb_spin_wait_delay 6
innodb_stats_auto_recalc ON
innodb_stats_include_delete_marked OFF
innodb_stats_method nulls_equal
innodb_stats_on_metadata OFF
innodb_stats_persistent ON
innodb_stats_persistent_sample_pages 20
innodb_stats_sample_pages 8
innodb_stats_transient_sample_pages 8
innodb_status_output OFF
innodb_status_output_locks OFF
innodb_strict_mode ON
innodb_support_xa ON
innodb_sync_array_size 1
innodb_sync_spin_loops 30
innodb_table_locks ON
innodb_temp_data_file_path ibtmp1ïŒ12MïŒèªåæ¡åŒµ
innodb_thread_concurrency 0
innodb_thread_sleep_delay 10000
innodb_tmpdir
innodb_undo_directory ./
innodb_undo_log_truncate OFF
innodb_undo_logs 128
innodb_undo_tablespaces 0
innodb_use_native_aio OFF
innodb_version 5.7.17
innodb_write_io_threads 4
innodb_adaptive_flushing_lwm 10
innodb_adaptive_hash_index ON
innodb_adaptive_hash_index_parts 8
innodb_adaptive_max_sleep_delay 150,000
innodb_api_bk_commit_interval 5
innodb_api_disable_rowlock OFF
innodb_api_enable_binlog OFF
innodb_api_enable_mdl OFF
innodb_api_trx_level 0
innodb_autoextend_increment 64
innodb_autoinc_lock_mode 1
innodb_buffer_pool_chunk_size 134217728
innodb_buffer_pool_dump_at_shutdown ON
innodb_buffer_pool_dump_now OFF
innodb_buffer_pool_dump_pct 25
innodb_buffer_pool_filename ib_buffer_pool
innodb_buffer_pool_instances 1
innodb_buffer_pool_load_abort OFF
innodb_buffer_pool_load_at_startup ON
innodb_buffer_pool_load_now OFF
innodb_buffer_pool_size 134217728
innodb_change_buffer_max_size 25
innodb_change_buffering all
innodb_checksum_algorithm crc32
innodb_checksums ON
innodb_cmp_per_index_enabled OFF
innodb_commit_concurrency 0
innodb_compression_failure_threshold_pct 5
innodb_compression_level 6
innodb_compression_pad_pct_max 50
innodb_concurrency_tickets 5000
innodb_data_file_path ibdata1ïŒ12MïŒèªåæ¡åŒµ
innodb_data_home_dir
innodb_deadlock_detect ON
innodb_default_row_formatåç
innodb_disable_sort_file_cache OFF
innodb_doublewrite ON
innodb_fast_shutdown 1
innodb_file_format Barracuda
innodb_file_format_check ON
innodb_file_format_max Barracuda
innodb_file_per_table ON
innodb_fill_factor 100
innodb_flush_log_at_timeout 1
innodb_flush_log_at_trx_commit 1
innodb_flush_method
innodb_flush_neighbors 1
innodb_flush_sync ON
innodb_flushing_avg_loops 30
innodb_force_load_corrupted OFF
innodb_force_recovery 0
innodb_ft_aux_table
innodb_ft_cache_size 8000000
innodb_ft_enable_diag_print OFF
innodb_ft_enable_stopword ON
innodb_ft_max_token_size 84
innodb_ft_min_token_size 3
innodb_ft_num_word_optimize 2000
innodb_ft_result_cache_limit 2,000,000,000
innodb_ft_server_stopword_table
innodb_ft_sort_pll_degree 2
innodb_ft_total_cache_size 640000000
innodb_ft_user_stopword_table
innodb_io_capacity 200
innodb_io_capacity_max 2000
innodb_large_prefix ON
innodb_lock_wait_timeout 50
innodb_locks_unsafe_for_binlog OFF
innodb_log_buffer_size 16777216
innodb_log_checksums ON
innodb_log_compressed_paââges ON
innodb_log_file_size 50331648
innodb_log_files_in_group 2
innodb_log_group_home_dir ./
innodb_log_write_ahead_size 8192
innodb_lru_scan_depth 1024
innodb_max_dirty_pages_pct 75.000000
innodb_max_dirty_pages_pct_lwm 0.000000
innodb_max_purge_lag 0
innodb_max_purge_lag_delay 0
innodb_max_undo_log_size 1073741824
innodb_monitor_disable
innodb_monitor_enable
innodb_monitor_reset
innodb_monitor_reset_all
innodb_old_blocks_pct 37
innodb_old_blocks_time 1000
innodb_online_alter_log_max_size 134217728
innodb_open_files 2000
innodb_optimize_fulltext_only OFF
innodb_page_cleaners 1
innodb_page_size 16384
innodb_print_all_deadlocks OFF
innodb_purge_batch_size 300
innodb_purge_rseg_truncate_frequency 128
innodb_purge_threads 4
innodb_random_read_ahead OFF
innodb_read_ahead_threshold 56
innodb_read_io_threads 4
innodb_read_only OFF
innodb_replication_delay 0
innodb_rollback_on_timeout OFF
innodb_rollback_segments 128
innodb_sort_buffer_size 1048576
innodb_spin_wait_delay 6
innodb_stats_auto_recalc ON
innodb_stats_include_delete_marked OFF
innodb_stats_method nulls_equal
innodb_stats_on_metadata OFF
innodb_stats_persistent ON
innodb_stats_persistent_sample_pages 20
innodb_stats_sample_pages 8
innodb_stats_transient_sample_pages 8
innodb_status_output OFF
innodb_status_output_locks OFF
innodb_strict_mode ON
innodb_support_xa ON
innodb_sync_array_size 1
innodb_sync_spin_loops 30
innodb_table_locks ON
innodb_temp_data_file_path ibtmp1ïŒ12MïŒèªåæ¡åŒµ
innodb_thread_concurrency 0
innodb_thread_sleep_delay 10000
innodb_tmpdir
innodb_undo_directory ./
innodb_undo_log_truncate OFF
innodb_undo_logs 128
innodb_undo_tablespaces 0
innodb_use_native_aio OFF
innodb_version 5.7.17
innodb_write_io_threads 4
LOAD DATA LOCAL INFILE 'tours.csv' INTO TABLE tours FIELDS TERMINATED BY ','
å å¡«äžã«ãããã«ããã¯ãã¯ã©ã€ã¢ã³ãã§ã¯ãªãMySQLãµãŒããŒã«ããããšã確èªãïŒã¯ã©ã€ã¢ã³ãã®CPU䜿çšçã100ïŒ ã§ãã£ãŠã¯ãªããŸããïŒããªã¯ãšã¹ãã®å®è¡æéã確èªããŸãã
Query OK, 10000000 rows affected, 11 warnings (1 min 35.09 sec) Records: 10000001 Deleted: 0 Skipped: 1 Warnings: 11
InnoDBã§ã¯ã1000äžä»¶ã®ã¬ã³ãŒããæ¿å ¥ããã®ã«1.5åã§ããŸããŸããã ååãããã«æžã蟌ãŸããŠãããããæ¬ é¥ã¯CSVãã¡ã€ã«ã®æåã®è¡ãåç §ããŸãã
çµæã®ããŒãã«ãµã€ãºã¯ã490 MBã®ããŒã¿ãš162 MBã®ã€ã³ããã¯ã¹ã§ãã ã¯ãšãªã®å®è¡äžãMySQLã¯3.5 GBã®ãã£ã¹ã¯ã«æžã蟌ã¿ãCPUè² è·ã¯çŽ100ïŒ ã§ããïŒãã¹ãã©ãããããã§ã¯4ã³ã¢ã®ãã¡1ã³ã¢ã䜿çšãããŸããïŒã
æ€çŽ¢ã¯ãšãªãå®è¡ããåã«ãããŒã¿ãæ¿å ¥ããããã®ä»ã®å¯èœãªãªãã·ã§ã³ãèŠãŠã¿ãŸãããã
InnoDB +äž»ããŒïŒdate_startãtour_idïŒ
ã»ãšãã©ã®ãªã¯ãšã¹ããåºçºæ¥ã®æ¯èŒççãç¯å²ã«ã®ã¿åœ±é¿ããããšãäºåã«ããã£ãŠãããããtour_idã®ä»£ããã«åºçºæ¥ã§ããŒã¿ãã¯ã©ã¹ã¿ãŒåã§ããŸã-ãã®å Žåãdate_startã«ããèªã¿åãã¯ãã£ã¹ã¯ïŒãŸãã¯buffer_poolïŒããã®ã©ã³ãã ãªèªã¿åããå°ãªãããŸãããã®ãããªããŒãã«ã¯ããé«éã«ãªããŸãã
æ¿å ¥ã®æ§åãèŠãŠã¿ãŸãããã
Query OK, 10000001 rows affected, 10 warnings (1 min 13.34 sec) Records: 10000001 Deleted: 0 Skipped: 0 Warnings: 10
äºæ³ã«åããŠããã®ãããªããŒãã«ãžã®æ¿å ¥ã¯ããéåžžã®ãæ§é ãžã®æ¿å ¥ãããå°ãé«éã§ããã ããã¯ããããããäœåãªãdate_startã€ã³ããã¯ã¹ããªããPRIMARY KEYã«å«ãŸããŠããããã§ãã ååãããå°ãå°ãªããããã3 GBããæžã蟌ãŸããŠããŸããã
ããŒãã«ã®ãµã€ãºã¯538 MBã®ããŒã¿ãš0 MBã®ã€ã³ããã¯ã¹ã§ãïŒã»ã«ã³ããªã€ã³ããã¯ã¹ã¯ãããŸããããPRIMARY KEYã¯InnoDBã®ããŒã¿ã®äžéšãšããŠæžã蟌ãŸããŸãïŒ
ãã€ãµã
æãMyISAMã¯MySQLã®ããã©ã«ããšã³ãžã³ã§ãããFULL SCANã®æ¿å ¥ãšå®è¡ã®é床ã§æåã§ããã ç§ãã¡ã®ä»äºã®çæ³çãªåè£ã§ã¯ãªããã®ã¯äœã§ããïŒ ããŒãã«æ§é ã¯ãInnoDBã®æåã®ããŒãžã§ã³ãšåããŸãŸã§ãã
Query OK, 10000000 rows affected, 11 warnings (40.39 sec) Records: 10000001 Deleted: 0 Skipped: 1 Warnings: 11
çµæã¯ç¢ºãã«åªããŠããŸãããæ¡éãã§ã¯ãããŸããã èšå®ã調æŽããããšã§ãMyISAMã®å ŽåãšInnoDBã®å Žåã®äž¡æ¹ã§ããè¯ãçµæãåŸãããšãã§ããŸãããããã¯å¥ã®å€§ããªèšäºã®ãããã¯ã§ãã 350 MBããã£ã¹ã¯ã«æžã蟌ãŸããããŒãã«ã®ãµã€ãºã¯286 MBã®ããŒã¿+ 205 MBã®ã€ã³ããã¯ã¹ã§ããã 楜åšã«ãããšãMyISAMã®ããŒãã«ã®ãµã€ãºãããå°ãããµã€ãºããã£ã¹ã¯ã«æžã蟌ãŸããã®ã¯ãªããããããŸããã§ããã èªè ã¯ãMySQLã€ã³ã¹ã¿ã³ã¹ã§å®éšãåçŸããŠãæ°å€ãæ¯èŒããããšããå ŽåããããŸãã
ã¯ãªãã¯ããŠã¹
æåŸã®ãªãã·ã§ã³ã¯ã ClickHouseãšããYandexã®ããŒã¿ããŒã¹ã§ã ã ããã¯ãã¯ãšãªã®èªå䞊ååãšãã®ä»ã®nishtyakovã®æãæã€åããŒã¿ããŒã¹ã§ãã Linuxããã³Dockerã³ã³ããçšã®ãã€ããªã¢ã»ã³ããªããããmacOSãµããŒããçºè¡šãããŠããŸãã macOSã®ãã€ããªã¢ã»ã³ããªãèŠã€ãããªãã£ãããã yadi.sk / d / RffdbxaM3GL7AcãåéããŠã¬ã€ã¢ãŠãããŸãã ïŒã¢ã»ã³ããªã«ã¯gcc-6ãæ°åã®ã¬ãã€ãã®ã¹ããŒã¹ãã©ãããããã§çŽ2æéå¿ èŠã§ãïŒã macOSã§ãã¹ããè¡ããŸãã
ãŸããããŒãã«ãäœæããŸãã
CREATE TABLE tours ( tour_id UInt64, package_id UInt64, date_start UInt8, stars UInt8, pansion UInt8, nights UInt8, region_id UInt16, hotel_id UInt32, airport_id UInt8, price UInt16, date Date MATERIALIZED toDate(date_start) ) ENGINE = MergeTree(date, date_start, 8192)
ã¿ã€ãMergeTreeã®ããŒãã«ãäœæããå ŽåïŒããã©ã«ãã§æšå¥šïŒãæ¥ä»ä»ãã®åãæå®ããå¿ èŠããããŸãïŒã·ã£ãŒãã£ã³ã°ãå®è¡ãããŸãïŒã ããã§ç§ã¯å°ãæ ããŠããŠãå€toDateïŒdate_startïŒãæã€MATERIALIZEDæ¥ä»åãäœæããŸããã å®éã®ããŒã¿ã§ã¯ãDateåã®date_startåãäœæããæ¹ãã¯ããã«ç°¡åã§ããã¯ãªãã¯ããŠã¹ã§ã¯ãåã®å§çž®ã®ããã«æ¥ä»ãå€ãã®ã¹ããŒã¹ãå æããŸããã
ClickHouseãããŒã¿æ¿å ¥
次ã«ãããŒã¿ãæ¿å ¥ããŸãã
$ cat tours.csv | pv | clickhouse --client --query 'INSERT INTO tours FORMAT CSVWithNames' 524MiB 0:00:04 [ 123MiB/s]
pvãŠãŒãã£ãªãã£ããŸã ã€ã³ã¹ããŒã«ãããŠããªãå Žåã¯ãã€ã³ã¹ããŒã«ããããšããå§ãããŸããããã«ãããæäœã®é²è¡ç¶æ³ãåºåãããã€ããééãããã€ãæ°ã衚瀺ã§ããŸãã
csvãã¡ã€ã«ã®æ¿å ¥ãçŽ100 Mb / sã®æ¿å ¥é床ã§4ç§ã§è¡ãããããšãããããŸãïŒèè ã«ãããšïŒã æ¿å ¥æã«ããµãŒããŒã¯7ç§ã®CPUæéãè²»ãããŸããã
ããŒã¿ãµã€ãºã¯378 MBã§ããã378 MBããã£ã¹ã¯ã«æžã蟌ãŸããŸããïŒã»ãšãã©ã®å Žåãããªã¥ãŒã å šäœãã¡ã¢ãªå ã§ãœãŒãããã1ã€ã®ããŒã¹ã«èšé²ãããŸããïŒã
æ®å¿µãªããããã¹ãããŒã¿ã¯ã©ã³ãã ã§ãããããåã®å§çž®ãã倧ããªå©ç¹ãåŒãåºãããšãã§ããŸããã§ããã å®éã®ããŒã¿ã¯ããé©åã«å§çž®ãããå¿ èŠããããããæçµãµã€ãºã¯ããã«å°ããããå¿ èŠããããŸãã
ããŒã¿æ¿å ¥æéãæ¯èŒ
1ã€ã®ããŒãã«ã«ãã¹ãŠã®æ¿å ¥ã€ã³ãžã±ãŒã¿ãŒãåéããŸãããã
æ¹æ³ | æé | ããŒãã«ãµã€ãº | ãã£ã¹ã¯ã«æžã蟌ã¿ãŸãã |
---|---|---|---|
Innodb | 95ç§ | 652 Mb | 3.5 GB |
InnoDB + PK | 73ç§ | 538 Mb | 3.0 GB |
ãã€ãµã | 40ç§ | 491 Mb | 350 MBïŒ |
ã¯ãªãã¯ããŠã¹ | 4ç§ | 378 Mb | 378 Mb |
ãµã³ããªã³ã°
ãã¢ãŒãæ€çŽ¢ããéã«ãå€å°ãªããšãçå®ã®çš®é¡ã®ã¯ãšãªã«å¯Ÿå¿ããããã€ãã®éžæãè¡ããŸãã
-- 1. « » SELECT * FROM tours ORDER BY price ASC LIMIT 20; -- 2. « » 10 (1/9 ) SELECT * FROM tours WHERE date_start BETWEEN 40 AND 50 ORDER BY price ASC LIMIT 20; -- 3. 5 500 600 SELECT * FROM tours WHERE nights = 5 AND price BETWEEN 500 AND 600 ORDER BY price ASC LIMIT 20; -- 4. 500 600 , SELECT * FROM tours WHERE price BETWEEN 500 AND 600 ORDER BY nights DESC, stars DESC LIMIT 20; -- 5. SELECT * FROM tours WHERE date_start BETWEEN 10 AND 20 AND hotel_id = 767036 ORDER BY price LIMIT 20;
MyISAMã§ã¯ãIGNORE INDEXïŒdate_startïŒãæå®ãããŠããå Žåãã¯ãšãªæéã¯æ¬åŒ§å ã«è¡šç€ºãããŸãã
ClickHouseã®å Žåã*ã§ã¯ãªãtour_idãšpriceã®ã¿ãéžæãããšãã¯ãšãªæéãæ¬åŒ§å ã«è¡šç€ºãããŸãã
çµæã¯æ¬¡ã®ãšããã§ãã
æ¹æ³ | 1ããªç§ | 2ããªç§ | 3ããªç§ | 4ããªç§ | 5ããªç§ |
---|---|---|---|---|---|
Innodb | 4300 | 3800 | 3800 | 3800 | 3700 |
InnoDB + PK | 4600 | 600 | 4000 | 4000 | 540 |
ãã€ãµã | 1300 | 1600 ïŒ1000ïŒ | 800 | 700 | 1500ïŒ670ïŒ |
ã¯ãªãã¯ããŠã¹ | 120ïŒ40ïŒ | 40ïŒ14ïŒ | 150ïŒ54ïŒ | 180ïŒ80ïŒ | 14ïŒ8ïŒ |
ã³ãŒã«ããã£ãã·ã¥ïŒã©ãããããSSDïŒã§ãåãã§ãïŒ
æ¹æ³ | 1ããªç§ | 2ããªç§ | 3ããªç§ | 4ããªç§ | 5ããªç§ |
---|---|---|---|---|---|
Innodb | 5500 | 5000 | 4800 | 4700 | 4700 |
InnoDB + PK | 12700 | 1960 | 12100 | 12000 | 1720 |
ãã€ãµã | 14800 ïŒ1060ïŒ | 800 | 920 | 799 | 14900ïŒ767ïŒ |
ã¯ãªãã¯ããŠã¹ | 570ïŒ188ïŒ | 177ïŒ90ïŒ | 591ïŒ224ïŒ | 608ïŒ254ïŒ | 122ïŒ55ïŒ |
åæ
ãã¥ãŒãã³ã°ãªãã§ãMyISAMã¯MySQLã«æé©ã§ãããdate_startã€ã³ããã¯ã¹ã¯ãç¹ã«ã³ãŒã«ããã£ãã·ã¥ã®å Žåã«ã®ã¿æªåããŸãïŒããã¯ãMyISAMã®æååãžã®ã©ã³ãã ã¢ã¯ã»ã¹ãéåžžã«å¹ççã§ã¯ãªãããã§ã-åžžã«1ã€ãã€èªã¿åããŸãã³ãŒã«ããã£ãã·ã¥ã®å ŽåãSSDäžã§ãå£æ» çãªçµæãããããreadïŒïŒã·ã¹ãã ã³ãŒã«ãå«ãè¡ïŒã äžéšã®ãªã¯ãšã¹ãã¯ãInnoDB + PKã¹ããŒã ã§ããé«éã«å®è¡ãããŸããããŠã©ãŒã ãã£ãã·ã¥ã§ã®ã¿å®è¡ãããŸãã ã³ãŒã«ãã¹ã¿ãŒãã®å ŽåãMyISAMã®æ¹ãã¯ããã«é©åã§ãããdate_startã«ã€ã³ããã¯ã¹ããããŸããïŒä»£ããã«ãæ¥ä»ç¯å²ã§ããŒãã«ãå±éããã¯ãšãªã䞊è¡ããŠéå§ã§ããŸãïŒã
ClickHouseã¯åããŒã¹ã§ãããããSELECT *ãšãã圢åŒã®ã¯ãšãªã¯ããŸã䟿å©ã§ã¯ãããŸãããããã¯ãã¯ãšãªã®å®è¡ã«ãããæéã§ç¢ºèªã§ããŸãã å¯èœã§ããã°ãå¿ èŠãªåã®ã¿ãéžæããå¿ èŠããããŸãïŒãããã«ããŠããtour_idã®ã¡ã¿æ å ±ã¯ä¿¡é Œã§ãããªããžããªã®ã©ããã«è€è£œããå¿ èŠããããClickHouseããçŽæ¥ååŸãã代ããã«ããããååŸã§ããŸãïŒã ãŸããClickHouseã¯å©çšå¯èœãªãã¹ãŠã®ã«ãŒãã«ãžã®ãªã¯ãšã¹ãã®å®è¡ãèªåçã«äžŠååããå¿ èŠãªåã®ã¿ãã¹ãã£ã³ããããããã£ãã·ã¥ããŠã©ãŒã ã¢ããããããšéåžžã«é«éã«åäœããŸãã ã³ãŒã«ãã¹ã¿ãŒãã®å Žåããã¹ãŠã®ã¹ããŒã«ãŒã§ã¯ãªããå¿ èŠãªã¹ããŒã«ãŒã®ã¿ãéžæããããšãæãŸããçç±ã¯ç¹ã«é¡èã§ãã
ãã ããã³ãŒã«ãã¹ã¿ãŒãã§ããClickHouseã¯äŸå€ãªãããã¹ãŠã®ã±ãŒã¹ã§ã¯ãšãªå®è¡æéã®ç¹ã§ãªãŒãããŠããŸãã
ãããã«
ãã®èšäºã§ã¯ãMySQLïŒ3ã€ã®ç°ãªãã¢ãããŒãïŒãšClickHouseã«åºã¥ããŠãã¹ããããèæ ®ããã«ãã¢ãŒãæ€çŽ¢ããããã®ç°¡ç¥åãããã¢ãã«ãæ§ç¯ããŸããã
ãã®èšäºãããã¢ãŒã§æ€çŽ¢ãè¡ã人ã®æ€çŽ¢é床ãåäžãããæ€çŽ¢ã³ã¹ããåæžããClickHouseãã©ã®ã¿ã¹ã¯ã«é©ããŠãããã«ã€ããŠã®åºæ¬çãªç解ãäžããããšãé¡ã£ãŠããŸãã æåŸãŸã§èªãã§ãããŠããããšããã³ã¡ã³ããèããŠããããã§ãã
PS MySQLãšClickHouseãé ããŠçµæãæ¹åãããã³ãããŒã¯ãå ¬éã§ããå Žåã¯ãã³ã¡ã³ãã«å¿ ãèšå ¥ããŠãã ãããããã¯èšäºãžã®è¿œå ãšããŠåœ¹ç«ã€ã§ãããã