From b95fdb38693647534f82d812402be71a7ce4fbdd Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 19 Oct 2026 22:17:47 +0300 Subject: [PATCH] incorrect but interesting --- payg.cfm | 125 +++++++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 99 insertions(+), 26 deletions(-) diff --git a/payg.cfm b/payg.cfm index 9f5857f..cf47065 100644 --- a/payg.cfm +++ b/payg.cfm @@ -64,11 +64,25 @@ ('Закрыта неуспешно',7,0),('Закрыта успешно',6,100),('Договор подписан',5,100),('Договор на подписании',15,90),('Договор на согласовании',12,70), ('Тестирование',8,50),('Отправлено ТКП',10,20),('Внутреннее согласование',37,10),('Проработка решения',4,10),('Сбор потребностей',1,0) ) - select upper(trim(k.id_klienta)) as wz, k.__id::text as contragent_uid, + + + select upper(trim(k.id_klienta)) as wz, + k.__id::text as contragent_uid, p.code, SUBSTRING(p.code FROM 1 FOR LENGTH(p.code) - 2) as sku_code, - p.price, p.discount as component_discount, k.__name as contragent, a.__name as contract, a.__id::text as contract_uid, d.__name as deal, d.__id::text as deal_uid, siv.abstractive_service as abstract_service, siv.modifier, siv.user_description, siv.hash as line_key - ,siv.date_nop as serviceStart, siv.date_end as serviceEnd, siv.discount as service_discount, siv.cnt as service_quantity + p.price, + p.discount as component_discount, + k.__name as contragent, + a.__name as contract, + a.__id::text as contract_uid, + d.__name as deal, + d.__id::text as deal_uid, + siv.abstractive_service as abstract_service, + siv.modifier, siv.user_description, + siv.hash as line_key + ,siv.date_nop as serviceStart, + siv.date_end as serviceEnd, + siv.discount as service_discount, siv.cnt as service_quantity /*,p.__name as line_key*/, p.ed_izm, p.name as component, p.type, p.cnt*coalesce(siv.cnt,1) as component_quantity, aa.__name as additional_agreement, aa.__id::text as additional_agreement_uid --, aa.is_actual @@ -515,24 +529,54 @@ FULL JOIN, потому что нам нужны бесхозные записи /*EXPLAIN PLAN FOR*/ +WITH + metric as (select count(*) as cnt, wz, code, max(dimension1) as dimension1, max(unit) as unit, max(raw_metric) as raw_metric, max(metric) as metric + from qUnifiedMetric + group by wz,code + ), + spec as (select count(*) as cnt, wz, sku_code, + max(end_customer_wz) as wze, + max(code) as code, + max(component_quantity) as component_quantity, + max(service_quantity) as service_quantity, + max(service_discount) as service_discount, + max(type) as type, + max(ed_izm) as ed_izm, + max(coalesce(service_quantity*(100.-service_discount)/100.*price*(100.-component_discount)/100., 0.)) as discounted_price, + max(serviceStart) as serviceStart, + max(serviceEnd) as serviceEnd, + max(line_key) as line_key, + max(price) as price, + max(component_discount) as component_discount, + max(contract) as contract, + max(contract_uid) as contract_uid, + max(additional_agreement) as additional_agreement, + max(additional_agreement_uid) as additional_agreement_uid, + max(deal) as deal, + max(deal_uid) as deal_uid, + max(abstract_service) as abstract_service, + max(modifier) as modifier, + max(component) as component, + max(user_description) as user_description, + max(CASE type WHEN 1 THEN 'install' WHEN 2 THEN 'fix' WHEN 3 THEN 'payg' ELSE NULL END) as pricing_model + from qSpec + group by wz, sku_code + ) + SELECT coalesce(coalesce(c.wz, m.wz), s.wz) as wz s.wz as wzs c.wz as wzc m.wz as wzm - s.end_customer_wz as wze + s.wze coalesce(s.sku_code, m.code) as code s.code as s_code s.sku_code as sku_code - m.code as m_code s.component_quantity s.service_quantity - s.service_discount - coalesce(ft.free_tier,0) as free_tier - m.dimension1 - s.type - m.unit + s.service_discount + s.type s.ed_izm coalesce(s.service_quantity*(100.-s.service_discount)/100.*s.price*(100.-s.component_discount)/100., 0.) as discounted_price s.serviceStart @@ -540,14 +584,6 @@ SELECT s.line_key s.price s.component_discount - m.raw_metric - m.metric - - c.contragent - c.contragent_uid - c.responsible - c.responsible_email - c.responsible_status s.contract s.contract_uid s.additional_agreement @@ -559,22 +595,40 @@ SELECT s.component s.user_description CASE s.type WHEN 1 THEN 'install' WHEN 2 THEN 'fix' WHEN 3 THEN 'payg' ELSE NULL END as pricing_model + + m.code as m_code + m.dimension1 + m.unit + m.raw_metric + m.metric + + coalesce(ft.free_tier,0) as free_tier + + c.contragent + c.contragent_uid + c.responsible + c.responsible_email + c.responsible_status + + s.cnt AS occurrences_spec + m.cnt AS occurrences_metric + -,'***' as delim,s.* -FROM qUnifiedMetric m + +FROM metric m INNER FULL -JOIN qSpec s ON (m.wz=s.wz AND m.code=s.sku_code) -- сервис или компонент, но не цена с типом тарификации, суффикс типа тарификации отрезан +JOIN spec s ON (m.wz=s.wz AND m.code=s.sku_code) -- сервис или компонент, но не цена с типом тарификации, суффикс типа тарификации отрезан --left outer join (values ('paas.s3.ceph.vol-m',1),('paas.s3.ceph.get-m',10),('paas.s3.ceph.put-m',1),('paas.s3.ceph.trf-m',100)) as ft(code,free_tier) ON (m.code=ft.code) left outer join (values ('paas.s3.ceph.vol',1),('paas.s3.ceph.get',10),('paas.s3.ceph.put',1),('paas.s3.ceph.trf',100)) as ft(code,free_tier) ON (m.code=ft.code) LEFT JOIN qContragent c ON ((coalesce(s.wz,m.wz))=(c.wz)) -- пробелы в составе WZ стоили нескольких часов работы ---(поскольку trim слева в джойне катастрофически замедляет работу, делаем чистку выше при формировании исходных резалтсетов) + WHERE 1=1 - AND EXISTS(select * from qSpec qs where qs.wz=m.wz AND qs.type=3) + AND EXISTS(select * from spec qs where qs.wz=m.wz AND qs.type=3) @@ -659,7 +713,7 @@ S3 операции и трафик: - + Услуга Артикул специф. Кол-во специф. @@ -697,8 +751,7 @@ S3 операции и трафик: Договор Допник Сделка - Конечник - + Конечник @@ -736,6 +789,26 @@ S3 операции и трафик: class="gray"> #currentRow# + #occurrences_spec#|#occurrences_metric# + + EXACT MATCH + + CRITICAL: Many-to-Many Explosion (Duplicates on BOTH sides) + + DUPLICATION: Multiple entries for this key in Spec + + DUPLICATION: Multiple entries for this key in Metrics + + ORPHAN: Only in Spec + + ORPHAN: Only in Metrics + + Other Discrepancy + + #abstract_service#: #modifier# style="background:lightgreen;color:black;">#s_code# "err r""r">#component_quantity#