explain.depesz.com

PostgreSQL's explain analyze made readable

Result: CD8 : Optimization for: plan #twPb

Settings

Optimization path:

# exclusive inclusive rows x rows loops node
1. 2.539 204.469 ↑ 1.0 1,000 1

Limit (cost=0.58..1,946,274.51 rows=1,000 width=12) (actual time=0.072..204.469 rows=1,000 loops=1)

2. 10.437 201.930 ↑ 52.4 1,000 1

Nested Loop (cost=0.58..102,017,841.33 rows=52,417 width=12) (actual time=0.069..201.930 rows=1,000 loops=1)

3. 7.493 7.493 ↑ 52.4 1,000 1

Index Scan Backward using empresas_sucursales_nro_patronal_key on empresas_sucursales (cost=0.29..5,658.86 rows=52,420 width=44) (actual time=0.015..7.493 rows=1,000 loops=1)

  • Filter: (type = 1)
  • Rows Removed by Filter: 148
4. 8.000 8.000 ↑ 1.0 1 1,000

Index Scan using empresas_pk on empresas emp (cost=0.29..0.38 rows=1 width=20) (actual time=0.007..0.008 rows=1 loops=1,000)

  • Index Cond: (id = empresas_sucursales.empresa_id)
  • Filter: (((document)::text <> '0'::text) AND ((document)::text <> ''::text) AND ((document)::text <> '-'::text))
5.          

SubPlan (forNested Loop)

6. 15.000 176.000 ↑ 1.0 1 1,000

Aggregate (cost=1,945.76..1,945.77 rows=1 width=8) (actual time=0.175..0.176 rows=1 loops=1,000)

7. 7.000 161.000 ↑ 60.0 1 1,000

Nested Loop (cost=0.72..1,945.61 rows=60 width=8) (actual time=0.073..0.161 rows=1 loops=1,000)

8. 8.000 8.000 ↑ 1.0 1 1,000

Index Only Scan using empresas_sucursales_nro_patronal_key on empresas_sucursales es (cost=0.29..2.31 rows=1 width=4) (actual time=0.007..0.008 rows=1 loops=1,000)

  • Index Cond: (nro_patronal = empresas_sucursales.nro_patronal)
  • Heap Fetches: 11
9. 24.944 146.000 ↑ 60.0 1 1,000

Index Scan using empleados_npatronal_idx on empleados (cost=0.43..1,942.71 rows=60 width=24) (actual time=0.062..0.146 rows=1 loops=1,000)

  • Index Cond: (npatronal = empresas_sucursales.nro_patronal)
  • Filter: (SubPlan 2)
  • Rows Removed by Filter: 0
10.          

SubPlan (forIndex Scan)

11. 4.656 121.056 ↑ 1.0 1 1,552

Limit (cost=14.15..14.16 rows=1 width=20) (actual time=0.078..0.078 rows=1 loops=1,552)

12. 13.968 116.400 ↑ 1.0 1 1,552

Sort (cost=14.15..14.16 rows=1 width=20) (actual time=0.075..0.075 rows=1 loops=1,552)

  • Sort Key: empleados_movimientos.fecha, empleados_movimientos.id
  • Sort Method: quicksort Memory: 25kB
13. 7.760 102.432 ↑ 1.0 1 1,552

Result (cost=0.43..14.14 rows=1 width=20) (actual time=0.059..0.066 rows=1 loops=1,552)

  • One-Time Filter: (empleados.empresa_id = emp.id)
14. 60.212 94.672 ↑ 1.0 1 1,552

Index Scan using empleados_movimientos_empleado_id_tipo_idx on empleados_movimientos (cost=0.43..14.14 rows=1 width=20) (actual time=0.056..0.061 rows=1 loops=1,552)

  • Index Cond: (empleado_id = empleados.id)
  • Filter: (NOT (SubPlan 1))
  • Rows Removed by Filter: 0
15.          

SubPlan (forIndex Scan)

16. 34.460 34.460 ↓ 0.0 0 1,723

Index Scan using multas_id_registro_multado_idx on multas (cost=0.00..4.02 rows=1 width=8) (actual time=0.020..0.020 rows=0 loops=1,723)

  • Index Cond: (id_registro_multado = empleados_movimientos.id)
  • Filter: ((estado IS NULL) AND (idtipo_multa = 11))
  • Rows Removed by Filter: 0