explain.depesz.com

PostgreSQL's explain analyze made readable

Result: sQAm

Settings
# exclusive inclusive rows x rows loops node
1. 719.875 1,284.277 ↑ 129.0 1 1

Seq Scan on chagrupamentos (cost=0.00..154,327.87 rows=129 width=32) (actual time=1,284.268..1,284.277 rows=1 loops=1)

  • Filter: ((row_to_json(ROW(codagrupamento, descricao, (SubPlan 2))) ->> 'membros'::text) IS NOT NULL)
  • Functions: 238
  • Options: Inlining false, Optimization false, Expressions true, Deforming true
  • Timing: Generation 123.983 ms, Inlining 0.000 ms, Optimization 42.384 ms, Emission 658.602 ms, Total 824.969 ms
2.          

SubPlan (for Seq Scan)

3. 0.820 258.747 ↑ 1.0 1 1

Aggregate (cost=595.80..595.81 rows=1 width=32) (actual time=258.745..258.747 rows=1 loops=1)

4. 0.119 257.927 ↓ 13.0 13 1

Subquery Scan on m (cost=595.76..595.79 rows=1 width=24) (actual time=257.296..257.927 rows=13 loops=1)

5. 0.536 257.808 ↓ 13.0 13 1

Unique (cost=595.76..595.78 rows=1 width=188) (actual time=257.264..257.808 rows=13 loops=1)

6. 0.713 257.272 ↓ 13.0 13 1

Sort (cost=595.76..595.76 rows=1 width=188) (actual time=257.261..257.272 rows=13 loops=1)

  • Sort Key: (COALESCE(chmensagens.dtcriacao, '2001-01-01 00:00:00'::timestamp without time zone)) DESC, (initcap((COALESCE(gbpessoas.nome, gbpessoas_1.nome))::text)), (COALESCE(gbusuarios.codusuario, gbpermissoesusuarios.codusuario)), (COALESCE((CASE WHEN (chusuarios.dtcomunicacao IS NULL) THEN ''::text WHEN (chusuarios.ocioso AND (chusuarios.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval))) THEN 'ocioso'::text WHEN ((chusuarios.dtdigitacao > (CURRENT_TIMESTAMP - '00:00:06'::interval)) AND (chusuarios.codusuarioconversa = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)) THEN 'digitando...'::text WHEN (chusuarios.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval)) THEN 'online'::text ELSE CASE WHEN ((chusuarios.dtcomunicacao)::date = CURRENT_DATE) THEN concat('visto por último hoje ', to_char(chusuarios.dtcomunicacao, '"às" HH24:MI'::text)) WHEN ((chusuarios.dtcomunicacao)::date = (CURRENT_DATE - '1 day'::interval)) THEN concat('visto por último ontem ', to_char(chusuarios.dtcomunicacao, '"às" HH24:MI'::text)) ELSE concat('visto por último em ', to_char(chusuarios.dtcomunicacao, 'DD/MM/YYYY "às" HH24:MI'::text)) END END), (CASE WHEN (chusuarios_1.dtcomunicacao IS NULL) THEN ''::text WHEN (chusuarios_1.ocioso AND (chusuarios_1.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval))) THEN 'ocioso'::text WHEN ((chusuarios_1.dtdigitacao > (CURRENT_TIMESTAMP - '00:00:06'::interval)) AND (chusuarios_1.codusuarioconversa = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)) THEN 'digitando...'::text WHEN (chusuarios_1.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval)) THEN 'online'::text ELSE CASE WHEN ((chusuarios_1.dtcomunicacao)::date = CURRENT_DATE) THEN concat('visto por último hoje ', to_char(chusuarios_1.dtcomunicacao, '"às" HH24:MI'::text)) WHEN ((chusuarios_1.dtcomunicacao)::date = (CURRENT_DATE - '1 day'::interval)) THEN concat('visto por último ontem ', to_char(chusuarios_1.dtcomunicacao, '"às" HH24:MI'::text)) ELSE concat('visto por último em ', to_char(chusuarios_1.dtcomunicacao, 'DD/MM/YYYY "às" HH24:MI'::text)) END END))), (CASE WHEN (COALESCE((CASE WHEN (chusuarios.dtcomunicacao IS NULL) THEN ''::text WHEN (chusuarios.ocioso AND (chusuarios.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval))) THEN 'ocioso'::text WHEN ((chusuarios.dtdigitacao > (CURRENT_TIMESTAMP - '00:00:06'::interval)) AND (chusuarios.codusuarioconversa = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)) THEN 'digitando...'::text WHEN (chusuarios.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval)) THEN 'online'::text ELSE CASE WHEN ((chusuarios.dtcomunicacao)::date = CURRENT_DATE) THEN concat('visto por último hoje ', to_char(chusuarios.dtcomunicacao, '"às" HH24:MI'::text)) WHEN ((chusuarios.dtcomunicacao)::date = (CURRENT_DATE - '1 day'::interval)) THEN concat('visto por último ontem ', to_char(chusuarios.dtcomunicacao, '"às" HH24:MI'::text)) ELSE concat('visto por último em ', to_char(chusuarios.dtcomunicacao, 'DD/MM/YYYY "às" HH24:MI'::text)) END END), (CASE WHEN (chusuarios_1.dtcomunicacao IS NULL) THEN ''::text WHEN (chusuarios_1.ocioso AND (chusuarios_1.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval))) THEN 'ocioso'::text WHEN ((chusuarios_1.dtdigitacao > (CURRENT_TIMESTAMP - '00:00:06'::interval)) AND (chusuarios_1.codusuarioconversa = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)) THEN 'digitando...'::text WHEN (chusuarios_1.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval)) THEN 'online'::text ELSE CASE WHEN ((chusuarios_1.dtcomunicacao)::date = CURRENT_DATE) THEN concat('visto por último hoje ', to_char(chusuarios_1.dtcomunicacao, '"às" HH24:MI'::text)) WHEN ((chusuarios_1.dtcomunicacao)::date = (CURRENT_DATE - '1 day'::interval)) THEN concat('visto por último ontem ', to_char(chusuarios_1.dtcomunicacao, '"às" HH24:MI'::text)) ELSE concat('visto por último em ', to_char(chusuarios_1.dtcomunicacao, 'DD/MM/YYYY "às" HH24:MI'::text)) END END)) = 'digitando...'::text) THEN 'digitando...'::text ELSE (CASE WHEN (chmensagens.codusuarioorigem = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid) THEN CASE WHEN ((chmensagens.dtexclusaoorigem IS NOT NULL) AND (chmensagens.dtexclusaodestino IS NOT NULL)) THEN 'Você apagou essa mensagem'::text WHEN ((chmensagens.dtexclusaoorigem IS NOT NULL) AND (chmensagens.dtexclusaodestino IS NULL)) THEN 'Você apagou essa mensagem'::text WHEN ((chmensagens.dtexclusaoorigem IS NULL) AND (chmensagens.dtexclusaodestino IS NOT NULL)) THEN chmensagens.mensagem ELSE chmensagens.mensagem END WHEN (chmensagens.codusuariodestino = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid) THEN CASE WHEN ((chmensagens.dtexclusaoorigem IS NOT NULL) AND (chmensagens.dtexclusaodestino IS NOT NULL)) THEN 'Essa mensagem foi apagada'::text WHEN ((chmensagens.dtexclusaoorigem IS NOT NULL) AND (chmensagens.dtexclusaodestino IS NULL)) THEN chmensagens.mensagem WHEN ((chmensagens.dtexclusaoorigem IS NULL) AND (chmensagens.dtexclusaodestino IS NOT NULL)) THEN 'Você apagou essa mensagem'::text ELSE chmensagens.mensagem END ELSE chmensagens.mensagem END) END), (CASE WHEN (chmensagens.codanexo IS NULL) THEN NULL::text ELSE concat(chmensagensanexos.descricao, chmensagensanexos.formato) END), ((COALESCE((count(*)), '0'::bigint))::integer), (CASE WHEN (gbimagens.hashimagem IS NULL) THEN NULL::text ELSE concat('https://jrsistemas.jrpowerp.com.br', '/gb/imagens/download/get/', gbimagens.hashimagem, gbimagens.formato) END)
  • Sort Method: quicksort Memory: 32kB
7. 0.297 256.559 ↓ 13.0 13 1

Nested Loop Left Join (cost=351.95..595.75 rows=1 width=188) (actual time=27.644..256.559 rows=13 loops=1)

  • Join Filter: (chmensagens_2.codusuarioorigem = COALESCE(gbusuarios.codusuario, gbpermissoesusuarios.codusuario))
8. 0.120 255.742 ↓ 13.0 13 1

Nested Loop (cost=213.30..457.01 rows=1 width=260) (actual time=27.147..255.742 rows=13 loops=1)

  • Join Filter: (COALESCE(cham.codunidade, '00000000-0000-0000-0000-000000000000'::uuid) = ('00000000-0000-0000-0000-000000000000'::uuid))
  • Rows Removed by Join Filter: 13
9. 0.352 255.258 ↓ 13.0 13 1

Nested Loop Left Join (cost=202.90..446.55 rows=1 width=276) (actual time=26.908..255.258 rows=13 loops=1)

  • Join Filter: ((CASE WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_1.codusuarioorigem) THEN chmensagens_1.codusuariodestino WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_1.codusuariodestino) THEN chmensagens_1.codusuarioorigem ELSE NULL::uuid END) = COALESCE(gbusuarios.codusuario, gbpermissoesusuarios.codusuario))
  • Rows Removed by Join Filter: 144
10. 0.127 8.777 ↓ 13.0 13 1

Nested Loop Left Join (cost=1.13..51.53 rows=1 width=192) (actual time=4.152..8.777 rows=13 loops=1)

  • Join Filter: (gbpermissoesusuarios.codgrupo = cham.codgrupo)
  • Rows Removed by Join Filter: 42
  • Filter: ((COALESCE(gbusuarios.codusuario, gbpermissoesusuarios.codusuario) IS NOT NULL) AND (COALESCE(gbusuarios.codusuario, gbpermissoesusuarios.codusuario) <> '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid))
  • Rows Removed by Filter: 1
11. 0.091 1.790 ↓ 14.0 14 1

Nested Loop (cost=0.84..25.42 rows=1 width=136) (actual time=0.155..1.790 rows=14 loops=1)

12. 0.112 1.531 ↓ 14.0 14 1

Nested Loop Left Join (cost=0.70..17.24 rows=1 width=152) (actual time=0.135..1.531 rows=14 loops=1)

13. 0.089 0.089 ↓ 14.0 14 1

Index Scan using idx_chagrupamentosmembros_05 on chagrupamentosmembros cham (cost=0.14..8.16 rows=1 width=64) (actual time=0.015..0.089 rows=14 loops=1)

  • Index Cond: (codagrupamento = chagrupamentos.codagrupamento)
14. 0.196 1.330 ↑ 1.0 1 14

Nested Loop Left Join (cost=0.55..9.07 rows=1 width=104) (actual time=0.084..0.095 rows=1 loops=14)

15. 0.154 0.994 ↑ 1.0 1 14

Nested Loop (cost=0.42..8.81 rows=1 width=72) (actual time=0.064..0.071 rows=1 loops=14)

  • Join Filter: (gbpessoas.codpessoa = chusuarios.codusuario)
16. 0.140 0.518 ↑ 1.0 1 14

Nested Loop (cost=0.28..8.42 rows=1 width=56) (actual time=0.033..0.037 rows=1 loops=14)

17. 0.280 0.280 ↑ 1.0 1 14

Index Only Scan using gbusuarios_pkey on gbusuarios (cost=0.14..8.16 rows=1 width=16) (actual time=0.017..0.020 rows=1 loops=14)

  • Index Cond: (codusuario = cham.codusuario)
  • Heap Fetches: 14
18. 0.098 0.098 ↑ 1.0 1 14

Index Scan using gbpessoas_pkey on gbpessoas (cost=0.14..0.25 rows=1 width=40) (actual time=0.007..0.007 rows=1 loops=14)

  • Index Cond: (codpessoa = gbusuarios.codusuario)
19. 0.322 0.322 ↑ 1.0 1 14

Index Scan using chusuarios_pkey on chusuarios (cost=0.14..0.37 rows=1 width=48) (actual time=0.023..0.023 rows=1 loops=14)

  • Index Cond: (codusuario = gbusuarios.codusuario)
20. 0.140 0.140 ↑ 1.0 1 14

Index Scan using idx_gbimagens01 on gbimagens (cost=0.14..0.25 rows=1 width=37) (actual time=0.007..0.010 rows=1 loops=14)

  • Index Cond: (codpessoa = gbusuarios.codusuario)
21. 0.168 0.168 ↑ 1.0 1 14

Index Only Scan using chagrupamentos_pkey on chagrupamentos cha (cost=0.14..8.16 rows=1 width=16) (actual time=0.008..0.012 rows=1 loops=14)

  • Index Cond: (codagrupamento = chagrupamentos.codagrupamento)
  • Heap Fetches: 14
22. 0.196 6.860 ↓ 3.0 3 14

Nested Loop Left Join (cost=0.29..26.10 rows=1 width=88) (actual time=0.366..0.490 rows=3 loops=14)

  • Join Filter: (gbimagens_1.codpessoa = chusuarios_1.codusuario)
23. 0.210 6.160 ↓ 3.0 3 14

Nested Loop (cost=0.29..23.91 rows=1 width=104) (actual time=0.345..0.440 rows=3 loops=14)

24. 3.864 5.530 ↓ 3.0 3 14

Nested Loop (cost=0.14..15.59 rows=1 width=104) (actual time=0.315..0.395 rows=3 loops=14)

25. 0.238 0.826 ↓ 3.0 3 14

Nested Loop (cost=0.14..10.35 rows=1 width=56) (actual time=0.029..0.059 rows=3 loops=14)

26. 0.252 0.252 ↓ 3.0 3 14

Index Scan using idx_gbpermissoesusuarios_02 on gbpermissoesusuarios (cost=0.14..8.16 rows=1 width=32) (actual time=0.013..0.018 rows=3 loops=14)

  • Index Cond: (codusuario = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
27. 0.336 0.336 ↑ 1.0 1 42

Seq Scan on gbpessoas gbpessoas_1 (cost=0.00..2.17 rows=1 width=40) (actual time=0.004..0.008 rows=1 loops=42)

  • Filter: (codpessoa = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
  • Rows Removed by Filter: 13
28. 0.840 0.840 ↑ 1.0 1 42

Seq Scan on chusuarios chusuarios_1 (cost=0.00..5.23 rows=1 width=48) (actual time=0.010..0.020 rows=1 loops=42)

  • Filter: (codusuario = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
  • Rows Removed by Filter: 13
29. 0.420 0.420 ↑ 1.0 1 42

Index Only Scan using gbusuariosgrupos_pkey on gbpermissoesgrupos (cost=0.14..8.16 rows=1 width=16) (actual time=0.010..0.010 rows=1 loops=42)

  • Index Cond: (codgrupo = gbpermissoesusuarios.codgrupo)
  • Heap Fetches: 42
30. 0.504 0.504 ↑ 1.0 1 42

Seq Scan on gbimagens gbimagens_1 (cost=0.00..2.17 rows=1 width=16) (actual time=0.010..0.012 rows=1 loops=42)

  • Filter: (codpessoa = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
  • Rows Removed by Filter: 13
31. 0.858 246.129 ↓ 12.0 12 13

Nested Loop Left Join (cost=201.77..395.01 rows=1 width=100) (actual time=16.512..18.933 rows=12 loops=13)

32. 92.347 244.959 ↓ 12.0 12 13

Hash Join (cost=201.62..394.84 rows=1 width=72) (actual time=16.487..18.843 rows=12 loops=13)

  • Hash Cond: (chmensagens.dtcriacao = (max(chmensagens_1.dtcriacao)))
  • Join Filter: (((CASE WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_1.codusuarioorigem) THEN chmensagens_1.codusuariodestino WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_1.codusuariodestino) THEN chmensagens_1.codusuarioorigem ELSE NULL::uuid END) = chmensagens.codusuarioorigem) OR ((CASE WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_1.codusuarioorigem) THEN chmensagens_1.codusuariodestino WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_1.codusuariodestino) THEN chmensagens_1.codusuarioorigem ELSE NULL::uuid END) = chmensagens.codusuariodestino))
33. 143.715 143.715 ↓ 1.1 2,465 13

Seq Scan on chmensagens (cost=0.00..182.78 rows=2,298 width=88) (actual time=0.013..11.055 rows=2,465 loops=13)

  • Filter: (('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = codusuarioorigem) OR ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = codusuariodestino))
  • Rows Removed by Filter: 1235
34. 0.021 8.897 ↑ 16.3 12 1

Hash (cost=199.18..199.18 rows=196 width=24) (actual time=8.895..8.897 rows=12 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
35. 5.522 8.876 ↑ 16.3 12 1

HashAggregate (cost=194.28..197.22 rows=196 width=24) (actual time=8.865..8.876 rows=12 loops=1)

  • Group Key: CASE WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_1.codusuarioorigem) THEN chmensagens_1.codusuariodestino WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_1.codusuariodestino) THEN chmensagens_1.codusuarioorigem ELSE NULL::uuid END
36. 3.354 3.354 ↓ 1.1 2,465 1

Seq Scan on chmensagens chmensagens_1 (cost=0.00..182.78 rows=2,298 width=24) (actual time=0.031..3.354 rows=2,465 loops=1)

  • Filter: (('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = codusuarioorigem) OR ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = codusuariodestino))
  • Rows Removed by Filter: 1235
37. 0.312 0.312 ↓ 0.0 0 156

Index Scan using chmensagensanexos_pkey on chmensagensanexos (cost=0.14..0.17 rows=1 width=44) (actual time=0.002..0.002 rows=0 loops=156)

  • Index Cond: (codanexo = chmensagens.codanexo)
38. 0.091 0.364 ↑ 1.0 2 13

Unique (cost=10.40..10.42 rows=2 width=48) (actual time=0.022..0.028 rows=2 loops=13)

39. 0.141 0.273 ↑ 1.0 2 13

Sort (cost=10.40..10.41 rows=2 width=48) (actual time=0.019..0.021 rows=2 loops=13)

  • Sort Key: ('00000000-0000-0000-0000-000000000000'::uuid), ('TODAS AS UNIDADES'::character varying)
  • Sort Method: quicksort Memory: 25kB
40. 0.007 0.132 ↑ 1.0 2 1

Append (cost=0.00..10.39 rows=2 width=48) (actual time=0.013..0.132 rows=2 loops=1)

41. 0.010 0.010 ↑ 1.0 1 1

Result (cost=0.00..0.01 rows=1 width=48) (actual time=0.009..0.010 rows=1 loops=1)

42. 0.032 0.115 ↑ 1.0 1 1

Hash Join (cost=8.17..10.35 rows=1 width=40) (actual time=0.100..0.115 rows=1 loops=1)

  • Hash Cond: (gbpessoas_2.codpessoa = gbusuariosunidades.codunidade)
43. 0.032 0.032 ↑ 1.0 14 1

Seq Scan on gbpessoas gbpessoas_2 (cost=0.00..2.14 rows=14 width=40) (actual time=0.019..0.032 rows=14 loops=1)

44. 0.007 0.051 ↑ 1.0 1 1

Hash (cost=8.16..8.16 rows=1 width=16) (actual time=0.050..0.051 rows=1 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
45. 0.044 0.044 ↑ 1.0 1 1

Index Scan using idx_gbusuariosunidades_03 on gbusuariosunidades (cost=0.14..8.16 rows=1 width=16) (actual time=0.041..0.044 rows=1 loops=1)

  • Index Cond: (codusuario = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
  • Filter: (codunidade IS NOT NULL)
46. 0.039 0.520 ↓ 0.0 0 13

GroupAggregate (cost=138.65..138.70 rows=1 width=40) (actual time=0.040..0.040 rows=0 loops=13)

  • Group Key: chmensagens_2.codusuarioorigem, chmensagens_2.codusuariodestino
  • Filter: (count(*) > 0)
47. 0.022 0.481 ↓ 0.0 0 13

Sort (cost=138.65..138.66 rows=2 width=32) (actual time=0.037..0.037 rows=0 loops=13)

  • Sort Key: chmensagens_2.codusuarioorigem
  • Sort Method: quicksort Memory: 25kB
48. 0.403 0.459 ↓ 0.0 0 1

Bitmap Heap Scan on chmensagens chmensagens_2 (cost=16.07..138.64 rows=2 width=32) (actual time=0.458..0.459 rows=0 loops=1)

  • Recheck Cond: (codusuariodestino = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
  • Filter: ((dtleitura IS NULL) AND (codusuarioorigem <> '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid))
  • Rows Removed by Filter: 496
  • Heap Blocks: exact=70
49. 0.056 0.056 ↑ 1.0 503 1

Bitmap Index Scan on idx_chmensagens_02 (cost=0.00..16.07 rows=505 width=0) (actual time=0.056..0.056 rows=503 loops=1)

  • Index Cond: (codusuariodestino = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
50. 0.430 305.655 ↑ 1.0 1 1

Aggregate (cost=595.80..595.81 rows=1 width=32) (actual time=305.654..305.655 rows=1 loops=1)

51. 0.120 305.225 ↓ 13.0 13 1

Subquery Scan on m_1 (cost=595.76..595.79 rows=1 width=24) (actual time=305.054..305.225 rows=13 loops=1)

52. 0.075 305.105 ↓ 13.0 13 1

Unique (cost=595.76..595.78 rows=1 width=188) (actual time=305.022..305.105 rows=13 loops=1)

53. 0.116 305.030 ↓ 13.0 13 1

Sort (cost=595.76..595.76 rows=1 width=188) (actual time=305.018..305.030 rows=13 loops=1)

  • Sort Key: (COALESCE(chmensagens_3.dtcriacao, '2001-01-01 00:00:00'::timestamp without time zone)) DESC, (initcap((COALESCE(gbpessoas_3.nome, gbpessoas_4.nome))::text)), (COALESCE(gbusuarios_1.codusuario, gbpermissoesusuarios_1.codusuario)), (COALESCE((CASE WHEN (chusuarios_2.dtcomunicacao IS NULL) THEN ''::text WHEN (chusuarios_2.ocioso AND (chusuarios_2.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval))) THEN 'ocioso'::text WHEN ((chusuarios_2.dtdigitacao > (CURRENT_TIMESTAMP - '00:00:06'::interval)) AND (chusuarios_2.codusuarioconversa = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)) THEN 'digitando...'::text WHEN (chusuarios_2.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval)) THEN 'online'::text ELSE CASE WHEN ((chusuarios_2.dtcomunicacao)::date = CURRENT_DATE) THEN concat('visto por último hoje ', to_char(chusuarios_2.dtcomunicacao, '"às" HH24:MI'::text)) WHEN ((chusuarios_2.dtcomunicacao)::date = (CURRENT_DATE - '1 day'::interval)) THEN concat('visto por último ontem ', to_char(chusuarios_2.dtcomunicacao, '"às" HH24:MI'::text)) ELSE concat('visto por último em ', to_char(chusuarios_2.dtcomunicacao, 'DD/MM/YYYY "às" HH24:MI'::text)) END END), (CASE WHEN (chusuarios_3.dtcomunicacao IS NULL) THEN ''::text WHEN (chusuarios_3.ocioso AND (chusuarios_3.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval))) THEN 'ocioso'::text WHEN ((chusuarios_3.dtdigitacao > (CURRENT_TIMESTAMP - '00:00:06'::interval)) AND (chusuarios_3.codusuarioconversa = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)) THEN 'digitando...'::text WHEN (chusuarios_3.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval)) THEN 'online'::text ELSE CASE WHEN ((chusuarios_3.dtcomunicacao)::date = CURRENT_DATE) THEN concat('visto por último hoje ', to_char(chusuarios_3.dtcomunicacao, '"às" HH24:MI'::text)) WHEN ((chusuarios_3.dtcomunicacao)::date = (CURRENT_DATE - '1 day'::interval)) THEN concat('visto por último ontem ', to_char(chusuarios_3.dtcomunicacao, '"às" HH24:MI'::text)) ELSE concat('visto por último em ', to_char(chusuarios_3.dtcomunicacao, 'DD/MM/YYYY "às" HH24:MI'::text)) END END))), (CASE WHEN (COALESCE((CASE WHEN (chusuarios_2.dtcomunicacao IS NULL) THEN ''::text WHEN (chusuarios_2.ocioso AND (chusuarios_2.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval))) THEN 'ocioso'::text WHEN ((chusuarios_2.dtdigitacao > (CURRENT_TIMESTAMP - '00:00:06'::interval)) AND (chusuarios_2.codusuarioconversa = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)) THEN 'digitando...'::text WHEN (chusuarios_2.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval)) THEN 'online'::text ELSE CASE WHEN ((chusuarios_2.dtcomunicacao)::date = CURRENT_DATE) THEN concat('visto por último hoje ', to_char(chusuarios_2.dtcomunicacao, '"às" HH24:MI'::text)) WHEN ((chusuarios_2.dtcomunicacao)::date = (CURRENT_DATE - '1 day'::interval)) THEN concat('visto por último ontem ', to_char(chusuarios_2.dtcomunicacao, '"às" HH24:MI'::text)) ELSE concat('visto por último em ', to_char(chusuarios_2.dtcomunicacao, 'DD/MM/YYYY "às" HH24:MI'::text)) END END), (CASE WHEN (chusuarios_3.dtcomunicacao IS NULL) THEN ''::text WHEN (chusuarios_3.ocioso AND (chusuarios_3.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval))) THEN 'ocioso'::text WHEN ((chusuarios_3.dtdigitacao > (CURRENT_TIMESTAMP - '00:00:06'::interval)) AND (chusuarios_3.codusuarioconversa = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)) THEN 'digitando...'::text WHEN (chusuarios_3.dtcomunicacao > (CURRENT_TIMESTAMP - '00:00:15'::interval)) THEN 'online'::text ELSE CASE WHEN ((chusuarios_3.dtcomunicacao)::date = CURRENT_DATE) THEN concat('visto por último hoje ', to_char(chusuarios_3.dtcomunicacao, '"às" HH24:MI'::text)) WHEN ((chusuarios_3.dtcomunicacao)::date = (CURRENT_DATE - '1 day'::interval)) THEN concat('visto por último ontem ', to_char(chusuarios_3.dtcomunicacao, '"às" HH24:MI'::text)) ELSE concat('visto por último em ', to_char(chusuarios_3.dtcomunicacao, 'DD/MM/YYYY "às" HH24:MI'::text)) END END)) = 'digitando...'::text) THEN 'digitando...'::text ELSE (CASE WHEN (chmensagens_3.codusuarioorigem = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid) THEN CASE WHEN ((chmensagens_3.dtexclusaoorigem IS NOT NULL) AND (chmensagens_3.dtexclusaodestino IS NOT NULL)) THEN 'Você apagou essa mensagem'::text WHEN ((chmensagens_3.dtexclusaoorigem IS NOT NULL) AND (chmensagens_3.dtexclusaodestino IS NULL)) THEN 'Você apagou essa mensagem'::text WHEN ((chmensagens_3.dtexclusaoorigem IS NULL) AND (chmensagens_3.dtexclusaodestino IS NOT NULL)) THEN chmensagens_3.mensagem ELSE chmensagens_3.mensagem END WHEN (chmensagens_3.codusuariodestino = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid) THEN CASE WHEN ((chmensagens_3.dtexclusaoorigem IS NOT NULL) AND (chmensagens_3.dtexclusaodestino IS NOT NULL)) THEN 'Essa mensagem foi apagada'::text WHEN ((chmensagens_3.dtexclusaoorigem IS NOT NULL) AND (chmensagens_3.dtexclusaodestino IS NULL)) THEN chmensagens_3.mensagem WHEN ((chmensagens_3.dtexclusaoorigem IS NULL) AND (chmensagens_3.dtexclusaodestino IS NOT NULL)) THEN 'Você apagou essa mensagem'::text ELSE chmensagens_3.mensagem END ELSE chmensagens_3.mensagem END) END), (CASE WHEN (chmensagens_3.codanexo IS NULL) THEN NULL::text ELSE concat(chmensagensanexos_1.descricao, chmensagensanexos_1.formato) END), ((COALESCE((count(*)), '0'::bigint))::integer), (CASE WHEN (gbimagens_2.hashimagem IS NULL) THEN NULL::text ELSE concat('https://jrsistemas.jrpowerp.com.br', '/gb/imagens/download/get/', gbimagens_2.hashimagem, gbimagens_2.formato) END)
  • Sort Method: quicksort Memory: 32kB
54. 0.354 304.914 ↓ 13.0 13 1

Nested Loop Left Join (cost=351.95..595.75 rows=1 width=188) (actual time=43.959..304.914 rows=13 loops=1)

  • Join Filter: (chmensagens_5.codusuarioorigem = COALESCE(gbusuarios_1.codusuario, gbpermissoesusuarios_1.codusuario))
55. 0.165 285.528 ↓ 13.0 13 1

Nested Loop (cost=213.30..457.01 rows=1 width=260) (actual time=24.917..285.528 rows=13 loops=1)

  • Join Filter: (COALESCE(cham_1.codunidade, '00000000-0000-0000-0000-000000000000'::uuid) = ('00000000-0000-0000-0000-000000000000'::uuid))
  • Rows Removed by Join Filter: 13
56. 0.257 279.773 ↓ 13.0 13 1

Nested Loop Left Join (cost=202.90..446.55 rows=1 width=276) (actual time=24.781..279.773 rows=13 loops=1)

  • Join Filter: ((CASE WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_4.codusuarioorigem) THEN chmensagens_4.codusuariodestino WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_4.codusuariodestino) THEN chmensagens_4.codusuarioorigem ELSE NULL::uuid END) = COALESCE(gbusuarios_1.codusuario, gbpermissoesusuarios_1.codusuario))
  • Rows Removed by Join Filter: 144
57. 0.152 13.198 ↓ 13.0 13 1

Nested Loop Left Join (cost=1.13..51.53 rows=1 width=192) (actual time=0.574..13.198 rows=13 loops=1)

  • Join Filter: (gbpermissoesusuarios_1.codgrupo = cham_1.codgrupo)
  • Rows Removed by Join Filter: 42
  • Filter: ((COALESCE(gbusuarios_1.codusuario, gbpermissoesusuarios_1.codusuario) IS NOT NULL) AND (COALESCE(gbusuarios_1.codusuario, gbpermissoesusuarios_1.codusuario) <> '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid))
  • Rows Removed by Filter: 1
58. 0.356 2.322 ↓ 14.0 14 1

Nested Loop (cost=0.84..25.42 rows=1 width=136) (actual time=0.252..2.322 rows=14 loops=1)

59. 0.121 1.770 ↓ 14.0 14 1

Nested Loop Left Join (cost=0.70..17.24 rows=1 width=152) (actual time=0.236..1.770 rows=14 loops=1)

60. 0.109 0.109 ↓ 14.0 14 1

Index Scan using idx_chagrupamentosmembros_05 on chagrupamentosmembros cham_1 (cost=0.14..8.16 rows=1 width=64) (actual time=0.062..0.109 rows=14 loops=1)

  • Index Cond: (codagrupamento = chagrupamentos.codagrupamento)
61. 0.224 1.540 ↑ 1.0 1 14

Nested Loop Left Join (cost=0.55..9.07 rows=1 width=104) (actual time=0.098..0.110 rows=1 loops=14)

62. 0.182 0.994 ↑ 1.0 1 14

Nested Loop (cost=0.42..8.81 rows=1 width=72) (actual time=0.065..0.071 rows=1 loops=14)

  • Join Filter: (gbpessoas_3.codpessoa = chusuarios_2.codusuario)
63. 0.168 0.476 ↑ 1.0 1 14

Nested Loop (cost=0.28..8.42 rows=1 width=56) (actual time=0.029..0.034 rows=1 loops=14)

64. 0.196 0.196 ↑ 1.0 1 14

Index Only Scan using gbusuarios_pkey on gbusuarios gbusuarios_1 (cost=0.14..8.16 rows=1 width=16) (actual time=0.011..0.014 rows=1 loops=14)

  • Index Cond: (codusuario = cham_1.codusuario)
  • Heap Fetches: 14
65. 0.112 0.112 ↑ 1.0 1 14

Index Scan using gbpessoas_pkey on gbpessoas gbpessoas_3 (cost=0.14..0.25 rows=1 width=40) (actual time=0.008..0.008 rows=1 loops=14)

  • Index Cond: (codpessoa = gbusuarios_1.codusuario)
66. 0.336 0.336 ↑ 1.0 1 14

Index Scan using chusuarios_pkey on chusuarios chusuarios_2 (cost=0.14..0.37 rows=1 width=48) (actual time=0.024..0.024 rows=1 loops=14)

  • Index Cond: (codusuario = gbusuarios_1.codusuario)
67. 0.322 0.322 ↑ 1.0 1 14

Index Scan using idx_gbimagens01 on gbimagens gbimagens_2 (cost=0.14..0.25 rows=1 width=37) (actual time=0.021..0.023 rows=1 loops=14)

  • Index Cond: (codpessoa = gbusuarios_1.codusuario)
68. 0.196 0.196 ↑ 1.0 1 14

Index Only Scan using chagrupamentos_pkey on chagrupamentos cha_1 (cost=0.14..8.16 rows=1 width=16) (actual time=0.009..0.014 rows=1 loops=14)

  • Index Cond: (codagrupamento = chagrupamentos.codagrupamento)
  • Heap Fetches: 14
69. 7.168 10.724 ↓ 3.0 3 14

Nested Loop Left Join (cost=0.29..26.10 rows=1 width=88) (actual time=0.579..0.766 rows=3 loops=14)

  • Join Filter: (gbimagens_3.codpessoa = chusuarios_3.codusuario)
70. 0.868 3.136 ↓ 3.0 3 14

Nested Loop (cost=0.29..23.91 rows=1 width=104) (actual time=0.061..0.224 rows=3 loops=14)

71. 0.196 2.016 ↓ 3.0 3 14

Nested Loop (cost=0.14..15.59 rows=1 width=104) (actual time=0.047..0.144 rows=3 loops=14)

72. 0.266 0.812 ↓ 3.0 3 14

Nested Loop (cost=0.14..10.35 rows=1 width=56) (actual time=0.026..0.058 rows=3 loops=14)

73. 0.210 0.210 ↓ 3.0 3 14

Index Scan using idx_gbpermissoesusuarios_02 on gbpermissoesusuarios gbpermissoesusuarios_1 (cost=0.14..8.16 rows=1 width=32) (actual time=0.011..0.015 rows=3 loops=14)

  • Index Cond: (codusuario = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
74. 0.336 0.336 ↑ 1.0 1 42

Seq Scan on gbpessoas gbpessoas_4 (cost=0.00..2.17 rows=1 width=40) (actual time=0.004..0.008 rows=1 loops=42)

  • Filter: (codpessoa = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
  • Rows Removed by Filter: 13
75. 1.008 1.008 ↑ 1.0 1 42

Seq Scan on chusuarios chusuarios_3 (cost=0.00..5.23 rows=1 width=48) (actual time=0.012..0.024 rows=1 loops=42)

  • Filter: (codusuario = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
  • Rows Removed by Filter: 13
76. 0.252 0.252 ↑ 1.0 1 42

Index Only Scan using gbusuariosgrupos_pkey on gbpermissoesgrupos gbpermissoesgrupos_1 (cost=0.14..8.16 rows=1 width=16) (actual time=0.006..0.006 rows=1 loops=42)

  • Index Cond: (codgrupo = gbpermissoesusuarios_1.codgrupo)
  • Heap Fetches: 42
77. 0.420 0.420 ↑ 1.0 1 42

Seq Scan on gbimagens gbimagens_3 (cost=0.00..2.17 rows=1 width=16) (actual time=0.008..0.010 rows=1 loops=42)

  • Filter: (codpessoa = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
  • Rows Removed by Filter: 13
78. 1.339 266.318 ↓ 12.0 12 13

Nested Loop Left Join (cost=201.77..395.01 rows=1 width=100) (actual time=13.910..20.486 rows=12 loops=13)

79. 114.588 264.355 ↓ 12.0 12 13

Hash Join (cost=201.62..394.84 rows=1 width=72) (actual time=13.875..20.335 rows=12 loops=13)

  • Hash Cond: (chmensagens_3.dtcriacao = (max(chmensagens_4.dtcriacao)))
  • Join Filter: (((CASE WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_4.codusuarioorigem) THEN chmensagens_4.codusuariodestino WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_4.codusuariodestino) THEN chmensagens_4.codusuarioorigem ELSE NULL::uuid END) = chmensagens_3.codusuarioorigem) OR ((CASE WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_4.codusuarioorigem) THEN chmensagens_4.codusuariodestino WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_4.codusuariodestino) THEN chmensagens_4.codusuarioorigem ELSE NULL::uuid END) = chmensagens_3.codusuariodestino))
80. 142.857 142.857 ↓ 1.1 2,465 13

Seq Scan on chmensagens chmensagens_3 (cost=0.00..182.78 rows=2,298 width=88) (actual time=0.015..10.989 rows=2,465 loops=13)

  • Filter: (('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = codusuarioorigem) OR ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = codusuariodestino))
  • Rows Removed by Filter: 1235
81. 0.025 6.910 ↑ 16.3 12 1

Hash (cost=199.18..199.18 rows=196 width=24) (actual time=6.909..6.910 rows=12 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
82. 2.499 6.885 ↑ 16.3 12 1

HashAggregate (cost=194.28..197.22 rows=196 width=24) (actual time=6.872..6.885 rows=12 loops=1)

  • Group Key: CASE WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_4.codusuarioorigem) THEN chmensagens_4.codusuariodestino WHEN ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = chmensagens_4.codusuariodestino) THEN chmensagens_4.codusuarioorigem ELSE NULL::uuid END
83. 4.386 4.386 ↓ 1.1 2,465 1

Seq Scan on chmensagens chmensagens_4 (cost=0.00..182.78 rows=2,298 width=24) (actual time=0.015..4.386 rows=2,465 loops=1)

  • Filter: (('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = codusuarioorigem) OR ('755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid = codusuariodestino))
  • Rows Removed by Filter: 1235
84. 0.624 0.624 ↓ 0.0 0 156

Index Scan using chmensagensanexos_pkey on chmensagensanexos chmensagensanexos_1 (cost=0.14..0.17 rows=1 width=44) (actual time=0.004..0.004 rows=0 loops=156)

  • Index Cond: (codanexo = chmensagens_3.codanexo)
85. 5.421 5.590 ↑ 1.0 2 13

Unique (cost=10.40..10.42 rows=2 width=48) (actual time=0.423..0.430 rows=2 loops=13)

86. 0.067 0.169 ↑ 1.0 2 13

Sort (cost=10.40..10.41 rows=2 width=48) (actual time=0.012..0.013 rows=2 loops=13)

  • Sort Key: ('00000000-0000-0000-0000-000000000000'::uuid), ('TODAS AS UNIDADES'::character varying)
  • Sort Method: quicksort Memory: 25kB
87. 0.005 0.102 ↑ 1.0 2 1

Append (cost=0.00..10.39 rows=2 width=48) (actual time=0.006..0.102 rows=2 loops=1)

88. 0.006 0.006 ↑ 1.0 1 1

Result (cost=0.00..0.01 rows=1 width=48) (actual time=0.004..0.006 rows=1 loops=1)

89. 0.034 0.091 ↑ 1.0 1 1

Hash Join (cost=8.17..10.35 rows=1 width=40) (actual time=0.075..0.091 rows=1 loops=1)

  • Hash Cond: (gbpessoas_5.codpessoa = gbusuariosunidades_1.codunidade)
90. 0.028 0.028 ↑ 1.0 14 1

Seq Scan on gbpessoas gbpessoas_5 (cost=0.00..2.14 rows=14 width=40) (actual time=0.014..0.028 rows=14 loops=1)

91. 0.007 0.029 ↑ 1.0 1 1

Hash (cost=8.16..8.16 rows=1 width=16) (actual time=0.028..0.029 rows=1 loops=1)

  • Buckets: 1024 Batches: 1 Memory Usage: 9kB
92. 0.022 0.022 ↑ 1.0 1 1

Index Scan using idx_gbusuariosunidades_03 on gbusuariosunidades gbusuariosunidades_1 (cost=0.14..8.16 rows=1 width=16) (actual time=0.019..0.022 rows=1 loops=1)

  • Index Cond: (codusuario = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
  • Filter: (codunidade IS NOT NULL)
93. 0.039 19.032 ↓ 0.0 0 13

GroupAggregate (cost=138.65..138.70 rows=1 width=40) (actual time=1.464..1.464 rows=0 loops=13)

  • Group Key: chmensagens_5.codusuarioorigem, chmensagens_5.codusuariodestino
  • Filter: (count(*) > 0)
94. 0.015 18.993 ↓ 0.0 0 13

Sort (cost=138.65..138.66 rows=2 width=32) (actual time=1.461..1.461 rows=0 loops=13)

  • Sort Key: chmensagens_5.codusuarioorigem
  • Sort Method: quicksort Memory: 25kB
95. 18.923 18.978 ↓ 0.0 0 1

Bitmap Heap Scan on chmensagens chmensagens_5 (cost=16.07..138.64 rows=2 width=32) (actual time=18.977..18.978 rows=0 loops=1)

  • Recheck Cond: (codusuariodestino = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
  • Filter: ((dtleitura IS NULL) AND (codusuarioorigem <> '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid))
  • Rows Removed by Filter: 496
  • Heap Blocks: exact=70
96. 0.055 0.055 ↑ 1.0 503 1

Bitmap Index Scan on idx_chmensagens_02 (cost=0.00..16.07 rows=505 width=0) (actual time=0.054..0.055 rows=503 loops=1)

  • Index Cond: (codusuariodestino = '755280a9-dbdc-4e31-9b02-389cfbb67eff'::uuid)
Planning time : 104.671 ms
Execution time : 1,419.050 ms