Приветствую.
Есьб такой запрос:
INSERT INTO traffic_stats (ts_spawn, ts_spawn_precise, user_id, offer_id, traffic_manager_id, country_id, prelanding_id, landing_id, platform_out_id, platform_id, slave_prefix, offer_targeting_id, traff_type, os_id, browser_id, operator_id, subacc_1, subacc_2, subacc_3, subacc_4, utm_medium, utm_source, utm_term, utm_campaign, utm_content, redirect_raw, redirect_uniq, uniq, raw, transit_raw, transit_uniq, time_on_site, clicked_on_site, scrolled_on_site, load_begins, dom_loaded, fully_loaded) SELECT (ts_spawn, ts_spawn, user_id, offer_id, traffic_manager_id, country_id, prelanding_id, landing_id, platform_out_id, platform_id, slave_prefix, offer_targeting_id, traff_type, os_id, browser_id, operator_id, subacc_1, subacc_2, subacc_3, subacc_4, utm_medium, utm_source, utm_term, utm_campaign, utm_content, actions, actions_uniq, uniq, raw, offer_clicks_raw, offer_clicks, time_on_site, clicked_on_site, scrolled_on_site, load_begins, dom_loaded, fully_loaded) from stats;
При выполнении получаю ошибку:
Code: 20. DB::Exception: Received from localhost:9000, ::1. DB::Exception: Number of columns in INSERT SELECT doesn't match.
И в INSERT, и в SELECT 37 колонок.
В логах:
2017.12.08 11:15:55.740018 [ 3522 ] <Debug> executeQuery: (from [::1]:45202, query_id: a7b1d944-6763-4298-8b06-65fb4cd027ab) INSERT INTO traffic_stats (ts_spawn, ts_spawn_precise, user_id, offer_id, traffic_manager_id, country_id, prelanding_id, landing_id, platform_out_id, platform_id, slave_prefix, offer_targeting_id, traff_type, os_id, browser_id, operator_id, subacc_1, subacc_2, subacc_3, subacc_4, utm_medium, utm_source, utm_term, utm_campaign, utm_content, redirect_raw, redirect_uniq, uniq, raw, transit_raw, transit_uniq, time_on_site, clicked_on_site, scrolled_on_site, load_begins, dom_loaded, fully_loaded) SELECT (ts_spawn, ts_spawn, user_id, offer_id, traffic_manager_id, country_id, prelanding_id, landing_id, platform_out_id, platform_id, slave_prefix, offer_targeting_id, traff_type, os_id, browser_id, operator_id, subacc_1, subacc_2, subacc_3, subacc_4, utm_medium, utm_source, utm_term, utm_campaign, utm_content, actions, actions_uniq, uniq, raw, offer_clicks_raw, offer_clicks, time_on_site, clicked_on_site, scrolled_on_site, load_begins, dom_loaded, fully_loaded) from stats
2017.12.08 11:15:55.742047 [ 3522 ] <Trace> InterpreterSelectQuery: WithMergeableState -> Complete
2017.12.08 11:15:55.743005 [ 3522 ] <Debug> MemoryTracker: Peak memory usage (for query): 32.00 B.
2017.12.08 11:15:55.743036 [ 3522 ] <Debug> MemoryTracker: Peak memory usage (for user): 32.00 B.
2017.12.08 11:15:55.743045 [ 3522 ] <Debug> MemoryTracker: Peak memory usage (total): 32.00 B.
2017.12.08 11:15:55.767870 [ 3522 ] <Information> TCPHandler: Processed in 0.029 sec.
SELECT *
FROM system.tables
WHERE name IN ('stats', 'traffic_stats')
┌─database──────┬─name──────────┬─engine──────────────┬─metadata_modification_time─┐
│ test │ stats │ Distributed │ 2017-10-18 09:15:12 │
│ test │ traffic_stats │ Distributed │ 2017-12-08 09:38:55 │
│ test_sh1_rep1 │ stats │ ReplicatedMergeTree │ 2017-10-18 09:15:05 │
│ test_sh1_rep1 │ traffic_stats │ ReplicatedMergeTree │ 2017-12-08 09:38:55 │
│ test_sh3_rep2 │ stats │ ReplicatedMergeTree │ 2017-10-18 09:15:05 │
│ test_sh3_rep2 │ traffic_stats │ ReplicatedMergeTree │ 2017-12-08 09:38:55 │
└───────────────┴───────────────┴─────────────────────┴────────────────────────────┘
SHOW CREATE TABLE traffic_stats
┌─statement───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ CREATE TABLE test.traffic_stats ( ts_spawn UInt32, ts_spawn_precise UInt32, user_id UInt32, offer_id UInt32, traffic_manager_id UInt32, country_id UInt8, prelanding_id UInt32, landing_id UInt32, platform_out_id UInt32, platform_id UInt32, slave_prefix String, offer_targeting_id UInt32, traff_type UInt8, os_id UInt32, browser_id UInt32, operator_id UInt32, subacc_1 String, subacc_2 String, subacc_3 String, subacc_4 String, utm_medium String, utm_source String, utm_term String, utm_campaign String, utm_content String, redirect_raw Int16, redirect_uniq Int16, uniq Int16, raw Int16, transit_uniq Int16, transit_raw Int16, time_on_site Int16, clicked_on_site Int16, scrolled_on_site Int16, load_begins Int16, dom_loaded Int16, fully_loaded Int16, analytics_counted Int16) ENGINE = Distributed(\'global_cluster\', \'\', \'traffic_stats\', rand()) │
└─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
SHOW CREATE TABLE test_sh1_rep1.traffic_stats
┌─statement──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ CREATE TABLE test_sh1_rep1.traffic_stats ( ts_spawn UInt32, ts_spawn_precise UInt32, user_id UInt32, offer_id UInt32, traffic_manager_id UInt32, country_id UInt8, prelanding_id UInt32, landing_id UInt32, platform_out_id UInt32, platform_id UInt32, slave_prefix String, offer_targeting_id UInt32, traff_type UInt8, os_id UInt32, browser_id UInt32, operator_id UInt32, subacc_1 String, subacc_2 String, subacc_3 String, subacc_4 String, utm_medium String, utm_source String, utm_term String, utm_campaign String, utm_content String, redirect_raw Int16, redirect_uniq Int16, uniq Int16, raw Int16, transit_uniq Int16, transit_raw Int16, time_on_site Int16, clicked_on_site Int16, scrolled_on_site Int16, load_begins Int16, dom_loaded Int16, fully_loaded Int16, analytics_counted Int16) ENGINE = ReplicatedMergeTree(\'/clickhouse/tables/test_sh1/traffic_stats\', \'test_sh1_rep1\') PARTITION BY toMonday(toDate(ts_spawn)) ORDER BY (user_id, offer_id, traffic_manager_id, prelanding_id, landing_id, country_id, platform_id) SETTINGS index_granularity = 8192 │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
SHOW CREATE TABLE stats
┌─statement──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ CREATE TABLE test.stats ( event_date Date DEFAULT toDate(ts_spawn), ts_spawn UInt32 DEFAULT CAST(0 AS UInt32), user_id UInt64 DEFAULT CAST(0 AS UInt64), offer_targeting_id UInt32 DEFAULT CAST(0 AS UInt32), offer_id UInt32 DEFAULT CAST(0 AS UInt32), traffic_manager_id UInt32 DEFAULT CAST(0 AS UInt32), traff_type UInt32 DEFAULT CAST(0 AS UInt32), operator_id UInt32 DEFAULT CAST(0 AS UInt32), country_id UInt32 DEFAULT CAST(0 AS UInt32), subacc_1 String DEFAULT \'\', subacc_2 String DEFAULT \'\', subacc_3 String DEFAULT \'\', subacc_4 String DEFAULT \'\', utm_source String DEFAULT \'\', utm_medium String DEFAULT \'\', utm_term String DEFAULT \'\', utm_content String DEFAULT \'\', utm_campaign String DEFAULT \'\', prelanding_id UInt32 DEFAULT CAST(0 AS UInt32), platform_id UInt32 DEFAULT CAST(0 AS UInt32), platform_out_id UInt32 DEFAULT CAST(0 AS UInt32), os_id UInt32 DEFAULT CAST(0 AS UInt32), browser_id UInt32 DEFAULT CAST(0 AS UInt32), actions UInt32 DEFAULT CAST(0 AS UInt32), uniq UInt32 DEFAULT CAST(0 AS UInt32), raw UInt32 DEFAULT CAST(0 AS UInt32), tb_uniq UInt32 DEFAULT CAST(0 AS UInt32), tb_raw UInt32 DEFAULT CAST(0 AS UInt32), offer_clicks UInt32 DEFAULT CAST(0 AS UInt32), landing_id UInt32 DEFAULT CAST(0 AS UInt32), slave_prefix String DEFAULT \'\', actions_uniq UInt32 DEFAULT CAST(0 AS UInt32), offer_clicks_raw UInt32 DEFAULT CAST(0 AS UInt32), clicked_on_site UInt32 DEFAULT CAST(0 AS UInt32), scrolled_on_site UInt32 DEFAULT CAST(0 AS UInt32), load_begins UInt32 DEFAULT CAST(0 AS UInt32), dom_loaded UInt32 DEFAULT CAST(0 AS UInt32), fully_loaded UInt32 DEFAULT CAST(0 AS UInt32), time_on_site UInt32 DEFAULT CAST(0 AS UInt32)) ENGINE = Distributed(\'global_cluster\', \'\', \'stats\', rand()) │
└────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
SHOW CREATE TABLE test_sh1_rep1.stats
┌─statement─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│ CREATE TABLE test_sh1_rep1.stats ( event_date Date DEFAULT toDate(ts_spawn), ts_spawn UInt32 DEFAULT CAST(0 AS UInt32), user_id UInt64 DEFAULT CAST(0 AS UInt64), offer_targeting_id UInt32 DEFAULT CAST(0 AS UInt32), offer_id UInt32 DEFAULT CAST(0 AS UInt32), traffic_manager_id UInt32 DEFAULT CAST(0 AS UInt32), traff_type UInt32 DEFAULT CAST(0 AS UInt32), operator_id UInt32 DEFAULT CAST(0 AS UInt32), country_id UInt32 DEFAULT CAST(0 AS UInt32), subacc_1 String DEFAULT \'\', subacc_2 String DEFAULT \'\', subacc_3 String DEFAULT \'\', subacc_4 String DEFAULT \'\', utm_source String DEFAULT \'\', utm_medium String DEFAULT \'\', utm_term String DEFAULT \'\', utm_content String DEFAULT \'\', utm_campaign String DEFAULT \'\', prelanding_id UInt32 DEFAULT CAST(0 AS UInt32), platform_id UInt32 DEFAULT CAST(0 AS UInt32), platform_out_id UInt32 DEFAULT CAST(0 AS UInt32), os_id UInt32 DEFAULT CAST(0 AS UInt32), browser_id UInt32 DEFAULT CAST(0 AS UInt32), actions UInt32 DEFAULT CAST(0 AS UInt32), uniq UInt32 DEFAULT CAST(0 AS UInt32), raw UInt32 DEFAULT CAST(0 AS UInt32), tb_uniq UInt32 DEFAULT CAST(0 AS UInt32), tb_raw UInt32 DEFAULT CAST(0 AS UInt32), offer_clicks UInt32 DEFAULT CAST(0 AS UInt32), landing_id UInt32 DEFAULT CAST(0 AS UInt32), slave_prefix String DEFAULT \'\', actions_uniq UInt32 DEFAULT CAST(0 AS UInt32), offer_clicks_raw UInt32 DEFAULT CAST(0 AS UInt32), clicked_on_site UInt32 DEFAULT CAST(0 AS UInt32), scrolled_on_site UInt32 DEFAULT CAST(0 AS UInt32), load_begins UInt32 DEFAULT CAST(0 AS UInt32), dom_loaded UInt32 DEFAULT CAST(0 AS UInt32), fully_loaded UInt32 DEFAULT CAST(0 AS UInt32), time_on_site UInt32 DEFAULT CAST(0 AS UInt32)) ENGINE = ReplicatedMergeTree(\'/clickhouse/tables/test_sh1/stat\', \'test_sh1_rep1\', event_date, (event_date, ts_spawn, user_id, offer_targeting_id, offer_id, traffic_manager_id, traff_type, operator_id, country_id, subacc_1, subacc_2, subacc_3, subacc_4, utm_source, utm_medium, utm_term, utm_content, utm_campaign, prelanding_id, platform_id, platform_out_id, os_id, browser_id, actions, uniq, raw, tb_uniq, tb_raw, offer_clicks, landing_id, slave_prefix), 8192) │
└───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
У остальных таблиц DDL аналогичен.
Можно заметить, что для таблиц stats крайне неудачно был выбран индекс. Испавляем это упущение пытаясь перелить данные в таблицу с корректным DDL.