|QUERY PLAN                                                                                                                                                                                                                                                         |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|Hash Right Join  (cost=252148.98..41737774.20 rows=1 width=5187) (actual time=129111.774..129111.812 rows=1 loops=1)                                                                                                                                               |
|  Hash Cond: ("*SELECT* 1".visit = v.visit)                                                                                                                                                                                                                        |
|  ->  Append  (cost=252118.87..41735934.43 rows=482575 width=756) (actual time=11246.030..129096.447 rows=25087 loops=1)                                                                                                                                           |
|        ->  Subquery Scan on "*SELECT* 1"  (cost=252118.87..41733521.50 rows=482573 width=5531) (actual time=11246.029..129087.060 rows=25087 loops=1)                                                                                                             |
|              ->  Hash Left Join  (cost=252118.87..41727489.33 rows=482573 width=5527) (actual time=11246.027..129066.972 rows=25087 loops=1)                                                                                                                      |
|                    Hash Cond: ((COALESCE(vs.unit_id, p.unit, "*SELECT* 1_1".unit)) = u.unit)                                                                                                                                                                      |
|                    ->  Hash Left Join  (cost=252069.39..41715978.74 rows=482573 width=5516) (actual time=11245.661..129029.288 rows=25087 loops=1)                                                                                                                |
|                          Hash Cond: ((vs.analyzer_id = p.analyzer_id) AND (vs.service = p.parameter_id))                                                                                                                                                          |
|                          ->  Hash Left Join  (cost=252068.11..1135513.99 rows=482573 width=448) (actual time=2077.195..2780.581 rows=25087 loops=1)                                                                                                               |
|                                Hash Cond: (vs.analyzer_id = an.analyzer_id)                                                                                                                                                                                       |
|                                ->  Hash Join  (cost=252063.07..1134207.37 rows=482573 width=425) (actual time=2077.133..2755.321 rows=25087 loops=1)                                                                                                              |
|                                      Hash Cond: (vs.visit = v_1.visit)                                                                                                                                                                                            |
|                                      ->  Nested Loop  (cost=0.44..634082.15 rows=2423693 width=353) (actual time=4.381..91.911 rows=26079 loops=1)                                                                                                                |
|                                            ->  Append  (cost=0.00..1534.58 rows=73 width=544) (actual time=2.733..43.158 rows=5787 loops=1)                                                                                                                       |
|                                                  ->  Subquery Scan on "*SELECT* 1_1"  (cost=0.00..0.00 rows=1 width=544) (actual time=0.000..0.002 rows=0 loops=1)                                                                                                |
|                                                        ->  Result  (cost=0.00..0.00 rows=0 width=568) (actual time=0.000..0.001 rows=0 loops=1)                                                                                                                   |
|                                                              One-Time Filter: false                                                                                                                                                                               |
|                                                  ->  Subquery Scan on "*SELECT* 2_1"  (cost=228.35..1534.21 rows=71 width=544) (actual time=2.732..42.553 rows=5787 loops=1)                                                                                      |
|                                                        ->  Nested Loop Left Join  (cost=228.35..1533.14 rows=71 width=536) (actual time=2.730..41.325 rows=5787 loops=1)                                                                                          |
|                                                              ->  Hash Full Join  (cost=228.07..1394.93 rows=71 width=476) (actual time=2.591..10.044 rows=5787 loops=1)                                                                                           |
|                                                                    Hash Cond: (mv_asc_lab_parameter.idparametr = l_1.idparametr)                                                                                                                                  |
|                                                                    Filter: (COALESCE(COALESCE(mv_asc_lab_parameter.param_type, l_1.param_type), '0'::bigint) = 20)                                                                                                |
|                                                                    Rows Removed by Filter: 8630                                                                                                                                                                   |
|                                                                    ->  Seq Scan on mv_asc_lab_parameter  (cost=0.00..1129.45 rows=14245 width=204) (actual time=0.006..2.130 rows=14245 loops=1)                                                                  |
|                                                                    ->  Hash  (cost=175.81..175.81 rows=4181 width=272) (actual time=2.180..2.182 rows=4182 loops=1)                                                                                               |
|                                                                          Buckets: 8192  Batches: 1  Memory Usage: 1070kB                                                                                                                                          |
|                                                                          ->  Seq Scan on parameter_config l_1  (cost=0.00..175.81 rows=4181 width=272) (actual time=0.007..0.988 rows=4182 loops=1)                                                               |
|                                                              ->  Index Scan using parameter_precision_pkey on parameter_precision p_1  (cost=0.28..0.30 rows=1 width=16) (actual time=0.001..0.001 rows=0 loops=5787)                                             |
|                                                                    Index Cond: (idparameter = COALESCE(mv_asc_lab_parameter.idparametr, l_1.idparametr))                                                                                                          |
|                                                              SubPlan 8                                                                                                                                                                                            |
|                                                                ->  Limit  (cost=0.29..0.74 rows=1 width=8) (actual time=0.001..0.001 rows=0 loops=5787)                                                                                                           |
|                                                                      ->  Index Only Scan using ix_servicesrvnote_service on servicesrvnote n  (cost=0.29..2.99 rows=6 width=8) (actual time=0.001..0.001 rows=0 loops=5787)                                       |
|                                                                            Index Cond: (service = COALESCE(mv_asc_lab_parameter.idparametr, l_1.idparametr))                                                                                                      |
|                                                                            Heap Fetches: 0                                                                                                                                                                        |
|                                                              SubPlan 10                                                                                                                                                                                           |
|                                                                ->  Seq Scan on tdic_mutation m  (cost=0.00..10.08 rows=508 width=8) (actual time=0.008..0.049 rows=508 loops=1)                                                                                   |
|                                                  ->  Subquery Scan on "*SELECT* 3_1"  (cost=0.00..0.00 rows=1 width=544) (actual time=0.002..0.003 rows=0 loops=1)                                                                                                |
|                                                        ->  Result  (cost=0.00..0.00 rows=0 width=568) (actual time=0.001..0.001 rows=0 loops=1)                                                                                                                   |
|                                                              One-Time Filter: false                                                                                                                                                                               |
|                                            ->  Index Scan using ix_service on visitservice vs  (cost=0.44..8333.02 rows=33201 width=177) (actual time=0.001..0.007 rows=5 loops=5787)                                                                             |
|                                                  Index Cond: (service = "*SELECT* 1_1".service)                                                                                                                                                                   |
|                                      ->  Hash  (cost=238317.79..238317.79 rows=545508 width=80) (actual time=2071.199..2071.203 rows=2729122 loops=1)                                                                                                             |
|                                            Buckets: 131072 (originally 131072)  Batches: 64 (originally 16)  Memory Usage: 7169kB                                                                                                                                 |
|                                            ->  Hash Join  (cost=14.21..238317.79 rows=545508 width=80) (actual time=0.083..1461.611 rows=2729122 loops=1)                                                                                                         |
|                                                  Hash Cond: (v_1.request_docconcept_id = COALESCE(a_1.analysis, mv_asc_lab_analysis_1.analysis))                                                                                                                  |
|                                                  ->  Seq Scan on visit v_1  (cost=0.00..212391.95 rows=2727540 width=72) (actual time=0.012..549.562 rows=2729122 loops=1)                                                                                        |
|                                                        Filter: (visitstatus <> ALL ('{1,2,9}'::bigint[]))                                                                                                                                                         |
|                                                        Rows Removed by Filter: 11399                                                                                                                                                                              |
|                                                  ->  Hash  (cost=13.71..13.71 rows=40 width=24) (actual time=0.065..0.067 rows=80 loops=1)                                                                                                                        |
|                                                        Buckets: 1024  Batches: 1  Memory Usage: 12kB                                                                                                                                                              |
|                                                        ->  Hash Left Join  (cost=3.19..13.71 rows=40 width=24) (actual time=0.038..0.056 rows=80 loops=1)                                                                                                         |
|                                                              Hash Cond: (mv_asc_lab_analysis_1.analysis = a_1.analysis)                                                                                                                                           |
|                                                              ->  Seq Scan on mv_asc_lab_analysis mv_asc_lab_analysis_1  (cost=0.00..10.40 rows=40 width=8) (actual time=0.008..0.013 rows=80 loops=1)                                                             |
|                                                              ->  Hash  (cost=2.53..2.53 rows=53 width=16) (actual time=0.021..0.022 rows=53 loops=1)                                                                                                              |
|                                                                    Buckets: 1024  Batches: 1  Memory Usage: 11kB                                                                                                                                                  |
|                                                                    ->  Seq Scan on analysis_config a_1  (cost=0.00..2.53 rows=53 width=16) (actual time=0.006..0.014 rows=53 loops=1)                                                                             |
|                                ->  Hash  (cost=3.35..3.35 rows=135 width=31) (actual time=0.050..0.050 rows=137 loops=1)                                                                                                                                          |
|                                      Buckets: 1024  Batches: 1  Memory Usage: 16kB                                                                                                                                                                                |
|                                      ->  Seq Scan on analyzer an  (cost=0.00..3.35 rows=135 width=31) (actual time=0.014..0.032 rows=137 loops=1)                                                                                                                 |
|                          ->  Hash  (cost=1.11..1.11 rows=11 width=32) (actual time=0.010..0.012 rows=11 loops=1)                                                                                                                                                  |
|                                Buckets: 1024  Batches: 1  Memory Usage: 9kB                                                                                                                                                                                       |
|                                ->  Seq Scan on analyzer_parameter p  (cost=0.00..1.11 rows=11 width=32) (actual time=0.007..0.008 rows=11 loops=1)                                                                                                                |
|                          SubPlan 1                                                                                                                                                                                                                                |
|                            ->  Index Scan using visitsortservice_visitsort_service_parent_service_key on visitsortservice vss  (cost=0.29..2.91 rows=1 width=8) (actual time=0.005..0.006 rows=1 loops=25087)                                                     |
|                                  Index Cond: ((visitsort = v_1.visitsort) AND (service = vs.service))                                                                                                                                                             |
|                          SubPlan 2                                                                                                                                                                                                                                |
|                            ->  Index Scan using visitsortservice_visitsort_service_parent_service_key on visitsortservice vss_1  (cost=0.29..2.91 rows=1 width=8) (never executed)                                                                                |
|                                  Index Cond: ((visitsort = v_1.visitsort) AND (service = vs.parent_service))                                                                                                                                                      |
|                          SubPlan 3                                                                                                                                                                                                                                |
|                            ->  Index Scan using visitsortservice_visitsort_service_parent_service_key on visitsortservice vss_2  (cost=0.29..2.91 rows=1 width=8) (never executed)                                                                                |
|                                  Index Cond: ((visitsort = v_1.visitsort) AND (service = CASE WHEN (('0'::bigint) = 23) THEN "*SELECT* 1_1".service WHEN ((('0'::bigint) = 50) AND ((NULL::bigint) IS NULL)) THEN "*SELECT* 1_1".service ELSE (NULL::bigint) END))|
|                          SubPlan 4                                                                                                                                                                                                                                |
|                            ->  Index Scan using visitsortservice_visitsort_service_parent_service_key on visitsortservice vss_3  (cost=0.29..2.91 rows=1 width=8) (never executed)                                                                                |
|                                  Index Cond: ((visitsort = v_1.visitsort) AND (service = vs.service))                                                                                                                                                             |
|                          SubPlan 5                                                                                                                                                                                                                                |
|                            ->  Hash Full Join  (cost=37.95..61.12 rows=6 width=516) (actual time=0.112..0.187 rows=1 loops=24057)                                                                                                                                 |
|                                  Hash Cond: (mv_asc_lab_srvnote.srvnote = s.srvnote)                                                                                                                                                                              |
|                                  Filter: (COALESCE(s.srvnote, mv_asc_lab_srvnote.srvnote) = vs.srvnote)                                                                                                                                                           |
|                                  Rows Removed by Filter: 1663                                                                                                                                                                                                     |
|                                  ->  Seq Scan on mv_asc_lab_srvnote  (cost=0.00..21.05 rows=805 width=29) (actual time=0.002..0.044 rows=805 loops=24057)                                                                                                         |
|                                  ->  Hash  (cost=22.42..22.42 rows=1242 width=30) (actual time=0.228..0.228 rows=1242 loops=1)                                                                                                                                    |
|                                        Buckets: 2048  Batches: 1  Memory Usage: 96kB                                                                                                                                                                              |
|                                        ->  Seq Scan on srvnote_config s  (cost=0.00..22.42 rows=1242 width=30) (actual time=0.004..0.101 rows=1242 loops=1)                                                                                                       |
|                          SubPlan 7                                                                                                                                                                                                                                |
|                            ->  Seq Scan on visitservice vs1  (cost=0.00..993970.14 rows=157281 width=8) (actual time=0.015..5644.224 rows=28192695 loops=1)                                                                                                       |
|                                  Filter: (((srvresult IS NOT NULL) OR (COALESCE(srvnote, '0'::bigint) <> 0) OR (srvtext IS NOT NULL)) AND (COALESCE(printed, '1'::bigint) <> 0) AND (COALESCE(result_status, '0'::bigint) = 0))                                   |
|                                  Rows Removed by Filter: 3448114                                                                                                                                                                                                  |
|                    ->  Hash  (cost=46.89..46.89 rows=208 width=19) (actual time=0.351..0.354 rows=208 loops=1)                                                                                                                                                    |
|                          Buckets: 1024  Batches: 1  Memory Usage: 19kB                                                                                                                                                                                            |
|                          ->  Subquery Scan on u  (cost=44.29..46.89 rows=208 width=19) (actual time=0.303..0.330 rows=208 loops=1)                                                                                                                                |
|                                ->  Sort  (cost=44.29..44.81 rows=208 width=1745) (actual time=0.302..0.313 rows=208 loops=1)                                                                                                                                      |
|                                      Sort Key: mv_asc_unit.unit_id                                                                                                                                                                                                |
|                                      Sort Method: quicksort  Memory: 34kB                                                                                                                                                                                         |
|                                      ->  Hash Left Join  (cost=29.32..36.28 rows=208 width=1745) (actual time=0.203..0.255 rows=208 loops=1)                                                                                                                      |
|                                            Hash Cond: (mv_asc_unit.nsi_unit_id = mv_nsi_unit.id_)                                                                                                                                                                 |
|                                            ->  Seq Scan on mv_asc_unit  (cost=0.00..5.08 rows=208 width=27) (actual time=0.023..0.036 rows=208 loops=1)                                                                                                           |
|                                            ->  Hash  (cost=21.92..21.92 rows=592 width=8) (actual time=0.172..0.173 rows=592 loops=1)                                                                                                                             |
|                                                  Buckets: 1024  Batches: 1  Memory Usage: 32kB                                                                                                                                                                    |
|                                                  ->  Seq Scan on mv_nsi_unit  (cost=0.00..21.92 rows=592 width=8) (actual time=0.012..0.119 rows=592 loops=1)                                                                                                     |
|                                                        Filter: (end_date IS NULL)                                                                                                                                                                                 |
|        ->  Result  (cost=0.00..0.06 rows=2 width=984) (actual time=0.003..0.004 rows=0 loops=1)                                                                                                                                                                   |
|              ->  Append  (cost=0.00..0.01 rows=2 width=940) (actual time=0.003..0.003 rows=0 loops=1)                                                                                                                                                             |
|                    ->  Result  (cost=0.00..0.00 rows=0 width=702) (actual time=0.001..0.001 rows=0 loops=1)                                                                                                                                                       |
|                          One-Time Filter: false                                                                                                                                                                                                                   |
|                    ->  Result  (cost=0.00..0.00 rows=0 width=724) (actual time=0.000..0.001 rows=0 loops=1)                                                                                                                                                       |
|                          One-Time Filter: false                                                                                                                                                                                                                   |
|  ->  Hash  (cost=30.09..30.09 rows=1 width=5248) (actual time=0.171..0.180 rows=1 loops=1)                                                                                                                                                                        |
|        Buckets: 1024  Batches: 1  Memory Usage: 10kB                                                                                                                                                                                                              |
|        ->  Nested Loop  (cost=7.16..30.09 rows=1 width=5248) (actual time=0.149..0.176 rows=1 loops=1)                                                                                                                                                            |
|              ->  Nested Loop  (cost=6.73..29.62 rows=1 width=4929) (actual time=0.139..0.165 rows=1 loops=1)                                                                                                                                                      |
|                    ->  Hash Left Join  (cost=6.31..29.16 rows=1 width=4437) (actual time=0.128..0.152 rows=1 loops=1)                                                                                                                                             |
|                          Hash Cond: (mv_asc_lab_analysis.analysis = a.analysis)                                                                                                                                                                                   |
|                          Filter: (v.request_docconcept_id = COALESCE(a.analysis, mv_asc_lab_analysis.analysis))                                                                                                                                                   |
|                          Rows Removed by Filter: 79                                                                                                                                                                                                               |
|                          ->  Nested Loop  (cost=3.11..25.85 rows=40 width=3513) (actual time=0.064..0.105 rows=80 loops=1)                                                                                                                                        |
|                                ->  Hash Join  (cost=3.11..15.05 rows=1 width=1901) (actual time=0.054..0.069 rows=1 loops=1)                                                                                                                                      |
|                                      Hash Cond: (mv_asc_lab_specimen.specimen = v.material_id)                                                                                                                                                                    |
|                                      ->  Seq Scan on mv_asc_lab_specimen  (cost=0.00..11.40 rows=140 width=548) (actual time=0.018..0.024 rows=86 loops=1)                                                                                                        |
|                                      ->  Hash  (cost=3.10..3.10 rows=1 width=1353) (actual time=0.027..0.030 rows=1 loops=1)                                                                                                                                      |
|                                            Buckets: 1024  Batches: 1  Memory Usage: 9kB                                                                                                                                                                           |
|                                            ->  Nested Loop  (cost=0.47..3.10 rows=1 width=1353) (actual time=0.024..0.027 rows=1 loops=1)                                                                                                                         |
|                                                  ->  HashAggregate  (cost=0.04..0.05 rows=1 width=8) (actual time=0.010..0.011 rows=1 loops=1)                                                                                                                    |
|                                                        Group Key: ((unnest('{4271109}'::text[])))::bigint                                                                                                                                                         |
|                                                        Batches: 1  Memory Usage: 24kB                                                                                                                                                                             |
|                                                        ->  Result  (cost=0.00..0.04 rows=1 width=8) (actual time=0.004..0.005 rows=1 loops=1)                                                                                                                     |
|                                                              ->  ProjectSet  (cost=0.00..0.02 rows=1 width=32) (actual time=0.002..0.003 rows=1 loops=1)                                                                                                          |
|                                                                    ->  Result  (cost=0.00..0.01 rows=1 width=0) (actual time=0.000..0.000 rows=1 loops=1)                                                                                                         |
|                                                  ->  Index Scan using visit_pkey on visit v  (cost=0.43..3.05 rows=1 width=1353) (actual time=0.011..0.011 rows=1 loops=1)                                                                                        |
|                                                        Index Cond: (visit = (((unnest('{4271109}'::text[])))::bigint))                                                                                                                                            |
|                                ->  Seq Scan on mv_asc_lab_analysis  (cost=0.00..10.40 rows=40 width=1612) (actual time=0.009..0.015 rows=80 loops=1)                                                                                                              |
|                          ->  Hash  (cost=2.53..2.53 rows=53 width=924) (actual time=0.033..0.033 rows=53 loops=1)                                                                                                                                                 |
|                                Buckets: 1024  Batches: 1  Memory Usage: 17kB                                                                                                                                                                                      |
|                                ->  Seq Scan on analysis_config a  (cost=0.00..2.53 rows=53 width=924) (actual time=0.007..0.019 rows=53 loops=1)                                                                                                                  |
|                    ->  Index Scan using case_history_pkey on case_history ch  (cost=0.43..0.46 rows=1 width=492) (actual time=0.008..0.008 rows=1 loops=1)                                                                                                        |
|                          Index Cond: (folder = v.folder)                                                                                                                                                                                                          |
|              ->  Index Scan using pk_patientlist on patientlist l  (cost=0.43..0.47 rows=1 width=319) (actual time=0.007..0.007 rows=1 loops=1)                                                                                                                   |
|                    Index Cond: (case_history = v.folder)                                                                                                                                                                                                          |
|Planning Time: 5.999 ms                                                                                                                                                                                                                                            |
|Execution Time: 129123.165 ms                                                                                                                                                                                                                                      |