EXPLAIN (1) =========== Unique (cost=10170.87..94163004.90 rows=64000000 width=24) (actual time=1062.753..285758.085 rows=8000 loops=1) -> Incremental Sort (cost=10170.87..89363004.90 rows=640000000 width=24) (actual time=1062.751..285756.251 rows=8000 loops=1) Sort Key: "BDN_EmployeeTerritories"."BDN_EmployeeTerritories_ID", "BDN_Terretories"."BDN_Terretories_ID", "BDN_EmployeeTerritories"."Reference_Date" Presorted Key: "BDN_EmployeeTerritories"."BDN_EmployeeTerritories_ID" Full-sort Groups: 250 Sort Method: quicksort Average Memory: 27kB Peak Memory: 27kB -> Nested Loop (cost=0.52..29242165.28 rows=640000000 width=24) (actual time=0.103..285748.981 rows=8000 loops=1) -> Index Scan using "PK_BDN_EmployeeTerritories" on "BDN_EmployeeTerritories" (cost=0.28..285.28 rows=8000 width=20) (actual time=0.030..9.174 rows=8000 loops=1) -> Nested Loop (cost=0.24..2855.24 rows=80000 width=8) (actual time=18.264..35.716 rows=1 loops=8000) -> Seq Scan on "BDN_Terretories" (cost=0.00..155.00 rows=8000 width=12) (actual time=0.002..0.754 rows=8000 loops=8000) -> Hash Join (cost=0.24..0.47 rows=10 width=0) (actual time=0.003..0.003 rows=0 loops=64000000) Hash Cond: (s.token = s_1.token) -> Function Scan on unnest s (cost=0.01..0.11 rows=10 width=32) (actual time=0.000..0.000 rows=1 loops=64000000) -> Hash (cost=0.11..0.11 rows=10 width=32) (actual time=0.002..0.002 rows=1 loops=64000000) Buckets: 1024 Batches: 1 Memory Usage: 9kB -> Function Scan on unnest s_1 (cost=0.01..0.11 rows=10 width=32) (actual time=0.001..0.001 rows=1 loops=64000000) Planning Time: 1.023 ms Execution Time: 285758.551 ms EXPLAIN (2) =========== SET enable_incremental_sort = off; HashAggregate (cost=97605201.00..113245201.00 rows=64000000 width=24) Group Key: "BDN_EmployeeTerritories"."BDN_EmployeeTerritories_ID", "BDN_Terretories"."BDN_Terretories_ID", "BDN_EmployeeTerritories"."Reference_Date" Planned Partitions: 256 -> Hash Join (cost=3246.00..7205201.00 rows=640000000 width=24) Hash Cond: (s_1.token = s.token) -> Nested Loop (cost=250.00..2005.00 rows=80000 width=40) -> Seq Scan on "BDN_Terretories" (cost=0.00..155.00 rows=8000 width=12) -> Function Scan on unnest s_1 (cost=250.00..250.10 rows=10 width=32) -> Hash (cost=1996.00..1996.00 rows=80000 width=48) -> Nested Loop (cost=250.00..1996.00 rows=80000 width=48) -> Seq Scan on "BDN_EmployeeTerritories" (cost=0.00..146.00 rows=8000 width=20) -> Function Scan on unnest s (cost=250.00..250.10 rows=10 width=32) EXPLAIN (3) =========== Unique (cost=76139.64..76219.64 rows=8000 width=24) (actual time=38.034..39.457 rows=8000 loops=1) Output: "BDN_EmployeeTerritories"."BDN_EmployeeTerritories_ID", "BDN_Terretories"."BDN_Terretories_ID", "BDN_EmployeeTerritories"."Reference_Date" -> Sort (cost=76139.64..76159.64 rows=8000 width=24) (actual time=38.033..38.302 rows=8000 loops=1) Output: "BDN_EmployeeTerritories"."BDN_EmployeeTerritories_ID", "BDN_Terretories"."BDN_Terretories_ID", "BDN_EmployeeTerritories"."Reference_Date" Sort Key: "BDN_EmployeeTerritories"."BDN_EmployeeTerritories_ID", "BDN_Terretories"."BDN_Terretories_ID", "BDN_EmployeeTerritories"."Reference_Date" Sort Method: quicksort Memory: 693kB -> Hash Join (cost=1846.01..75621.01 rows=8000 width=24) (actual time=18.806..36.903 rows=8000 loops=1) Output: "BDN_EmployeeTerritories"."BDN_EmployeeTerritories_ID", "BDN_Terretories"."BDN_Terretories_ID", "BDN_EmployeeTerritories"."Reference_Date" Hash Cond: (s_1.token = s.token) -> Nested Loop (cost=0.01..1755.01 rows=8000 width=40) (actual time=0.057..15.617 rows=8000 loops=1) Output: "BDN_Terretories"."BDN_Terretories_ID", s_1.token -> Seq Scan on public."BDN_Terretories" (cost=0.00..155.00 rows=8000 width=12) (actual time=0.026..0.789 rows=8000 loops=1) Output: "BDN_Terretories"."BDN_Terretories_ID", "BDN_Terretories"."Title", "BDN_Terretories"."Description", "BDN_Terretories"."Reference_Date", "BDN_Terretories"."TerretoryID", "BDN_Terretories"."EMP_TerretoryID", "BDN_Terretor ies"."RegionID_545", "BDN_Terretories"."xpl_isUpdated" -> Function Scan on pg_catalog.unnest s_1 (cost=0.01..0.11 rows=10 width=32) (actual time=0.001..0.001 rows=1 loops=8000) Output: s_1.token Function Call: unnest(string_to_array("BDN_Terretories"."EMP_TerretoryID", ';'::text)) -> Hash (cost=1746.01..1746.01 rows=8000 width=48) (actual time=18.733..18.734 rows=8000 loops=1) Output: "BDN_EmployeeTerritories"."BDN_EmployeeTerritories_ID", "BDN_EmployeeTerritories"."Reference_Date", s.token Buckets: 8192 Batches: 1 Memory Usage: 477kB -> Nested Loop (cost=0.01..1746.01 rows=8000 width=48) (actual time=0.020..16.994 rows=8000 loops=1) Output: "BDN_EmployeeTerritories"."BDN_EmployeeTerritories_ID", "BDN_EmployeeTerritories"."Reference_Date", s.token -> Seq Scan on public."BDN_EmployeeTerritories" (cost=0.00..146.00 rows=8000 width=20) (actual time=0.011..0.826 rows=8000 loops=1) Output: "BDN_EmployeeTerritories"."BDN_EmployeeTerritories_ID", "BDN_EmployeeTerritories"."Title", "BDN_EmployeeTerritories"."Description", "BDN_EmployeeTerritories"."Reference_Date", "BDN_EmployeeTerritories"."EMP_Terret oryID", "BDN_EmployeeTerritories"."EmployeeID", "BDN_EmployeeTerritories"."xpl_isUpdated" -> Function Scan on pg_catalog.unnest s (cost=0.01..0.11 rows=10 width=32) (actual time=0.002..0.002 rows=1 loops=8000) Output: s.token Function Call: unnest(string_to_array("BDN_EmployeeTerritories"."EMP_TerretoryID", ';'::text)) Planning Time: 1.055 ms Execution Time: 39.810 ms