Ad Widget

Collapse

Performance troubles in API

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vadimipatov
    Junior Member
    Zabbix Certified Specialist
    • Oct 2012
    • 7

    #1

    Performance troubles in API

    Query in function fetchLatestValues(array $serviceIds, $beforeTime) is VERY SLOW. Usage of LEFT OUTER JOIN there does not seems as best decision. Is it possible to optimize this query?

    Query:
    Code:
    SELECT 
      sa.serviceid,
      sa.value 
    FROM
      service_alarms sa 
      LEFT OUTER JOIN service_alarms sa2 
        ON (
          sa.serviceid = sa2.serviceid 
          AND sa.clock < sa2.clock 
          AND sa2.clock < '1352728919'
        ) 
    WHERE sa2.servicealarmid IS NULL 
      AND sa.clock < '1352728919' 
      AND (
        sa.serviceid IN (
          '3',
          '13',
          '34',
          '36',
          '38',
          '40',
          '41',
          '42',
          '43',
          '44',
          '45',
          '46',
          '49',
          '50',
          '51',
          '53',
          '54',
          '55',
          '56',
          '57',
          '58',
          '59',
          '60',
          '61',
          '62',
          '63',
          '64',
          '65',
          '66',
          '67',
          '68',
          '69',
          '70',
          '71',
          '72',
          '73',
          '74',
          '75',
          '76',
          '77',
          '80',
          '81'
        )
      ) 
    ORDER BY sa.servicealarmid
    And there are several screenshots from SQLyog:
    Attached Files
Working...