Subject | Re: Speed difference between TIBQuery and TIB_Query? |
---|---|
Author | sgharp |
Post date | 2004-05-22T18:00:52Z |
Gee. I don't know what else to tell you so I'll just post some code.
procedure TForm1.CalcItemUsage;
var
Extension,
Yield,
QtySold,
TotQtySold: double;
function CalcLegit(ParentExtension: double; Dataset: TIB_Query):
double;
//called recursively for each menu item
var
Ext: double;
qryLeg: TIB_Query;
begin
//calculate the extension which is the amount of the inventory
item used in this recipe
Ext := ParentExtension * SafeDivide((DataSet.FieldByName
('Quantity').asFloat * DataSet.FieldByName('Conversion').asFloat),
(DataSet.FieldByName('YieldQty').asFloat * DataSet.FieldByName
('Conversion2').asFloat));
//you have to create a tibquery since we are calling this
recursively
qryLeg := TIB_Query.Create(self);
try
//qryLeg.Database := dbaXM;
qryLeg.IB_Connection := conIB;
qryLeg.Active := False;
qryLeg.SQL.Clear;
//get the menu items that have this menu item as an ingredient
qryLeg.SQL.Add('select i.quantity, mi.itemname,
mi.yieldsizeid, mi.yieldqty, mi.sales, mi.menuitemid, s.conversion,
s2.conversion as conversion2');
qryLeg.SQL.Add('from xingredient i join xmenuitem mi on
i.menuitemid=mi.menuitemid join xsize s on i.sizeid=s.sizeid join
xsize s2 on mi.yieldsizeid=s2.sizeid where i.invitemid=' +
DataSet.FieldByName('MenuItemID').asString);
qryLeg.Open;
while not qryLeg.EOF do
begin
//call calclegit recursively passing the extension for this
menu item as the parent extension
Extension := CalcLegit(Ext, qryLeg);
QtySold := Extension * qryLeg.FieldByName('Sales').asFloat;
//add this menu item's usage to the totqtysold
TotQtySold := TotQtySold + QtySold;
qryLeg.Next;
end;
finally
qryLeg.Free;
end;
Result := Ext;
end;
begin
qryItem.Active := False;
qryItem.SQL.Clear;
//calc all items if the FRec.invitemid=0
if FRec.InvItemID = 0 then
qryItem.SQL.Add('select i.invitemid, i.menucostingyield,
menucostingquantity, s.conversion from xinvitem i join xsize s on
i.menucostingsizeid=s.sizeid')
else
qryItem.SQL.Add('select i.invitemid, i.menucostingyield,
menucostingquantity, s.conversion from xinvitem i join xsize s on
i.menucostingsizeid=s.sizeid where i.invitemid=' + IntToStr
(FRec.InvItemID));
qryItem.Open;
while not qryItem.EOF do
begin
TotQtySold := 0;
qryIngr.Active := False;
qryIngr.SQL.Clear;
//get the menu items that have this inventory item as an
ingredient
qryIngr.SQL.Add('select i.quantity, mi.itemname, mi.yieldsizeid,
mi.yieldqty, mi.sales, mi.menuitemid, s.conversion, s2.conversion as
conversion2');
qryIngr.SQL.Add('from xingredient i join xmenuitem mi on
i.menuitemid=mi.menuitemid join xsize s on i.sizeid=s.sizeid join
xsize s2 on mi.yieldsizeid=s2.sizeid where i.invitemid=' +
qryItem.FieldByName('InvItemID').asString);
qryIngr.Open;
while not qryIngr.Eof do
begin
//inventory items use the yield for the parent extension
Yield := (1 / (qryItem.FieldByName
('MenuCostingYield').asFloat / 100));
Extension := CalcLegit(Yield, qryIngr);
QtySold := Extension * qryIngr.FieldByName('Sales').asFloat;
//add this inventory item's usage to the totqtysold
TotQtySold := TotQtySold + QtySold;
qryIngr.Next;
end;
//total quantity sold is calculated using the base size so
convert it back to the recipe size
TotQtySold := SafeDivide(TotQtySold, qryItem.FieldByName
('MenuCostingQuantity').asFloat * qryItem.FieldByName
('Conversion').asFloat);
qryUpdate.Active := False;
qryUpdate.SQL.Clear;
//update the ideal usage field in the xinvitem table
qryUpdate.SQL.Add('update xinvitem set idealusage=' + FloatToStr
(TotQtySold) + ' where invitemid=' + qryItem.FieldByName
('invitemid').asString);
qryUpdate.ExecSQL;
qryItem.Next;
end;
ibtTrans.Commit;
end;
--- In IBObjects@yahoogroups.com, "Jason Wharton" <jwharton@i...>
wrote:
procedure TForm1.CalcItemUsage;
var
Extension,
Yield,
QtySold,
TotQtySold: double;
function CalcLegit(ParentExtension: double; Dataset: TIB_Query):
double;
//called recursively for each menu item
var
Ext: double;
qryLeg: TIB_Query;
begin
//calculate the extension which is the amount of the inventory
item used in this recipe
Ext := ParentExtension * SafeDivide((DataSet.FieldByName
('Quantity').asFloat * DataSet.FieldByName('Conversion').asFloat),
(DataSet.FieldByName('YieldQty').asFloat * DataSet.FieldByName
('Conversion2').asFloat));
//you have to create a tibquery since we are calling this
recursively
qryLeg := TIB_Query.Create(self);
try
//qryLeg.Database := dbaXM;
qryLeg.IB_Connection := conIB;
qryLeg.Active := False;
qryLeg.SQL.Clear;
//get the menu items that have this menu item as an ingredient
qryLeg.SQL.Add('select i.quantity, mi.itemname,
mi.yieldsizeid, mi.yieldqty, mi.sales, mi.menuitemid, s.conversion,
s2.conversion as conversion2');
qryLeg.SQL.Add('from xingredient i join xmenuitem mi on
i.menuitemid=mi.menuitemid join xsize s on i.sizeid=s.sizeid join
xsize s2 on mi.yieldsizeid=s2.sizeid where i.invitemid=' +
DataSet.FieldByName('MenuItemID').asString);
qryLeg.Open;
while not qryLeg.EOF do
begin
//call calclegit recursively passing the extension for this
menu item as the parent extension
Extension := CalcLegit(Ext, qryLeg);
QtySold := Extension * qryLeg.FieldByName('Sales').asFloat;
//add this menu item's usage to the totqtysold
TotQtySold := TotQtySold + QtySold;
qryLeg.Next;
end;
finally
qryLeg.Free;
end;
Result := Ext;
end;
begin
qryItem.Active := False;
qryItem.SQL.Clear;
//calc all items if the FRec.invitemid=0
if FRec.InvItemID = 0 then
qryItem.SQL.Add('select i.invitemid, i.menucostingyield,
menucostingquantity, s.conversion from xinvitem i join xsize s on
i.menucostingsizeid=s.sizeid')
else
qryItem.SQL.Add('select i.invitemid, i.menucostingyield,
menucostingquantity, s.conversion from xinvitem i join xsize s on
i.menucostingsizeid=s.sizeid where i.invitemid=' + IntToStr
(FRec.InvItemID));
qryItem.Open;
while not qryItem.EOF do
begin
TotQtySold := 0;
qryIngr.Active := False;
qryIngr.SQL.Clear;
//get the menu items that have this inventory item as an
ingredient
qryIngr.SQL.Add('select i.quantity, mi.itemname, mi.yieldsizeid,
mi.yieldqty, mi.sales, mi.menuitemid, s.conversion, s2.conversion as
conversion2');
qryIngr.SQL.Add('from xingredient i join xmenuitem mi on
i.menuitemid=mi.menuitemid join xsize s on i.sizeid=s.sizeid join
xsize s2 on mi.yieldsizeid=s2.sizeid where i.invitemid=' +
qryItem.FieldByName('InvItemID').asString);
qryIngr.Open;
while not qryIngr.Eof do
begin
//inventory items use the yield for the parent extension
Yield := (1 / (qryItem.FieldByName
('MenuCostingYield').asFloat / 100));
Extension := CalcLegit(Yield, qryIngr);
QtySold := Extension * qryIngr.FieldByName('Sales').asFloat;
//add this inventory item's usage to the totqtysold
TotQtySold := TotQtySold + QtySold;
qryIngr.Next;
end;
//total quantity sold is calculated using the base size so
convert it back to the recipe size
TotQtySold := SafeDivide(TotQtySold, qryItem.FieldByName
('MenuCostingQuantity').asFloat * qryItem.FieldByName
('Conversion').asFloat);
qryUpdate.Active := False;
qryUpdate.SQL.Clear;
//update the ideal usage field in the xinvitem table
qryUpdate.SQL.Add('update xinvitem set idealusage=' + FloatToStr
(TotQtySold) + ' where invitemid=' + qryItem.FieldByName
('invitemid').asString);
qryUpdate.ExecSQL;
qryItem.Next;
end;
ibtTrans.Commit;
end;
--- In IBObjects@yahoogroups.com, "Jason Wharton" <jwharton@i...>
wrote:
> Yes, but this still isn't very helpful to resolve your speed issue.wrote:
>
> More details please...
>
> Jason Wharton
> www.ibobjects.com
>
> -----Original Message-----
> From: sgharp [mailto:steve@h...]
> Sent: Saturday, May 22, 2004 9:08 AM
> To: IBObjects@yahoogroups.com
> Subject: Re: [IBO] Speed difference between TIBQuery and TIB_Query?
>
>
> --- In IBObjects@yahoogroups.com, Helen Borrie <helebor@t...>
> > At 03:42 PM 21/05/2004 -0400, you wrote:Firebird
> > >Hi All,
> > >
> > >I have a short utility that I'm writing to run against a
> database.the
> > >Using TIBQuery components (that come with D7), I can run the
> process in 11
> > >seconds. Using the exact same code but with TIB_Query
> components, it takes
> > >2 minutes and 3 seconds. I'm sure I'm not setting something up
> correctly.
> > >Any ideas? Why would IBObjects v4.3 be so much slower?
>
> > Help us to help you by providing some information about what
> you're trying
> > to do...
>
> I'm doing a query on a table with about 1500 records and then, for
> each record, performing a calculation which requires other queries
> (some joins) agains other tables to calculate a number and lastly,
> update the original table with this number. For each record in
> first table, I might have to do from about 1 - 20 recursions.There
> are 3 static query objects involved plus one query object that isconfiguration
> created dynamically within a recursive procedure.
>
> I'm thinking that the performance difference must be a
> issue. If TIB_Query was that much slower than TIBQuery, itwouldn't
> seem that IBObects would be so popular. 11 seconds compared tomore
> than 2 minutes is significant.