QUERY PLAN
Subquery Scan on sub (cost=9600.73..10163.61 rows=1 width=36)
Filter: ((sub.id = 7535) AND (sub.type = 2))
-> WindowAgg (cost=9600.73..9952.53 rows=14072 width=40)
InitPlan 2 (returns $1)
-> Aggregate (cost=2575.28..2575.29 rows=1 width=32)
-> Sort (cost=2472.33..2489.49 rows=6863 width=20)
Sort Key: c_2.start_at DESC NULLS LAST, c_2.created_at DESC
-> HashAggregate (cost=1966.37..2035.00 rows=6863 width=20)
Group Key: c_2.id
-> Hash Left Join (cost=1228.56..1901.52 rows=25939 width=20)
Hash Cond: (c_2.id = cccr_2.case_id)
Filter: ((c_2.deduct_points_from = ANY ('{1001,5049,5301,5022,5209,5026,5293,5309,5356,5329,5299,5303,5302,5332,5047,1026,5096,5070,5448,5420,1029,5037,5087,1008,5048,5043,5045,5230,5031,5088,5208,1003,5467,5294,5357,5044,1030,5076,5300,5027,5089,5311,5066,5069,5364,1009,5295,1013,5128,5203,1025,5032,5075,5476,1004,5072,5033,5359,5412,5409,5229,1005,5304,5449,5358,1006,5093}'::integer[])) OR (c_2.deduct_points_from IS NULL) OR (c_2.last_engineer = 1001) OR (crr_2.user_id = 1001) OR (hashed SubPlan 1) OR (cccr_2.user_id = 1001) OR (c_2.created_by = 1001))
-> Hash Left Join (cost=1217.87..1793.24 rows=25939 width=40)
Hash Cond: (c_2.id = crd_2.case_id)
-> Hash Left Join (cost=1173.12..1687.79 rows=6863 width=36)
Hash Cond: (c_2.last_engineer = egr_2.engineer_id)
-> Hash Left Join (cost=1171.51..1592.23 rows=6863 width=36)
Hash Cond: (c_2.deduct_points_from = sgr_2.sales_id)
-> Hash Left Join (cost=1169.37..1506.90 rows=6863 width=36)
Hash Cond: (c_2.id = ps_3.case_id)
-> Hash Left Join (cost=1060.53..1333.46 rows=6863 width=36)
Hash Cond: (c_2.client_id = client_2.id)
-> Hash Right Join (cost=926.58..1181.45 rows=6863 width=36)
Hash Cond: (cb_2.case_id = c_2.id)
-> Seq Scan on tbl_callback_records cb_2 (cost=0.00..163.80 rows=7780 width=4)
-> Hash (cost=840.79..840.79 rows=6863 width=36)
-> Hash Right Join (cost=802.70..840.79 rows=6863 width=36)
Hash Cond: (i_2.case_id = c_2.id)
-> Hash Right Join (cost=428.15..447.78 rows=7029 width=4)
Hash Cond: (iri_2.implement_record_id = i_2.id)
-> Seq Scan on tbl_implement_items iri_2 (cost=0.00..18.04 rows=604 width=4)
-> Hash (cost=340.29..340.29 rows=7029 width=8)
-> Seq Scan on tbl_implement_records i_2 (cost=0.00..340.29 rows=7029 width=8)
-> Hash (cost=288.76..288.76 rows=6863 width=44)
-> Seq Scan on tbl_cases c_2 (cost=0.00..288.76 rows=6863 width=44)
Filter: (case_type = 2)
-> Hash (cost=108.98..108.98 rows=1998 width=4)
-> Seq Scan on tbl_clients client_2 (cost=0.00..108.98 rows=1998 width=4)
-> Hash (cost=88.37..88.37 rows=1637 width=4)
-> Seq Scan on tbl_pre_sales ps_3 (cost=0.00..88.37 rows=1637 width=4)
-> Hash (cost=1.51..1.51 rows=51 width=4)
-> Seq Scan on tbl_sales_group_relationships sgr_2 (cost=0.00..1.51 rows=51 width=4)
-> Hash (cost=1.27..1.27 rows=27 width=4)
-> Seq Scan on tbl_engineer_group_relationships egr_2 (cost=0.00..1.27 rows=27 width=4)
-> Hash (cost=30.39..30.39 rows=1149 width=8)
-> Hash Right Join (cost=8.84..30.39 rows=1149 width=8)
Hash Cond: (crr_2.remind_date_id = crd_2.id)
-> Seq Scan on tbl_case_remind_receivers crr_2 (cost=0.00..18.49 rows=1149 width=8)
-> Hash (cost=5.04..5.04 rows=304 width=8)
-> Seq Scan on tbl_case_remind_dates crd_2 (cost=0.00..5.04 rows=304 width=8)
-> Hash (cost=1.01..1.01 rows=1 width=8)
-> Seq Scan on tbl_case_carbon_copy_rels cccr_2 (cost=0.00..1.01 rows=1 width=8)
SubPlan 1
-> Seq Scan on tbl_user_visit_clients (cost=0.00..9.66 rows=1 width=4)
Filter: (user_id = 1001)
-> Sort (cost=7025.44..7060.62 rows=14072 width=32)
Sort Key: (array_position($1, ir.case_id)), ir.left_at DESC NULLS LAST, ir.created_at DESC
-> Result (cost=2643.91..6055.84 rows=14072 width=32)
-> Append (cost=2643.91..5879.94 rows=14072 width=28)
-> Hash Join (cost=2643.91..3002.65 rows=7171 width=28)
Hash Cond: (ir.case_id = "ANY_subquery".id)
-> Seq Scan on tbl_implement_records ir (cost=0.00..340.29 rows=7024 width=24)
Filter: (NOT is_draft)
-> Hash (cost=2558.12..2558.12 rows=6863 width=4)
-> Subquery Scan on "ANY_subquery" (cost=2472.33..2558.12 rows=6863 width=4)
-> Sort (cost=2472.33..2489.49 rows=6863 width=20)
Sort Key: c.start_at DESC NULLS LAST, c.created_at DESC
-> HashAggregate (cost=1966.37..2035.00 rows=6863 width=20)
Group Key: c.id
-> Hash Left Join (cost=1228.56..1901.52 rows=25939 width=20)
Hash Cond: (c.id = cccr.case_id)
Filter: ((c.deduct_points_from = ANY ('{1001,5049,5301,5022,5209,5026,5293,5309,5356,5329,5299,5303,5302,5332,5047,1026,5096,5070,5448,5420,1029,5037,5087,1008,5048,5043,5045,5230,5031,5088,5208,1003,5467,5294,5357,5044,1030,5076,5300,5027,5089,5311,5066,5069,5364,1009,5295,1013,5128,5203,1025,5032,5075,5476,1004,5072,5033,5359,5412,5409,5229,1005,5304,5449,5358,1006,5093}'::integer[])) OR (c.deduct_points_from IS NULL) OR (c.last_engineer = 1001) OR (crr.user_id = 1001) OR (hashed SubPlan 3) OR (cccr.user_id = 1001) OR (c.created_by = 1001))
-> Hash Left Join (cost=1217.87..1793.24 rows=25939 width=40)
Hash Cond: (c.id = crd.case_id)
-> Hash Left Join (cost=1173.12..1687.79 rows=6863 width=36)
Hash Cond: (c.last_engineer = egr.engineer_id)
-> Hash Left Join (cost=1171.51..1592.23 rows=6863 width=36)
Hash Cond: (c.deduct_points_from = sgr.sales_id)
-> Hash Left Join (cost=1169.37..1506.90 rows=6863 width=36)
Hash Cond: (c.id = ps.case_id)
-> Hash Left Join (cost=1060.53..1333.46 rows=6863 width=36)
Hash Cond: (c.client_id = client.id)
-> Hash Right Join (cost=926.58..1181.45 rows=6863 width=36)
Hash Cond: (cb.case_id = c.id)
-> Seq Scan on tbl_callback_records cb (cost=0.00..163.80 rows=7780 width=4)
-> Hash (cost=840.79..840.79 rows=6863 width=36)
-> Hash Right Join (cost=802.70..840.79 rows=6863 width=36)
Hash Cond: (i.case_id = c.id)
-> Hash Right Join (cost=428.15..447.78 rows=7029 width=4)
Hash Cond: (iri.implement_record_id = i.id)
-> Seq Scan on tbl_implement_items iri (cost=0.00..18.04 rows=604 width=4)
-> Hash (cost=340.29..340.29 rows=7029 width=8)
-> Seq Scan on tbl_implement_records i (cost=0.00..340.29 rows=7029 width=8)
-> Hash (cost=288.76..288.76 rows=6863 width=44)
-> Seq Scan on tbl_cases c (cost=0.00..288.76 rows=6863 width=44)
Filter: (case_type = 2)
-> Hash (cost=108.98..108.98 rows=1998 width=4)
-> Seq Scan on tbl_clients client (cost=0.00..108.98 rows=1998 width=4)
-> Hash (cost=88.37..88.37 rows=1637 width=4)
-> Seq Scan on tbl_pre_sales ps (cost=0.00..88.37 rows=1637 width=4)
-> Hash (cost=1.51..1.51 rows=51 width=4)
-> Seq Scan on tbl_sales_group_relationships sgr (cost=0.00..1.51 rows=51 width=4)
-> Hash (cost=1.27..1.27 rows=27 width=4)
-> Seq Scan on tbl_engineer_group_relationships egr (cost=0.00..1.27 rows=27 width=4)
-> Hash (cost=30.39..30.39 rows=1149 width=8)
-> Hash Right Join (cost=8.84..30.39 rows=1149 width=8)
Hash Cond: (crr.remind_date_id = crd.id)
-> Seq Scan on tbl_case_remind_receivers crr (cost=0.00..18.49 rows=1149 width=8)
-> Hash (cost=5.04..5.04 rows=304 width=8)
-> Seq Scan on tbl_case_remind_dates crd (cost=0.00..5.04 rows=304 width=8)
-> Hash (cost=1.01..1.01 rows=1 width=8)
-> Seq Scan on tbl_case_carbon_copy_rels cccr (cost=0.00..1.01 rows=1 width=8)
SubPlan 3
-> Seq Scan on tbl_user_visit_clients tbl_user_visit_clients_1 (cost=0.00..9.66 rows=1 width=4)
Filter: (user_id = 1001)
-> Hash Join (cost=2643.91..2736.58 rows=6901 width=28)
Hash Cond: (ps_1.case_id = "ANY_subquery_1".id)
-> Seq Scan on tbl_pre_sales ps_1 (cost=0.00..88.37 rows=1635 width=24)
Filter: (NOT is_draft)
-> Hash (cost=2558.12..2558.12 rows=6863 width=4)
-> Subquery Scan on "ANY_subquery_1" (cost=2472.33..2558.12 rows=6863 width=4)
-> Sort (cost=2472.33..2489.49 rows=6863 width=20)
Sort Key: c_1.start_at DESC NULLS LAST, c_1.created_at DESC
-> HashAggregate (cost=1966.37..2035.00 rows=6863 width=20)
Group Key: c_1.id
-> Hash Left Join (cost=1228.56..1901.52 rows=25939 width=20)
Hash Cond: (c_1.id = cccr_1.case_id)
Filter: ((c_1.deduct_points_from = ANY ('{1001,5049,5301,5022,5209,5026,5293,5309,5356,5329,5299,5303,5302,5332,5047,1026,5096,5070,5448,5420,1029,5037,5087,1008,5048,5043,5045,5230,5031,5088,5208,1003,5467,5294,5357,5044,1030,5076,5300,5027,5089,5311,5066,5069,5364,1009,5295,1013,5128,5203,1025,5032,5075,5476,1004,5072,5033,5359,5412,5409,5229,1005,5304,5449,5358,1006,5093}'::integer[])) OR (c_1.deduct_points_from IS NULL) OR (c_1.last_engineer = 1001) OR (crr_1.user_id = 1001) OR (hashed SubPlan 4) OR (cccr_1.user_id = 1001) OR (c_1.created_by = 1001))
-> Hash Left Join (cost=1217.87..1793.24 rows=25939 width=40)
Hash Cond: (c_1.id = crd_1.case_id)
-> Hash Left Join (cost=1173.12..1687.79 rows=6863 width=36)
Hash Cond: (c_1.last_engineer = egr_1.engineer_id)
-> Hash Left Join (cost=1171.51..1592.23 rows=6863 width=36)
Hash Cond: (c_1.deduct_points_from = sgr_1.sales_id)
-> Hash Left Join (cost=1169.37..1506.90 rows=6863 width=36)
Hash Cond: (c_1.id = ps_2.case_id)
-> Hash Left Join (cost=1060.53..1333.46 rows=6863 width=36)
Hash Cond: (c_1.client_id = client_1.id)
-> Hash Right Join (cost=926.58..1181.45 rows=6863 width=36)
Hash Cond: (cb_1.case_id = c_1.id)
-> Seq Scan on tbl_callback_records cb_1 (cost=0.00..163.80 rows=7780 width=4)
-> Hash (cost=840.79..840.79 rows=6863 width=36)
-> Hash Right Join (cost=802.70..840.79 rows=6863 width=36)
Hash Cond: (i_1.case_id = c_1.id)
-> Hash Right Join (cost=428.15..447.78 rows=7029 width=4)
Hash Cond: (iri_1.implement_record_id = i_1.id)
-> Seq Scan on tbl_implement_items iri_1 (cost=0.00..18.04 rows=604 width=4)
-> Hash (cost=340.29..340.29 rows=7029 width=8)
-> Seq Scan on tbl_implement_records i_1 (cost=0.00..340.29 rows=7029 width=8)
-> Hash (cost=288.76..288.76 rows=6863 width=44)
-> Seq Scan on tbl_cases c_1 (cost=0.00..288.76 rows=6863 width=44)
Filter: (case_type = 2)
-> Hash (cost=108.98..108.98 rows=1998 width=4)
-> Seq Scan on tbl_clients client_1 (cost=0.00..108.98 rows=1998 width=4)
-> Hash (cost=88.37..88.37 rows=1637 width=4)
-> Seq Scan on tbl_pre_sales ps_2 (cost=0.00..88.37 rows=1637 width=4)
-> Hash (cost=1.51..1.51 rows=51 width=4)
-> Seq Scan on tbl_sales_group_relationships sgr_1 (cost=0.00..1.51 rows=51 width=4)
-> Hash (cost=1.27..1.27 rows=27 width=4)
-> Seq Scan on tbl_engineer_group_relationships egr_1 (cost=0.00..1.27 rows=27 width=4)
-> Hash (cost=30.39..30.39 rows=1149 width=8)
-> Hash Right Join (cost=8.84..30.39 rows=1149 width=8)
Hash Cond: (crr_1.remind_date_id = crd_1.id)
-> Seq Scan on tbl_case_remind_receivers crr_1 (cost=0.00..18.49 rows=1149 width=8)
-> Hash (cost=5.04..5.04 rows=304 width=8)
-> Seq Scan on tbl_case_remind_dates crd_1 (cost=0.00..5.04 rows=304 width=8)
-> Hash (cost=1.01..1.01 rows=1 width=8)
-> Seq Scan on tbl_case_carbon_copy_rels cccr_1 (cost=0.00..1.01 rows=1 width=8)
SubPlan 4
-> Seq Scan on tbl_user_visit_clients tbl_user_visit_clients_2 (cost=0.00..9.66 rows=1 width=4)
Filter: (user_id = 1001)