Subject Re: 3rd attempt: HELP needed for optimization
Author mircostange
Yes, speed is the essential problem. The query produces the correct
results, so this is not an issue.

In case you really want to see the query :-)
here:
----------------------------
CREATE PROCEDURE ProPXSelectProfileResults(sampleGroupID DOUBLE
PRECISION,profileNo CHAR(10), lookupRefVal SMALLINT)
RETURNS (sampleNo CHAR(35),sampleTypeNo CHAR(10), assayCategory CHAR
(30), assayNo CHAR(30), assayName CHAR(50), assayCategoryDisplayPos
NUMERIC, assayDisplayPos NUMERIC, resultID DOUBLE PRECISION, val CHAR
(50), displayVal CHAR(50), unitNo CHAR(15), refVal DOUBLE PRECISION,
refLow DOUBLE PRECISION, refHigh DOUBLE PRECISION, displayRefVal CHAR
(50), displayRefLow CHAR(50), displayRefHigh CHAR(50), sampleorderID
DOUBLE PRECISION)
AS
DECLARE VARIABLE assayID DOUBLE PRECISION;
DECLARE VARIABLE unitID DOUBLE PRECISION;
DECLARE VARIABLE sampleTypeID DOUBLE PRECISION;
DECLARE VARIABLE instrumentID DOUBLE PRECISION;
DECLARE VARIABLE patientAge NUMERIC;
DECLARE VARIABLE patientSex CHAR(1);
BEGIN
patientAge = NULL;
patientSex = NULL;

FOR SELECT
Sample.SampleNo,
SampleType.sampleTypeNo,
AssayCategory.name,
Assay.assayNo,
Assay.name,
AssayCategory.displayPos,
ProfileAssay.displayPos,
Result.resultID,
Result.val,
Result.displayVal,
Unit.unitNo,
Result.unitID,
Assay.assayID,
SampleType.sampleTypeID,
Test.instrumentID,
SampleOrder.SampleOrderID,
Patient.age,
Patient.sex
FROM
Profile
JOIN ProfileAssay ON
ProfileAssay.ProfileID=profile.profileID
LEFT OUTER JOIN AssayCategory ON
AssayCategory.assayCategoryID=ProfileAssay.assayCategoryID
JOIN Assay ON ProfileAssay.assayID=Assay.assayID
LEFT OUTER JOIN SampleType ON
ProfileAssay.sampleTypeID=sampleType.sampleTypeID
LEFT OUTER JOIN
(
SampleGroup
JOIN Sample ON
SampleGroup.sampleGroupID=Sample.sampleGroupID AND
Sample.sampleGroupID=:sampleGroupID
LEFT OUTER JOIN SampleOrder ON
SampleOrder.sampleID=Sample.sampleID AND
SampleOrder.assayID=ProfileAssay.assayID
LEFT OUTER JOIN TestRequest ON
TestRequest.sampleorderID=SampleOrder.sampleOrderID
LEFT OUTER JOIN Test ON
TestRequest.testID=Test.testID
LEFT OUTER JOIN Result ON
Result.testRequestID=TestRequest.testRequestID
LEFT OUTER JOIN Unit ON
Result.unitID=Unit.unitID
LEFT OUTER JOIN Patient ON
SampleGroup.patientID=Patient.patientID
)
ON Sample.sampleTypeID=ProfileAssay.sampleTypeID
WHERE
Profile.profileNo=:profileNo
ORDER BY
AssayCategory.displayPos, ProfileAssay.displayPos
INTO

:sampleNo,:sampleTypeNo,:assayCategory,:assayNo,:assayName,:as
sayCategoryDisplayPos,:assayDisplayPos,:resultID,:val,:displayVal,:uni
tNo,:unitID,:assayID,:sampleTypeID,:instrumentID,:sampleOrderID,:patie
ntAge,:patientSex
DO
BEGIN
IF (lookupRefVal>0) THEN BEGIN
EXECUTE PROCEDURE ProPXGetReferenceValue
(assayID,sampleTypeID,instrumentID,patientSex,patientAge,unitID)
RETURNING_VALUES refVal,refHigh,refLow;
displayRefVal=ProPXFormatNVal(refVal,'');
displayRefLow=ProPXFormatNVal(refLow,'');
displayRefHigh=ProPXFormatNVal(refHigh,'');

END ELSE BEGIN
refVal = NULL;
refLow = NULL;
refHigh = NULL;
displayRefVal = NULL;
displayRefLow = NULL;
displayRefHigh = NULL;
END
suspend;
END
END!!

-----

XAK* indeces are unique. What do you mean by "size" of assay table?
Number of rows or columns?