Add optimization

QUERY PLAN ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=48098.22..48098.47 rows=20 width=366) (actual time=2464.053..2464.075 rows=20 loops=1) -> Subquery Scan on ifxview (cost=48098.22..51633.65 rows=282834 width=366) (actual time=2464.052..2464.071 rows=20 loops=1) -> Sort (cost=48098.22..48805.31 rows=282834 width=152) (actual time=2464.046..2464.055 rows=20 loops=1) Sort Key: element.name, interface.ifindex Sort Method: external merge Disk: 44048kB -> Hash Join (cost=2456.39..22488.18 rows=282834 width=152) (actual time=159.682..944.449 rows=282834 loops=1) Hash Cond: (ittislocationcontactprofile.ittislocationid = ittislocation.ittislocationid) -> Hash Join (cost=2036.80..15704.82 rows=282834 width=127) (actual time=131.854..573.405 rows=282834 loops=1) Hash Cond: (interface.elementid = element.elementid) -> Seq Scan on interface (cost=0.00..8011.34 rows=282834 width=91) (actual time=0.005..65.660 rows=282834 loops=1) -> Hash (cost=1872.81..1872.81 rows=13119 width=44) (actual time=131.809..131.809 rows=13119 loops=1) Buckets: 2048 Batches: 1 Memory Usage: 1005kB -> Hash Join (cost=444.07..1872.81 rows=13119 width=44) (actual time=20.037..116.920 rows=13119 loops=1) Hash Cond: (element.ittislocationcontactprofileid = ittislocationcontactprofile.ittislocationcontactprofileid) -> Hash Join (cost=367.97..1599.92 rows=13119 width=44) (actual time=16.472..93.469 rows=13119 loops=1) Hash Cond: (element_extensions.managementareaid = managementarea.managementareaid) -> Hash Join (cost=366.18..1417.75 rows=13119 width=43) (actual time=16.395..75.119 rows=13119 loops=1) Hash Cond: (element.elementid = element_extensions.elementid) -> Seq Scan on element (cost=0.00..789.19 rows=13119 width=35) (actual time=0.003..6.767 rows=13119 loops=1) -> Hash (cost=202.19..202.19 rows=13119 width=8) (actual time=16.363..16.363 rows=13119 loops=1) Buckets: 2048 Batches: 1 Memory Usage: 615kB -> Seq Scan on element_extensions (cost=0.00..202.19 rows=13119 width=8) (actual time=0.007..5.687 rows=13119 loops=1) -> Hash (cost=1.35..1.35 rows=35 width=9) (actual time=0.061..0.061 rows=35 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 2kB -> Seq Scan on managementarea (cost=0.00..1.35 rows=35 width=9) (actual time=0.004..0.025 rows=35 loops=1) -> Hash (cost=48.27..48.27 rows=2227 width=8) (actual time=3.550..3.550 rows=2227 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 87kB -> Seq Scan on ittislocationcontactprofile (cost=0.00..48.27 rows=2227 width=8) (actual time=0.005..1.706 rows=2227 loops=1) -> Hash (cost=392.83..392.83 rows=2141 width=33) (actual time=27.787..27.787 rows=2141 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 134kB -> Hash Left Join (cost=274.81..392.83 rows=2141 width=33) (actual time=16.932..25.337 rows=2141 loops=1) Hash Cond: (address.cityid = city.cityid) -> Hash Left Join (cost=93.15..168.35 rows=2141 width=26) (actual time=5.300..10.210 rows=2141 loops=1) Hash Cond: (ittislocation.addressid = address.addressid) -> Seq Scan on ittislocation (cost=0.00..40.41 rows=2141 width=8) (actual time=0.008..0.972 rows=2141 loops=1) -> Hash (cost=56.40..56.40 rows=2940 width=26) (actual time=5.271..5.271 rows=2940 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 175kB -> Seq Scan on address (cost=0.00..56.40 rows=2940 width=26) (actual time=0.008..2.169 rows=2940 loops=1) -> Hash (cost=109.07..109.07 rows=5807 width=19) (actual time=11.614..11.614 rows=5807 loops=1) Buckets: 1024 Batches: 1 Memory Usage: 304kB -> Seq Scan on city (cost=0.00..109.07 rows=5807 width=19) (actual time=0.005..4.382 rows=5807 loops=1)