🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.interbase.sql
Article #570

Join takes too much time

#570
From: Olivier Peter
Date: Thu, 04 Oct 2007 07:32
65 lines
2341 bytes
I have a Table T_EMPLOYEE_GENERAL which i want to combine with a stored
procedure SP_EMPLOYEE_WORKPOINTSHISTORY.
The stored calculates the sum of points the employee has worked during
certain period grouped by Employee and Date.

The stored procedure itself takes about 1 second to calculate as does the
retrieval of the employees.
The table contains about 30 Employees who do about 30 jobs (for the point
count) a day.
Still the following query takes about 15 seconds to finish.

SELECT
  EG.EG_EMPLOYEEID,
  EG.EG_EMPLOYEEFULLNAME,
  EWPH.EWPH_WORKPOINTS
FROM
  T_EMPLOYEE_GENERAL EG
  LEFT JOIN SP_EMPLOYEE_WORKPOINTSHISTORY(1, 'SEP-26-2007','SEP-26-2007')
EWPH
    ON (EG.EG_EMPLOYEEID = EWPH.EWPH_EMPLOYEEID)
WHERE (EG.EG_EMPLOYEELOCATIONID = 1)


Stored Procedure:

CREATE PROCEDURE "SP_EMPLOYEE_WORKPOINTSHISTORY"
(
  "LOCATIONID" INTEGER,
  "WORKDATEFROM" DATE,
  "WORKDATETILL" DATE
)
RETURNS
(
  "EWPH_EMPLOYEEID" INTEGER,
  "EWPH_WORKDATE" DATE,
  "EWPH_WORKPOINTS" INTEGER
)
AS
BEGIN
  FOR
    SELECT
      GH_EMPREADY,
      GH_DATEREADY,
      SUM(GH_POINTSINV)
    FROM
      T_BASKET_GENERAL_HISTORY
    WHERE
      (GH_READYOK = 1)
    AND
      (GH_SCREADY = :LocationID)
    AND
      (GH_DATEREADY >= :WorkDateFrom)
    AND
      (GH_DATEREADY <= :WorkDateTill)
    GROUP BY
      GH_EMPREADY,
      GH_DATEREADY
    INTO
      EWPH_EMPLOYEEID, EWPH_WORKDATE, EWPH_WORKPOINTS
  DO
  SUSPEND;
  END

Olivier Peter
Technical Details
Message-ID: <47049703$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 114a0e,cd7986aef1014d63,start
X-Google-Attributes: gid114a0e,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Olivier Peter" <peterolivier@hotmail.com>
Sender: "Olivier Peter" <peterolivier@hotmail.com>
Reply-To: "Olivier Peter" <peterolivier@hotmail.com>
Subject: Join takes too much time
Newsgroups: borland.public.interbase.sql
X-User-Info: 213.219.171.30     
NNTP-Posting-Host: 207.105.83.66
Message-ID: <47049703$1@newsgroups.borland.com>
Date: 4 Oct 2007 00:32:19 -0700
X-Trace: newsgroups.borland.com 1191483139 207.105.83.66 (4 Oct 2007 00:32:19 -0700)
Lines: 66
Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx02.iad01.newshosting.com!newshosting.com!203.109.252.33.MISMATCH!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail