Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/12/2012, 13:58
EduardoSk
 
Fecha de Ingreso: diciembre-2012
Mensajes: 1
Antigüedad: 11 años, 4 meses
Puntos: 0
Consulta Demora mas de 10 minutos

Hola tengo un query que tarda mas de 10 minutos y termina expirando del PHP

La tabla es la siguiente y tiene 49000 registros

Código MySQL:
Ver original
  1. CREATE TABLE IF NOT EXISTS `os_dispatch_closed` (
  2.   `EnterpriseDocumentId` text,
  3.   `SourceSystem` text,
  4.   `BusinessProcess` text,
  5.   `ObjectChangeActionType` text,
  6.   `IntegrationCreationDateTime` datetime DEFAULT NULL,
  7.   `Americas` text,
  8.   `EMEA` text,
  9.   `APG` text,
  10.   `SenderId` text,
  11.   `SenderName` text,
  12.   `OriginalPartnerId` text,
  13.   `OriginalPartnerName` text,
  14.   `PurposeCode` text,
  15.   `SPAccount` text,
  16.   `ActivityDescription` text,
  17.   `ActivityType` text,
  18.   `AdditionalInformation` text,
  19.   `BeginningTime` datetime DEFAULT NULL,
  20.   `CallNumber` text,
  21.   `CannedMessages` text,
  22.   `DiagnosticCode` text,
  23.   `Instructions` text,
  24.   `RecommendedType` text,
  25.   `ResolutionTime` datetime DEFAULT NULL,
  26.   `ServiceLevelAgreementConfirmation` text,
  27.   `ServiceRequestCommittedDate` text,
  28.   `ShipToRequest` text,
  29.   `WorkOrderNumber` text,
  30.   `WorkOrderRequestedServiceDate` datetime DEFAULT NULL,
  31.   `Severity` text,
  32.   `ActivityCreateDateTime` datetime DEFAULT NULL,
  33.   `Other` text,
  34.   `SpecialTerms` text,
  35.   `VersionOfWorkEffortIdentifier` text,
  36.   `ReliefDate` datetime DEFAULT NULL,
  37.   `ProductName` text,
  38.   `DeviceTagCustomer` text,
  39.   `DeviceTagDellService` text,
  40.   `DeviceTagOem` text,
  41.   `DeviceTagPpid` text,
  42.   `DeviceTagServiceProvider` text,
  43.   `AssetTag` text,
  44.   `SerialNumber` text,
  45.   `ProductIdentifier` text,
  46.   `Model` text,
  47.   `Type` text,
  48.   `Reading` text,
  49.   `AccountName` text,
  50.   `AddressLineOne` text,
  51.   `AddressLineTwo` text,
  52.   `AddressLineThree` text,
  53.   `City` text,
  54.   `Code` text,
  55.   `ContactName` text,
  56.   `Country` text,
  57.   `County` text,
  58.   `FirstName` text,
  59.   `LastName` text,
  60.   `Name` text,
  61.   `PostalCode` text,
  62.   `Province` text,
  63.   `PhysicalLocation1` text,
  64.   `PhysicalLocation2` text,
  65.   `PhysicalLocation3` text,
  66.   `State` text,
  67.   `StateProvince` text,
  68.   `CustomerPhone` text,
  69.   `ShipToContactTelephone` text,
  70.   `MarketingName` text,
  71.   `TLIPartNumber` text,
  72.   `Quantity` text,
  73.   `MachineTypeModelNumber` text,
  74.   `ActivityLineNumber` text,
  75.   `id_prestador` int(11) DEFAULT '0',
  76.   `observaciones` text NOT NULL,
  77.   `id_estado` int(11) NOT NULL DEFAULT '1',
  78.   `id_activitystatus` int(11) NOT NULL DEFAULT '0',
  79.   `FileID` text NOT NULL,
  80.   `fecha_registro` datetime NOT NULL,
  81.   PRIMARY KEY (`id`)
  82. );
y el query que estoy haciendo es este

Código MySQL:
Ver original
  1.     f.id,  
  2.     DATE_FORMAT(f.BeginningTime,'%d-%m-%Y %H:%i:%s') as fechacreacionsrv,
  3.     f.CallNumber as servicio,
  4.     f.WorkOrderNumber as nrocaso,
  5.     f.ResolutionTime as fecharta,
  6.     f.AdditionalInformation as sla,
  7.     f.City as localidad,
  8.     f.SerialNumber as nroserie,
  9.     f.Model as modelo,
  10.     modelos.model AS modeloReal,
  11.     AccountName as ctaem presa,
  12.     activitystatus.descripcion as estadolmk,
  13.     estado,razonsocial,
  14.     f.observaciones
  15. from  
  16.     modelos,
  17.     estados_os,
  18.     prestadores,
  19.     activitystatus,
  20.     (SELECT CallNumber, max(f echa_registro) as fechaupd  
  21.     FROM os_dispatch_closed by CallNumber) as x  
  22.     inner join os_dispatch_closed as f on f.CallNumber= x.CallNumber and f.fecha_registro= x.fechaupd
  23.     f.id_a ctivitystatus=activitystatus.id  
  24.     and f.id_estado=estados_os.id  
  25.     and f.id_prestador=prestadores.id  
  26.     and REPLACE(f.model,';','')=modelos.machinetype  
  27.     and f.id_acti vitystatus not like 82
  28. ORDER BY fecha_registro DESC;

como puedo optimizarlo?

Última edición por gnzsoloyo; 10/12/2012 a las 14:04 Razón: Código SQL sin etiquetar. Sin estructurado.