"QUERY PLAN"
"Nested Loop  (cost=86.44..6585612.52 rows=1 width=5967)"
"  Join Filter: (tc.release_id = pc.release_id)"
"  ->  Nested Loop Left Join  (cost=81.94..6547041.30 rows=1 width=4589)"
"        Filter: (CASE WHEN ((tc.source)::text = 'MILES'::text) THEN COALESCE(tem.family_id, '0'::bigint) ELSE COALESCE(ted.terr_family_id, '0'::bigint) END = ANY ('{0,1281,2137,2055,2138,2139,2140,2141,2142,2143,2144,2145,2146,2147,2225,2148,2241,2150,2151,2152,2153,2154,2203,2155,2169,2045,2160,2162,1280,2164,2054,2172,2163,2165,2166,2170,2167,2174,2194,2173,2175,2109,9,1282,2176,2108,1275,1283,1261,1274,2177,2179,2180,2181,2182,2183,11,2184,2185,2186,1278,2188,2187,2103,10,2115,2189,2052,2044,2038,14,1284,2159,2046,1279,2075,2058,2057,1277,2252,2061,2062,2006,2063,2192,2064,2065,2066,2067,2068,2069,12,2071,2072,2073,2074,2077,2078,2076,2060,2059,2079,2080,2082,2083,2084,2086,2087,2088,2048,2092,2253,2168,2089,2090,2091,2094,2093,2204,13,1285,2096,2097,2099,2098,2095,1276,1286,2049,2100,2101,2102,2104,2050,2107,2110,2111,2081,2114,2113,2112,2116,2117,15,1287,2118,2119,2120,2121,2123,2122,2124,2126,2128,2125,2127,2129,2132,2131,2130,2133,2134,2212,2213,2214,2215,16,2218,2219,2216,2217,2193,2220,2135,2221,2161,2229,17,2231,2224,2222,2223,2227,2232,2226,2230,2233,2234,2235,2236,2237,2239,2242,2243,2047,2244,2149,2245,2246,2247,2248,2249,2251,2250,2255,23,1288,2001,2003,2004,2005,2156,2019,2056,2020,2205,2021,2254,2007,2008,2158,2191,2009,2011,2010,2053,2016,2022,2013,2014,2207,2051,2256,2023,2032,2178,2024,2018,2025,2012,2027,2028,2026,2209,2210,2029,2070,2030,2031,2033,2034,2036,2035,2037,2039,2041,2042,2040,2043,2238,2195,18,19,1291,1289,20,21,22,1290,2240,2085,2196,24,2211,2197,2257,2258,2198,2228,2199,2200,25,2201,2171,2202,1137,2208,2017,2105,2136,2106,2206,2002}'::bigint[]))"
"        ->  Nested Loop Left Join  (cost=81.52..6547038.53 rows=1 width=4472)"
"              ->  Nested Loop Left Join  (cost=81.37..6547038.24 rows=1 width=4464)"
"                    ->  Nested Loop  (cost=80.95..6547035.82 rows=1 width=4455)"
"                          Join Filter: ((tc.country_iso)::text = (c.iso_code_2)::text)"
"                          ->  Nested Loop Left Join  (cost=2.42..6546950.78 rows=1 width=4455)"
"                                ->  Nested Loop Left Join  (cost=1.85..6546944.79 rows=1 width=4367)"
"                                      ->  Nested Loop Left Join  (cost=1.42..6546942.34 rows=1 width=4336)"
"                                            ->  Nested Loop Left Join  (cost=0.99..6546939.90 rows=1 width=4322)"
"                                                  ->  Nested Loop Left Join  (cost=0.57..6546937.44 rows=1 width=4244)"
"                                                        Join Filter: (((tc.source)::text = (tdsw.source)::text) AND (tc.release_id = tdsw.release_id) AND ((tc.country_iso)::text = (tdsw.iso_code_2)::text))"
"                                                        ->  Nested Loop Left Join  (cost=0.57..6535022.07 rows=1 width=1204)"
"                                                              Join Filter: ((tc.release_id = tecprice.release_id) AND ((tc.source)::bpchar = tecprice.source) AND (tc.version_id = COALESCE(tecprice.version_id, '1'::bigint)))"
"                                                              ->  Nested Loop Left Join  (cost=0.57..6528901.31 rows=1 width=1144)"
"                                                                    Join Filter: ((tc.release_id = tec.release_id) AND ((tc.source)::bpchar = tec.source) AND ((tc.country_iso)::text = (tec.country_iso)::text) AND (tc.version_id = tec.version_id))"
"                                                                    ->  Nested Loop Left Join  (cost=0.57..6494236.56 rows=1 width=1064)"
"                                                                          Filter: ((COALESCE(ted.opt_out, 'Y'::character varying))::text = 'N'::text)"
"                                                                          ->  Seq Scan on t_territory_common tc  (cost=0.00..6494012.54 rows=49 width=232)"
"                                                                                Filter: (((source)::text = 'DSCHED'::text) AND ((COALESCE(terr_release_date_type, 'Specific Date'::character varying))::text = 'Specific Date'::text) AND ((terr_type)::text = ANY ('{Core,Local}'::text[])) AND (((terr_release_date >= to_date('2019-09-16'::text, 'YYYY-MM-DD'::text)) AND (terr_release_date <= to_date('2019-11-01'::text, 'YYYY-MM-DD'::text))) OR ((COALESCE(terr_release_date_type, 'Specific Date'::character varying))::text = 'TBC'::text)))"
"                                                                          ->  Index Scan using idx_terr_extn_dschd on t_territory_extn_dsched ted  (cost=0.57..4.53 rows=3 width=850)"
"                                                                                Index Cond: ((tc.release_id = release_id) AND ((tc.country_iso)::text = (country_iso)::text) AND ((tc.source)::bpchar = source))"
"                                                                    ->  Seq Scan on t_territory_extn_cprs tec  (cost=0.00..20022.25 rows=732125 width=104)"
"                                                              ->  Seq Scan on t_territory_cprs_pricing tecprice  (cost=0.00..3588.82 rows=144682 width=81)"
"                                                        ->  Seq Scan on t_terr_dsched_second_workflow tdsw  (cost=0.00..7810.24 rows=234579 width=3058)"
"                                                              Filter: ((source)::text = 'DSCHED'::text)"
"                                                  ->  Index Scan using t_product_common_idx on t_product_common p  (cost=0.43..2.45 rows=1 width=92)"
"                                                        Index Cond: (tc.release_id = release_id)"
"                                                        Filter: (((source)::text = 'DSCHED'::text) AND ((tc.source)::text = (source)::text))"
"                                            ->  Index Scan using idx_prod_extn_dsched on t_product_extn_dsched ped  (cost=0.42..2.44 rows=1 width=29)"
"                                                  Index Cond: ((tc.release_id = release_id) AND ((tc.source)::bpchar = source))"
"                                      ->  Index Scan using t_dsched_terr_dsc_preorder_idx on t_dsched_terr_dsc_preorder toupre  (cost=0.43..2.45 rows=1 width=49)"
"                                            Index Cond: ((tc.release_id = release_id) AND ((tc.source)::bpchar = source) AND ((tc.country_iso)::text = (country_code)::text))"
"                                ->  Index Scan using t_dsched_terr_dsc_tou_idx1 on t_dsched_terr_dsc_tou toutou  (cost=0.57..5.98 rows=1 width=106)"
"                                      Index Cond: ((tc.release_id = release_id) AND ((tc.country_iso)::text = (country_code)::text))"
"                                      Filter: ((((source)::character varying(8))::text = 'DSCHED'::text) AND ((tc.source)::text = ((source)::character varying(8))::text))"
"                          ->  HashAggregate  (cost=78.53..80.53 rows=200 width=32)"
"                                Group Key: c.iso_code_2"
"                                ->  HashAggregate  (cost=72.03..74.92 rows=289 width=80)"
"                                      Group Key: rf.id, rf.family_name, rf.country_id, c.iso_code_2"
"                                      ->  Append  (cost=10.18..69.14 rows=289 width=80)"
"                                            ->  Hash Join  (cost=10.18..64.87 rows=288 width=30)"
"                                                  Hash Cond: (rf.country_id = c.id)"
"                                                  ->  Index Scan using releasing_family_pk on releasing_family rf  (cost=0.15..54.08 rows=288 width=27)"
"                                                        Index Cond: (id = ANY ('{0,1281,2137,2055,2138,2139,2140,2141,2142,2143,2144,2145,2146,2147,2225,2148,2241,2150,2151,2152,2153,2154,2203,2155,2169,2045,2160,2162,1280,2164,2054,2172,2163,2165,2166,2170,2167,2174,2194,2173,2175,2109,9,1282,2176,2108,1275,1283,1261,1274,2177,2179,2180,2181,2182,2183,11,2184,2185,2186,1278,2188,2187,2103,10,2115,2189,2052,2044,2038,14,1284,2159,2046,1279,2075,2058,2057,1277,2252,2061,2062,2006,2063,2192,2064,2065,2066,2067,2068,2069,12,2071,2072,2073,2074,2077,2078,2076,2060,2059,2079,2080,2082,2083,2084,2086,2087,2088,2048,2092,2253,2168,2089,2090,2091,2094,2093,2204,13,1285,2096,2097,2099,2098,2095,1276,1286,2049,2100,2101,2102,2104,2050,2107,2110,2111,2081,2114,2113,2112,2116,2117,15,1287,2118,2119,2120,2121,2123,2122,2124,2126,2128,2125,2127,2129,2132,2131,2130,2133,2134,2212,2213,2214,2215,16,2218,2219,2216,2217,2193,2220,2135,2221,2161,2229,17,2231,2224,2222,2223,2227,2232,2226,2230,2233,2234,2235,2236,2237,2239,2242,2243,2047,2244,2149,2245,2246,2247,2248,2249,2251,2250,2255,23,1288,2001,2003,2004,2005,2156,2019,2056,2020,2205,2021,2254,2007,2008,2158,2191,2009,2011,2010,2053,2016,2022,2013,2014,2207,2051,2256,2023,2032,2178,2024,2018,2025,2012,2027,2028,2026,2209,2210,2029,2070,2030,2031,2033,2034,2036,2035,2037,2039,2041,2042,2040,2043,2238,2195,18,19,1291,1289,20,21,22,1290,2240,2085,2196,24,2211,2197,2257,2258,2198,2228,2199,2200,25,2201,2171,2202,1137,2208,2017,2105,2136,2106,2206,2002}'::bigint[]))"
"                                                        Filter: ((status)::text = 'A'::text)"
"                                                  ->  Hash  (cost=6.68..6.68 rows=268 width=11)"
"                                                        ->  Seq Scan on country c  (cost=0.00..6.68 rows=268 width=11)"
"                                            ->  Seq Scan on t_releasing_family_no_null  (cost=0.00..1.38 rows=1 width=80)"
"                                                  Filter: (id = ANY ('{0,1281,2137,2055,2138,2139,2140,2141,2142,2143,2144,2145,2146,2147,2225,2148,2241,2150,2151,2152,2153,2154,2203,2155,2169,2045,2160,2162,1280,2164,2054,2172,2163,2165,2166,2170,2167,2174,2194,2173,2175,2109,9,1282,2176,2108,1275,1283,1261,1274,2177,2179,2180,2181,2182,2183,11,2184,2185,2186,1278,2188,2187,2103,10,2115,2189,2052,2044,2038,14,1284,2159,2046,1279,2075,2058,2057,1277,2252,2061,2062,2006,2063,2192,2064,2065,2066,2067,2068,2069,12,2071,2072,2073,2074,2077,2078,2076,2060,2059,2079,2080,2082,2083,2084,2086,2087,2088,2048,2092,2253,2168,2089,2090,2091,2094,2093,2204,13,1285,2096,2097,2099,2098,2095,1276,1286,2049,2100,2101,2102,2104,2050,2107,2110,2111,2081,2114,2113,2112,2116,2117,15,1287,2118,2119,2120,2121,2123,2122,2124,2126,2128,2125,2127,2129,2132,2131,2130,2133,2134,2212,2213,2214,2215,16,2218,2219,2216,2217,2193,2220,2135,2221,2161,2229,17,2231,2224,2222,2223,2227,2232,2226,2230,2233,2234,2235,2236,2237,2239,2242,2243,2047,2244,2149,2245,2246,2247,2248,2249,2251,2250,2255,23,1288,2001,2003,2004,2005,2156,2019,2056,2020,2205,2021,2254,2007,2008,2158,2191,2009,2011,2010,2053,2016,2022,2013,2014,2207,2051,2256,2023,2032,2178,2024,2018,2025,2012,2027,2028,2026,2209,2210,2029,2070,2030,2031,2033,2034,2036,2035,2037,2039,2041,2042,2040,2043,2238,2195,18,19,1291,1289,20,21,22,1290,2240,2085,2196,24,2211,2197,2257,2258,2198,2228,2199,2200,25,2201,2171,2202,1137,2208,2017,2105,2136,2106,2206,2002}'::bigint[]))"
"                    ->  Index Scan using idx_prod_extn_cprs on t_product_extn_cprs pec  (cost=0.42..2.42 rows=1 width=22)"
"                          Index Cond: ((tc.release_id = release_id) AND ((tc.source)::bpchar = source))"
"              ->  Index Scan using ""idx$$_4661a0002"" on country cc  (cost=0.15..0.29 rows=1 width=11)"
"                    Index Cond: ((tc.country_iso)::text = (iso_code_2)::text)"
"        ->  Index Scan using t_territory_extn_miles_idx on t_territory_extn_miles tem  (cost=0.42..2.39 rows=1 width=134)"
"              Index Cond: ((tc.release_id = release_id) AND ((tc.source)::text = (source)::text) AND ((source)::text = 'DSCHED'::text) AND ((tc.country_iso)::text = (country_iso)::text))"
"  ->  Nested Loop Left Join  (cost=4.50..38549.62 rows=1717 width=22)"
"        ->  Nested Loop Left Join  (cost=4.08..37770.00 rows=1717 width=22)"
"              ->  Merge Left Join  (cost=3.66..36987.39 rows=1717 width=22)"
"                    Merge Cond: (pc.release_id = dscpo.release_id)"
"                    Join Filter: ((pc.source)::text = (dscpo.source)::text)"
"                    ->  Nested Loop Left Join  (cost=3.38..36570.23 rows=1717 width=22)"
"                          ->  Nested Loop Left Join  (cost=2.95..35764.61 rows=1717 width=22)"
"                                ->  Nested Loop Left Join  (cost=2.53..34959.60 rows=1717 width=22)"
"                                      ->  Nested Loop Left Join  (cost=2.11..34171.62 rows=1717 width=22)"
"                                            ->  Nested Loop Left Join  (cost=1.69..33375.90 rows=1717 width=22)"
"                                                  ->  Nested Loop Left Join  (cost=1.27..32587.16 rows=1717 width=22)"
"                                                        ->  Nested Loop  (cost=0.85..31812.64 rows=1717 width=22)"
"                                                              ->  Index Only Scan using idx_prod_extn_dsched on t_product_extn_dsched ped_1  (cost=0.42..23770.48 rows=3965 width=15)"
"                                                                    Filter: (((release_scope)::text = ANY ('{""Digital Equivalent"",""Digital Only"",""Null""}'::text[])) AND ((source)::text = 'DSCHED'::text))"
"                                                              ->  Index Scan using t_product_common_idx on t_product_common pc  (cost=0.43..2.03 rows=1 width=14)"
"                                                                    Index Cond: (release_id = ped_1.release_id)"
"                                                                    Filter: (((source)::text = 'DSCHED'::text) AND ((status)::text = ANY ('{Scheduled,Final,Delivered,Draft}'::text[])))"
"                                                        ->  Index Only Scan using idx_prod_common_national on t_product_common_national pcn  (cost=0.42..0.44 rows=1 width=14)"
"                                                              Index Cond: ((release_id = pc.release_id) AND (source = (pc.source)::text) AND (source = 'DSCHED'::text))"
"                                                  ->  Index Only Scan using idx_prod_extn_cprs on t_product_extn_cprs pec_1  (cost=0.42..0.45 rows=1 width=13)"
"                                                        Index Cond: (release_id = pc.release_id)"
"                                                        Filter: (((source)::text = 'DSCHED'::text) AND ((pc.source)::text = (source)::text))"
"                                            ->  Index Scan using idx_terr_cprs_pricing on t_territory_cprs_pricing  (cost=0.42..0.45 rows=1 width=13)"
"                                                  Index Cond: (pc.release_id = release_id)"
"                                                  Filter: ((version_id IS NULL) AND (parent_bomid IS NULL) AND ((source)::text = 'DSCHED'::text) AND ((pc.source)::text = (source)::text))"
"                                      ->  Index Only Scan using idx_prod_terr_rights on t_prod_cprs_extn_terr_rights pcetr  (cost=0.42..0.45 rows=1 width=13)"
"                                            Index Cond: (release_id = pc.release_id)"
"                                            Filter: (((source)::text = 'DSCHED'::text) AND ((pc.source)::text = (source)::text))"
"                                ->  Index Only Scan using t_product_dsched_prim_wrkflow_idx on t_product_dsched_prim_wrkflow pdpw  (cost=0.42..0.46 rows=1 width=15)"
"                                      Index Cond: (release_id = pc.release_id)"
"                                      Filter: (((source)::text = 'DSCHED'::text) AND ((pc.source)::text = (source)::text))"
"                          ->  Index Only Scan using idx_prod_extn_summaries on t_prod_dsched_extn_summaries pdes  (cost=0.42..0.46 rows=1 width=15)"
"                                Index Cond: (release_id = pc.release_id)"
"                                Filter: (((source)::text = 'DSCHED'::text) AND ((pc.source)::text = (source)::text))"
"                    ->  Index Only Scan using idx_prod_dsc_preorder on t_dsched_product_dsc_preorder dscpo  (cost=0.29..412.65 rows=82 width=15)"
"                          Filter: ((source)::text = 'DSCHED'::text)"
"              ->  Index Only Scan using idx_prod_dsc_tou on t_dsched_product_dsc_tou dsctou  (cost=0.42..0.45 rows=1 width=15)"
"                    Index Cond: (release_id = pc.release_id)"
"                    Filter: (((source)::text = 'DSCHED'::text) AND ((pc.source)::text = (source)::text))"
"        ->  Index Only Scan using t_territory_extn_miles_idx on t_territory_extn_miles tem_1  (cost=0.42..0.44 rows=1 width=14)"
"              Index Cond: ((release_id = pc.release_id) AND (source = (pc.source)::text) AND (source = 'DSCHED'::text))"