query codeigniter postgres

0

I have a problem with codeigniter and postgresql, my database has around 230,000 records, and I'm doing a report which points to a view that is made up of 4 tables,

The problem starts when I ask a query to that view on short dates for example from 02/23/2018 to 02/26/2018.

this database has records since October 2016

this is the code I use for the query

public function reporteGeneral($condicionesAdicionales="", $datos=array(), $x=""){
  extract($datos);
  if(isset($fecha_inicio) &&  $fecha_inicio != ''){
    $fecha_inicio = $fecha_inicio.' 00:00:00';
  }
  if(isset($fecha_fin) && $fecha_fin != ''){
    $fecha_fin = $fecha_fin.' 23:59:59';
  }
  $SQL = "
        SELECT
          (SELECT count(*) 
            FROM dean_eapg.v_evaluaciones 
               WHERE
              ( codigo_descripcion_situacion in('1','2','3') )
            AND
            ( codigo_genero in('1','2') )
            {$condicionesAdicionales}
            AND
            ( fecha_registro >= '{$fecha_inicio}'  AND fecha_registro <= '{$fecha_fin}' ) 

          ) AS TOTAL,

          (SELECT count(*) 
          FROM dean_eapg.v_evaluaciones 
          WHERE
            ( codigo_descripcion_situacion ='1' )
            AND
            ( codigo_genero in('1','2') )
            {$condicionesAdicionales}
            AND
            ( fecha_registro >= '{$fecha_inicio}'  AND fecha_registro <= '{$fecha_fin}') ) AS TOTAL_A,
          (SELECT count(*) 
          FROM dean_eapg.v_evaluaciones 
          WHERE
            (codigo_descripcion_situacion ='2')
            AND
            (codigo_genero in ('1','2'))
            {$condicionesAdicionales}
            AND
            (fecha_registro >= '{$fecha_inicio}'  AND fecha_registro <= '{$fecha_fin}')) AS TOTAL_B,
          (SELECT count(*) 
          FROM dean_eapg.v_evaluaciones 
          WHERE
            ( codigo_descripcion_situacion ='3' )
            AND
            ( codigo_genero in('1','2') )
            {$condicionesAdicionales}
            AND
            ( fecha_registro >= '{$fecha_inicio}'  AND fecha_registro <= '{$fecha_fin}' ) ) AS TOTAL_C      
  ";


  $query = $this->db->query($SQL);
  $resultado = $query->row_array();
  //prp($this->db->last_query(),1);
  return $resultado;

When I consult dates close to the origin of the load, it performs without problems in a short time, but more distant dates (2018) take a long time.

will you know what that is? Could it be the view that generates that slowness?

    
asked by Angel Gutierrez 27.02.2018 в 14:46
source

0 answers