Subject | RE: [firebird-support] Performancelost after Migration to FB 2 |
---|---|
Author | Leyne, Sean |
Post date | 2007-07-17T19:35:48Z |
Guido,
need).
The changes try to create a SELECT Statement which meets the needs of
the runtime criteria.
CREATE PROCEDURE TEST
...
declare variable SelectStatement VarChar( 10000);
declare variable PCTitleList_Filter VarChar( 1000);
declare variable PCEANList_Filter VarChar( 1000);
declare variable PCGTIDList_Filter VarChar( 1000);
declare variable PublisherList_Filter VarChar( 1000);
declare variable PO500IDList_Filter VarChar( 1000);
AS
if (PCTitleList is NULL) then
PCTitleList_Filter = '';
else
PCTitleList_Filter = ' and ' || PCTitleList || ' containing '';'' ||
F_LRTrim( GDTitle) || '';''';
if (PCEANList is NULL) then
PCEANList_Filter = '';
else
PCEANList_Filter = ' and ' || PCEANList || ' containing '';'' ||
F_LRTrim( GDEAN) || '';''';
if (PCGTIDList is NULL) then
PCGTIDList_Filter = '';
else
PCGTIDList_Filter = ' and ' || PCGTIDList || ' containing '';'' ||
F_LRTrim( GDGTID) || '';''';
if (PublisherList is NULL) then
PublisherList_Filter = '';
else
PublisherList_Filter = ' and ''' || PublisherList || ''' containing
'';'' || F_LRTrim( GDPublisher) || '';''';
if (PO500IDList is NULL) then
PO500IDList_Filter = '';
else
PO500IDList_Filter = ' and exists (select PCID from PRODUCTS where
''' || PO500IDList || ''' containing '';'' || PCPOID500 || '';'' and
PCID=GFK_DATA.GDPCID';
SelectStatement = '
select
GDTitle,GDEAN,GDPUBLISHER,GDPCID
from GFK_DATA
join GFK_PRODUCTAREAS on GDGAID=GAID
where
GAIsHardware=:Hardware
and GDTitleDistinct=GAID'
|| PCTitleList_Filter
|| PCEANList_Filter
|| PCGTIDList_Filter
|| PCTitleList_Filter
|| ' order by GDTitle collate de_de, GDEAN';
for
EXECUTE STATEMENT
SelectStatement
into
:GDTitle,
:GDEAN,
:GDPUBLISHER,
:GDPCID
do
begin
select
GDPiecesPanel,
GDValuePanel,
GDPiecesMarket,
GDValueMarket
from
GFK_DATA
where
GDTitle=:GDTitle
and GDEAN=:GDEAN
and GDCalendarWeek=:CalendarWeek
and GDYear=:CalendarYear
into
:GDPiecesPanel_WeekOfTheYear,
:GDValuePanel_WeekOfTheYear,
:GDPiecesMarket_WeekOfTheYear,
:GDValueMarket_WeekOfTheYear;
end
> The SP does only one SQL StatementCan you try the following changes to the SP (modifying to fit the exact
need).
The changes try to create a SELECT Statement which meets the needs of
the runtime criteria.
CREATE PROCEDURE TEST
...
declare variable SelectStatement VarChar( 10000);
declare variable PCTitleList_Filter VarChar( 1000);
declare variable PCEANList_Filter VarChar( 1000);
declare variable PCGTIDList_Filter VarChar( 1000);
declare variable PublisherList_Filter VarChar( 1000);
declare variable PO500IDList_Filter VarChar( 1000);
AS
if (PCTitleList is NULL) then
PCTitleList_Filter = '';
else
PCTitleList_Filter = ' and ' || PCTitleList || ' containing '';'' ||
F_LRTrim( GDTitle) || '';''';
if (PCEANList is NULL) then
PCEANList_Filter = '';
else
PCEANList_Filter = ' and ' || PCEANList || ' containing '';'' ||
F_LRTrim( GDEAN) || '';''';
if (PCGTIDList is NULL) then
PCGTIDList_Filter = '';
else
PCGTIDList_Filter = ' and ' || PCGTIDList || ' containing '';'' ||
F_LRTrim( GDGTID) || '';''';
if (PublisherList is NULL) then
PublisherList_Filter = '';
else
PublisherList_Filter = ' and ''' || PublisherList || ''' containing
'';'' || F_LRTrim( GDPublisher) || '';''';
if (PO500IDList is NULL) then
PO500IDList_Filter = '';
else
PO500IDList_Filter = ' and exists (select PCID from PRODUCTS where
''' || PO500IDList || ''' containing '';'' || PCPOID500 || '';'' and
PCID=GFK_DATA.GDPCID';
SelectStatement = '
select
GDTitle,GDEAN,GDPUBLISHER,GDPCID
from GFK_DATA
join GFK_PRODUCTAREAS on GDGAID=GAID
where
GAIsHardware=:Hardware
and GDTitleDistinct=GAID'
|| PCTitleList_Filter
|| PCEANList_Filter
|| PCGTIDList_Filter
|| PCTitleList_Filter
|| ' order by GDTitle collate de_de, GDEAN';
for
EXECUTE STATEMENT
SelectStatement
into
:GDTitle,
:GDEAN,
:GDPUBLISHER,
:GDPCID
do
begin
select
GDPiecesPanel,
GDValuePanel,
GDPiecesMarket,
GDValueMarket
from
GFK_DATA
where
GDTitle=:GDTitle
and GDEAN=:GDEAN
and GDCalendarWeek=:CalendarWeek
and GDYear=:CalendarYear
into
:GDPiecesPanel_WeekOfTheYear,
:GDValuePanel_WeekOfTheYear,
:GDPiecesMarket_WeekOfTheYear,
:GDValueMarket_WeekOfTheYear;
end