Performance Ideas

From: "Eric" <emayo(at)pozicom(dot)net>
To: pgsql-sql(at)postgresql(dot)org
Subject: Performance Ideas
Date: 2002-06-25 19:37:39
Message-ID: afagq4$mcm$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I have a SQL which uses a function for one of the returned rows. This
stored function does calculations that are expensive & slow. I am looking
for ways to speed up this query but having no luck.

Any SQL geniuses out there help me with this?

select
o.orderid,
ol.itemcode,
ol.itemname,
ol.uom,
qty_available( ol.itemcode, ol.uom ) as "Qty On Hand"

from
orders o,
orderlines ol,

where
o.status = 'OPEN' and
ol.orderid = o.orderid and
qty_onhand( ol.itemcode, ol.uom ) > 0;

The function, qty_onhand, calculates the Qty on hand and returns a value in
units of measure passed (ol.uom). This function is an expensive function to
use -- degrades performance. With out the function in the WHERE or SELECT
clause, performances is acceptable.

I get marginally better performance if I "select into temporary table"
without the function and then run a query on the temporary table which
includes the qty_onhand function.

I am trying to present the user with a list of open orders that are "READY"
to be fulfilled which requires me to do a "stock level check."

My fall back solution is to make the user enter some pre-query information
like the orderid she is trying to ship against but my customer really likes
the current view they have which shows all open orders that are READY to be
fulfilled.

Any ideas??!?!?! Tricks of the trade?!?!?!

Also, side note, I tried creating views assuming PostgreSQL would optimize
the view after a vacuum but it does not. Also, the function seems faster in
the temporary table, why? Why wouldn't the funciton only evaluate values
that match the first 2 criteria (OPEN and ol.orderid = o.orderid)? It's as
if the qty_onhand is evaluating ALL records in the orderlines (ol) table.

Thanks , Eric

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Eric 2002-06-25 19:48:10 Re: Limiting database size
Previous Message Eric 2002-06-25 19:25:32 2 Selects 1 is faster, why?