Como mejorar velocidad en una Vista
Buenas tardes, estoy utilizando Firebird, con delphi 6,
Mi duda es la siguiente hice unos reportes basados en una vista a la cual le llame vistakardex en la cual al usar una campo con el nombre fecha tarda hasta 10 minutos y no presenta el reporte con informacion, al principio pense que era debido al reporte, pero es la vista que al poner el filtro de select * from vistakardex where fecha ='01/26/2007' se tarda muuuuuucho tiempo en presentar informacion. La vista hace lo siguiente tengo una tabla productos y de movimientos de inventario entradas y salidas(mpdoc2) y traigo informacion de otras tablas la cual es optativa si existe el nombre del producto y unos agrupadores a los que llamo clas1..5 y otra tabla que tiene la informacion. uso left join ya que si no existe relacion necesito que si se presente el producto. Alguien podria darme algun tip para mejor la velocidad de la vista que presento a continuacion. CREATE VIEW VISTAKARDEX( NATURALEZACA, GRUPODOC, SERIE, FOLIO, ALMACEN, FECHA, UNIDADES, UNIDAD, COSTOCOSTOPROMEDIO, AFECTAINV, FACTORCONVERSION, TIPODOC, CODIGO, NOMBRE_PROD, TIPODOCDESC, NOMBREPROD, ULTIMO_COSTO, CLAS1, CLAS2, CLAS3, CLAS4, CLAS5, FECHACREACION, HORACREACION, CLAS1DESCRIPCION, CLAS2DESCRIPCION, CLAS3DESCRIPCION, CLAS4DESCRIPCION, CLAS5DESCRIPCION, UNIDAD_PRIMARIA, UNIDAD_SECUNDARIA, COSTO_PROM, COSTOCOSTOULTIMO, NETOPARTIDA, AFECTACXCOCXP, AFECTACOMPRAVENTA) AS SELECT MPDOC2.NATURALEZACA, MPDOC2.GRUPODOC, MPDOC2.SERIE, MPDOC2.FOLIO, MPDOC2.ALMACEN, MPDOC2.FECHA, MPDOC2.UNIDADES, MPDOC2.UNIDAD, MPDOC2.COSTOCOSTOPROMEDIO, MPDOC2.AFECTAINV, PRODUCTOS.factor_c, MPDOC2.TIPODOC, PRODUCTOS.CODIGO, PRODUCTOS.NOMBRE, TIPODOC.nombre, PRODUCTOS.nombre , PRODUCTOS.ultimo_costo, Productos.clas1, Productos.clas2, Productos.clas3, Productos.clas4, Productos.clas5, MPDOC1.fechacreacion, MPDOC1.horacreacion, CLASPROD1.descripcion, CLASPROD2.descripcion, CLASPROD3.descripcion, CLASPROD4.descripcion, CLASPROD5.descripcion, Productos.unidad_p, Productos.unidad_s, Productos.costo_prom, MPDOC2.costoultimocosto, MPDOC2.netopartida, MPDOC2.afectacxcocxp, MPDOC2.afectacompraventa FROM PRODUCTOS PRODUCTOS_1 left outer JOIN MPDOC2 ON (MPDOC2.CODPRODUCTO = PRODUCTOS_1.CODIGO) LEFT JOIN MPDOC1 ON (MPDOC1.FOLIO = MPDOC2.FOLIO) AND (MPDOC1.SERIE = MPDOC2.SERIE) AND (MPDOC1.TIPODOC = MPDOC2.TIPODOC) AND (MPDOC1.NATURALEZACA = MPDOC2.NATURALEZACA) AND (MPDOC1.SUCURSAL = MPDOC2.SUCURSAL) LEFT join tipodoc on ( tipodoc.tipo =mpdoc2.tipodoc) LEFT join CLASPROD1 on ( CLASPROD1.codigo=PRODUCTOS.cLAS1 ) LEFT join CLASPROD2 on ( CLASPROD2.codigo=PRODUCTOS.cLAS2) LEFT join CLASPROD3 on ( CLASPROD3.codigo=PRODUCTOS.cLAS3) LEFT join CLASPROD4 on ( CLASPROD4.codigo=PRODUCTOS.cLAS4) LEFT join CLASPROD5 on ( CLASPROD5.codigo=PRODUCTOS.cLAS5) where (mpdoc2.afectainv='S' or (mpdoc2.afectainv is null )) AND(MPDOC2.estatus<>'C' ) ; |
Supongo que el problema está en que tienes muchos joins y que hay muchos registros. Prueba a crear índices sobre los campos que incluyes en los where (si no los tienes), sobre todo en el de fecha, que dices que es el que hace que vaya lenta la consulta.
|
El campo Fecha ¿lo tienes declarado como Date o como String? porque lo pasas como String....
Saludos |
La franja horaria es GMT +2. Ahora son las 19:41:10. |
Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi