Limit (cost=1424336.80..1424336.85 rows=21 width=660) (actual time=5885.950..5885.954 rows=21 loops=1)
Output: s.id, s.begin_dt, s.issue_dt, (CASE WHEN ((state.code)::text = '3'::text) THEN (SubPlan 1) ELSE NULL::integer END), (CASE WHEN ((state.code)::text = ANY ('{3,5}'::text[])) THEN COALESCE((SubPlan 2), (SubPlan 3)) ELSE NULL::text END), (CASE WHEN ((SubPlan 4) OR ((state.code)::text = '3'::text)) THEN s.end_dt ELSE NULL::date END), (CASE WHEN (s.type_id = 1) THEN s.days ELSE sickdoc.get_sickdoc_days_count(s.id) END), (((s.parent_id IS NOT NULL) AND ((type.code)::text <> '3'::text))), (((type.code)::text = '3'::text)), (((state.code)::text = '5'::text)), (((state.code)::text = '3'::text)), ((((SubPlan 5) AND ((state.code)::text = '3'::text)) OR (SubPlan 6))), (((state.code)::text = '2'::text)), (((state.code)::text = '1'::text)), ((se.disability_reason_id = 5)), s.clinic_id, ($11), s.workplace_id, ((SubPlan 9)), (COALESCE((SubPlan 10), (SubPlan 11))), s.clinic_id, s.registered_clinic_id, (sickdoc.sickdoc_has_max_available_count_of_periods(s.id)), kind.code, s.parent_id, s.individual_id, (concat(individual.surname, ((' '::text || "left"((individual.name)::text, 1)) || '.'::text), ((' '::text || "left"(CASE WHEN (btrim((individual.patr_name)::text) = ANY ('{"",NULL}'::text[])) THEN NULL::text ELSE btrim((individual.patr_name)::text) END, 1)) || '.'::text), ((' ('::text || to_char((individual.birth_dt)::timestamp with time zone, 'DD.MM.YYYY'::text)) || ')'::text))), individual.gender_id, (CASE WHEN (individual.birth_dt IS NULL) THEN NULL::double precision ELSE date_part('year'::text, age((('now'::cstring)::date)::timestamp with time zone, (individual.birth_dt)::timestamp with time zone)) END), (NULL::unknown), (NULL::unknown), s.ready_to_work_dt, s.ready_to_work_other_id, (CASE WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = ''::text)) THEN 'request'::text WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = ANY ('{010,020}'::text[])) AND (s.end_dt < ('now'::cstring)::date)) THEN 'expired'::text WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = ANY ('{010,020}'::text[]))) THEN 'opened'::text WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = '030'::text)) THEN 'closed'::text WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = '090'::text)) THEN 'annulled'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = ANY ('{1,2}'::text[])) AND (s.end_dt < ('now'::cstring)::date)) THEN 'expired'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '1'::text)) THEN 'request'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '2'::text)) THEN 'opened'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '3'::text)) THEN 'closed'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '4'::text)) THEN 'expired'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '5'::text)) THEN 'annulled'::text ELSE NULL::text END), ((COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text <> ALL ('{"",090}'::text[])))), s.number, s.workplace_id, (COALESCE(s.workplace_print, (SubPlan 12))), s.workplace_type_id, ((s.number IS NULL)), s.workplace_type_id, ((s.workplace_type_id = 1)), s.transfer_from_clinic, (COALESCE((s.clinic_id <> 164), true)), ((s.registered_clinic_id = 164)), ((s.type_id = 1)), ((s.type_id = 2)), ((s.type_id = 3)), ((((rwo.code)::text = '31'::text) OR ((rwo.code)::text = '37'::text))), s.journal_id, s.state_id, (COALESCE(s.is_eln, false)), ((SubPlan 13)), s.fss_state_code, (((COALESCE(s.fss_state_code, ''::character varying))::text = '030'::text)), (((COALESCE(s.fss_state_code, ''::character varying))::text = '040'::text)), (((COALESCE(s.fss_state_code, ''::character varying))::text = '090'::text)), (((COALESCE(s.fss_state_code, ''::character varying))::text <> ''::text)), fss_request_state.id, fss_request_state.name, ("substring"(regexp_replace((fss_request.stacktrace)::text, '(Найдены.*Дополнительная информация: [\r\n])'::text, ''::text), 0, 399)), (COALESCE(s.is_from_fss, false)), (NULL::unknown), (NULL::unknown), (CASE WHEN (s.is_eln AND ((SubPlan 14) OR (((((s.hospital_from_dt IS NOT NULL) OR (s.hospital_to_dt IS NOT NULL)) AND (s.issue_dt >= COALESCE(s.hospital_from_dt, '-infinity'::date)) AND (s.issue_dt <= (COALESCE(s.hospital_to_dt, ('now'::cstring)::date) + '2 days'::interval))) OR (s.issue_dt <= s.begin_dt) OR (SubPlan 15)) IS FALSE) OR (((alternatives: SubPlan 16 or hashed SubPlan 17) OR ((s.issue_dt + '2 days'::interval) >= ('now'::cstring)::date) OR (SubPlan 18) OR (SubPlan 19) OR (NOT (SubPlan 20))) IS FALSE) OR (((5 = se.disability_reason_edited_id) OR ((5 = se.disability_reason_id) AND (se.disability_reason_edited_id IS NULL)) OR (SubPlan 21)) IS FALSE))) THEN 'Да'::text ELSE 'Нет'::text END), (CASE WHEN ((alternatives: SubPlan 22 or hashed SubPlan 23) OR ((state.code)::text = '3'::text)) THEN s.end_dt ELSE NULL::date END)
Buffers: shared hit=1721844
InitPlan 8 (returns $11)
-> Result (cost=0.01..0.02 rows=1 width=0) (actual time=0.001..0.001 rows=1 loops=1)
Output: $10
InitPlan 7 (returns $10)
-> Result (cost=0.00..0.01 rows=1 width=0) (actual time=0.000..0.000 rows=0 loops=1)
One-Time Filter: false
-> Sort (cost=1424336.78..1424353.54 rows=6703 width=660) (actual time=5885.948..5885.948 rows=21 loops=1)
Output: s.id, s.begin_dt, s.issue_dt, (CASE WHEN ((state.code)::text = '3'::text) THEN (SubPlan 1) ELSE NULL::integer END), (CASE WHEN ((state.code)::text = ANY ('{3,5}'::text[])) THEN COALESCE((SubPlan 2), (SubPlan 3)) ELSE NULL::text END), (CASE WHEN ((SubPlan 4) OR ((state.code)::text = '3'::text)) THEN s.end_dt ELSE NULL::date END), (CASE WHEN (s.type_id = 1) THEN s.days ELSE sickdoc.get_sickdoc_days_count(s.id) END), (((s.parent_id IS NOT NULL) AND ((type.code)::text <> '3'::text))), (((type.code)::text = '3'::text)), (((state.code)::text = '5'::text)), (((state.code)::text = '3'::text)), ((((SubPlan 5) AND ((state.code)::text = '3'::text)) OR (SubPlan 6))), (((state.code)::text = '2'::text)), (((state.code)::text = '1'::text)), ((se.disability_reason_id = 5)), s.clinic_id, ($11), s.workplace_id, ((SubPlan 9)), (COALESCE((SubPlan 10), (SubPlan 11))), s.clinic_id, s.registered_clinic_id, (sickdoc.sickdoc_has_max_available_count_of_periods(s.id)), kind.code, s.parent_id, s.individual_id, (concat(individual.surname, ((' '::text || "left"((individual.name)::text, 1)) || '.'::text), ((' '::text || "left"(CASE WHEN (btrim((individual.patr_name)::text) = ANY ('{"",NULL}'::text[])) THEN NULL::text ELSE btrim((individual.patr_name)::text) END, 1)) || '.'::text), ((' ('::text || to_char((individual.birth_dt)::timestamp with time zone, 'DD.MM.YYYY'::text)) || ')'::text))), individual.gender_id, (CASE WHEN (individual.birth_dt IS NULL) THEN NULL::double precision ELSE date_part('year'::text, age((('now'::cstring)::date)::timestamp with time zone, (individual.birth_dt)::timestamp with time zone)) END), (NULL::unknown), (NULL::unknown), s.ready_to_work_dt, s.ready_to_work_other_id, (CASE WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = ''::text)) THEN 'request'::text WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = ANY ('{010,020}'::text[])) AND (s.end_dt < ('now'::cstring)::date)) THEN 'expired'::text WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = ANY ('{010,020}'::text[]))) THEN 'opened'::text WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = '030'::text)) THEN 'closed'::text WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = '090'::text)) THEN 'annulled'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = ANY ('{1,2}'::text[])) AND (s.end_dt < ('now'::cstring)::date)) THEN 'expired'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '1'::text)) THEN 'request'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '2'::text)) THEN 'opened'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '3'::text)) THEN 'closed'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '4'::text)) THEN 'expired'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '5'::text)) THEN 'annulled'::text ELSE NULL::text END), ((COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text <> ALL ('{"",090}'::text[])))), s.number, s.workplace_id, (COALESCE(s.workplace_print, (SubPlan 12))), s.workplace_type_id, ((s.number IS NULL)), s.workplace_type_id, ((s.workplace_type_id = 1)), s.transfer_from_clinic, (COALESCE((s.clinic_id <> 164), true)), ((s.registered_clinic_id = 164)), ((s.type_id = 1)), ((s.type_id = 2)), ((s.type_id = 3)), ((((rwo.code)::text = '31'::text) OR ((rwo.code)::text = '37'::text))), s.journal_id, s.state_id, (COALESCE(s.is_eln, false)), ((SubPlan 13)), s.fss_state_code, (((COALESCE(s.fss_state_code, ''::character varying))::text = '030'::text)), (((COALESCE(s.fss_state_code, ''::character varying))::text = '040'::text)), (((COALESCE(s.fss_state_code, ''::character varying))::text = '090'::text)), (((COALESCE(s.fss_state_code, ''::character varying))::text <> ''::text)), fss_request_state.id, fss_request_state.name, ("substring"(regexp_replace((fss_request.stacktrace)::text, '(Найдены.*Дополнительная информация: [\r\n])'::text, ''::text), 0, 399)), (COALESCE(s.is_from_fss, false)), (NULL::unknown), (NULL::unknown), (CASE WHEN (s.is_eln AND ((SubPlan 14) OR (((((s.hospital_from_dt IS NOT NULL) OR (s.hospital_to_dt IS NOT NULL)) AND (s.issue_dt >= COALESCE(s.hospital_from_dt, '-infinity'::date)) AND (s.issue_dt <= (COALESCE(s.hospital_to_dt, ('now'::cstring)::date) + '2 days'::interval))) OR (s.issue_dt <= s.begin_dt) OR (SubPlan 15)) IS FALSE) OR (((alternatives: SubPlan 16 or hashed SubPlan 17) OR ((s.issue_dt + '2 days'::interval) >= ('now'::cstring)::date) OR (SubPlan 18) OR (SubPlan 19) OR (NOT (SubPlan 20))) IS FALSE) OR (((5 = se.disability_reason_edited_id) OR ((5 = se.disability_reason_id) AND (se.disability_reason_edited_id IS NULL)) OR (SubPlan 21)) IS FALSE))) THEN 'Да'::text ELSE 'Нет'::text END), (CASE WHEN ((alternatives: SubPlan 22 or hashed SubPlan 23) OR ((state.code)::text = '3'::text)) THEN s.end_dt ELSE NULL::date END)
Sort Key: (CASE WHEN ((alternatives: SubPlan 22 or hashed SubPlan 23) OR ((state.code)::text = '3'::text)) THEN s.end_dt ELSE NULL::date END) DESC
Sort Method: top-N heapsort Memory: 30kB
Buffers: shared hit=1721844
-> Merge Right Join (cost=82597.08..1424156.06 rows=6703 width=660) (actual time=539.280..5836.684 rows=19913 loops=1)
Output: s.id, s.begin_dt, s.issue_dt, CASE WHEN ((state.code)::text = '3'::text) THEN (SubPlan 1) ELSE NULL::integer END, CASE WHEN ((state.code)::text = ANY ('{3,5}'::text[])) THEN COALESCE((SubPlan 2), (SubPlan 3)) ELSE NULL::text END, CASE WHEN ((SubPlan 4) OR ((state.code)::text = '3'::text)) THEN s.end_dt ELSE NULL::date END, CASE WHEN (s.type_id = 1) THEN s.days ELSE sickdoc.get_sickdoc_days_count(s.id) END, ((s.parent_id IS NOT NULL) AND ((type.code)::text <> '3'::text)), ((type.code)::text = '3'::text), ((state.code)::text = '5'::text), ((state.code)::text = '3'::text), (((SubPlan 5) AND ((state.code)::text = '3'::text)) OR (SubPlan 6)), ((state.code)::text = '2'::text), ((state.code)::text = '1'::text), (se.disability_reason_id = 5), s.clinic_id, $11, s.workplace_id, (SubPlan 9), COALESCE((SubPlan 10), (SubPlan 11)), s.clinic_id, s.registered_clinic_id, sickdoc.sickdoc_has_max_available_count_of_periods(s.id), kind.code, s.parent_id, s.individual_id, concat(individual.surname, ((' '::text || "left"((individual.name)::text, 1)) || '.'::text), ((' '::text || "left"(CASE WHEN (btrim((individual.patr_name)::text) = ANY ('{"",NULL}'::text[])) THEN NULL::text ELSE btrim((individual.patr_name)::text) END, 1)) || '.'::text), ((' ('::text || to_char((individual.birth_dt)::timestamp with time zone, 'DD.MM.YYYY'::text)) || ')'::text)), individual.gender_id, CASE WHEN (individual.birth_dt IS NULL) THEN NULL::double precision ELSE date_part('year'::text, age((('now'::cstring)::date)::timestamp with time zone, (individual.birth_dt)::timestamp with time zone)) END, NULL::unknown, NULL::unknown, s.ready_to_work_dt, s.ready_to_work_other_id, CASE WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = ''::text)) THEN 'request'::text WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = ANY ('{010,020}'::text[])) AND (s.end_dt < ('now'::cstring)::date)) THEN 'expired'::text WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = ANY ('{010,020}'::text[]))) THEN 'opened'::text WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = '030'::text)) THEN 'closed'::text WHEN (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text = '090'::text)) THEN 'annulled'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = ANY ('{1,2}'::text[])) AND (s.end_dt < ('now'::cstring)::date)) THEN 'expired'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '1'::text)) THEN 'request'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '2'::text)) THEN 'opened'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '3'::text)) THEN 'closed'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '4'::text)) THEN 'expired'::text WHEN ((NOT COALESCE(s.is_eln, false)) AND ((state.code)::text = '5'::text)) THEN 'annulled'::text ELSE NULL::text END, (COALESCE(s.is_eln, false) AND ((COALESCE(s.fss_state_code, ''::character varying))::text <> ALL ('{"",090}'::text[]))), s.number, s.workplace_id, COALESCE(s.workplace_print, (SubPlan 12)), s.workplace_type_id, (s.number IS NULL), s.workplace_type_id, (s.workplace_type_id = 1), s.transfer_from_clinic, COALESCE((s.clinic_id <> 164), true), (s.registered_clinic_id = 164), (s.type_id = 1), (s.type_id = 2), (s.type_id = 3), (((rwo.code)::text = '31'::text) OR ((rwo.code)::text = '37'::text)), s.journal_id, s.state_id, COALESCE(s.is_eln, false), (SubPlan 13), s.fss_state_code, ((COALESCE(s.fss_state_code, ''::character varying))::text = '030'::text), ((COALESCE(s.fss_state_code, ''::character varying))::text = '040'::text), ((COALESCE(s.fss_state_code, ''::character varying))::text = '090'::text), ((COALESCE(s.fss_state_code, ''::character varying))::text <> ''::text), fss_request_state.id, fss_request_state.name, "substring"(regexp_replace((fss_request.stacktrace)::text, '(Найдены.*Дополнительная информация: [\r\n])'::text, ''::text), 0, 399), COALESCE(s.is_from_fss, false), NULL::unknown, NULL::unknown, CASE WHEN (s.is_eln AND ((SubPlan 14) OR (((((s.hospital_from_dt IS NOT NULL) OR (s.hospital_to_dt IS NOT NULL)) AND (s.issue_dt >= COALESCE(s.hospital_from_dt, '-infinity'::date)) AND (s.issue_dt <= (COALESCE(s.hospital_to_dt, ('now'::cstring)::date) + '2 days'::interval))) OR (s.issue_dt <= s.begin_dt) OR (SubPlan 15)) IS FALSE) OR (((alternatives: SubPlan 16 or hashed SubPlan 17) OR ((s.issue_dt + '2 days'::interval) >= ('now'::cstring)::date) OR (SubPlan 18) OR (SubPlan 19) OR (NOT (SubPlan 20))) IS FALSE) OR (((5 = se.disability_reason_edited_id) OR ((5 = se.disability_reason_id) AND (se.disability_reason_edited_id IS NULL)) OR (SubPlan 21)) IS FALSE))) THEN 'Да'::text ELSE 'Нет'::text END, CASE WHEN ((alternatives: SubPlan 22 or hashed SubPlan 23) OR ((state.code)::text = '3'::text)) THEN s.end_dt ELSE NULL::date END
Merge Cond: (fss_request.sicklist_n2o_id = s.id)
Buffers: shared hit=1721844
-> Nested Loop Left Join (cost=27617.79..34558.93 rows=1058 width=472) (actual time=173.854..438.592 rows=56569 loops=1)
Output: fss_request.stacktrace, fss_request.sicklist_n2o_id, fss_request_state.id, fss_request_state.name
Join Filter: (fss_request_state.id = fss_request.state_id)
Rows Removed by Join Filter: 169707
Buffers: shared hit=6787
-> Subquery Scan on fss_request (cost=27617.79..34494.40 rows=1058 width=447) (actual time=173.826..376.451 rows=56569 loops=1)
Output: fss_request.id, fss_request.uid, fss_request.type_id, fss_request.state_id, fss_request.initiator_id, fss_request.org_id, fss_request.eln_number, fss_request.eln_number_range, fss_request.create_dt, fss_request.receive_resp_dt, fss_request.request_text, fss_request.response_text, fss_request.stacktrace, fss_request.platform, fss_request.sicklist_n2o_id, fss_request.params, fss_request.aud_who, fss_request.aud_when, fss_request.aud_source, fss_request.aud_who_create, fss_request.aud_when_create, fss_request.aud_source_create, fss_request.rn
Filter: (fss_request.rn = 1)
Rows Removed by Filter: 111869
Buffers: shared hit=6786
-> WindowAgg (cost=27617.79..31849.55 rows=211588 width=455) (actual time=173.807..351.116 rows=168438 loops=1)
Output: NULL::integer, NULL::character varying, NULL::integer, r.state_id, NULL::integer, NULL::integer, NULL::character varying, NULL::character varying, r.create_dt, NULL::timestamp without time zone, NULL::character varying, NULL::character varying, r.stacktrace, NULL::integer, r.sicklist_n2o_id, NULL::json, NULL::character varying, NULL::timestamp without time zone, NULL::character varying, NULL::character varying, NULL::timestamp without time zone, NULL::character varying, row_number() OVER (?)
Buffers: shared hit=6786
-> Sort (cost=27617.79..28146.76 rows=211588 width=455) (actual time=173.785..211.782 rows=168438 loops=1)
Output: r.create_dt, r.sicklist_n2o_id, r.state_id, r.stacktrace
Sort Key: r.sicklist_n2o_id, r.create_dt DESC NULLS LAST
Sort Method: quicksort Memory: 33785kB
Buffers: shared hit=6786
-> Seq Scan on sickdoc.fss_request r (cost=0.00..8901.88 rows=211588 width=455) (actual time=0.006..64.072 rows=196181 loops=1)
Output: r.create_dt, r.sicklist_n2o_id, r.state_id, r.stacktrace
Buffers: shared hit=6786
-> Materialize (cost=0.00..1.06 rows=4 width=29) (actual time=0.000..0.000 rows=4 loops=56569)
Output: fss_request_state.id, fss_request_state.name
Buffers: shared hit=1
-> Seq Scan on sickdoc.fss_request_state (cost=0.00..1.04 rows=4 width=29) (actual time=0.016..0.016 rows=4 loops=1)
Output: fss_request_state.id, fss_request_state.name
Buffers: shared hit=1
-> Sort (cost=54979.29..54996.04 rows=6703 width=192) (actual time=256.112..264.062 rows=19913 loops=1)
Output: s.id, s.begin_dt, s.issue_dt, s.end_dt, s.type_id, s.days, s.parent_id, s.clinic_id, s.workplace_id, s.registered_clinic_id, s.individual_id, s.ready_to_work_dt, s.ready_to_work_other_id, s.is_eln, s.fss_state_code, s.number, s.workplace_print, s.workplace_type_id, s.transfer_from_clinic, s.journal_id, s.state_id, s.is_from_fss, s.hospital_from_dt, s.hospital_to_dt, se.disability_reason_id, se.disability_reason_edited_id, kind.code, state.code, individual.surname, individual.name, individual.patr_name, individual.birth_dt, individual.gender_id, type.code, rwo.code
Sort Key: s.id
Sort Method: quicksort Memory: 6048kB
Buffers: shared hit=84914
-> Hash Left Join (cost=5229.21..54553.29 rows=6703 width=192) (actual time=41.829..233.734 rows=19913 loops=1)
Output: s.id, s.begin_dt, s.issue_dt, s.end_dt, s.type_id, s.days, s.parent_id, s.clinic_id, s.workplace_id, s.registered_clinic_id, s.individual_id, s.ready_to_work_dt, s.ready_to_work_other_id, s.is_eln, s.fss_state_code, s.number, s.workplace_print, s.workplace_type_id, s.transfer_from_clinic, s.journal_id, s.state_id, s.is_from_fss, s.hospital_from_dt, s.hospital_to_dt, se.disability_reason_id, se.disability_reason_edited_id, kind.code, state.code, individual.surname, individual.name, individual.patr_name, individual.birth_dt, individual.gender_id, type.code, rwo.code
Hash Cond: (s.ready_to_work_other_id = rwo.id)
Buffers: shared hit=84914
-> Nested Loop Left Join (cost=5228.05..54520.06 rows=6703 width=189) (actual time=41.810..226.700 rows=19913 loops=1)
Output: s.id, s.begin_dt, s.issue_dt, s.end_dt, s.type_id, s.days, s.parent_id, s.clinic_id, s.workplace_id, s.registered_clinic_id, s.individual_id, s.ready_to_work_dt, s.ready_to_work_other_id, s.is_eln, s.fss_state_code, s.number, s.workplace_print, s.workplace_type_id, s.transfer_from_clinic, s.journal_id, s.state_id, s.is_from_fss, s.hospital_from_dt, s.hospital_to_dt, se.disability_reason_id, se.disability_reason_edited_id, kind.code, state.code, individual.surname, individual.name, individual.patr_name, individual.birth_dt, individual.gender_id, type.code
Join Filter: (type.id = s.type_id)
Rows Removed by Join Filter: 39826
Buffers: shared hit=84913
-> Nested Loop Left Join (cost=5228.05..54217.39 rows=6703 width=187) (actual time=41.799..207.125 rows=19913 loops=1)
Output: s.id, s.begin_dt, s.issue_dt, s.end_dt, s.type_id, s.days, s.parent_id, s.clinic_id, s.workplace_id, s.registered_clinic_id, s.individual_id, s.ready_to_work_dt, s.ready_to_work_other_id, s.is_eln, s.fss_state_code, s.number, s.workplace_print, s.workplace_type_id, s.transfer_from_clinic, s.journal_id, s.state_id, s.is_from_fss, s.hospital_from_dt, s.hospital_to_dt, se.disability_reason_id, se.disability_reason_edited_id, kind.code, state.code, individual.surname, individual.name, individual.patr_name, individual.birth_dt, individual.gender_id
Buffers: shared hit=84912
-> Hash Join (cost=5227.62..8807.32 rows=6703 width=129) (actual time=41.769..102.146 rows=19913 loops=1)
Output: s.id, s.begin_dt, s.issue_dt, s.end_dt, s.type_id, s.days, s.parent_id, s.clinic_id, s.workplace_id, s.registered_clinic_id, s.individual_id, s.ready_to_work_dt, s.ready_to_work_other_id, s.is_eln, s.fss_state_code, s.number, s.workplace_print, s.workplace_type_id, s.transfer_from_clinic, s.journal_id, s.state_id, s.is_from_fss, s.hospital_from_dt, s.hospital_to_dt, se.disability_reason_id, se.disability_reason_edited_id, kind.code, state.code
Hash Cond: (s.state_id = state.id)
Buffers: shared hit=5135
-> Hash Join (cost=5226.51..8714.05 rows=6703 width=127) (actual time=41.747..95.241 rows=19913 loops=1)
Output: s.id, s.begin_dt, s.issue_dt, s.end_dt, s.type_id, s.days, s.parent_id, s.clinic_id, s.workplace_id, s.registered_clinic_id, s.individual_id, s.ready_to_work_dt, s.ready_to_work_other_id, s.is_eln, s.fss_state_code, s.number, s.workplace_print, s.workplace_type_id, s.transfer_from_clinic, s.journal_id, s.state_id, s.is_from_fss, s.hospital_from_dt, s.hospital_to_dt, se.disability_reason_id, se.disability_reason_edited_id, kind.code
Hash Cond: (se.id = s.id)
Buffers: shared hit=5134
-> Seq Scan on sickdoc.sickdoc_extended se (cost=0.00..2949.64 rows=125564 width=12) (actual time=0.003..12.078 rows=124819 loops=1)
Output: se.id, se.address_id, se.disability_from_dt, se.disability_reason_edited_id, se.disability_reason_ext_id, se.disability_reason_id, se.disability_to_dt, se.family_member_1_id, se.family_member_2_id, se.is_disability_group_changed, se.is_early_pregnancy_register, se.mse_emp, se.mse_examination_dt, se.mse_org_id, se.mse_referral_dt, se.mse_register_dt, se.on_placement_service, se.regimen_id, se.regimen_violation_doctor_id, se.regimen_violation_dt, se.regimen_violation_id, se.sanatorium_id, se.sanatorium_ogrn_code, se.voucher_code, se.aud_who, se.aud_when, se.aud_source, se.aud_who_create, se.aud_when_create, se.aud_source_create, se.family_member_1_relation_id_lsd, se.family_member_1_age_lsd, se.family_member_1_age_month_lsd, se.family_member_1_name_lsd, se.family_member_2_relation_id_lsd, se.family_member_2_age_lsd, se.family_member_2_age_month_lsd, se.family_member_2_name_lsd, se.disability_group
Buffers: shared hit=1694
-> Hash (cost=5142.72..5142.72 rows=6703 width=119) (actual time=41.668..41.668 rows=19913 loops=1)
Output: s.id, s.begin_dt, s.issue_dt, s.end_dt, s.type_id, s.days, s.parent_id, s.clinic_id, s.workplace_id, s.registered_clinic_id, s.individual_id, s.ready_to_work_dt, s.ready_to_work_other_id, s.is_eln, s.fss_state_code, s.number, s.workplace_print, s.workplace_type_id, s.transfer_from_clinic, s.journal_id, s.state_id, s.is_from_fss, s.hospital_from_dt, s.hospital_to_dt, kind.code
Buckets: 32768 (originally 8192) Batches: 1 (originally 1) Memory Usage: 2916kB
Buffers: shared hit=3440
-> Hash Join (cost=1.05..5142.72 rows=6703 width=119) (actual time=0.027..33.355 rows=19913 loops=1)
Output: s.id, s.begin_dt, s.issue_dt, s.end_dt, s.type_id, s.days, s.parent_id, s.clinic_id, s.workplace_id, s.registered_clinic_id, s.individual_id, s.ready_to_work_dt, s.ready_to_work_other_id, s.is_eln, s.fss_state_code, s.number, s.workplace_print, s.workplace_type_id, s.transfer_from_clinic, s.journal_id, s.state_id, s.is_from_fss, s.hospital_from_dt, s.hospital_to_dt, kind.code
Hash Cond: (s.kind_id = kind.id)
Buffers: shared hit=3440
-> Seq Scan on sickdoc.sickdoc s (cost=0.00..4999.24 rows=20108 width=125) (actual time=0.011..21.984 rows=19913 loops=1)
Output: s.id, s.begin_dt, s.case_id, s.clinic_id, s.days, s.end_dt, s.final_diagnosis_id, s.hospital_from_dt, s.hospital_to_dt, s.individual_id, s.initial_diagnosis_id, s.issue_dt, s.journal_id, s.kind_id, s.number, s.parent_id, s.ready_to_work_dt, s.ready_to_work_other_dt, s.ready_to_work_other_id, s.registrator_id, s.state_id, s.transfer_to_o_clinic, s.transfer_from_clinic, s.workplace_id, s.workplace_print, s.workplace_type_id, s.type_id, s.aud_who, s.aud_when, s.aud_source, s.aud_who_create, s.aud_when_create, s.aud_source_create, s.md_sicklist_id, s.registered_clinic_id, s.is_eln, s.is_print, s.range_id, s.ln_result_signature, s.hospital_breach_signature, s.fss_state_code, s.eln_hash, s.annual_reason_id, s.fss_annual_reason_comment, s.fss_annual_reason_id, s.print_clinic, s.parent_number_print, s.main_job_print_number, s.is_from_fss, s.print_clinic_ogrn, s.print_clinic_address
Filter: (s.clinic_id = 164)
Rows Removed by Filter: 104906
Buffers: shared hit=3439
-> Hash (cost=1.04..1.04 rows=1 width=6) (actual time=0.008..0.008 rows=1 loops=1)
Output: kind.code, kind.id
Buckets: 1024 Batches: 1 Memory Usage: 9kB
Buffers: shared hit=1
-> Seq Scan on sickdoc.rf_kind kind (cost=0.00..1.04 rows=1 width=6) (actual time=0.005..0.006 rows=1 loops=1)
Output: kind.code, kind.id
Filter: ((kind.code)::text = '1'::text)
Rows Removed by Filter: 2
Buffers: shared hit=1
-> Hash (cost=1.05..1.05 rows=5 width=6) (actual time=0.008..0.008 rows=5 loops=1)
Output: state.code, state.id
Buckets: 1024 Batches: 1 Memory Usage: 9kB
Buffers: shared hit=1
-> Seq Scan on public.md_sicklist_state state (cost=0.00..1.05 rows=5 width=6) (actual time=0.004..0.004 rows=5 loops=1)
Output: state.code, state.id
Buffers: shared hit=1
-> Index Scan using pim_individual_pk on public.pim_individual individual (cost=0.43..6.76 rows=1 width=62) (actual time=0.004..0.005 rows=1 loops=19913)
Output: individual.id, individual.birth_dt, individual.death_dt, individual.has_citizenship, individual.name, individual.patr_name, individual.surname, individual.gender_id, individual.nationality_id, individual.list_identity_doc, individual.list_oms_doc, individual.list_job_org, individual.list_reg_name, individual.list_snils, individual.list_uid, individual.aud_who, individual.aud_when, individual.aud_source, individual.aud_who_create, individual.aud_when_create, individual.aud_source_create, individual.birth_place, individual.age_year, individual.age_month, individual.age_day, individual.list_main_contact
Index Cond: (individual.id = s.individual_id)
Buffers: shared hit=79777
-> Materialize (cost=0.00..1.04 rows=3 width=6) (actual time=0.000..0.000 rows=3 loops=19913)
Output: type.code, type.id
Buffers: shared hit=1
-> Seq Scan on public.md_sicklist_type type (cost=0.00..1.03 rows=3 width=6) (actual time=0.002..0.003 rows=3 loops=1)
Output: type.code, type.id
Buffers: shared hit=1
-> Hash (cost=1.07..1.07 rows=7 width=7) (actual time=0.006..0.006 rows=7 loops=1)
Output: rwo.code, rwo.id
Buckets: 1024 Batches: 1 Memory Usage: 9kB
Buffers: shared hit=1
-> Seq Scan on public.md_sl_readytowork_other rwo (cost=0.00..1.07 rows=7 width=7) (actual time=0.002..0.004 rows=7 loops=1)
Output: rwo.code, rwo.id
Buffers: shared hit=1
SubPlan 1
-> Limit (cost=8.50..8.50 rows=1 width=8) (actual time=0.010..0.011 rows=1 loops=13275)
Output: p.issued_employee_id, p.from_dt
Buffers: shared hit=65635
-> Sort (cost=8.50..8.50 rows=2 width=8) (actual time=0.010..0.010 rows=1 loops=13275)
Output: p.issued_employee_id, p.from_dt
Sort Key: p.from_dt DESC
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=65635
-> Index Scan using period_sickdoc_id_ix on sickdoc.period p (cost=0.42..8.49 rows=2 width=8) (actual time=0.005..0.006 rows=2 loops=13275)
Output: p.issued_employee_id, p.from_dt
Index Cond: (p.sickdoc_id = s.id)
Buffers: shared hit=65635
SubPlan 2
-> Limit (cost=37.74..37.74 rows=1 width=105) (actual time=0.044..0.044 rows=1 loops=13549)
Output: (concat(i.surname, ((' '::text || "left"((i.name)::text, 1)) || '.'::text), ((' '::text || "left"((i.patr_name)::text, 1)) || '.'::text), (', '::text || (pp.name)::text))), p_1.from_dt
Buffers: shared hit=423283
-> Sort (cost=37.74..37.74 rows=2 width=105) (actual time=0.043..0.043 rows=1 loops=13549)
Output: (concat(i.surname, ((' '::text || "left"((i.name)::text, 1)) || '.'::text), ((' '::text || "left"((i.patr_name)::text, 1)) || '.'::text), (', '::text || (pp.name)::text))), p_1.from_dt
Sort Key: p_1.from_dt DESC
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=423283
-> Nested Loop (cost=1.72..37.73 rows=2 width=105) (actual time=0.024..0.040 rows=2 loops=13549)
Output: concat(i.surname, ((' '::text || "left"((i.name)::text, 1)) || '.'::text), ((' '::text || "left"((i.patr_name)::text, 1)) || '.'::text), (', '::text || (pp.name)::text)), p_1.from_dt
Buffers: shared hit=423283
-> Nested Loop (cost=1.29..26.62 rows=2 width=59) (actual time=0.014..0.024 rows=2 loops=13549)
Output: p_1.from_dt, pp.name, e.individual_id
Buffers: shared hit=313639
-> Nested Loop (cost=1.00..25.89 rows=2 width=59) (actual time=0.011..0.018 rows=2 loops=13549)
Output: p_1.from_dt, ep.employee_id, pp.name
Buffers: shared hit=231331
-> Nested Loop (cost=0.71..25.12 rows=2 width=12) (actual time=0.007..0.011 rows=2 loops=13549)
Output: p_1.from_dt, ep.position_id, ep.employee_id
Buffers: shared hit=149098
-> Index Scan using period_sickdoc_id_ix on sickdoc.period p_1 (cost=0.42..8.49 rows=2 width=8) (actual time=0.002..0.003 rows=2 loops=13549)
Output: p_1.id, p_1.clinic_id, p_1.from_dt, p_1.issued_employee_id, p_1.issued_employee_position, p_1.sickdoc_id, p_1.step_id, p_1.to_dt, p_1.witness_employee_id, p_1.witness_employee_position, p_1.aud_who, p_1.aud_when, p_1.aud_source, p_1.aud_who_create, p_1.aud_when_create, p_1.aud_source_create, p_1.signature_num, p_1.doctor_signature, p_1.chairman_signature, p_1.is_sent_to_fss, p_1.witness_employee_print, p_1.issued_employee_print
Index Cond: (p_1.sickdoc_id = s.id)
Buffers: shared hit=66865
-> Index Scan using pim_employee_position_pk on public.pim_employee_position ep (cost=0.29..8.31 rows=1 width=12) (actual time=0.003..0.003 rows=1 loops=27412)
Output: ep.id, ep.dismissal_order_code, ep.start_date, ep.hiring_order_code, ep.rate, ep.end_date, ep.dismissal_reason_id, ep.employee_id, ep.employment_type_id, ep.hiring_type_id, ep.position_id, ep.position_type_id, ep.unit_id, ep.code, ep.aud_who, ep.aud_when, ep.aud_source, ep.aud_who_create, ep.aud_when_create, ep.aud_source_create, ep.pref_prescription, ep.extra_payment, ep.target_training, ep.leaving_reason_id
Index Cond: (ep.id = p_1.issued_employee_id)
Buffers: shared hit=82233
-> Index Scan using pim_position_pk on public.pim_position pp (cost=0.29..0.37 rows=1 width=55) (actual time=0.002..0.002 rows=1 loops=27411)
Output: pp.id, pp.code, pp.start_date, pp.name, pp.end_date, pp.department_id, pp.organization_id, pp.role_id, pp.speciality_id, pp.rate, pp.aud_who, pp.aud_when, pp.aud_source, pp.aud_who_create, pp.aud_when_create, pp.aud_source_create, pp.pref_prescription, pp.payment_fond, pp.staff_event1, pp.staff_event2
Index Cond: (pp.id = ep.position_id)
Buffers: shared hit=82233
-> Index Scan using pim_employee_pk on public.pim_employee e (cost=0.29..0.36 rows=1 width=8) (actual time=0.002..0.002 rows=1 loops=27411)
Output: e.id, e.note, e.number, e.photo, e.callup_subject_id, e.individual_id, e.organization_id, e.is_dismissed, e.employment_dt, e.dismissal_dt, e.aud_who, e.aud_when, e.aud_source, e.aud_who_create, e.aud_when_create, e.aud_source_create, e.accreditation_id
Index Cond: (e.id = ep.employee_id)
Buffers: shared hit=82308
-> Index Scan using pim_individual_pk on public.pim_individual i (cost=0.43..5.52 rows=1 width=54) (actual time=0.003..0.004 rows=1 loops=27411)
Output: i.id, i.birth_dt, i.death_dt, i.has_citizenship, i.name, i.patr_name, i.surname, i.gender_id, i.nationality_id, i.list_identity_doc, i.list_oms_doc, i.list_job_org, i.list_reg_name, i.list_snils, i.list_uid, i.aud_who, i.aud_when, i.aud_source, i.aud_who_create, i.aud_when_create, i.aud_source_create, i.birth_place, i.age_year, i.age_month, i.age_day, i.list_main_contact
Index Cond: (i.id = e.individual_id)
Buffers: shared hit=109644
SubPlan 3
-> Limit (cost=8.51..8.51 rows=1 width=45) (never executed)
Output: ((((p_2.issued_employee_print)::text || ' '::text) || (p_2.issued_employee_position)::text)), p_2.from_dt
-> Sort (cost=8.51..8.51 rows=2 width=45) (never executed)
Output: ((((p_2.issued_employee_print)::text || ' '::text) || (p_2.issued_employee_position)::text)), p_2.from_dt
Sort Key: p_2.from_dt DESC
-> Index Scan using period_sickdoc_id_ix on sickdoc.period p_2 (cost=0.42..8.50 rows=2 width=45) (never executed)
Output: (((p_2.issued_employee_print)::text || ' '::text) || (p_2.issued_employee_position)::text), p_2.from_dt
Index Cond: (p_2.sickdoc_id = s.id)
SubPlan 4
-> Aggregate (cost=8.46..8.47 rows=1 width=0) (actual time=0.005..0.005 rows=1 loops=19913)
Output: (count(1) > 1)
Buffers: shared hit=63236
-> Index Only Scan using period_sickdoc_id_ix on sickdoc.period (cost=0.42..8.46 rows=2 width=0) (actual time=0.003..0.003 rows=2 loops=19913)
Output: period.sickdoc_id
Index Cond: (period.sickdoc_id = s.id)
Heap Fetches: 3501
Buffers: shared hit=63236
SubPlan 5
-> Seq Scan on public.md_sl_disability_reason _sdr (cost=0.00..1.19 rows=1 width=3) (actual time=0.002..0.003 rows=1 loops=19913)
Output: ((_sdr.code)::text = '05'::text)
Filter: (_sdr.id = se.disability_reason_id)
Rows Removed by Filter: 14
Buffers: shared hit=19913
SubPlan 6
-> Seq Scan on public.md_sl_disability_reason _sdr_1 (cost=0.00..1.19 rows=1 width=3) (actual time=0.001..0.002 rows=1 loops=19913)
Output: ((_sdr_1.code)::text <> '05'::text)
Filter: (_sdr_1.id = se.disability_reason_id)
Rows Removed by Filter: 14
Buffers: shared hit=19913
SubPlan 9
-> Limit (cost=8.50..8.50 rows=1 width=8) (actual time=0.009..0.009 rows=1 loops=19913)
Output: p_3.issued_employee_id, p_3.from_dt
Buffers: shared hit=94077
-> Sort (cost=8.50..8.50 rows=2 width=8) (actual time=0.008..0.008 rows=1 loops=19913)
Output: p_3.issued_employee_id, p_3.from_dt
Sort Key: p_3.from_dt
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=94077
-> Index Scan using period_sickdoc_id_ix on sickdoc.period p_3 (cost=0.42..8.49 rows=2 width=8) (actual time=0.003..0.004 rows=2 loops=19913)
Output: p_3.issued_employee_id, p_3.from_dt
Index Cond: (p_3.sickdoc_id = s.id)
Buffers: shared hit=94077
SubPlan 10
-> Limit (cost=37.74..37.74 rows=1 width=105) (actual time=0.034..0.035 rows=1 loops=19913)
Output: (concat(i_1.surname, ((' '::text || "left"((i_1.name)::text, 1)) || '.'::text), ((' '::text || "left"((i_1.patr_name)::text, 1)) || '.'::text), (', '::text || (pp_1.name)::text))), p_4.from_dt
Buffers: shared hit=541423
-> Sort (cost=37.74..37.74 rows=2 width=105) (actual time=0.034..0.034 rows=1 loops=19913)
Output: (concat(i_1.surname, ((' '::text || "left"((i_1.name)::text, 1)) || '.'::text), ((' '::text || "left"((i_1.patr_name)::text, 1)) || '.'::text), (', '::text || (pp_1.name)::text))), p_4.from_dt
Sort Key: p_4.from_dt
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=541423
-> Nested Loop (cost=1.72..37.73 rows=2 width=105) (actual time=0.019..0.031 rows=2 loops=19913)
Output: concat(i_1.surname, ((' '::text || "left"((i_1.name)::text, 1)) || '.'::text), ((' '::text || "left"((i_1.patr_name)::text, 1)) || '.'::text), (', '::text || (pp_1.name)::text)), p_4.from_dt
Buffers: shared hit=541423
-> Nested Loop (cost=1.29..26.62 rows=2 width=59) (actual time=0.011..0.019 rows=2 loops=19913)
Output: p_4.from_dt, pp_1.name, e_1.individual_id
Buffers: shared hit=403815
-> Nested Loop (cost=1.00..25.89 rows=2 width=59) (actual time=0.009..0.014 rows=2 loops=19913)
Output: p_4.from_dt, ep_1.employee_id, pp_1.name
Buffers: shared hit=300489
-> Nested Loop (cost=0.71..25.12 rows=2 width=12) (actual time=0.006..0.009 rows=2 loops=19913)
Output: p_4.from_dt, ep_1.position_id, ep_1.employee_id
Buffers: shared hit=197283
-> Index Scan using period_sickdoc_id_ix on sickdoc.period p_4 (cost=0.42..8.49 rows=2 width=8) (actual time=0.002..0.003 rows=2 loops=19913)
Output: p_4.id, p_4.clinic_id, p_4.from_dt, p_4.issued_employee_id, p_4.issued_employee_position, p_4.sickdoc_id, p_4.step_id, p_4.to_dt, p_4.witness_employee_id, p_4.witness_employee_position, p_4.aud_who, p_4.aud_when, p_4.aud_source, p_4.aud_who_create, p_4.aud_when_create, p_4.aud_source_create, p_4.signature_num, p_4.doctor_signature, p_4.chairman_signature, p_4.is_sent_to_fss, p_4.witness_employee_print, p_4.issued_employee_print
Index Cond: (p_4.sickdoc_id = s.id)
Buffers: shared hit=94077
-> Index Scan using pim_employee_position_pk on public.pim_employee_position ep_1 (cost=0.29..8.31 rows=1 width=12) (actual time=0.002..0.002 rows=1 loops=35971)
Output: ep_1.id, ep_1.dismissal_order_code, ep_1.start_date, ep_1.hiring_order_code, ep_1.rate, ep_1.end_date, ep_1.dismissal_reason_id, ep_1.employee_id, ep_1.employment_type_id, ep_1.hiring_type_id, ep_1.position_id, ep_1.position_type_id, ep_1.unit_id, ep_1.code, ep_1.aud_who, ep_1.aud_when, ep_1.aud_source, ep_1.aud_who_create, ep_1.aud_when_create, ep_1.aud_source_create, ep_1.pref_prescription, ep_1.extra_payment, ep_1.target_training, ep_1.leaving_reason_id
Index Cond: (ep_1.id = p_4.issued_employee_id)
Buffers: shared hit=103206
-> Index Scan using pim_position_pk on public.pim_position pp_1 (cost=0.29..0.37 rows=1 width=55) (actual time=0.002..0.002 rows=1 loops=34402)
Output: pp_1.id, pp_1.code, pp_1.start_date, pp_1.name, pp_1.end_date, pp_1.department_id, pp_1.organization_id, pp_1.role_id, pp_1.speciality_id, pp_1.rate, pp_1.aud_who, pp_1.aud_when, pp_1.aud_source, pp_1.aud_who_create, pp_1.aud_when_create, pp_1.aud_source_create, pp_1.pref_prescription, pp_1.payment_fond, pp_1.staff_event1, pp_1.staff_event2
Index Cond: (pp_1.id = ep_1.position_id)
Buffers: shared hit=103206
-> Index Scan using pim_employee_pk on public.pim_employee e_1 (cost=0.29..0.36 rows=1 width=8) (actual time=0.002..0.002 rows=1 loops=34402)
Output: e_1.id, e_1.note, e_1.number, e_1.photo, e_1.callup_subject_id, e_1.individual_id, e_1.organization_id, e_1.is_dismissed, e_1.employment_dt, e_1.dismissal_dt, e_1.aud_who, e_1.aud_when, e_1.aud_source, e_1.aud_who_create, e_1.aud_when_create, e_1.aud_source_create, e_1.accreditation_id
Index Cond: (e_1.id = ep_1.employee_id)
Buffers: shared hit=103326
-> Index Scan using pim_individual_pk on public.pim_individual i_1 (cost=0.43..5.52 rows=1 width=54) (actual time=0.003..0.003 rows=1 loops=34402)
Output: i_1.id, i_1.birth_dt, i_1.death_dt, i_1.has_citizenship, i_1.name, i_1.patr_name, i_1.surname, i_1.gender_id, i_1.nationality_id, i_1.list_identity_doc, i_1.list_oms_doc, i_1.list_job_org, i_1.list_reg_name, i_1.list_snils, i_1.list_uid, i_1.aud_who, i_1.aud_when, i_1.aud_source, i_1.aud_who_create, i_1.aud_when_create, i_1.aud_source_create, i_1.birth_place, i_1.age_year, i_1.age_month, i_1.age_day, i_1.list_main_contact
Index Cond: (i_1.id = e_1.individual_id)
Buffers: shared hit=137608
SubPlan 11
-> Limit (cost=8.51..8.51 rows=1 width=45) (actual time=0.005..0.005 rows=1 loops=1711)
Output: ((((p_5.issued_employee_print)::text || ' '::text) || (p_5.issued_employee_position)::text)), p_5.from_dt
Buffers: shared hit=6710
-> Sort (cost=8.51..8.51 rows=2 width=45) (actual time=0.004..0.004 rows=1 loops=1711)
Output: ((((p_5.issued_employee_print)::text || ' '::text) || (p_5.issued_employee_position)::text)), p_5.from_dt
Sort Key: p_5.from_dt
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=6710
-> Index Scan using period_sickdoc_id_ix on sickdoc.period p_5 (cost=0.42..8.50 rows=2 width=45) (actual time=0.003..0.003 rows=1 loops=1711)
Output: (((p_5.issued_employee_print)::text || ' '::text) || (p_5.issued_employee_position)::text), p_5.from_dt
Index Cond: (p_5.sickdoc_id = s.id)
Buffers: shared hit=6710
SubPlan 12
-> Index Scan using pim_organization_pk on public.pim_organization o (cost=0.29..8.31 rows=1 width=92) (actual time=0.001..0.001 rows=0 loops=2395)
Output: o.short_name
Index Cond: (o.id = s.workplace_id)
Buffers: shared hit=582
SubPlan 13
-> Limit (cost=0.00..1.11 rows=1 width=31) (actual time=0.007..0.007 rows=0 loops=19913)
Output: fss_state.name
Buffers: shared hit=19913
-> Seq Scan on sickdoc.fss_sickdoc_state fss_state (cost=0.00..1.11 rows=1 width=31) (actual time=0.003..0.003 rows=0 loops=19913)
Output: fss_state.name
Filter: ((fss_state.code)::text = (s.fss_state_code)::text)
Rows Removed by Filter: 8
Buffers: shared hit=19913
SubPlan 14
-> Result (cost=0.42..8.49 rows=1 width=0) (actual time=0.006..0.006 rows=0 loops=19913)
One-Time Filter: (s.is_from_fss IS NULL)
Buffers: shared hit=89235
-> Index Scan using period_sickdoc_id_ix on sickdoc.period p_6 (cost=0.42..8.49 rows=1 width=0) (actual time=0.005..0.005 rows=0 loops=19913)
Output: p_6.id, p_6.clinic_id, p_6.from_dt, p_6.issued_employee_id, p_6.issued_employee_position, p_6.sickdoc_id, p_6.step_id, p_6.to_dt, p_6.witness_employee_id, p_6.witness_employee_position, p_6.aud_who, p_6.aud_when, p_6.aud_source, p_6.aud_who_create, p_6.aud_when_create, p_6.aud_source_create, p_6.signature_num, p_6.doctor_signature, p_6.chairman_signature, p_6.is_sent_to_fss, p_6.witness_employee_print, p_6.issued_employee_print
Index Cond: (p_6.sickdoc_id = s.id)
Filter: ((p_6.witness_employee_id IS NOT NULL) AND (p_6.chairman_signature IS NULL))
Rows Removed by Filter: 1
Buffers: shared hit=89235
SubPlan 15
-> Limit (cost=8.50..8.51 rows=1 width=26) (actual time=0.008..0.008 rows=1 loops=3049)
Output: (((s.issue_dt > p_7.from_dt) AND (p_7.witness_employee_id IS NOT NULL) AND (p_7.chairman_signature IS NOT NULL))), p_7.from_dt
Buffers: shared hit=12654
-> Sort (cost=8.50..8.51 rows=2 width=26) (actual time=0.007..0.007 rows=1 loops=3049)
Output: (((s.issue_dt > p_7.from_dt) AND (p_7.witness_employee_id IS NOT NULL) AND (p_7.chairman_signature IS NOT NULL))), p_7.from_dt
Sort Key: p_7.from_dt
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=12654
-> Index Scan using period_sickdoc_id_ix on sickdoc.period p_7 (cost=0.42..8.49 rows=2 width=26) (actual time=0.003..0.003 rows=1 loops=3049)
Output: ((s.issue_dt > p_7.from_dt) AND (p_7.witness_employee_id IS NOT NULL) AND (p_7.chairman_signature IS NOT NULL)), p_7.from_dt
Index Cond: (p_7.sickdoc_id = s.id)
Buffers: shared hit=12654
SubPlan 16
-> Nested Loop (cost=0.84..16.93 rows=1 width=0) (never executed)
-> Index Scan using period_sickdoc_id_ix on sickdoc.period p_8 (cost=0.42..8.49 rows=1 width=4) (never executed)
Output: p_8.id, p_8.clinic_id, p_8.from_dt, p_8.issued_employee_id, p_8.issued_employee_position, p_8.sickdoc_id, p_8.step_id, p_8.to_dt, p_8.witness_employee_id, p_8.witness_employee_position, p_8.aud_who, p_8.aud_when, p_8.aud_source, p_8.aud_who_create, p_8.aud_when_create, p_8.aud_source_create, p_8.signature_num, p_8.doctor_signature, p_8.chairman_signature, p_8.is_sent_to_fss, p_8.witness_employee_print, p_8.issued_employee_print
Index Cond: (p_8.sickdoc_id = s.id)
Filter: p_8.is_sent_to_fss
-> Index Only Scan using sickdoc_pk on sickdoc.sickdoc ms (cost=0.42..8.44 rows=1 width=4) (never executed)
Output: ms.id
Index Cond: (ms.id = s.id)
Heap Fetches: 0
SubPlan 17
-> Hash Join (cost=6225.49..13202.35 rows=94926 width=4) (actual time=46.034..127.704 rows=95759 loops=1)
Output: p_9.sickdoc_id
Hash Cond: (p_9.sickdoc_id = ms_1.id)
Buffers: shared hit=23261
-> Seq Scan on sickdoc.period p_9 (cost=0.00..5671.63 rows=94926 width=4) (actual time=0.015..42.826 rows=95759 loops=1)
Output: p_9.id, p_9.clinic_id, p_9.from_dt, p_9.issued_employee_id, p_9.issued_employee_position, p_9.sickdoc_id, p_9.step_id, p_9.to_dt, p_9.witness_employee_id, p_9.witness_employee_position, p_9.aud_who, p_9.aud_when, p_9.aud_source, p_9.aud_who_create, p_9.aud_when_create, p_9.aud_source_create, p_9.signature_num, p_9.doctor_signature, p_9.chairman_signature, p_9.is_sent_to_fss, p_9.witness_employee_print, p_9.issued_employee_print
Filter: p_9.is_sent_to_fss
Rows Removed by Filter: 101650
Buffers: shared hit=3709
-> Hash (cost=4665.25..4665.25 rows=124819 width=4) (actual time=45.871..45.871 rows=124819 loops=1)
Output: ms_1.id
Buckets: 131072 Batches: 1 Memory Usage: 5413kB
Buffers: shared hit=19552
-> Index Only Scan using sickdoc_pk on sickdoc.sickdoc ms_1 (cost=0.42..4665.25 rows=124819 width=4) (actual time=0.018..26.269 rows=124819 loops=1)
Output: ms_1.id
Heap Fetches: 20852
Buffers: shared hit=19552
SubPlan 18
-> Result (cost=0.42..8.49 rows=1 width=0) (actual time=0.000..0.000 rows=0 loops=9726)
One-Time Filter: s.is_eln
Buffers: shared hit=489
-> Index Scan using period_sickdoc_id_ix on sickdoc.period p_10 (cost=0.42..8.49 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=152)
Output: p_10.id, p_10.clinic_id, p_10.from_dt, p_10.issued_employee_id, p_10.issued_employee_position, p_10.sickdoc_id, p_10.step_id, p_10.to_dt, p_10.witness_employee_id, p_10.witness_employee_position, p_10.aud_who, p_10.aud_when, p_10.aud_source, p_10.aud_who_create, p_10.aud_when_create, p_10.aud_source_create, p_10.signature_num, p_10.doctor_signature, p_10.chairman_signature, p_10.is_sent_to_fss, p_10.witness_employee_print, p_10.issued_employee_print
Index Cond: (p_10.sickdoc_id = s.id)
Filter: ((p_10.witness_employee_id IS NOT NULL) AND (p_10.chairman_signature IS NOT NULL))
Rows Removed by Filter: 0
Buffers: shared hit=489
SubPlan 19
-> Result (cost=0.42..8.49 rows=1 width=0) (actual time=0.000..0.000 rows=0 loops=9722)
One-Time Filter: s.is_eln
Buffers: shared hit=473
-> Index Scan using period_sickdoc_id_ix on sickdoc.period p_11 (cost=0.42..8.49 rows=1 width=0) (actual time=0.002..0.002 rows=0 loops=148)
Output: p_11.id, p_11.clinic_id, p_11.from_dt, p_11.issued_employee_id, p_11.issued_employee_position, p_11.sickdoc_id, p_11.step_id, p_11.to_dt, p_11.witness_employee_id, p_11.witness_employee_position, p_11.aud_who, p_11.aud_when, p_11.aud_source, p_11.aud_who_create, p_11.aud_when_create, p_11.aud_source_create, p_11.signature_num, p_11.doctor_signature, p_11.chairman_signature, p_11.is_sent_to_fss, p_11.witness_employee_print, p_11.issued_employee_print
Index Cond: (p_11.sickdoc_id = s.id)
Filter: ((p_11.witness_employee_id IS NOT NULL) AND (p_11.chairman_signature IS NOT NULL))
Rows Removed by Filter: 0
Buffers: shared hit=473
SubPlan 20
-> Result (cost=0.42..8.46 rows=2 width=0) (actual time=0.000..0.000 rows=0 loops=9722)
One-Time Filter: s.is_eln
Buffers: shared hit=450
-> Index Only Scan using period_sickdoc_id_ix on sickdoc.period p_12 (cost=0.42..8.46 rows=2 width=0) (actual time=0.002..0.002 rows=0 loops=148)
Output: p_12.sickdoc_id
Index Cond: (p_12.sickdoc_id = s.id)
Heap Fetches: 5
Buffers: shared hit=450
SubPlan 21
-> Limit (cost=9.00..9.01 rows=1 width=26) (actual time=0.091..0.091 rows=1 loops=11763)
Output: ((((p_13.witness_employee_id IS NOT NULL) AND (p_13.chairman_signature IS NOT NULL)) OR (COALESCE(sickdoc.get_sickdoc_days_count(s.id), 0) < 16))), p_13.to_dt
Buffers: shared hit=130375
-> Sort (cost=9.00..9.01 rows=2 width=26) (actual time=0.090..0.090 rows=1 loops=11763)
Output: ((((p_13.witness_employee_id IS NOT NULL) AND (p_13.chairman_signature IS NOT NULL)) OR (COALESCE(sickdoc.get_sickdoc_days_count(s.id), 0) < 16))), p_13.to_dt
Sort Key: p_13.to_dt DESC
Sort Method: quicksort Memory: 25kB
Buffers: shared hit=130375
-> Index Scan using period_sickdoc_id_ix on sickdoc.period p_13 (cost=0.42..8.99 rows=2 width=26) (actual time=0.054..0.086 rows=2 loops=11763)
Output: (((p_13.witness_employee_id IS NOT NULL) AND (p_13.chairman_signature IS NOT NULL)) OR (COALESCE(sickdoc.get_sickdoc_days_count(s.id), 0) < 16)), p_13.to_dt
Index Cond: (p_13.sickdoc_id = s.id)
Buffers: shared hit=130375
SubPlan 22
-> Index Only Scan using period_sickdoc_id_ix on sickdoc.period period_1 (cost=0.42..8.46 rows=2 width=0) (never executed)
Index Cond: (period_1.sickdoc_id = s.id)
Heap Fetches: 0
SubPlan 23
-> Seq Scan on sickdoc.period period_2 (cost=0.00..5671.63 rows=196263 width=4) (actual time=0.004..46.083 rows=197409 loops=1)
Output: period_2.sickdoc_id
Buffers: shared hit=3709
Planning time: 7.734 ms
Execution time: 5886.682 ms