<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#006600">
Hola Fernando, hola lista!<br>
Luego de probar de agregar los índices que me recomendó fernando, la
consulta tardo 20 minutos menos.<br>
Les paso el nuevo explain analyze:<br>
<a class="moz-txt-link-freetext" href="http://explain-analyze.info/query_plans/1521-nicolasdom-siu-2">http://explain-analyze.info/query_plans/1521-nicolasdom-siu-2</a><br>
<br>
Se les ocurre algo mas para que mejore? ya que 1 hora me parece que es
mucho tiempo.<br>
Muchas Gracias!<br>
<br>
Nicolas.<br>
<br>
Rodriguez Fernando escribió:
<blockquote cite="mid:474F045B(dot)7010000(at)ort(dot)edu(dot)uy" type="cite">tenes
indices sobre las tablas?, si no los tenes, se me ocurren los
siguientes (verificale los nombres) :
<br>
rrhh_cubo_publicado_810 cod_rrhh_importacion + cod_institucion
<br>
rrhh_cargos. cod_rrhh_importacion + cod_rrhh_escalafon +
cod_rrhh_nivel_ensenianza + numero_cargo
<br>
rrhh_detalles_liquidaciones_haberes cod_rrhh_importacion
<br>
rrhh_escalafones_universidades cod_rrhh_importacion +
cod_rrhh_escalafon + cod_cargo_universidad
<br>
rrhh_cargos cod_rrhh_importacion + cod_rrhh_escalafon +
cod_cargo_universidad
<br>
<br>
Saludos Fernando
<br>
<br>
Nicolás Domínguez Florit wrote:
<br>
<blockquote type="cite">Tengo una consulta que me esta tardando mucho
y me gustaría que cuando tengan unos minutos le echen un vistazo para
ver si se les ocurre algo. Les paso las tabas, los registros de cada
tabla, la consulta y el explain analyze.
<br>
<br>
Uso un motor 8.2.4,
<br>
<br>
Tablas:
<br>
-------
<br>
<br>
CREATE TABLE rrhh_cargos
<br>
(
<br>
numero_cargo numeric(9) NOT NULL,
<br>
cod_ona_unidad_academica integer NOT NULL,
<br>
cod_ona_rama character(4) NOT NULL,
<br>
cod_ona_disciplina character(4) NOT NULL,
<br>
cod_ona_area character(4) NOT NULL,
<br>
cod_fuente_financiamiento numeric(2) NOT NULL,
<br>
cod_rrhh_importacion integer NOT NULL,
<br>
cuil_cuit numeric(11) NOT NULL,
<br>
cod_cargo_universidad character(4) NOT NULL,
<br>
cod_rrhh_estado_laboral integer NOT NULL,
<br>
cod_rrhh_estado_cargo character(1),
<br>
cod_rrhh_tipo_planta character(1) NOT NULL,
<br>
cod_rrhh_situacion_laboral integer NOT NULL,
<br>
cod_rrhh_agrupamiento_no_docente character(1),
<br>
cod_rrhh_nivel_ensenianza integer NOT NULL,
<br>
grado numeric(1) NOT NULL,
<br>
horas_dedicacion numeric(2) NOT NULL,
<br>
meses_antiguedad numeric(3) NOT NULL,
<br>
anios_antiguedad numeric(2) NOT NULL,
<br>
fecha_alta date NOT NULL,
<br>
fecha_baja date,
<br>
cod_dependencia numeric(2) NOT NULL,
<br>
cod_sub_dependencia numeric(2) NOT NULL,
<br>
programa numeric(2) NOT NULL,
<br>
subprograma numeric(2) NOT NULL,
<br>
proyecto numeric(2) NOT NULL,
<br>
actividad numeric(2) NOT NULL,
<br>
jefatura character(1) NOT NULL,
<br>
cod_rrhh_equivalencia_cargo integer NOT NULL,
<br>
cod_rrhh_escalafon character(1) NOT NULL,
<br>
numero_cargo_persona integer,
<br>
dedicacion_docente numeric(5,2),
<br>
dedicacion_investigacion numeric(5,2),
<br>
dedicacion_extension numeric(5,2),
<br>
dedicacion_gestion numeric(5,2),
<br>
CONSTRAINT rrhh_cargos_pkey PRIMARY KEY (numero_cargo,
cod_rrhh_importacion),
<br>
CONSTRAINT rrhh_cargos_cod_cargo_universidad_fkey FOREIGN KEY
(cod_cargo_universidad, cod_rrhh_escalafon, cod_rrhh_importacion)
<br>
REFERENCES rrhh_escalafones_universidades (cod_cargo_universidad,
cod_rrhh_escalafon, cod_rrhh_importacion) MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT rrhh_cargos_cod_fuente_financiamiento_fkey FOREIGN KEY
(cod_fuente_financiamiento)
<br>
REFERENCES fuentes_financiamiento (cod_fuente_financiamiento)
MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT rrhh_cargos_cod_ona_rama_fkey FOREIGN KEY (cod_ona_rama,
cod_ona_disciplina, cod_ona_area)
<br>
REFERENCES ona_jerarquias (cod_ona_rama, cod_ona_disciplina,
cod_ona_area) MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT rrhh_cargos_cod_ona_unidad_academica_fkey FOREIGN KEY
(cod_ona_unidad_academica)
<br>
REFERENCES ona_unidades_academicas (cod_ona_unidad_academica)
MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT rrhh_cargos_cod_rrhh_agrupamiento_no_docente_fkey FOREIGN
KEY (cod_rrhh_agrupamiento_no_docente)
<br>
REFERENCES rrhh_agrupamientos_no_docentes
(cod_rrhh_agrupamiento_no_docente) MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT rrhh_cargos_cod_rrhh_equivalencia_cargo_fkey FOREIGN KEY
(cod_rrhh_equivalencia_cargo, cod_rrhh_escalafon)
<br>
REFERENCES rrhh_equivalencias_cargos
(cod_rrhh_equivalencia_cargo, cod_rrhh_escalafon) MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT rrhh_cargos_cod_rrhh_estado_cargo_fkey FOREIGN KEY
(cod_rrhh_estado_cargo)
<br>
REFERENCES rrhh_estados_cargos (cod_rrhh_estado_cargo) MATCH
SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT rrhh_cargos_cod_rrhh_estado_laboral_fkey FOREIGN KEY
(cod_rrhh_estado_laboral)
<br>
REFERENCES rrhh_estados_laborales (cod_rrhh_estado_laboral) MATCH
SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT rrhh_cargos_cod_rrhh_nivel_ensenianza_fkey FOREIGN KEY
(cod_rrhh_nivel_ensenianza)
<br>
REFERENCES rrhh_niveles_ensenianza (cod_rrhh_nivel_ensenianza)
MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT rrhh_cargos_cod_rrhh_situacion_laboral_fkey FOREIGN KEY
(cod_rrhh_situacion_laboral)
<br>
REFERENCES rrhh_situaciones_laborales
(cod_rrhh_situacion_laboral) MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT rrhh_cargos_cod_rrhh_tipo_planta_fkey FOREIGN KEY
(cod_rrhh_tipo_planta)
<br>
REFERENCES rrhh_tipos_planta (cod_rrhh_tipo_planta) MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT rrhh_cargos_cuil_cuit_fkey FOREIGN KEY (cuil_cuit,
cod_rrhh_importacion)
<br>
REFERENCES rrhh_datos_personales (cuil_cuit,
cod_rrhh_importacion) MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT
<br>
) ;
<br>
-- cantidad de registros: 1.749.254
<br>
<br>
<br>
CREATE TABLE rrhh_escalafones_universidades
<br>
(
<br>
cod_cargo_universidad character(4) NOT NULL,
<br>
cod_rrhh_equivalencia_cargo integer NOT NULL,
<br>
cod_rrhh_escalafon character(1) NOT NULL,
<br>
cod_rrhh_importacion integer NOT NULL,
<br>
cod_rrhh_nivel_ensenianza integer NOT NULL,
<br>
descripcion character varying(30) NOT NULL,
<br>
dedicacion character varying(30) NOT NULL,
<br>
horas_dedicacion numeric(2) NOT NULL,
<br>
sueldo_basico numeric(10,2) NOT NULL,
<br>
remunerativo_bonificable numeric(10,2) NOT NULL,
<br>
remunerativo_no_bonificable numeric(10,2) NOT NULL,
<br>
no_remunerativo_bonificable numeric(10,2) NOT NULL,
<br>
no_remunerativo_no_bonificable numeric(10,2) NOT NULL,
<br>
otra_remuneraciones numeric(10,2) NOT NULL,
<br>
decreto_1610 numeric(10,2) NOT NULL,
<br>
gastos_representacion numeric(10,2) NOT NULL,
<br>
CONSTRAINT rrhh_escalafones_universidades_pkey PRIMARY KEY
(cod_cargo_universidad, cod_rrhh_escalafon, cod_rrhh_importacion),
<br>
CONSTRAINT
rrhh_escalafones_universidades_cod_rrhh_equivalencia_cargo_fkey FOREIGN
KEY (cod_rrhh_equivalencia_cargo, cod_rrhh_escalafon)
<br>
REFERENCES rrhh_equivalencias_cargos
(cod_rrhh_equivalencia_cargo, cod_rrhh_escalafon) MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT rrhh_escalafones_universidades_cod_rrhh_importacion_fkey
FOREIGN KEY (cod_rrhh_importacion)
<br>
REFERENCES rrhh_importaciones (cod_rrhh_importacion) MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT
rrhh_escalafones_universidades_cod_rrhh_nivel_ensenianza_fkey FOREIGN
KEY (cod_rrhh_nivel_ensenianza)
<br>
REFERENCES rrhh_niveles_ensenianza (cod_rrhh_nivel_ensenianza)
MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT
<br>
) ;
<br>
-- cantidad de registros: 24.063
<br>
<br>
<br>
CREATE TABLE rrhh_cubo_publicado_810
<br>
(
<br>
cod_rrhh_importacion integer,
<br>
cod_pedido integer,
<br>
cod_institucion integer,
<br>
periodo date,
<br>
fecha_desde timestamp without time zone,
<br>
fecha_publicacion timestamp with time zone
<br>
) ;
<br>
-- cantidad de registros: 283
<br>
<br>
<br>
CREATE TABLE rrhh_detalles_liquidaciones_haberes
<br>
(
<br>
cod_rrhh_concepto_liquidacion_haberes numeric(6) NOT NULL,
<br>
cod_rrhh_importacion integer NOT NULL,
<br>
numero_cargo numeric(9) NOT NULL,
<br>
importe numeric(12,2) NOT NULL,
<br>
anio_retroactivo numeric(4) NOT NULL,
<br>
mes_retroactivo numeric(2) NOT NULL,
<br>
CONSTRAINT
rrhh_detalles_liquidaciones_h_cod_rrhh_concepto_liquidacio_fkey FOREIGN
KEY (cod_rrhh_concepto_liquidacion_haberes, cod_rrhh_importacion)
<br>
REFERENCES rrhh_conceptos_liquidaciones_haberes
(cod_rrhh_concepto_liquidacion_haberes, cod_rrhh_importacion) MATCH
SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT
rrhh_detalles_liquidaciones_haberes_cod_rrhh_importacion_fkey FOREIGN
KEY (cod_rrhh_importacion)
<br>
REFERENCES rrhh_importaciones (cod_rrhh_importacion) MATCH SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT,
<br>
CONSTRAINT rrhh_detalles_liquidaciones_haberes_numero_cargo_fkey
FOREIGN KEY (numero_cargo, cod_rrhh_importacion)
<br>
REFERENCES rrhh_cargos (numero_cargo, cod_rrhh_importacion) MATCH
SIMPLE
<br>
ON UPDATE RESTRICT ON DELETE RESTRICT
<br>
) ;
<br>
-- cantidad de registros: 29.566.415
<br>
<br>
<br>
Consulta:
<br>
---------
<br>
<br>
explain analyze
<br>
select t.periodo,
<br>
t.cod_institucion,
<br>
ca.numero_cargo,
<br>
ca.cuil_cuit,
<br>
ca.cod_rrhh_escalafon,
<br>
ca.cod_cargo_universidad,
<br>
eu.descripcion as categ_univ_descripcion,
<br>
eu.dedicacion as categ_univ_dedicacion,
<br>
ca.cod_rrhh_equivalencia_cargo,
<br>
ca.cod_ona_unidad_academica,
<br>
ca.cod_fuente_financiamiento,
<br>
ca.cod_rrhh_estado_laboral,
<br>
ca.cod_rrhh_estado_cargo,
<br>
ca.cod_rrhh_tipo_planta,
<br>
ca.cod_rrhh_situacion_laboral,
<br>
ca.cod_rrhh_nivel_ensenianza,
<br>
ca.meses_antiguedad,
<br>
ca.horas_dedicacion,
<br>
ca.numero_cargo_persona as nro_cargo_pers,
<br>
ca.cod_rrhh_agrupamiento_no_docente,
<br>
d.cod_rrhh_concepto_liquidacion_haberes,
<br>
d.anio_retroactivo,
<br>
d.mes_retroactivo,
<br>
d.importe,
<br>
1 as Cant_ConceptosXCargos from rrhh_cargos ca,
<br>
rrhh_escalafones_universidades eu,
<br>
rrhh_cubo_publicado_810 t,
<br>
rrhh_detalles_liquidaciones_haberes d
<br>
where t.cod_institucion<>7 and
<br>
ca.cod_rrhh_importacion=t.cod_rrhh_importacion
<br>
and eu.cod_cargo_universidad = ca.cod_cargo_universidad
<br>
and eu.cod_rrhh_importacion = ca.cod_rrhh_importacion
<br>
and eu.cod_rrhh_escalafon = ca.cod_rrhh_escalafon
<br>
and (ca.cod_rrhh_escalafon = 'D') and (ca.cod_rrhh_nivel_ensenianza = 1
)
<br>
and d.cod_rrhh_importacion=t.cod_rrhh_importacion
<br>
and d.numero_cargo = ca.numero_cargo
<br>
<br>
<br>
Explain Analyze:
<br>
-----------------
<br>
<br>
<a class="moz-txt-link-freetext" href="http://explain-analyze.info/query_plans/1499-nicolasdom-siu">http://explain-analyze.info/query_plans/1499-nicolasdom-siu</a>
<br>
<br>
<br>
Antes de correr la consulta se habia realizado:
<br>
analyze rrhh_cargos;
<br>
analyze rrhh_escalafones_universidades;
<br>
analyze rrhh_cubo_publicado_810;
<br>
analyze rrhh_detalles_liquidaciones_haberes ;
<br>
<br>
<br>
Muchas Gracias!
<br>
<br>
Nicolas.
<br>
<br>
</blockquote>
--
<br>
TIP 4: No hagas 'kill -9' a postmaster
<br>
<br>
<br>
</blockquote>
</body>
</html>