--EXPLAIN (ANALYZE, COSTS, VERBOSE, BUFFERS, FORMAT JSON)

explain
select a11.* from (
select *

from	DEVETLMSTR.V_TERRITORY	a11
where	(a11.SOURCE in ('DSCHED')
 and a11.OPT_OUT = 'N'
 and ((a11.TERR_RELEASE_DATE >=  to_date('2019-09-16'::text,'YYYY-MM-DD')
 and a11.TERR_RELEASE_DATE <=  to_date('2019-11-01'::text,'YYYY-MM-DD'))
 or a11.TERR_RELEASE_DATE_TYPE in ('TBC'))
 and a11.TERR_RELEASE_DATE_TYPE in ('Specific Date')
 --
 and a11.TERR_FAMILY_ID in (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)
 --
 and a11.TERR_TYPE in ('Core', 'Local')
 and a11.COUNTRY_ISO in  (select distinct country_iso from DEVETLMSTR.v_releasing_family_no_null where id in ( 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)))
) a11
join	DEVETLMSTR.V_PRODUCT_ALL	a13
  on 	(a11.RELEASE_ID = a13.RELEASE_ID and 
a11.SOURCE = a13.SOURCE)
where a13.RELEASE_SCOPE in ('Digital Equivalent', 'Digital Only', 'Null')
and a13.STATUS in ('Scheduled', 'Final', 'Delivered', 'Draft');