Unique  (cost=272421.25..274508.55 rows=166984 width=50) (actual time=5668.815..5669.074 rows=808 loops=1)
  ->  Sort  (cost=272421.25..272838.71 rows=166984 width=50) (actual time=5668.813..5668.856 rows=808 loops=1)
        Sort Key: ('teryt'::text), *SELECT* 1.count, *SELECT* 1.wojewodztwo_jednostki_id, *SELECT* 1.nazwapl
        Sort Method:  quicksort  Memory: 118kB
        ->  Append  (cost=30588.71..257935.94 rows=166984 width=50) (actual time=372.459..5657.258 rows=808 loops=1)
              ->  Subquery Scan *SELECT* 1  (cost=30588.71..35989.07 rows=166165 width=32) (actual time=372.457..372.860 rows=16 loops=1)
                    ->  HashAggregate  (cost=30588.71..34327.42 rows=166165 width=32) (actual time=372.455..372.851 rows=16 loops=1)
                          InitPlan
                            ->  Aggregate  (cost=4440.21..4440.22 rows=1 width=0) (actual time=9.104..9.104 rows=1 loops=1)
                                  ->  Limit  (cost=0.00..4440.18 rows=2 width=8) (actual time=0.017..9.100 rows=2 loops=1)
                                        ->  Unique  (cost=0.00..33301.34 rows=15 width=8) (actual time=0.016..9.099 rows=2 loops=1)
                                              ->  Index Scan using wojewodztwo_i on catalogue c  (cost=0.00..32885.93 rows=166165 width=8) (actual time=0.013..7.967 rows=14893 loops=1)
                                                    Filter: ((kategoria_jednostki)::text = '1'::text)
                            ->  Aggregate  (cost=4440.21..4440.22 rows=1 width=0) (actual time=8.713..8.713 rows=1 loops=1)
                                  ->  Limit  (cost=0.00..4440.18 rows=2 width=8) (actual time=0.016..8.708 rows=2 loops=1)
                                        ->  Unique  (cost=0.00..33301.34 rows=15 width=8) (actual time=0.015..8.706 rows=2 loops=1)
                                              ->  Index Scan using wojewodztwo_i on catalogue c  (cost=0.00..32885.93 rows=166165 width=8) (actual time=0.014..7.554 rows=14893 loops=1)
                                                    Filter: ((kategoria_jednostki)::text = '1'::text)
                            ->  Aggregate  (cost=4440.21..4440.22 rows=1 width=0) (actual time=14.030..14.030 rows=1 loops=1)
                                  ->  Limit  (cost=0.00..4440.18 rows=2 width=8) (actual time=0.021..14.020 rows=2 loops=1)
                                        ->  Unique  (cost=0.00..33301.34 rows=15 width=8) (actual time=0.021..14.019 rows=2 loops=1)
                                              ->  Index Scan using wojewodztwo_i on catalogue c  (cost=0.00..32885.93 rows=166165 width=8) (actual time=0.019..12.137 rows=14893 loops=1)
                                                    Filter: ((kategoria_jednostki)::text = '1'::text)
                          ->  Hash Join  (cost=167.61..16021.82 rows=166165 width=32) (actual time=27.201..277.557 rows=166323 loops=1)
                                Hash Cond: (CASE WHEN (1 = $3) THEN c.powiat_jednostki_id ELSE c.wojewodztwo_jednostki_id END = t.id)
                                ->  Seq Scan on catalogue c  (cost=0.00..11700.09 rows=166165 width=16) (actual time=0.028..123.981 rows=166323 loops=1)
                                      Filter: ((kategoria_jednostki)::text = '1'::text)
                                ->  Hash  (cost=116.16..116.16 rows=4116 width=24) (actual time=4.403..4.403 rows=4116 loops=1)
                                      ->  Seq Scan on teryty t  (cost=0.00..116.16 rows=4116 width=24) (actual time=0.016..2.344 rows=4116 loops=1)
              ->  Subquery Scan *SELECT* 2  (cost=12143.90..12238.25 rows=6 width=2) (actual time=156.637..158.072 rows=8 loops=1)
                    ->  HashAggregate  (cost=12143.90..12238.19 rows=6 width=2) (actual time=156.612..158.042 rows=8 loops=1)
                          ->  Seq Scan on catalogue c  (cost=0.00..11256.27 rows=177527 width=2) (actual time=0.037..73.885 rows=177527 loops=1)
                          SubPlan
                            ->  Limit  (cost=15.46..15.70 rows=1 width=18) (actual time=0.188..0.188 rows=1 loops=8)
                                  ->  Unique  (cost=15.46..15.70 rows=1 width=18) (actual time=0.187..0.187 rows=1 loops=8)
                                        ->  Sort  (cost=15.46..15.58 rows=48 width=18) (actual time=0.185..0.185 rows=1 loops=8)
                                              Sort Key: k.nazwapl
                                              Sort Method:  quicksort  Memory: 17kB
                                              ->  Bitmap Heap Scan on kategorie k  (cost=3.62..15.22 rows=48 width=18) (actual time=0.022..0.041 rows=67 loops=8)
                                                    Recheck Cond: ((kod)::text = ($0)::text)
                                                    ->  Bitmap Index Scan on kategorie_kod_i  (cost=0.00..3.61 rows=48 width=0) (actual time=0.019..0.019 rows=67 loops=8)
                                                          Index Cond: ((kod)::text = ($0)::text)
              ->  Subquery Scan *SELECT* 3  (cost=22989.13..22989.96 rows=30 width=23) (actual time=470.851..470.879 rows=29 loops=1)
                    ->  HashAggregate  (cost=22989.13..22989.66 rows=30 width=23) (actual time=470.849..470.871 rows=29 loops=1)
                          ->  Hash Join  (cost=13779.82..21778.72 rows=161388 width=23) (actual time=185.801..395.440 rows=159834 loops=1)
                                Hash Cond: (sk.specjalnosc_id = x.id)
                                ->  Hash Join  (cost=13777.15..19556.96 rows=161388 width=8) (actual time=185.755..331.287 rows=159834 loops=1)
                                      Hash Cond: (sk.komorka_id = c.komorka_id)
                                      ->  Seq Scan on specjalnosci_komorki sk  (cost=0.00..2657.23 rows=172423 width=16) (actual time=0.013..30.556 rows=172423 loops=1)
                                      ->  Hash  (cost=11700.09..11700.09 rows=166165 width=8) (actual time=185.696..185.696 rows=166323 loops=1)
                                            ->  Seq Scan on catalogue c  (cost=0.00..11700.09 rows=166165 width=8) (actual time=0.018..133.912 rows=166323 loops=1)
                                                  Filter: ((kategoria_jednostki)::text = '1'::text)
                                ->  Hash  (cost=2.30..2.30 rows=30 width=23) (actual time=0.038..0.038 rows=30 loops=1)
                                      ->  Seq Scan on specjalnosci x  (cost=0.00..2.30 rows=30 width=23) (actual time=0.015..0.028 rows=30 loops=1)
              ->  Subquery Scan *SELECT* 4  (cost=23013.23..23017.05 rows=139 width=28) (actual time=472.333..472.448 rows=136 loops=1)
                    ->  HashAggregate  (cost=23013.23..23015.66 rows=139 width=28) (actual time=472.330..472.419 rows=136 loops=1)
                          ->  Hash Join  (cost=13787.28..21800.53 rows=161693 width=28) (actual time=188.551..396.704 rows=159950 loops=1)
                                Hash Cond: (dk.dyscyplina_id = x.id)
                                ->  Hash Join  (cost=13777.15..19567.12 rows=161693 width=8) (actual time=188.168..331.237 rows=159950 loops=1)
                                      Hash Cond: (dk.komorka_id = c.komorka_id)
                                      ->  Seq Scan on dyscypliny_komorki dk  (cost=0.00..2661.49 rows=172749 width=16) (actual time=0.014..30.121 rows=172749 loops=1)
                                      ->  Hash  (cost=11700.09..11700.09 rows=166165 width=8) (actual time=188.097..188.097 rows=166323 loops=1)
                                            ->  Seq Scan on catalogue c  (cost=0.00..11700.09 rows=166165 width=8) (actual time=0.022..134.479 rows=166323 loops=1)
                                                  Filter: ((kategoria_jednostki)::text = '1'::text)
                                ->  Hash  (cost=8.39..8.39 rows=139 width=28) (actual time=0.369..0.369 rows=139 loops=1)
                                      ->  Seq Scan on dyscypliny x  (cost=0.00..8.39 rows=139 width=28) (actual time=0.231..0.309 rows=139 loops=1)
              ->  Subquery Scan *SELECT* 5  (cost=23991.24..24003.31 rows=439 width=42) (actual time=511.216..511.658 rows=414 loops=1)
                    ->  HashAggregate  (cost=23991.24..23998.92 rows=439 width=42) (actual time=511.214..511.549 rows=414 loops=1)
                          ->  Hash Join  (cost=13799.03..22651.56 rows=178624 width=42) (actual time=173.285..412.885 rows=176840 loops=1)
                                Hash Cond: (rkk.rodzaje_komorek_id = x.id)
                                ->  Hash Join  (cost=13777.15..20173.60 rows=178624 width=8) (actual time=172.931..333.677 rows=176840 loops=1)
                                      Hash Cond: (rkk.komorka_id = c.komorka_id)
                                      ->  Seq Scan on rodzaje_komorek_komorka rkk  (cost=0.00..2940.38 rows=190838 width=16) (actual time=0.012..33.692 rows=190838 loops=1)
                                      ->  Hash  (cost=11700.09..11700.09 rows=166165 width=8) (actual time=172.875..172.875 rows=166323 loops=1)
                                            ->  Seq Scan on catalogue c  (cost=0.00..11700.09 rows=166165 width=8) (actual time=0.020..124.292 rows=166323 loops=1)
                                                  Filter: ((kategoria_jednostki)::text = '1'::text)
                                ->  Hash  (cost=16.39..16.39 rows=439 width=42) (actual time=0.341..0.341 rows=439 loops=1)
                                      ->  Seq Scan on rodzaje_komorek x  (cost=0.00..16.39 rows=439 width=42) (actual time=0.015..0.178 rows=439 loops=1)
              ->  Subquery Scan *SELECT* 6  (cost=26344.18..26344.71 rows=19 width=48) (actual time=551.876..551.892 rows=19 loops=1)
                    ->  HashAggregate  (cost=26344.18..26344.52 rows=19 width=48) (actual time=551.874..551.886 rows=19 loops=1)
                          ->  Hash Join  (cost=13778.58..24692.50 rows=220225 width=48) (actual time=186.064..436.403 rows=216484 loops=1)
                                Hash Cond: (rck.rodzaj_choroby_id = x.id)
                                ->  Hash Join  (cost=13777.15..21662.97 rows=220225 width=8) (actual time=186.020..349.118 rows=216484 loops=1)
                                      Hash Cond: (rck.komorka_id = c.komorka_id)
                                      ->  Seq Scan on rodzaje_chorob_komorki rck  (cost=0.00..3624.84 rows=235284 width=16) (actual time=0.013..36.593 rows=235284 loops=1)
                                      ->  Hash  (cost=11700.09..11700.09 rows=166165 width=8) (actual time=185.961..185.961 rows=166323 loops=1)
                                            ->  Seq Scan on catalogue c  (cost=0.00..11700.09 rows=166165 width=8) (actual time=0.021..133.693 rows=166323 loops=1)
                                                  Filter: ((kategoria_jednostki)::text = '1'::text)
                                ->  Hash  (cost=1.19..1.19 rows=19 width=48) (actual time=0.030..0.030 rows=19 loops=1)
                                      ->  Seq Scan on rodzaje_chorob x  (cost=0.00..1.19 rows=19 width=48) (actual time=0.017..0.022 rows=19 loops=1)
              ->  Subquery Scan *SELECT* 7  (cost=113348.47..113353.59 rows=186 width=50) (actual time=3119.219..3119.379 rows=186 loops=1)
                    ->  HashAggregate  (cost=113348.47..113351.73 rows=186 width=50) (actual time=3119.217..3119.341 rows=186 loops=1)
                          ->  Hash Join  (cost=13788.34..100261.57 rows=1744920 width=50) (actual time=188.775..2069.786 rows=1715282 loops=1)
                                Hash Cond: (sck.sekcja_choroby_id = x.id)
                                ->  Hash Join  (cost=13777.15..76257.74 rows=1744920 width=8) (actual time=188.601..1301.393 rows=1715282 loops=1)
                                      Hash Cond: (sck.komorka_id = c.komorka_id)
                                      ->  Seq Scan on sekcje_chorob_komorki sck  (cost=0.00..28719.34 rows=1864234 width=16) (actual time=0.014..296.119 rows=1864234 loops=1)
                                      ->  Hash  (cost=11700.09..11700.09 rows=166165 width=8) (actual time=188.543..188.543 rows=166323 loops=1)
                                            ->  Seq Scan on catalogue c  (cost=0.00..11700.09 rows=166165 width=8) (actual time=0.020..135.434 rows=166323 loops=1)
                                                  Filter: ((kategoria_jednostki)::text = '1'::text)
                                ->  Hash  (cost=8.86..8.86 rows=186 width=50) (actual time=0.162..0.162 rows=186 loops=1)
                                      ->  Seq Scan on sekcje_chorob x  (cost=0.00..8.86 rows=186 width=50) (actual time=0.015..0.089 rows=186 loops=1)
Total runtime: 5675.655 ms

 

Reply to Paste