Subject | Re: [firebird-support] Optimizing this select Query |
---|---|
Author | Alexandre Benson Smith |
Post date | 2014-04-10T22:21:55Z |
SELECT
Sum(SALEITEMS.QUANTITY),
Sum(SALEITEMS.QUANTITY * SALEITEMS.COSTPRICEEX)
FROM
SALES SALES
INNER JOIN SALEITEMS SALEITEMS ON SALES.LINECODE = SALEITEMS.LINECODE
WHERE
SALES.POSTSTATUS = 'Posted' AND
SALES.SALE_DATE BETWEEN :vStartDate AND :vEndDate AND
SALEITEMS.SKU = :vSKU AND
SALES.CASHCREDIT = 'Cash'
The first thing...
Are the indices statistics up to date ?
If so...
You could try this one:
SELECT
Sum(SALEITEMS.QUANTITY),
Sum(SALEITEMS.QUANTITY * SALEITEMS.COSTPRICEEX)
FROM
SALES SALES
INNER JOIN SALEITEMS SALEITEMS ON SALES.LINECODE = SALEITEMS.LINECODE
WHERE
SALES.POSTSTATUS = 'Posted' AND
SALES.SALE_DATE BETWEEN :vStartDate AND :vEndDate AND
SALEITEMS.SKU+0 = :vSKU AND
SALES.CASHCREDIT = 'Cash'
and see if it uses the Date index.
see you !