Query optimizado sin función de fechas_clase.
This commit is contained in:
@@ -32,8 +32,8 @@ try {
|
||||
// Define relevant columns
|
||||
$relevant_columns = [
|
||||
'registro_id',
|
||||
'fechas.registro_fecha_ideal',
|
||||
'fechas.horario_id',
|
||||
'fechas.fecha as registro_fecha_ideal',
|
||||
'horario.horario_id',
|
||||
'profesor.profesor_id',
|
||||
'salon',
|
||||
'profesor_clave',
|
||||
@@ -85,7 +85,7 @@ try {
|
||||
"SELECT horario_id FROM horario
|
||||
WHERE horario_dia IN ($DaysWeek)
|
||||
AND periodo_id IN ($PeriodosHorarios)
|
||||
AND :fecha_inicio BETWEEN horario_fecha_inicio AND COALESCE(horario_fecha_fin, :fecha_fin)
|
||||
AND (:fecha_inicio, :fecha_fin) OVERLAPS (horario_fecha_inicio, COALESCE(horario_fecha_fin, :fecha_fin))
|
||||
AND facultad_id = COALESCE(:facultad_id, facultad_id)",
|
||||
array_merge($fechas, [
|
||||
':facultad_id' => $user->facultad['facultad_id'],
|
||||
@@ -95,15 +95,7 @@ try {
|
||||
|
||||
$Horarios = $db->query(
|
||||
"WITH fechas AS (
|
||||
SELECT fechas_clase(
|
||||
_horario_id => h.horario_id,
|
||||
_todos => false,
|
||||
_fecha_inicio => :fecha_inicio,
|
||||
_fecha_fin => :fecha_fin
|
||||
) AS registro_fecha_ideal, h.horario_id, profesor_id
|
||||
FROM horario h
|
||||
JOIN horario_profesor USING (horario_id)
|
||||
WHERE horario_id IN ($HorariosID)
|
||||
SELECT generate_series(:fecha_inicio, :fecha_fin, '1 day'::INTERVAL)::DATE AS fecha
|
||||
)
|
||||
SELECT
|
||||
$RelevantColumns,
|
||||
@@ -112,16 +104,18 @@ try {
|
||||
ELSE 'primary'
|
||||
END AS color
|
||||
FROM horario
|
||||
JOIN fechas USING (horario_id)
|
||||
JOIN horario_profesor USING (horario_id)
|
||||
JOIN fechas ON EXTRACT(DOW FROM fechas.fecha) = horario.horario_dia
|
||||
JOIN profesor USING (profesor_id)
|
||||
JOIN salon USING (salon_id)
|
||||
LEFT JOIN REGISTRO ON
|
||||
REGISTRO.profesor_id = PROFESOR.profesor_id AND
|
||||
REGISTRO.horario_id = FECHAS.horario_id AND
|
||||
FECHAS.registro_fecha_ideal = REGISTRO.registro_fecha_ideal
|
||||
REGISTRO.profesor_id = horario_profesor.profesor_id AND
|
||||
REGISTRO.horario_id = horario.horario_id AND
|
||||
REGISTRO.registro_fecha_ideal = fechas.fecha
|
||||
LEFT JOIN usuario ON usuario.usuario_id = REGISTRO.supervisor_id
|
||||
JOIN estado_supervisor ON estado_supervisor.estado_supervisor_id = COALESCE(REGISTRO.estado_supervisor_id, 0)
|
||||
ORDER BY fechas.registro_fecha_ideal, horario_hora",
|
||||
WHERE horario.horario_id IN ($HorariosID)
|
||||
ORDER BY fechas.fecha, horario_hora",
|
||||
$fechas
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user