explain.depesz.com

PostgreSQL's explain analyze made readable

Result: AJda

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

Nested Loop Left Join (cost=11,241.75..11,249.79 rows=1 width=353) (actual time=8.569..8.574 rows=1 loops=1)

  • Join Filter: (((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) AND (((tt_2.exclusive_origin_id = wto.exclusive_origin_id) AND (tt_2.origin_priority_type = wto.origin_priority_type)) OR ((tt_2.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))))
2.          

CTE worker_state_machine_trail

3. 0.368 0.368 ↓ 262.0 262 1

Index Scan using idx_state_machine_trail_id_type_smid_created_date on state_machine_trail (cost=0.71..4.82 rows=1 width=124) (actual time=0.032..0.368 rows=262 loops=1)

  • Index Cond: ((entity_id = 242396) AND (created_date >= (to_timestamp('2020-01-22 10:00:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text) - '2 days'::interval)) AND (created_date <= (to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text) + '2 days'::interval)))
4.          

CTE workers_turn_on

5. 0.000 0.206 ↑ 1.0 1 1

Nested Loop (cost=40.69..171.73 rows=1 width=60) (actual time=0.205..0.206 rows=1 loops=1)

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

Initplan (for Nested Loop)

7. 0.008 0.008 ↑ 1.0 1 1

Index Scan using idx_attribute_key_name on attribute_key (cost=0.27..4.38 rows=1 width=8) (actual time=0.008..0.008 rows=1 loops=1)

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

Index Scan using idx_attribute_key_name on attribute_key attribute_key_1 (cost=0.27..4.38 rows=1 width=8) (actual time=0.008..0.008 rows=1 loops=1)

  • Index Cond: ((name)::text = 'PRIORITY_ORIGIN_ID'::text)
9. 0.006 0.006 ↑ 1.0 1 1

Index Scan using idx_attribute_key_name on attribute_key attribute_key_2 (cost=0.27..4.38 rows=1 width=8) (actual time=0.006..0.006 rows=1 loops=1)

  • Index Cond: ((name)::text = 'SUB_REGION_ID'::text)
10. 0.013 0.013 ↑ 1.0 1 1

Index Scan using idx_attribute_key_name on attribute_key attribute_key_3 (cost=0.27..4.38 rows=1 width=8) (actual time=0.013..0.013 rows=1 loops=1)

  • Index Cond: ((name)::text = 'LOGISTICS_OPERATORS_ID'::text)
11. 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)
12. 0.007 0.007 ↑ 1.0 1 1

Index Scan using idx_attribute_key_name on attribute_key attribute_key_4 (cost=0.27..4.38 rows=1 width=8) (actual time=0.006..0.007 rows=1 loops=1)

  • Index Cond: ((name)::text = 'TAG'::text)
13. 0.007 0.007 ↑ 1.0 1 1

Index Scan using idx_attribute_key_name on attribute_key attribute_key_5 (cost=0.27..4.38 rows=1 width=8) (actual time=0.007..0.007 rows=1 loops=1)

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

Index Scan using idx_attribute_key_name on attribute_key attribute_key_6 (cost=0.27..4.38 rows=1 width=8) (actual time=0.006..0.006 rows=1 loops=1)

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

Nested Loop (cost=4.96..18.32 rows=1 width=80) (actual time=0.184..0.185 rows=1 loops=1)

  • Join Filter: (e_1.id = ea_1.state_machine_event_id)
16. 0.009 0.156 ↑ 1.0 1 1

Nested Loop (cost=4.25..15.10 rows=1 width=72) (actual time=0.155..0.156 rows=1 loops=1)

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

Nested Loop Left Join (cost=3.54..11.89 rows=1 width=64) (actual time=0.124..0.125 rows=1 loops=1)

18. 0.010 0.113 ↑ 1.0 1 1

Nested Loop Left Join (cost=2.83..10.13 rows=1 width=54) (actual time=0.112..0.113 rows=1 loops=1)

19. 0.009 0.097 ↑ 1.0 1 1

Nested Loop Left Join (cost=2.13..8.37 rows=1 width=44) (actual time=0.097..0.097 rows=1 loops=1)

20. 0.015 0.079 ↑ 1.0 1 1

Nested Loop (cost=1.42..6.61 rows=1 width=34) (actual time=0.078..0.079 rows=1 loops=1)

21. 0.034 0.034 ↑ 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.033..0.034 rows=1 loops=1)

  • Index Cond: ((entity_id = 242396) AND ((entity_type)::text = 'WORKER'::text) AND ((event_id)::text = 'TURN_ON'::text) AND (event_date >= to_timestamp('2020-01-22 10:00:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)) AND (event_date <= to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Filter: ((event_status)::text = 'ACCEPTED'::text)
22. 0.030 0.030 ↑ 110.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.71..118.47 rows=110 width=18) (actual time=0.030..0.030 rows=1 loops=1)

  • Index Cond: ((state_machine_event_id = e_1.id) AND (attribute_key_id = $4))
  • Filter: ((value)::integer <> $5)
23. 0.009 0.009 ↓ 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.71..117.64 rows=111 width=18) (actual time=0.009..0.009 rows=0 loops=1)

  • Index Cond: ((e_1.id = state_machine_event_id) AND (attribute_key_id = $1))
24. 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_priority_origin_id (cost=0.71..117.64 rows=111 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))
25. 0.005 0.005 ↓ 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.71..117.64 rows=111 width=18) (actual time=0.005..0.005 rows=0 loops=1)

  • Index Cond: ((e_1.id = state_machine_event_id) AND (attribute_key_id = $3))
26. 0.022 0.022 ↑ 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.71..3.11 rows=1 width=8) (actual time=0.022..0.022 rows=1 loops=1)

  • Index Cond: ((attribute_key_id = $6) AND (value = 'REGULAR'::text) AND (state_machine_event_id = logistics_operators_id.state_machine_event_id))
  • Heap Fetches: 1
27. 0.020 0.020 ↑ 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.71..3.11 rows=1 width=8) (actual time=0.020..0.020 rows=1 loops=1)

  • Index Cond: ((attribute_key_id = $7) AND (value = 'ALMOCO LOOP BSB'::text) AND (state_machine_event_id = logistics_operators_id.state_machine_event_id))
  • Heap Fetches: 1
28. 0.011 0.011 ↑ 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.71..118.26 rows=1 width=8) (actual time=0.011..0.011 rows=1 loops=1)

  • Index Cond: ((state_machine_event_id = logistics_operators_id.state_machine_event_id) AND (attribute_key_id = $8))
  • Filter: ((value)::integer = 8)
29.          

CTE shift_orders

30. 0.008 1.711 ↓ 16.0 16 1

Nested Loop (cost=1.14..2,234.49 rows=1 width=806) (actual time=0.576..1.711 rows=16 loops=1)

31. 1.607 1.607 ↓ 16.0 16 1

Index Scan using idx_order_delivery_worker_id on order_delivery o_2 (cost=0.57..2,229.81 rows=1 width=806) (actual time=0.556..1.607 rows=16 loops=1)

  • Index Cond: (worker_id = 242396)
  • Filter: (((shift)::text = 'ALMOCO LOOP BSB'::text) AND (created_date <= to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)) AND (created_date >= ((to_date('2020-01-22'::text, 'YYYY-MM-DD'::text) - 4))::timestamp without time zone))
  • Rows Removed by Filter: 737
32. 0.096 0.096 ↑ 1.0 1 16

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=16)

  • Index Cond: ((order_id = o_2.id) AND (subset_id = 8))
  • Heap Fetches: 16
33.          

CTE turn_on_turn_off_times

34. 0.001 0.545 ↑ 1.0 1 1

Unique (cost=0.97..0.99 rows=1 width=72) (actual time=0.544..0.545 rows=1 loops=1)

35. 0.018 0.544 ↑ 1.0 1 1

Sort (cost=0.97..0.98 rows=1 width=72) (actual time=0.544..0.544 rows=1 loops=1)

  • Sort Key: workers_turn_on.worker_id, workers_turn_on.exclusive_origin_id, workers_turn_on.origin_priority_type, workers_turn_on.sub_region_id, (GREATEST((max(turn_on.created_date))::timestamp with time zone, to_timestamp('2020-01-22 10:00:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text))), (LEAST((min(turn_off.created_date))::timestamp with time zone, to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Sort Method: quicksort Memory: 25kB
36. 0.008 0.526 ↑ 1.0 1 1

HashAggregate (cost=0.85..0.96 rows=1 width=72) (actual time=0.526..0.526 rows=1 loops=1)

  • Group Key: turn_on.id, workers_turn_on.worker_id, workers_turn_on.exclusive_origin_id, workers_turn_on.origin_priority_type, workers_turn_on.sub_region_id
  • Filter: (GREATEST((max(turn_on.created_date))::timestamp with time zone, to_timestamp('2020-01-22 10:00:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)) < LEAST((min(turn_off.created_date))::timestamp with time zone, to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
37. 0.001 0.518 ↑ 1.0 1 1

Nested Loop Left Join (cost=0.00..0.82 rows=1 width=72) (actual time=0.499..0.518 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: 2
38. 0.002 0.229 ↑ 1.0 1 1

Nested Loop (cost=0.00..0.51 rows=1 width=72) (actual time=0.210..0.229 rows=1 loops=1)

  • Join Filter: (workers_turn_on.event_id = turn_on.event_id)
  • Rows Removed by Join Filter: 4
39. 0.001 0.001 ↑ 1.0 1 1

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

40. 0.226 0.226 ↓ 5.0 5 1

CTE Scan on worker_state_machine_trail turn_on (cost=0.00..0.21 rows=1 width=32) (actual time=0.077..0.226 rows=5 loops=1)

  • Filter: (((state_machine_id)::text = 'WORKER_SHIFT_STATE_MACHINE'::text) AND (created_date < to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Rows Removed by Filter: 257
41. 0.288 0.288 ↓ 2.0 2 1

CTE Scan on worker_state_machine_trail turn_off (cost=0.00..0.21 rows=1 width=16) (actual time=0.009..0.288 rows=2 loops=1)

  • Filter: (((current_state)::text = 'OFF_SHIFT'::text) AND ((state_machine_id)::text = 'WORKER_SHIFT_STATE_MACHINE'::text) AND (created_date < to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Rows Removed by Filter: 260
42.          

CTE workers_on_shift_on_off_times

43. 0.003 0.993 ↑ 1.0 1 1

Nested Loop Left Join (cost=0.97..1.41 rows=1 width=64) (actual time=0.992..0.993 rows=1 loops=1)

  • Join Filter: (((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('2020-01-22 10:00: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('2020-01-22 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) AND (((wto_1.exclusive_origin_id = tt_3.exclusive_origin_id) AND (wto_1.origin_priority_type = tt_3.origin_priority_type)) OR ((wto_1.exclusive_origin_id IS NULL) AND (tt_3.exclusive_origin_id IS NULL))))
44. 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=64) (actual time=0.001..0.001 rows=1 loops=1)

45. 0.001 0.989 ↑ 1.0 1 1

Unique (cost=0.97..0.99 rows=1 width=72) (actual time=0.989..0.989 rows=1 loops=1)

46. 0.010 0.988 ↑ 1.0 1 1

Sort (cost=0.97..0.97 rows=1 width=72) (actual time=0.988..0.988 rows=1 loops=1)

  • Sort Key: wto_1.worker_id, wto_1.exclusive_origin_id, wto_1.origin_priority_type, wto_1.sub_region_id, (GREATEST((max(on_trail.created_date))::timestamp with time zone, to_timestamp('2020-01-22 10:00:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text))), (LEAST((min(off_trail.created_date))::timestamp with time zone, to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Sort Method: quicksort Memory: 25kB
47. 0.127 0.978 ↑ 1.0 1 1

HashAggregate (cost=0.84..0.96 rows=1 width=72) (actual time=0.964..0.978 rows=1 loops=1)

  • Group Key: on_trail.id, wto_1.worker_id, wto_1.exclusive_origin_id, wto_1.origin_priority_type, wto_1.sub_region_id
  • Filter: (GREATEST((max(on_trail.created_date))::timestamp with time zone, to_timestamp('2020-01-22 10:00:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)) < LEAST((min(off_trail.created_date))::timestamp with time zone, to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Rows Removed by Filter: 16
48. 0.085 0.851 ↓ 238.0 238 1

Nested Loop Left Join (cost=0.00..0.82 rows=1 width=72) (actual time=0.009..0.851 rows=238 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: 136
49. 0.004 0.052 ↓ 17.0 17 1

Nested Loop (cost=0.00..0.51 rows=1 width=72) (actual time=0.007..0.052 rows=17 loops=1)

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

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

51. 0.047 0.047 ↓ 17.0 17 1

CTE Scan on worker_state_machine_trail on_trail (cost=0.00..0.21 rows=1 width=24) (actual time=0.005..0.047 rows=17 loops=1)

  • Filter: (((current_state)::text = 'ONLINE'::text) AND ((state_machine_id)::text = 'WORKER_CONNECTIVITY_STATE_MACHINE'::text) AND (created_date < to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Rows Removed by Filter: 245
52. 0.714 0.714 ↓ 22.0 22 17

CTE Scan on worker_state_machine_trail off_trail (cost=0.00..0.21 rows=1 width=16) (actual time=0.001..0.042 rows=22 loops=17)

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

CTE workers_on_shift_block_unblock_times

54. 0.006 0.157 ↓ 0.0 0 1

Nested Loop Left Join (cost=0.84..1.38 rows=1 width=64) (actual time=0.156..0.157 rows=0 loops=1)

  • Join Filter: ((((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) AND ((((max(wto_2.exclusive_origin_id)) = oo_1.exclusive_origin_id) AND ((max(wto_2.origin_priority_type)) = oo_1.origin_priority_type)) OR (((max(wto_2.exclusive_origin_id)) IS NULL) AND (oo_1.exclusive_origin_id IS NULL))))
  • 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: 4
55. 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=64) (actual time=0.000..0.000 rows=1 loops=1)

56. 0.006 0.151 ↓ 4.0 4 1

HashAggregate (cost=0.84..0.94 rows=1 width=72) (actual time=0.150..0.151 rows=4 loops=1)

  • Group Key: block.id
57. 0.002 0.145 ↓ 10.0 10 1

Nested Loop Left Join (cost=0.00..0.82 rows=1 width=72) (actual time=0.006..0.145 rows=10 loops=1)

  • Join Filter: ((unblock.created_date > block.created_date) AND (unblock.entity_id = block.entity_id))
  • Rows Removed by Join Filter: 6
58. 0.002 0.031 ↓ 4.0 4 1

Nested Loop Left Join (cost=0.00..0.51 rows=1 width=72) (actual time=0.002..0.031 rows=4 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=48) (actual time=0.000..0.000 rows=1 loops=1)

60. 0.029 0.029 ↓ 4.0 4 1

CTE Scan on worker_state_machine_trail block (cost=0.00..0.21 rows=1 width=24) (actual time=0.001..0.029 rows=4 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: 258
61. 0.112 0.112 ↓ 4.0 4 4

CTE Scan on worker_state_machine_trail unblock (cost=0.00..0.21 rows=1 width=16) (actual time=0.002..0.028 rows=4 loops=4)

  • 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: 258
62.          

CTE workers_on_shift_online_working_times

63. 0.007 1.973 ↓ 9.0 9 1

Nested Loop (cost=0.97..1.41 rows=1 width=64) (actual time=1.967..1.973 rows=9 loops=1)

  • Join Filter: (((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('2020-01-22 10:00: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('2020-01-22 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) AND (((wto_3.exclusive_origin_id = oo_2.exclusive_origin_id) AND (wto_3.origin_priority_type = oo_2.origin_priority_type)) OR ((wto_3.exclusive_origin_id IS NULL) AND (oo_2.exclusive_origin_id IS NULL))))
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=64) (actual time=0.000..0.000 rows=1 loops=1)

65. 0.001 1.966 ↓ 9.0 9 1

Unique (cost=0.97..0.99 rows=1 width=72) (actual time=1.964..1.966 rows=9 loops=1)

66. 0.014 1.965 ↓ 9.0 9 1

Sort (cost=0.97..0.98 rows=1 width=72) (actual time=1.964..1.965 rows=9 loops=1)

  • Sort Key: wto_3.worker_id, wto_3.exclusive_origin_id, wto_3.origin_priority_type, wto_3.sub_region_id, (GREATEST((max(start_work_trail.created_date))::timestamp with time zone, to_timestamp('2020-01-22 10:00:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text))), (LEAST((min(end_work_trail.created_date))::timestamp with time zone, to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Sort Method: quicksort Memory: 25kB
67. 0.427 1.951 ↓ 9.0 9 1

HashAggregate (cost=0.85..0.96 rows=1 width=72) (actual time=1.921..1.951 rows=9 loops=1)

  • Group Key: start_work_trail.id, wto_3.worker_id, wto_3.exclusive_origin_id, wto_3.origin_priority_type, wto_3.sub_region_id
  • Filter: (GREATEST((max(start_work_trail.created_date))::timestamp with time zone, to_timestamp('2020-01-22 10:00:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)) < LEAST((min(end_work_trail.created_date))::timestamp with time zone, to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Rows Removed by Filter: 17
68. 0.242 1.524 ↓ 1,287.0 1,287 1

Nested Loop Left Join (cost=0.00..0.83 rows=1 width=72) (actual time=0.010..1.524 rows=1,287 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: 325
69. 0.019 0.086 ↓ 26.0 26 1

Nested Loop (cost=0.00..0.51 rows=1 width=72) (actual time=0.005..0.086 rows=26 loops=1)

  • Join Filter: (wto_3.worker_id = start_work_trail.entity_id)
70. 0.001 0.001 ↑ 1.0 1 1

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

71. 0.066 0.066 ↓ 26.0 26 1

CTE Scan on worker_state_machine_trail start_work_trail (cost=0.00..0.21 rows=1 width=24) (actual time=0.004..0.066 rows=26 loops=1)

  • Filter: (((current_state)::text = 'WORKING'::text) AND ((state_machine_id)::text = 'WORKER_STATE_MACHINE'::text) AND (created_date < to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text)))
  • Rows Removed by Filter: 236
72. 1.196 1.196 ↓ 62.0 62 26

CTE Scan on worker_state_machine_trail end_work_trail (cost=0.00..0.21 rows=1 width=16) (actual time=0.004..0.046 rows=62 loops=26)

  • 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: 200
73.          

CTE workers_on_shift_online_blocked_working_times

74. 0.000 0.000 ↓ 0.0 0 1

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

  • Join Filter: (((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) AND (((t_3.exclusive_origin_id = b.exclusive_origin_id) AND (t_3.origin_priority_type = b.origin_priority_type)) OR ((t_3.exclusive_origin_id IS NULL) AND (b.exclusive_origin_id IS NULL))))
75. 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=64) (actual time=0.000..0.000 rows=0 loops=1)

76. 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=64) (never executed)

77. 0.002 8.191 ↑ 1.0 1 1

Nested Loop Left Join (cost=8,439.21..8,446.81 rows=1 width=281) (actual time=8.185..8.191 rows=1 loops=1)

  • Join Filter: (((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) AND (((t_2.exclusive_origin_id = wto.exclusive_origin_id) AND (t_2.origin_priority_type = wto.origin_priority_type)) OR ((t_2.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))))
78. 0.001 8.188 ↑ 1.0 1 1

Nested Loop Left Join (cost=8,438.99..8,446.28 rows=1 width=273) (actual time=8.184..8.188 rows=1 loops=1)

  • Join Filter: (((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) AND (((t_1.exclusive_origin_id = wto.exclusive_origin_id) AND (t_1.origin_priority_type = wto.origin_priority_type)) OR ((t_1.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))))
79. 0.001 6.197 ↑ 1.0 1 1

Nested Loop Left Join (cost=8,438.78..8,445.75 rows=1 width=265) (actual time=6.193..6.197 rows=1 loops=1)

  • Join Filter: (((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) AND (((t.exclusive_origin_id = wto.exclusive_origin_id) AND (t.origin_priority_type = wto.origin_priority_type)) OR ((t.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))))
80. 0.003 6.039 ↑ 1.0 1 1

Nested Loop Left Join (cost=8,438.56..8,445.23 rows=1 width=257) (actual time=6.035..6.039 rows=1 loops=1)

  • Join Filter: (((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) AND (((oo.exclusive_origin_id = wto.exclusive_origin_id) AND (oo.origin_priority_type = wto.origin_priority_type)) OR ((oo.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))))
81. 0.002 5.038 ↑ 1.0 1 1

Nested Loop Left Join (cost=8,438.34..8,444.70 rows=1 width=249) (actual time=5.035..5.038 rows=1 loops=1)

  • Join Filter: (((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) AND (((tt_1.exclusive_origin_id = wto.exclusive_origin_id) AND (tt_1.origin_priority_type = wto.origin_priority_type)) OR ((tt_1.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))))
82. 0.003 2.944 ↑ 1.0 1 1

Nested Loop Left Join (cost=8,046.80..8,052.82 rows=1 width=201) (actual time=2.941..2.944 rows=1 loops=1)

  • Join Filter: (((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) AND (((tt.exclusive_origin_id = wto.exclusive_origin_id) AND (tt.origin_priority_type = wto.origin_priority_type)) OR ((tt.exclusive_origin_id IS NULL) AND (wto.exclusive_origin_id IS NULL))))
83. 0.001 0.274 ↑ 1.0 1 1

Nested Loop (cost=1.65..7.29 rows=1 width=129) (actual time=0.271..0.274 rows=1 loops=1)

84. 0.001 0.263 ↑ 1.0 1 1

Nested Loop (cost=1.22..6.74 rows=1 width=120) (actual time=0.261..0.263 rows=1 loops=1)

85. 0.001 0.253 ↓ 3.0 3 1

Nested Loop (cost=1.07..6.37 rows=1 width=128) (actual time=0.248..0.253 rows=3 loops=1)

86. 0.001 0.237 ↑ 1.0 1 1

Nested Loop (cost=0.64..4.87 rows=1 width=60) (actual time=0.236..0.237 rows=1 loops=1)

87. 0.001 0.222 ↑ 1.0 1 1

Group (cost=0.21..0.23 rows=1 width=52) (actual time=0.221..0.222 rows=1 loops=1)

  • Group Key: wto.worker_id, wto.logistics_operator_id, wto.exclusive_origin_id, wto.origin_priority_type, wto.sub_region_id
88. 0.013 0.221 ↑ 1.0 1 1

Sort (cost=0.21..0.22 rows=1 width=52) (actual time=0.220..0.221 rows=1 loops=1)

  • Sort Key: wto.worker_id, wto.logistics_operator_id, wto.exclusive_origin_id, wto.origin_priority_type, wto.sub_region_id
  • Sort Method: quicksort Memory: 25kB
89. 0.208 0.208 ↑ 1.0 1 1

CTE Scan on workers_turn_on wto (cost=0.00..0.20 rows=1 width=52) (actual time=0.207..0.208 rows=1 loops=1)

90. 0.014 0.014 ↑ 1.0 1 1

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

  • Index Cond: (id = wto.worker_id)
91. 0.015 0.015 ↑ 1.7 3 1

Index Scan using user_attribute_user_id_attribute_key_id_key on user_attribute ua (cost=0.43..1.00 rows=5 width=68) (actual time=0.011..0.015 rows=3 loops=1)

  • Index Cond: (user_id = w.user_id)
92. 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
93. 0.010 0.010 ↑ 1.0 1 1

Index Scan using pk_user_fleet on user_fleet u (cost=0.43..0.55 rows=1 width=33) (actual time=0.010..0.010 rows=1 loops=1)

  • Index Cond: (id = w.user_id)
94. 0.297 2.667 ↑ 1.0 1 1

GroupAggregate (cost=8,045.15..8,045.32 rows=1 width=120) (actual time=2.667..2.667 rows=1 loops=1)

  • Group Key: r.worker_id, tt.exclusive_origin_id, tt.origin_priority_type, tt.sub_region_id
95.          

Initplan (for GroupAggregate)

96. 0.010 0.010 ↑ 1.0 1 1

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

  • Index Cond: ((name)::text = 'GEOFENCE_VIOLATED'::text)
97. 0.104 2.360 ↓ 261.0 261 1

Sort (cost=8,040.77..8,040.78 rows=1 width=105) (actual time=2.337..2.360 rows=261 loops=1)

  • Sort Key: r.worker_id, tt.exclusive_origin_id, tt.origin_priority_type, tt.sub_region_id
  • Sort Method: quicksort Memory: 61kB
98. 0.041 2.256 ↓ 261.0 261 1

Nested Loop Left Join (cost=1.99..8,040.76 rows=1 width=105) (actual time=0.858..2.256 rows=261 loops=1)

99. 0.064 1.891 ↓ 54.0 54 1

Nested Loop (cost=1.29..4,787.09 rows=1 width=87) (actual time=0.846..1.891 rows=54 loops=1)

100. 0.003 1.458 ↑ 13.0 9 1

Nested Loop (cost=0.57..1,692.54 rows=117 width=56) (actual time=0.816..1.458 rows=9 loops=1)

101. 0.556 0.556 ↑ 1.0 1 1

CTE Scan on turn_on_turn_off_times tt (cost=0.00..0.20 rows=1 width=64) (actual time=0.555..0.556 rows=1 loops=1)

102. 0.899 0.899 ↑ 13.0 9 1

Index Scan using idx_route_worker_id on route r (cost=0.57..1,680.64 rows=117 width=24) (actual time=0.260..0.899 rows=9 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: 729
103. 0.369 0.369 ↓ 6.0 6 9

Index Scan using idx_state_machine_event_ei_et_ei_ed on state_machine_event e (cost=0.72..26.35 rows=1 width=39) (actual time=0.010..0.041 rows=6 loops=9)

  • Index Cond: ((entity_id = r.id) AND ((entity_type)::text = 'ROUTE'::text) AND ((event_id)::text = ANY ('{CHECK_IN,CHECK_OUT,CANCEL_OFFER_TIMEOUT,REJECT,OFFER,CANCEL_OFFER,ACCEPT,AUTO_CANCEL,CANCEL}'::text[])) AND (event_date >= (to_timestamp('2020-01-22 10:00:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text) - '00:03:00'::interval)) AND (event_date <= (to_timestamp('2020-01-22 14:29:00'::text, 'YYYY-MM-DD HH24:MI:SS'::text) + '01:00:00'::interval)))
  • Filter: ((event_status)::text = 'ACCEPTED'::text)
104. 0.324 0.324 ↑ 575.2 5 54

Index Scan using state_machine_event_attribute_state_machine_event_id_attrib_key on state_machine_event_attribute a (cost=0.71..2,966.07 rows=2,876 width=26) (actual time=0.005..0.006 rows=5 loops=54)

  • Index Cond: (e.id = state_machine_event_id)
105. 0.009 2.092 ↑ 1.0 1 1

GroupAggregate (cost=391.54..391.67 rows=1 width=96) (actual time=2.092..2.092 rows=1 loops=1)

  • Group Key: r_1.worker_id, tt_1.exclusive_origin_id, tt_1.origin_priority_type, tt_1.sub_region_id
106. 0.009 2.083 ↓ 9.0 9 1

Sort (cost=391.54..391.55 rows=1 width=72) (actual time=2.083..2.083 rows=9 loops=1)

  • Sort Key: tt_1.exclusive_origin_id, tt_1.origin_priority_type, tt_1.sub_region_id
  • Sort Method: quicksort Memory: 25kB
107. 0.011 2.074 ↓ 9.0 9 1

Nested Loop (cost=200.06..391.53 rows=1 width=72) (actual time=2.025..2.074 rows=9 loops=1)

  • Join Filter: ((r_1.created_date >= tt_1.turn_on_time) AND (r_1.created_date <= tt_1.turn_off_time))
  • Rows Removed by Join Filter: 6
108. 0.002 2.063 ↓ 15.0 15 1

Nested Loop (cost=200.06..391.23 rows=1 width=40) (actual time=1.989..2.063 rows=15 loops=1)

109. 0.004 1.976 ↑ 2.8 17 1

Unique (cost=199.49..199.73 rows=48 width=8) (actual time=1.971..1.976 rows=17 loops=1)

110. 0.011 1.972 ↑ 1.4 34 1

Sort (cost=199.49..199.61 rows=48 width=8) (actual time=1.970..1.972 rows=34 loops=1)

  • Sort Key: s.route_id
  • Sort Method: quicksort Memory: 26kB
111. 0.002 1.961 ↑ 1.4 34 1

Nested Loop (cost=1.14..198.15 rows=48 width=8) (actual time=0.607..1.961 rows=34 loops=1)

112. 0.013 1.823 ↑ 1.4 34 1

Nested Loop (cost=0.57..15.76 rows=48 width=8) (actual time=0.593..1.823 rows=34 loops=1)

113. 1.730 1.730 ↓ 16.0 16 1

CTE Scan on shift_orders o (cost=0.00..0.20 rows=1 width=8) (actual time=0.579..1.730 rows=16 loops=1)

114. 0.080 0.080 ↑ 24.0 2 16

Index Scan using idx_loaded_orders_order_id on loaded_orders lo (cost=0.57..10.76 rows=48 width=16) (actual time=0.005..0.005 rows=2 loops=16)

  • Index Cond: (order_id = o.id)
115. 0.136 0.136 ↑ 1.0 1 34

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

  • Index Cond: (id = lo.service_id)
116. 0.085 0.085 ↑ 1.0 1 17

Index Scan using pk_route on route r_1 (cost=0.57..3.98 rows=1 width=40) (actual time=0.005..0.005 rows=1 loops=17)

  • Index Cond: (id = s.route_id)
  • Filter: ((worker_id = 242396) AND ((route_state)::text = 'COMPLETED'::text))
  • Rows Removed by Filter: 0
117. 0.000 0.000 ↑ 1.0 1 15

CTE Scan on turn_on_turn_off_times tt_1 (cost=0.00..0.20 rows=1 width=64) (actual time=0.000..0.000 rows=1 loops=15)

  • Filter: (worker_id = 242396)
118. 0.004 0.998 ↑ 1.0 1 1

HashAggregate (cost=0.22..0.32 rows=1 width=56) (actual time=0.998..0.998 rows=1 loops=1)

  • Group Key: oo.worker_id, oo.exclusive_origin_id, oo.origin_priority_type, oo.sub_region_id
119. 0.994 0.994 ↑ 1.0 1 1

CTE Scan on workers_on_shift_on_off_times oo (cost=0.00..0.20 rows=1 width=64) (actual time=0.993..0.994 rows=1 loops=1)

120. 0.000 0.157 ↓ 0.0 0 1

HashAggregate (cost=0.22..0.32 rows=1 width=56) (actual time=0.157..0.157 rows=0 loops=1)

  • Group Key: t.worker_id, t.exclusive_origin_id, t.origin_priority_type, t.sub_region_id
121. 0.157 0.157 ↓ 0.0 0 1

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

122. 0.014 1.990 ↑ 1.0 1 1

HashAggregate (cost=0.22..0.32 rows=1 width=56) (actual time=1.990..1.990 rows=1 loops=1)

  • Group Key: t_1.worker_id, t_1.exclusive_origin_id, t_1.origin_priority_type, t_1.sub_region_id
123. 1.976 1.976 ↓ 9.0 9 1

CTE Scan on workers_on_shift_online_working_times t_1 (cost=0.00..0.20 rows=1 width=64) (actual time=1.968..1.976 rows=9 loops=1)

124. 0.000 0.001 ↓ 0.0 0 1

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

  • Group Key: t_2.worker_id, t_2.exclusive_origin_id, t_2.origin_priority_type, t_2.sub_region_id
125. 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=64) (actual time=0.001..0.001 rows=0 loops=1)

126. 0.004 0.367 ↑ 1.0 1 1

GroupAggregate (cost=385.79..385.95 rows=1 width=56) (actual time=0.367..0.367 rows=1 loops=1)

  • Group Key: o_1.worker_id, tt_2.exclusive_origin_id, tt_2.origin_priority_type, tt_2.sub_region_id
127. 0.017 0.363 ↓ 2.5 10 1

Sort (cost=385.79..385.80 rows=4 width=48) (actual time=0.363..0.363 rows=10 loops=1)

  • Sort Key: o_1.worker_id, tt_2.exclusive_origin_id, tt_2.origin_priority_type, tt_2.sub_region_id
  • Sort Method: quicksort Memory: 25kB
128. 0.005 0.346 ↓ 2.5 10 1

Nested Loop (cost=1.71..385.75 rows=4 width=48) (actual time=0.050..0.346 rows=10 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))
  • Rows Removed by Join Filter: 6
129. 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=64) (actual time=0.001..0.001 rows=1 loops=1)

130. 0.020 0.340 ↑ 2.5 16 1

Nested Loop (cost=1.71..381.25 rows=40 width=16) (actual time=0.047..0.340 rows=16 loops=1)

131. 0.004 0.252 ↑ 1.4 34 1

Nested Loop (cost=1.14..198.16 rows=48 width=16) (actual time=0.035..0.252 rows=34 loops=1)

132. 0.011 0.112 ↑ 1.4 34 1

Nested Loop (cost=0.57..15.76 rows=48 width=16) (actual time=0.020..0.112 rows=34 loops=1)

133. 0.005 0.005 ↓ 16.0 16 1

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

  • Filter: ((order_state)::text = 'COMPLETED'::text)
134. 0.096 0.096 ↑ 24.0 2 16

Index Scan using idx_loaded_orders_order_id on loaded_orders lo_1 (cost=0.57..10.76 rows=48 width=16) (actual time=0.006..0.006 rows=2 loops=16)

  • Index Cond: (order_id = o_1.id)
135. 0.136 0.136 ↑ 1.0 1 34

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

  • Index Cond: (id = lo_1.service_id)
136. 0.068 0.068 ↓ 0.0 0 34

Index Scan using pk_route on route r_2 (cost=0.57..3.81 rows=1 width=16) (actual time=0.002..0.002 rows=0 loops=34)

  • Index Cond: (id = s_1.route_id)
  • Filter: ((route_state)::text = 'COMPLETED'::text)
  • Rows Removed by Filter: 0
Planning time : 11.522 ms
Execution time : 9.801 ms