explain.depesz.com

PostgreSQL's explain analyze made readable

Result: 4IF

Settings
# exclusive inclusive rows x rows loops node
1. 0.016 9.892 ↑ 1.0 1 1

Nested Loop Left Join (cost=7,060.31..7,068.43 rows=1 width=382) (actual time=9.888..9.892 rows=1 loops=1)

  • Join Filter: (((tt_2.exclusive_origin_id = wto.exclusive_origin_id) OR ((tt_2.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))) AND ((tt_2.sub_region_id = wto.sub_region_id) OR ((tt_2.sub_region_id IS NULL) AND (wto.sub_region_id IS NULL))) AND (o_1.worker_id = w.id))
2.          

CTE worker_state_machine_trail

3. 0.299 0.299 ↓ 24.4 244 1

Index Scan using idx_state_machine_trail_id_type_smid_created_date on state_machine_trail (cost=0.71..20.27 rows=10 width=124) (actual time=0.021..0.299 rows=244 loops=1)

  • Index Cond: ((entity_id = 396,701) AND (created_date >= (to_timestamp('2019-09-16 10:30:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text) - '2 days'::interval)) AND (created_date <= (to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text) + '2 days'::interval)))
4.          

CTE workers_turn_on

5. 0.000 0.171 ↑ 1.0 1 1

Nested Loop (cost=34.32..125.85 rows=1 width=28) (actual time=0.170..0.171 rows=1 loops=1)

  • Join Filter: (e_1.id = ea_2.state_machine_event_id)
6.          

Initplan (for Nested Loop)

7. 0.007 0.007 ↑ 1.0 1 1

Index Scan using idx_attribute_key_name on attribute_key (cost=0.14..4.25 rows=1 width=8) (actual time=0.007..0.007 rows=1 loops=1)

  • Index Cond: ((name)::text = 'EXCLUSIVE_ORIGIN_ID'::text)
8. 0.006 0.006 ↑ 1.0 1 1

Index Scan using idx_attribute_key_name on attribute_key attribute_key_1 (cost=0.14..4.25 rows=1 width=8) (actual time=0.006..0.006 rows=1 loops=1)

  • Index Cond: ((name)::text = 'SUB_REGION_ID'::text)
9. 0.011 0.011 ↑ 1.0 1 1

Index Scan using idx_attribute_key_name on attribute_key attribute_key_2 (cost=0.14..4.25 rows=1 width=8) (actual time=0.010..0.011 rows=1 loops=1)

  • Index Cond: ((name)::text = 'LOGISTICS_OPERATORS_ID'::text)
10. 0.011 0.011 ↑ 1.0 1 1

Index Scan using idx_subset_name on subset (cost=0.28..4.38 rows=1 width=8) (actual time=0.011..0.011 rows=1 loops=1)

  • Index Cond: ((name)::text = 'Operador Nuvem'::text)
11. 0.005 0.005 ↑ 1.0 1 1

Index Scan using idx_attribute_key_name on attribute_key attribute_key_3 (cost=0.14..4.25 rows=1 width=8) (actual time=0.005..0.005 rows=1 loops=1)

  • Index Cond: ((name)::text = 'TAG'::text)
12. 0.008 0.008 ↑ 1.0 1 1

Index Scan using idx_attribute_key_name on attribute_key attribute_key_4 (cost=0.14..4.25 rows=1 width=8) (actual time=0.008..0.008 rows=1 loops=1)

  • Index Cond: ((name)::text = 'SHIFT'::text)
13. 0.006 0.006 ↑ 1.0 1 1

Index Scan using idx_attribute_key_name on attribute_key attribute_key_5 (cost=0.14..4.25 rows=1 width=8) (actual time=0.006..0.006 rows=1 loops=1)

  • Index Cond: ((name)::text = 'REGION_ID'::text)
14. 0.009 0.154 ↑ 1.0 1 1

Nested Loop (cost=3.85..16.29 rows=1 width=70) (actual time=0.153..0.154 rows=1 loops=1)

  • Join Filter: (e_1.id = ea_1.state_machine_event_id)
15. 0.008 0.128 ↑ 1.0 1 1

Nested Loop (cost=3.15..13.40 rows=1 width=62) (actual time=0.127..0.128 rows=1 loops=1)

  • Join Filter: (e_1.id = ea.state_machine_event_id)
16. 0.007 0.103 ↑ 1.0 1 1

Nested Loop Left Join (cost=2.44..10.51 rows=1 width=54) (actual time=0.103..0.103 rows=1 loops=1)

17. 0.008 0.090 ↑ 1.0 1 1

Nested Loop Left Join (cost=1.87..8.62 rows=1 width=44) (actual time=0.090..0.090 rows=1 loops=1)

18. 0.013 0.075 ↑ 1.0 1 1

Nested Loop (cost=1.29..6.74 rows=1 width=34) (actual time=0.075..0.075 rows=1 loops=1)

19. 0.031 0.031 ↑ 1.0 1 1

Index Scan using idx_state_machine_event_ei_et_ei_ed on state_machine_event e_1 (cost=0.71..4.83 rows=1 width=16) (actual time=0.030..0.031 rows=1 loops=1)

  • Index Cond: ((entity_id = 396,701) AND ((entity_type)::text = 'WORKER'::text) AND ((event_id)::text = 'TURN_ON'::text) AND (event_date >= to_timestamp('2019-09-16 10:30:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)) AND (event_date <= to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Filter: ((event_status)::text = 'ACCEPTED'::text)
20. 0.031 0.031 ↑ 60.0 1 1

Index Scan using state_machine_event_attribute_state_machine_event_id_attrib_key on state_machine_event_attribute logistics_operators_id (cost=0.58..80.63 rows=60 width=18) (actual time=0.031..0.031 rows=1 loops=1)

  • Index Cond: ((state_machine_event_id = e_1.id) AND (attribute_key_id = $3))
  • Filter: ((value)::integer <> $4)
21. 0.007 0.007 ↓ 0.0 0 1

Index Scan using state_machine_event_attribute_state_machine_event_id_attrib_key on state_machine_event_attribute e_exclusive_origin_id (cost=0.58..80.17 rows=61 width=18) (actual time=0.007..0.007 rows=0 loops=1)

  • Index Cond: ((e_1.id = state_machine_event_id) AND (attribute_key_id = $1))
22. 0.006 0.006 ↓ 0.0 0 1

Index Scan using state_machine_event_attribute_state_machine_event_id_attrib_key on state_machine_event_attribute e_sub_regions_id (cost=0.58..80.17 rows=61 width=18) (actual time=0.006..0.006 rows=0 loops=1)

  • Index Cond: ((e_1.id = state_machine_event_id) AND (attribute_key_id = $2))
23. 0.017 0.017 ↑ 1.0 1 1

Index Only Scan using idx_state_machine_event_attribute_attribute_key_id_value on state_machine_event_attribute ea (cost=0.70..2.79 rows=1 width=8) (actual time=0.017..0.017 rows=1 loops=1)

  • Index Cond: ((attribute_key_id = $5) AND (value = 'REGULAR'::text) AND (state_machine_event_id = logistics_operators_id.state_machine_event_id))
  • Heap Fetches: 1
24. 0.017 0.017 ↑ 1.0 1 1

Index Only Scan using idx_state_machine_event_attribute_attribute_key_id_value on state_machine_event_attribute ea_1 (cost=0.70..2.79 rows=1 width=8) (actual time=0.017..0.017 rows=1 loops=1)

  • Index Cond: ((attribute_key_id = $6) AND (value = 'ALMOCO LOOP'::text) AND (state_machine_event_id = logistics_operators_id.state_machine_event_id))
  • Heap Fetches: 1
25. 0.008 0.008 ↑ 1.0 1 1

Index Scan using state_machine_event_attribute_state_machine_event_id_attrib_key on state_machine_event_attribute ea_2 (cost=0.58..79.55 rows=1 width=8) (actual time=0.008..0.008 rows=1 loops=1)

  • Index Cond: ((state_machine_event_id = logistics_operators_id.state_machine_event_id) AND (attribute_key_id = $7))
  • Filter: ((value)::integer = 31)
26.          

CTE shift_orders

27. 0.004 4.006 ↓ 4.0 4 1

Nested Loop (cost=1.13..1,423.67 rows=1 width=801) (actual time=0.353..4.006 rows=4 loops=1)

28. 3.978 3.978 ↓ 4.0 4 1

Index Scan using idx_order_delivery_worker_id on order_delivery o_2 (cost=0.56..1,419.00 rows=1 width=801) (actual time=0.339..3.978 rows=4 loops=1)

  • Index Cond: (worker_id = 396,701)
  • Filter: (((shift)::text = 'ALMOCO LOOP'::text) AND (created_date <= to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)) AND (created_date >= ((to_date('2019-09-16'::text, 'YYYY-MM-DD'::text) - 4))::timestamp without time zone))
  • Rows Removed by Filter: 2,137
29. 0.024 0.024 ↑ 1.0 1 4

Index Only Scan using order_subset_pkey on order_subset os (cost=0.57..4.68 rows=1 width=8) (actual time=0.006..0.006 rows=1 loops=4)

  • Index Cond: ((order_id = o_2.id) AND (subset_id = 31))
  • Heap Fetches: 0
30.          

CTE turn_on_turn_off_times

31. 0.001 0.483 ↑ 1.0 1 1

Unique (cost=4.74..4.76 rows=1 width=40) (actual time=0.482..0.483 rows=1 loops=1)

32. 0.009 0.482 ↑ 1.0 1 1

Sort (cost=4.74..4.75 rows=1 width=40) (actual time=0.482..0.482 rows=1 loops=1)

  • Sort Key: workers_turn_on.worker_id, workers_turn_on.exclusive_origin_id, workers_turn_on.sub_region_id, (GREATEST((max(turn_on.created_date))::timestamp with time zone, to_timestamp('2019-09-16 10:30:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text))), (LEAST((min(turn_off.created_date))::timestamp with time zone, to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Sort Method: quicksort Memory: 25kB
33. 0.007 0.473 ↑ 1.0 1 1

GroupAggregate (cost=4.59..4.73 rows=1 width=40) (actual time=0.473..0.473 rows=1 loops=1)

  • Group Key: turn_on.id, workers_turn_on.worker_id, workers_turn_on.exclusive_origin_id, workers_turn_on.sub_region_id
  • Filter: (GREATEST((max(turn_on.created_date))::timestamp with time zone, to_timestamp('2019-09-16 10:30:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)) < LEAST((min(turn_off.created_date))::timestamp with time zone, to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
34. 0.010 0.466 ↑ 1.0 1 1

Sort (cost=4.59..4.60 rows=1 width=40) (actual time=0.466..0.466 rows=1 loops=1)

  • Sort Key: turn_on.id, workers_turn_on.worker_id, workers_turn_on.exclusive_origin_id, workers_turn_on.sub_region_id
  • Sort Method: quicksort Memory: 25kB
35. 0.002 0.456 ↑ 1.0 1 1

Nested Loop Left Join (cost=0.00..4.58 rows=1 width=40) (actual time=0.444..0.456 rows=1 loops=1)

  • Join Filter: ((turn_on.created_date < turn_off.created_date) AND (turn_on.entity_id = turn_off.entity_id))
  • Rows Removed by Join Filter: 6
36. 0.002 0.319 ↑ 1.0 1 1

Nested Loop (cost=0.00..2.38 rows=1 width=40) (actual time=0.307..0.319 rows=1 loops=1)

  • Join Filter: (workers_turn_on.event_id = turn_on.event_id)
  • Rows Removed by Join Filter: 12
37. 0.000 0.000 ↑ 1.0 1 1

CTE Scan on workers_turn_on (cost=0.00..0.20 rows=1 width=24) (actual time=0.000..0.000 rows=1 loops=1)

38. 0.317 0.317 ↓ 13.0 13 1

CTE Scan on worker_state_machine_trail turn_on (cost=0.00..2.08 rows=1 width=32) (actual time=0.025..0.317 rows=13 loops=1)

  • Filter: (((state_machine_id)::text = 'WORKER_SHIFT_STATE_MACHINE'::text) AND (created_date < to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Rows Removed by Filter: 231
39. 0.135 0.135 ↓ 6.0 6 1

CTE Scan on worker_state_machine_trail turn_off (cost=0.00..2.10 rows=1 width=16) (actual time=0.007..0.135 rows=6 loops=1)

  • Filter: (((current_state)::text = 'OFF_SHIFT'::text) AND ((state_machine_id)::text = 'WORKER_SHIFT_STATE_MACHINE'::text) AND (created_date < to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Rows Removed by Filter: 238
40.          

CTE workers_on_shift_on_off_times

41. 0.002 0.406 ↑ 1.0 1 1

Nested Loop Left Join (cost=4.72..5.15 rows=1 width=32) (actual time=0.405..0.406 rows=1 loops=1)

  • Join Filter: (((wto_1.exclusive_origin_id = tt_3.exclusive_origin_id) OR ((wto_1.exclusive_origin_id IS NULL) AND (tt_3.exclusive_origin_id IS NULL))) AND ((wto_1.sub_region_id = tt_3.sub_region_id) OR ((wto_1.sub_region_id IS NULL) AND (tt_3.sub_region_id IS NULL))) AND "overlaps"(COALESCE((GREATEST((max(on_trail.created_date))::timestamp with time zone, to_timestamp('2019-09-16 10:30:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text))), tt_3.turn_on_time), COALESCE((LEAST((min(off_trail.created_date))::timestamp with time zone, to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text))), tt_3.turn_off_time), tt_3.turn_on_time, tt_3.turn_off_time) AND (wto_1.worker_id = tt_3.worker_id))
42. 0.001 0.001 ↑ 1.0 1 1

CTE Scan on turn_on_turn_off_times tt_3 (cost=0.00..0.20 rows=1 width=32) (actual time=0.000..0.001 rows=1 loops=1)

43. 0.001 0.403 ↑ 1.0 1 1

Unique (cost=4.72..4.73 rows=1 width=40) (actual time=0.402..0.403 rows=1 loops=1)

44. 0.007 0.402 ↑ 1.0 1 1

Sort (cost=4.72..4.72 rows=1 width=40) (actual time=0.402..0.402 rows=1 loops=1)

  • Sort Key: wto_1.worker_id, wto_1.exclusive_origin_id, wto_1.sub_region_id, (GREATEST((max(on_trail.created_date))::timestamp with time zone, to_timestamp('2019-09-16 10:30:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text))), (LEAST((min(off_trail.created_date))::timestamp with time zone, to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Sort Method: quicksort Memory: 25kB
45. 0.034 0.395 ↑ 1.0 1 1

GroupAggregate (cost=4.57..4.71 rows=1 width=40) (actual time=0.395..0.395 rows=1 loops=1)

  • Group Key: on_trail.id, wto_1.worker_id, wto_1.exclusive_origin_id, wto_1.sub_region_id
  • Filter: (GREATEST((max(on_trail.created_date))::timestamp with time zone, to_timestamp('2019-09-16 10:30:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)) < LEAST((min(off_trail.created_date))::timestamp with time zone, to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Rows Removed by Filter: 10
46. 0.033 0.361 ↓ 121.0 121 1

Sort (cost=4.57..4.57 rows=1 width=40) (actual time=0.357..0.361 rows=121 loops=1)

  • Sort Key: on_trail.id, wto_1.worker_id, wto_1.exclusive_origin_id, wto_1.sub_region_id
  • Sort Method: quicksort Memory: 34kB
47. 0.017 0.328 ↓ 121.0 121 1

Nested Loop Left Join (cost=0.00..4.56 rows=1 width=40) (actual time=0.015..0.328 rows=121 loops=1)

  • Join Filter: ((on_trail.created_date < off_trail.created_date) AND (on_trail.entity_id = off_trail.entity_id))
  • Rows Removed by Join Filter: 66
48. 0.002 0.036 ↓ 11.0 11 1

Nested Loop (cost=0.00..2.40 rows=1 width=40) (actual time=0.007..0.036 rows=11 loops=1)

  • Join Filter: (wto_1.worker_id = on_trail.entity_id)
49. 0.001 0.001 ↑ 1.0 1 1

CTE Scan on workers_turn_on wto_1 (cost=0.00..0.20 rows=1 width=16) (actual time=0.000..0.001 rows=1 loops=1)

50. 0.033 0.033 ↓ 11.0 11 1

CTE Scan on worker_state_machine_trail on_trail (cost=0.00..2.10 rows=1 width=24) (actual time=0.006..0.033 rows=11 loops=1)

  • Filter: (((current_state)::text = 'ONLINE'::text) AND ((state_machine_id)::text = 'WORKER_CONNECTIVITY_STATE_MACHINE'::text) AND (created_date < to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Rows Removed by Filter: 233
51. 0.275 0.275 ↓ 17.0 17 11

CTE Scan on worker_state_machine_trail off_trail (cost=0.00..2.05 rows=1 width=16) (actual time=0.003..0.025 rows=17 loops=11)

  • Filter: (((current_state)::text = 'OFFLINE'::text) AND ((state_machine_id)::text = 'WORKER_CONNECTIVITY_STATE_MACHINE'::text))
  • Rows Removed by Filter: 227
52.          

CTE workers_on_shift_block_unblock_times

53. 0.007 0.225 ↓ 0.0 0 1

Nested Loop Left Join (cost=4.57..5.13 rows=1 width=32) (actual time=0.225..0.225 rows=0 loops=1)

  • Join Filter: ((((max(wto_2.exclusive_origin_id)) = oo_1.exclusive_origin_id) OR (((max(wto_2.exclusive_origin_id)) IS NULL) AND (oo_1.exclusive_origin_id IS NULL))) AND (((max(wto_2.sub_region_id)) = oo_1.sub_region_id) OR (((max(wto_2.sub_region_id)) IS NULL) AND (oo_1.sub_region_id IS NULL))) AND ((max(wto_2.worker_id)) = oo_1.worker_id))
  • Filter: ((CASE WHEN (((min(block.created_date)) < oo_1.on_time) OR (((min(block.created_date)) IS NULL) AND ((min(unblock.created_date)) IS NOT NULL))) THEN oo_1.on_time ELSE ((min(block.created_date)))::timestamp with time zone END IS NOT NULL) AND (CASE WHEN (((min(unblock.created_date)) > oo_1.off_time) OR (((min(unblock.created_date)) IS NULL) AND ((min(block.created_date)) IS NOT NULL))) THEN oo_1.off_time ELSE ((min(unblock.created_date)))::timestamp with time zone END IS NOT NULL) AND "overlaps"(CASE WHEN (((min(block.created_date)) < oo_1.on_time) OR (((min(block.created_date)) IS NULL) AND ((min(unblock.created_date)) IS NOT NULL))) THEN oo_1.on_time ELSE ((min(block.created_date)))::timestamp with time zone END, CASE WHEN (((min(unblock.created_date)) > oo_1.off_time) OR (((min(unblock.created_date)) IS NULL) AND ((min(block.created_date)) IS NOT NULL))) THEN oo_1.off_time ELSE ((min(unblock.created_date)))::timestamp with time zone END, oo_1.on_time, oo_1.off_time))
  • Rows Removed by Filter: 7
54. 0.000 0.000 ↑ 1.0 1 1

CTE Scan on workers_on_shift_on_off_times oo_1 (cost=0.00..0.20 rows=1 width=32) (actual time=0.000..0.000 rows=1 loops=1)

55. 0.007 0.218 ↓ 7.0 7 1

GroupAggregate (cost=4.57..4.69 rows=1 width=40) (actual time=0.213..0.218 rows=7 loops=1)

  • Group Key: block.id
56. 0.016 0.211 ↓ 28.0 28 1

Sort (cost=4.57..4.57 rows=1 width=40) (actual time=0.209..0.211 rows=28 loops=1)

  • Sort Key: block.id
  • Sort Method: quicksort Memory: 27kB
57. 0.008 0.195 ↓ 28.0 28 1

Nested Loop Left Join (cost=0.00..4.56 rows=1 width=40) (actual time=0.014..0.195 rows=28 loops=1)

  • Join Filter: ((unblock.created_date > block.created_date) AND (unblock.entity_id = block.entity_id))
  • Rows Removed by Join Filter: 21
58. 0.002 0.026 ↓ 7.0 7 1

Nested Loop Left Join (cost=0.00..2.38 rows=1 width=40) (actual time=0.007..0.026 rows=7 loops=1)

  • Join Filter: (wto_2.worker_id = block.entity_id)
59. 0.000 0.000 ↑ 1.0 1 1

CTE Scan on workers_turn_on wto_2 (cost=0.00..0.20 rows=1 width=16) (actual time=0.000..0.000 rows=1 loops=1)

60. 0.024 0.024 ↓ 7.0 7 1

CTE Scan on worker_state_machine_trail block (cost=0.00..2.08 rows=1 width=24) (actual time=0.006..0.024 rows=7 loops=1)

  • Filter: (((current_state)::text = 'BLOCKED'::text) AND ((previous_state)::text = 'UNBLOCKED'::text) AND ((state_machine_id)::text = 'WORKER_BLOCK_STATE_MACHINE'::text))
  • Rows Removed by Filter: 237
61. 0.161 0.161 ↓ 7.0 7 7

CTE Scan on worker_state_machine_trail unblock (cost=0.00..2.08 rows=1 width=16) (actual time=0.005..0.023 rows=7 loops=7)

  • Filter: (((current_state)::text = 'UNBLOCKED'::text) AND ((previous_state)::text = 'BLOCKED'::text) AND ((state_machine_id)::text = 'WORKER_BLOCK_STATE_MACHINE'::text))
  • Rows Removed by Filter: 237
62.          

CTE workers_on_shift_online_working_times

63. 0.003 1.911 ↓ 4.0 4 1

Nested Loop (cost=4.74..5.17 rows=1 width=32) (actual time=1.909..1.911 rows=4 loops=1)

  • Join Filter: (((wto_3.exclusive_origin_id = oo_2.exclusive_origin_id) OR ((wto_3.exclusive_origin_id IS NULL) AND (oo_2.exclusive_origin_id IS NULL))) AND ((wto_3.sub_region_id = oo_2.sub_region_id) OR ((wto_3.sub_region_id IS NULL) AND (oo_2.sub_region_id IS NULL))) AND "overlaps"(COALESCE((GREATEST((max(start_work_trail.created_date))::timestamp with time zone, to_timestamp('2019-09-16 10:30:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text))), oo_2.on_time), COALESCE((LEAST((min(end_work_trail.created_date))::timestamp with time zone, to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text))), oo_2.off_time), oo_2.on_time, oo_2.off_time) AND (oo_2.worker_id = wto_3.worker_id))
64. 0.000 0.000 ↑ 1.0 1 1

CTE Scan on workers_on_shift_on_off_times oo_2 (cost=0.00..0.20 rows=1 width=32) (actual time=0.000..0.000 rows=1 loops=1)

65. 0.001 1.908 ↓ 4.0 4 1

Unique (cost=4.74..4.76 rows=1 width=40) (actual time=1.907..1.908 rows=4 loops=1)

66. 0.006 1.907 ↓ 4.0 4 1

Sort (cost=4.74..4.75 rows=1 width=40) (actual time=1.907..1.907 rows=4 loops=1)

  • Sort Key: wto_3.worker_id, wto_3.exclusive_origin_id, wto_3.sub_region_id, (GREATEST((max(start_work_trail.created_date))::timestamp with time zone, to_timestamp('2019-09-16 10:30:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text))), (LEAST((min(end_work_trail.created_date))::timestamp with time zone, to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Sort Method: quicksort Memory: 25kB
67. 0.226 1.901 ↓ 4.0 4 1

GroupAggregate (cost=4.59..4.73 rows=1 width=40) (actual time=1.889..1.901 rows=4 loops=1)

  • Group Key: start_work_trail.id, wto_3.worker_id, wto_3.exclusive_origin_id, wto_3.sub_region_id
  • Filter: (GREATEST((max(start_work_trail.created_date))::timestamp with time zone, to_timestamp('2019-09-16 10:30:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)) < LEAST((min(end_work_trail.created_date))::timestamp with time zone, to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Rows Removed by Filter: 38
68. 0.300 1.675 ↓ 1,281.0 1,281 1

Sort (cost=4.59..4.60 rows=1 width=40) (actual time=1.625..1.675 rows=1,281 loops=1)

  • Sort Key: start_work_trail.id, wto_3.worker_id, wto_3.exclusive_origin_id, wto_3.sub_region_id
  • Sort Method: quicksort Memory: 149kB
69. 0.178 1.375 ↓ 1,281.0 1,281 1

Nested Loop Left Join (cost=0.00..4.58 rows=1 width=40) (actual time=0.011..1.375 rows=1,281 loops=1)

  • Join Filter: ((start_work_trail.created_date < end_work_trail.created_date) AND (start_work_trail.entity_id = end_work_trail.entity_id))
  • Rows Removed by Join Filter: 861
70. 0.007 0.063 ↓ 42.0 42 1

Nested Loop (cost=0.00..2.40 rows=1 width=40) (actual time=0.009..0.063 rows=42 loops=1)

  • Join Filter: (wto_3.worker_id = start_work_trail.entity_id)
71. 0.000 0.000 ↑ 1.0 1 1

CTE Scan on workers_turn_on wto_3 (cost=0.00..0.20 rows=1 width=16) (actual time=0.000..0.000 rows=1 loops=1)

72. 0.056 0.056 ↓ 42.0 42 1

CTE Scan on worker_state_machine_trail start_work_trail (cost=0.00..2.10 rows=1 width=24) (actual time=0.008..0.056 rows=42 loops=1)

  • Filter: (((current_state)::text = 'WORKING'::text) AND ((state_machine_id)::text = 'WORKER_STATE_MACHINE'::text) AND (created_date < to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Rows Removed by Filter: 202
73. 1.134 1.134 ↓ 51.0 51 42

CTE Scan on worker_state_machine_trail end_work_trail (cost=0.00..2.08 rows=1 width=16) (actual time=0.000..0.027 rows=51 loops=42)

  • Filter: (((previous_state)::text = 'WORKING'::text) AND ((current_state)::text = 'FREE'::text) AND ((state_machine_id)::text = 'WORKER_STATE_MACHINE'::text))
  • Rows Removed by Filter: 193
74.          

CTE workers_on_shift_online_blocked_working_times

75. 0.000 0.000 ↓ 0.0 0 1

Nested Loop (cost=0.00..0.52 rows=1 width=32) (actual time=0.000..0.000 rows=0 loops=1)

  • Join Filter: (((t_3.exclusive_origin_id = b.exclusive_origin_id) OR ((t_3.exclusive_origin_id IS NULL) AND (b.exclusive_origin_id IS NULL))) AND ((t_3.sub_region_id = b.sub_region_id) OR ((t_3.sub_region_id IS NULL) AND (b.sub_region_id IS NULL))) AND "overlaps"(t_3.start_work_time, t_3.end_work_time, b.block_time, b.unblock_time) AND (b.worker_id = t_3.worker_id))
76. 0.000 0.000 ↓ 0.0 0 1

CTE Scan on workers_on_shift_block_unblock_times b (cost=0.00..0.20 rows=1 width=32) (actual time=0.000..0.000 rows=0 loops=1)

77. 0.000 0.000 ↓ 0.0 0

CTE Scan on workers_on_shift_online_working_times t_3 (cost=0.00..0.20 rows=1 width=32) (never executed)

78. 0.001 9.766 ↑ 1.0 1 1

Nested Loop Left Join (cost=5,367.05..5,374.77 rows=1 width=246) (actual time=9.762..9.766 rows=1 loops=1)

  • Join Filter: (((t_2.exclusive_origin_id = wto.exclusive_origin_id) OR ((t_2.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))) AND ((t_2.sub_region_id = wto.sub_region_id) OR ((t_2.sub_region_id IS NULL) AND (wto.sub_region_id IS NULL))) AND (t_2.worker_id = w.id))
79. 0.001 9.764 ↑ 1.0 1 1

Nested Loop Left Join (cost=5,366.83..5,374.25 rows=1 width=238) (actual time=9.760..9.764 rows=1 loops=1)

  • Join Filter: (((t_1.exclusive_origin_id = wto.exclusive_origin_id) OR ((t_1.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))) AND ((t_1.sub_region_id = wto.sub_region_id) OR ((t_1.sub_region_id IS NULL) AND (wto.sub_region_id IS NULL))) AND (t_1.worker_id = w.id))
80. 0.001 7.844 ↑ 1.0 1 1

Nested Loop Left Join (cost=5,366.62..5,373.73 rows=1 width=230) (actual time=7.841..7.844 rows=1 loops=1)

  • Join Filter: (((t.exclusive_origin_id = wto.exclusive_origin_id) OR ((t.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))) AND ((t.sub_region_id = wto.sub_region_id) OR ((t.sub_region_id IS NULL) AND (wto.sub_region_id IS NULL))) AND (t.worker_id = w.id))
81. 0.001 7.617 ↑ 1.0 1 1

Nested Loop Left Join (cost=5,366.40..5,373.20 rows=1 width=222) (actual time=7.614..7.617 rows=1 loops=1)

  • Join Filter: (((oo.exclusive_origin_id = wto.exclusive_origin_id) OR ((oo.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))) AND ((oo.sub_region_id = wto.sub_region_id) OR ((oo.sub_region_id IS NULL) AND (wto.sub_region_id IS NULL))) AND (oo.worker_id = w.id))
82. 0.002 7.202 ↑ 1.0 1 1

Nested Loop Left Join (cost=5,366.19..5,372.68 rows=1 width=214) (actual time=7.199..7.202 rows=1 loops=1)

  • Join Filter: (((tt_1.exclusive_origin_id = wto.exclusive_origin_id) OR ((tt_1.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))) AND ((tt_1.sub_region_id = wto.sub_region_id) OR ((tt_1.sub_region_id IS NULL) AND (wto.sub_region_id IS NULL))) AND (r_1.worker_id = w.id))
83. 0.002 3.035 ↑ 1.0 1 1

Nested Loop Left Join (cost=5,082.24..5,088.38 rows=1 width=166) (actual time=3.032..3.035 rows=1 loops=1)

  • Join Filter: (((tt.exclusive_origin_id = wto.exclusive_origin_id) OR ((tt.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))) AND ((tt.sub_region_id = wto.sub_region_id) OR ((tt.sub_region_id IS NULL) AND (wto.sub_region_id IS NULL))) AND (r.worker_id = w.id))
84. 0.000 0.237 ↑ 1.0 1 1

Nested Loop (cost=1.64..7.40 rows=1 width=94) (actual time=0.235..0.237 rows=1 loops=1)

85. 0.003 0.226 ↑ 1.0 1 1

Nested Loop (cost=1.21..6.83 rows=1 width=85) (actual time=0.223..0.226 rows=1 loops=1)

86. 0.001 0.214 ↓ 1.5 3 1

Nested Loop (cost=1.07..6.21 rows=2 width=93) (actual time=0.211..0.214 rows=3 loops=1)

87. 0.001 0.202 ↑ 1.0 1 1

Nested Loop (cost=0.64..4.86 rows=1 width=28) (actual time=0.201..0.202 rows=1 loops=1)

88. 0.001 0.186 ↑ 1.0 1 1

Group (cost=0.21..0.23 rows=1 width=20) (actual time=0.185..0.186 rows=1 loops=1)

  • Group Key: wto.worker_id, wto.logistics_operator_id, wto.exclusive_origin_id, wto.sub_region_id
89. 0.012 0.185 ↑ 1.0 1 1

Sort (cost=0.21..0.22 rows=1 width=20) (actual time=0.184..0.185 rows=1 loops=1)

  • Sort Key: wto.worker_id, wto.logistics_operator_id, wto.exclusive_origin_id, wto.sub_region_id
  • Sort Method: quicksort Memory: 25kB
90. 0.173 0.173 ↑ 1.0 1 1

CTE Scan on workers_turn_on wto (cost=0.00..0.20 rows=1 width=20) (actual time=0.172..0.173 rows=1 loops=1)

91. 0.015 0.015 ↑ 1.0 1 1

Index Scan using pk_worker on worker w (cost=0.43..4.54 rows=1 width=16) (actual time=0.015..0.015 rows=1 loops=1)

  • Index Cond: (id = wto.worker_id)
92. 0.011 0.011 ↑ 1.3 3 1

Index Scan using user_attribute_user_id_attribute_key_id_key on user_attribute ua (cost=0.43..0.95 rows=4 width=65) (actual time=0.010..0.011 rows=3 loops=1)

  • Index Cond: (user_id = w.user_id)
93. 0.009 0.009 ↓ 0.0 0 3

Index Scan using pk_attribute_key on attribute_key uak (cost=0.14..0.26 rows=1 width=8) (actual time=0.003..0.003 rows=0 loops=3)

  • Index Cond: (id = ua.attribute_key_id)
  • Filter: ((name)::text = 'CPF'::text)
  • Rows Removed by Filter: 1
94. 0.011 0.011 ↑ 1.0 1 1

Index Scan using pk_user_fleet on user_fleet u (cost=0.42..0.57 rows=1 width=33) (actual time=0.011..0.011 rows=1 loops=1)

  • Index Cond: (id = w.user_id)
95. 0.111 2.796 ↑ 1.0 1 1

GroupAggregate (cost=5,080.60..5,080.77 rows=1 width=88) (actual time=2.795..2.796 rows=1 loops=1)

  • Group Key: r.worker_id, tt.exclusive_origin_id, tt.sub_region_id
96.          

Initplan (for GroupAggregate)

97. 0.010 0.010 ↑ 1.0 1 1

Index Scan using idx_attribute_key_name on attribute_key ak (cost=0.14..4.25 rows=1 width=8) (actual time=0.010..0.010 rows=1 loops=1)

  • Index Cond: ((name)::text = 'GEOFENCE_VIOLATED'::text)
98. 0.047 2.675 ↓ 128.0 128 1

Sort (cost=5,076.35..5,076.35 rows=1 width=73) (actual time=2.670..2.675 rows=128 loops=1)

  • Sort Key: r.worker_id, tt.exclusive_origin_id, tt.sub_region_id
  • Sort Method: quicksort Memory: 43kB
99. 0.021 2.628 ↓ 128.0 128 1

Nested Loop Left Join (cost=1.85..5,076.34 rows=1 width=73) (actual time=0.718..2.628 rows=128 loops=1)

100. 0.013 2.479 ↓ 32.0 32 1

Nested Loop (cost=1.28..3,195.40 rows=1 width=55) (actual time=0.707..2.479 rows=32 loops=1)

101. 0.002 2.382 ↑ 22.0 4 1

Nested Loop (cost=0.56..1,092.52 rows=88 width=24) (actual time=0.687..2.382 rows=4 loops=1)

102. 0.484 0.484 ↑ 1.0 1 1

CTE Scan on turn_on_turn_off_times tt (cost=0.00..0.20 rows=1 width=32) (actual time=0.483..0.484 rows=1 loops=1)

103. 1.896 1.896 ↑ 22.0 4 1

Index Scan using idx_route_worker_id on route r (cost=0.56..1,083.52 rows=88 width=24) (actual time=0.203..1.896 rows=4 loops=1)

  • Index Cond: (worker_id = tt.worker_id)
  • Filter: ((created_date >= tt.turn_on_time) AND (created_date <= tt.turn_off_time))
  • Rows Removed by Filter: 1,995
104. 0.084 0.084 ↓ 8.0 8 4

Index Scan using idx_state_machine_event_ei_et_ei_ed on state_machine_event e (cost=0.71..23.80 rows=1 width=39) (actual time=0.010..0.021 rows=8 loops=4)

  • Index Cond: ((entity_id = r.id) AND ((entity_type)::text = 'ROUTE'::text) AND (event_date >= to_timestamp('2019-09-16 10:30:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)) AND (event_date <= (to_timestamp('2019-09-16 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text) + '01:00:00'::interval)))
  • Filter: (((event_status)::text = 'ACCEPTED'::text) AND ((event_id)::text = ANY ('{CHECK_IN,CHECK_OUT,CANCEL_OFFER_TIMEOUT,REJECT,OFFER,CANCEL_OFFER,ACCEPT,AUTO_CANCEL,CANCEL}'::text[])))
  • Rows Removed by Filter: 7
105. 0.128 0.128 ↑ 349.0 4 32

Index Scan using state_machine_event_attribute_state_machine_event_id_attrib_key on state_machine_event_attribute a (cost=0.58..1,741.34 rows=1,396 width=26) (actual time=0.003..0.004 rows=4 loops=32)

  • Index Cond: (e.id = state_machine_event_id)
106. 0.012 4.165 ↑ 1.0 1 1

GroupAggregate (cost=283.95..284.10 rows=1 width=64) (actual time=4.165..4.165 rows=1 loops=1)

  • Group Key: r_1.worker_id, tt_1.exclusive_origin_id, tt_1.sub_region_id
107. 0.003 4.153 ↓ 2.0 2 1

Sort (cost=283.95..283.95 rows=1 width=61) (actual time=4.153..4.153 rows=2 loops=1)

  • Sort Key: tt_1.exclusive_origin_id, tt_1.sub_region_id
  • Sort Method: quicksort Memory: 25kB
108. 0.002 4.150 ↓ 2.0 2 1

Nested Loop Left Join (cost=62.10..283.94 rows=1 width=61) (actual time=4.139..4.150 rows=2 loops=1)

109. 0.001 4.140 ↓ 2.0 2 1

Nested Loop Left Join (cost=61.54..200.90 rows=1 width=53) (actual time=4.132..4.140 rows=2 loops=1)

110. 0.001 4.125 ↓ 2.0 2 1

Nested Loop (cost=60.97..117.46 rows=1 width=45) (actual time=4.119..4.125 rows=2 loops=1)

  • Join Filter: ((r_1.created_date >= tt_1.turn_on_time) AND (r_1.created_date <= tt_1.turn_off_time))
111. 0.004 4.122 ↓ 2.0 2 1

Nested Loop (cost=60.97..117.15 rows=1 width=45) (actual time=4.117..4.122 rows=2 loops=1)

112. 0.002 4.098 ↑ 4.0 4 1

Unique (cost=60.41..60.49 rows=16 width=8) (actual time=4.096..4.098 rows=4 loops=1)

113. 0.005 4.096 ↑ 1.0 16 1

Sort (cost=60.41..60.45 rows=16 width=8) (actual time=4.095..4.096 rows=16 loops=1)

  • Sort Key: s.route_id
  • Sort Method: quicksort Memory: 25kB
114. 0.008 4.091 ↑ 1.0 16 1

Nested Loop (cost=1.14..60.09 rows=16 width=8) (actual time=0.381..4.091 rows=16 loops=1)

115. 0.002 4.051 ↑ 1.0 16 1

Nested Loop (cost=0.57..9.36 rows=16 width=8) (actual time=0.369..4.051 rows=16 loops=1)

116. 4.013 4.013 ↓ 4.0 4 1

CTE Scan on shift_orders o (cost=0.00..0.20 rows=1 width=8) (actual time=0.357..4.013 rows=4 loops=1)

117. 0.036 0.036 ↑ 4.0 4 4

Index Scan using idx_loaded_orders_order_id on loaded_orders lo (cost=0.57..7.56 rows=16 width=16) (actual time=0.008..0.009 rows=4 loops=4)

  • Index Cond: (order_id = o.id)
118. 0.032 0.032 ↑ 1.0 1 16

Index Scan using pk_service on service s (cost=0.57..3.17 rows=1 width=16) (actual time=0.002..0.002 rows=1 loops=16)

  • Index Cond: (id = lo.service_id)
119. 0.020 0.020 ↓ 0.0 0 4

Index Scan using pk_route on route r_1 (cost=0.56..3.52 rows=1 width=45) (actual time=0.005..0.005 rows=0 loops=4)

  • Index Cond: (id = s.route_id)
  • Filter: ((worker_id = 396,701) AND ((route_execution_state)::text = 'COMPLETED'::text))
  • Rows Removed by Filter: 0
120. 0.002 0.002 ↑ 1.0 1 2

CTE Scan on turn_on_turn_off_times tt_1 (cost=0.00..0.20 rows=1 width=32) (actual time=0.001..0.001 rows=1 loops=2)

  • Filter: (worker_id = 396,701)
121. 0.014 0.014 ↓ 0.0 0 2

Index Scan using route_attribute_route_id_attribute_key_id_key on route_attribute ra (cost=0.56..82.64 rows=8 width=16) (actual time=0.007..0.007 rows=0 loops=2)

  • Index Cond: (route_id = r_1.id)
  • Filter: ((attributes_key_name)::text = 'MIN_FREIGHT_VALUE'::text)
  • Rows Removed by Filter: 3
122. 0.008 0.008 ↓ 0.0 0 2

Index Scan using route_attribute_route_id_attribute_key_id_key on route_attribute ramax (cost=0.56..82.64 rows=4 width=16) (actual time=0.004..0.004 rows=0 loops=2)

  • Index Cond: (route_id = r_1.id)
  • Filter: ((attributes_key_name)::text = 'MAX_FREIGHT_VALUE'::text)
  • Rows Removed by Filter: 3
123. 0.007 0.414 ↑ 1.0 1 1

HashAggregate (cost=0.22..0.32 rows=1 width=24) (actual time=0.414..0.414 rows=1 loops=1)

  • Group Key: oo.worker_id, oo.exclusive_origin_id, oo.sub_region_id
124. 0.407 0.407 ↑ 1.0 1 1

CTE Scan on workers_on_shift_on_off_times oo (cost=0.00..0.20 rows=1 width=32) (actual time=0.406..0.407 rows=1 loops=1)

125. 0.000 0.226 ↓ 0.0 0 1

HashAggregate (cost=0.22..0.32 rows=1 width=24) (actual time=0.226..0.226 rows=0 loops=1)

  • Group Key: t.worker_id, t.exclusive_origin_id, t.sub_region_id
126. 0.226 0.226 ↓ 0.0 0 1

CTE Scan on workers_on_shift_block_unblock_times t (cost=0.00..0.20 rows=1 width=32) (actual time=0.226..0.226 rows=0 loops=1)

127. 0.006 1.919 ↑ 1.0 1 1

HashAggregate (cost=0.22..0.32 rows=1 width=24) (actual time=1.918..1.919 rows=1 loops=1)

  • Group Key: t_1.worker_id, t_1.exclusive_origin_id, t_1.sub_region_id
128. 1.913 1.913 ↓ 4.0 4 1

CTE Scan on workers_on_shift_online_working_times t_1 (cost=0.00..0.20 rows=1 width=32) (actual time=1.910..1.913 rows=4 loops=1)

129. 0.000 0.001 ↓ 0.0 0 1

HashAggregate (cost=0.22..0.32 rows=1 width=24) (actual time=0.001..0.001 rows=0 loops=1)

  • Group Key: t_2.worker_id, t_2.exclusive_origin_id, t_2.sub_region_id
130. 0.001 0.001 ↓ 0.0 0 1

CTE Scan on workers_on_shift_online_blocked_working_times t_2 (cost=0.00..0.20 rows=1 width=32) (actual time=0.001..0.001 rows=0 loops=1)

131. 0.002 0.110 ↑ 1.0 1 1

GroupAggregate (cost=102.73..102.85 rows=1 width=24) (actual time=0.110..0.110 rows=1 loops=1)

  • Group Key: o_1.worker_id, tt_2.exclusive_origin_id, tt_2.sub_region_id
132. 0.009 0.108 ↓ 4.0 4 1

Sort (cost=102.73..102.74 rows=1 width=16) (actual time=0.108..0.108 rows=4 loops=1)

  • Sort Key: o_1.worker_id, tt_2.exclusive_origin_id, tt_2.sub_region_id
  • Sort Method: quicksort Memory: 25kB
133. 0.002 0.099 ↓ 4.0 4 1

Nested Loop (cost=1.70..102.72 rows=1 width=16) (actual time=0.037..0.099 rows=4 loops=1)

  • Join Filter: ((r_2.created_date >= tt_2.turn_on_time) AND (r_2.created_date <= tt_2.turn_off_time) AND (o_1.worker_id = tt_2.worker_id))
134. 0.001 0.001 ↑ 1.0 1 1

CTE Scan on turn_on_turn_off_times tt_2 (cost=0.00..0.20 rows=1 width=32) (actual time=0.000..0.001 rows=1 loops=1)

135. 0.009 0.096 ↑ 3.2 4 1

Nested Loop (cost=1.70..101.12 rows=13 width=16) (actual time=0.035..0.096 rows=4 loops=1)

136. 0.006 0.071 ↑ 1.0 16 1

Nested Loop (cost=1.14..54.97 rows=16 width=16) (actual time=0.027..0.071 rows=16 loops=1)

137. 0.003 0.033 ↑ 1.0 16 1

Nested Loop (cost=0.57..9.36 rows=16 width=16) (actual time=0.016..0.033 rows=16 loops=1)

138. 0.002 0.002 ↓ 4.0 4 1

CTE Scan on shift_orders o_1 (cost=0.00..0.20 rows=1 width=16) (actual time=0.001..0.002 rows=4 loops=1)

  • Filter: ((order_routing_state)::text = 'DELIVERED'::text)
139. 0.028 0.028 ↑ 4.0 4 4

Index Scan using idx_loaded_orders_order_id on loaded_orders lo_1 (cost=0.57..7.56 rows=16 width=16) (actual time=0.006..0.007 rows=4 loops=4)

  • Index Cond: (order_id = o_1.id)
140. 0.032 0.032 ↑ 1.0 1 16

Index Scan using pk_service on service s_1 (cost=0.57..2.85 rows=1 width=16) (actual time=0.002..0.002 rows=1 loops=16)

  • Index Cond: (id = lo_1.service_id)
141. 0.016 0.016 ↓ 0.0 0 16

Index Scan using pk_route on route r_2 (cost=0.56..2.88 rows=1 width=16) (actual time=0.001..0.001 rows=0 loops=16)

  • Index Cond: (id = s_1.route_id)
  • Filter: ((route_execution_state)::text = 'COMPLETED'::text)
  • Rows Removed by Filter: 0
Planning time : 9.626 ms
Execution time : 10.992 ms