Здравствуйте, странное поведение clickhouse.
Запросы по логике почти идентичны, во втором если добавить условие - то имя колонки меняется.
1- запрос
SELECT sub.country_id, SUM(sub.follow) AS follow
FROM pops_stat.stat_pack_pops sub
INNER JOIN push.campaign c ON c.id = sub.campaign_id
INNER JOIN push.users adv ON adv.id = sub.advertiser_id
WHERE 1
AND (c.category_id=37)
AND (adv.manager_id IN (16836, 25979, 28606))
AND (sub.t_event >= toDateTime('2023-07-29 00:00:00', 'UTC')) AND (sub.t_event <= toDateTime('2023-08-04 23:59:59', 'UTC'))
GROUP BY country_id 2-й запрос (закоментим условие и join)
SELECT sub.country_id, SUM(sub.follow) AS follow
FROM pops_stat.stat_pack_pops sub
--INNER JOIN push.campaign c ON c.id = sub.campaign_id
INNER JOIN push.users adv ON adv.id = sub.advertiser_id
WHERE 1
--AND (c.category_id=37)
AND (adv.manager_id IN (16836, 25979, 28606))
AND (sub.t_event >= toDateTime('2023-07-29 00:00:00', 'UTC')) AND (sub.t_event <= toDateTime('2023-08-04 23:59:59', 'UTC'))
GROUP BY country_id
в первом имя колонки в группировке sub.country_id, а во втором country_id
по сути в запросе ничего не меняется касательно select и group by но почему-то разные имена колонок.
результат первого запроса
результат второго запроса
уточню что таблицы
push.campaign и
push.users engine=Mysql и в них нет колонок с именем country_id.
Версия clickhouse: Connected to ClickHouse server version 23.5.4 revision 54462
clickhouse на 1 сервере.
струкутра таблицы (view)
CREATE MATERIALIZED VIEW pops_stat.stat_pack_pops
(
`t_event` DateTime('Etc/UTC'),
`source_id` UInt32,
`campaign_id` UInt32,
`country_id` UInt32,
`webmaster_id` UInt32,
`advertiser_id` UInt32,
`browser_id` UInt32,
`operation_system_id` UInt32,
`type` Enum8('default' = 1, 'feed' = 2),
`decline` Enum8('no' = 1, 'not_found' = 2),
`mark_id` UInt32,
`quality` UInt8,
`follow` Int64,
`sum` Decimal(38, 12),
`pay` Decimal(38, 12)
)
ENGINE = SummingMergeTree
PARTITION BY toYYYYMM(t_event)
PRIMARY KEY (t_event, source_id, campaign_id, country_id)
ORDER BY (t_event, source_id, campaign_id, country_id, webmaster_id, advertiser_id, browser_id, operation_system_id, type, decline, mark_id, quality)
SETTINGS index_granularity = 8192 AS
SELECT toStartOfFiveMinute(t_event) AS t_event,
source_id,
campaign_id,
country_id,
webmaster_id,
advertiser_id,
browser_id,
operation_system_id,
type,
decline,
mark_id,
quality,
sum(sign) AS follow,
sum(sum * sign) AS sum,
sum(pay * sign) AS pay
FROM pops_stat.pops_items
GROUP BY t_event,
source_id,
country_id,
campaign_id,
webmaster_id,
advertiser_id,
browser_id,
operation_system_id,
type,
decline,
mark_id,
quality
HAVING sum(sign) > 0;