DB2问题获取300个记录的-101但相同的查询适用于1000和10000个记录

时间:2010-12-23 06:10:26

标签: sql db2

我在Db2面临着一个奇怪的问题 我收到DB2 SQL错误:SQLCODE:-101,SQLSTATE:54001,SQLERRMC:1
相同的查询适用于1000甚至10000条记录,但不适用于特定的记录集(150-300)。我现在可以使用这些记录重现。
查询仅使用Select和With cause 所以我不认为增加STMT堆内存会有任何意义,因为查询适用于更大的记录 查询很大,仅包含选择加入和少量案例声明 查询也使用With语句 @Note每条记录都是独立的,与另一条记录有关系。

这是查询

WITH
itemStyle_ AS (
    SELECT * FROM item.itemStyle WHERE itemSTY_SEQ 
---- This Parameter gets changes to 1000 only 
IN( 'awudhjqwdvwd12'  )


),CustomsInfo AS
(SELECT 3 AS ReitemrtGrp, 3 AS REitemRTGRP2, HSYS_NO, NHSYS_NO, itemCUSTOMSINFO.itemDEL_SEQ,-1 AS COL_NO,
        itemStyle.MyApp_item_NO, itemStyle.SIZE_TNAME, itemStyle.CS_DATE, itemStyle.SIZ1TABID, itemDELIVERY.DS_NO,
itemStyle.ABM_Date, itemStyle.RS_Date,itemStyle.CustCo_NO, itemStyle.Cust_Code, itemStyle.UCustCo_No, itemStyle.Prodiv_desc, itemStyle.Busunidesc,itemStyle.COno, itemStyle.STY_NO
    FROM item.itemCUSTOMSINFO itemCUSTOMSINFO INNER JOIN item.itemDELIVERY itemDELIVERY ON itemCUSTOMSINFO.itemDEL_SEQ = itemDELIVERY.itemDEL_SEQ, itemStyle_ itemStyle
        WHERE (HSYS_NO IS NOT NULL OR NHSYS_NO IS NOT NULL)
            AND itemCUSTOMSINFO.itemSTY_SEQ = itemStyle.itemSTY_SEQ
            ),
SizeInfo AS(
SELECT  1 AS ReitemrtGrp2,
    itemStyle.SIZ1TABID, itemDELCOLOR.itemDEL_SEQ, itemStyle.MyApp_item_NO, itemStyle.CS_DATE, itemStyle.STY_NO,
    itemStyle.ABM_Date, itemStyle.RS_Date,itemStyle.CustCo_NO, itemStyle.Cust_Code, itemStyle.UCustCo_No, itemStyle.Prodiv_desc, itemStyle.Busunidesc,itemStyle.COno,itemDELCOLOR.DS_NO,
    itemColor.COL_NO,CUSIZ_CODE,
    itemDELSIZE.QUANTITY,itemDELSIZE.OCP_FACTOR,itemDELSIZE.SKU_CODE,
    itemSIZE.SIZE_CODE, itemSIZE.UNIT_PRC,itemSIZE.SURCHARGE,itemSIZE.SIZNUM itemSIZE_NUM, itemSIZE.UNIT_DISC, itemSIZE.PACK_UNIT
FROM
    itemStyle_ AS itemStyle
    INNER JOIN item.itemColor  itemColor ON itemStyle.itemSTY_SEQ = itemColor.itemSTY_SEQ
    INNER JOIN item.itemDELCOLOR itemDELCOLOR ON itemDELCOLOR.itemCOL_SEQ = itemColor.itemCOL_SEQ
    INNER JOIN item.itemDELSIZE itemDELSIZE ON itemDELCOLOR.itemDELCOL_SEQ = itemDELSIZE.itemDELCOL_SEQ
    INNER JOIN item.itemSIZE itemSIZE ON itemDELSIZE.itemSIZ_SEQ = itemSIZE.itemSIZ_SEQ
),OrderChar AS(
   SELECT 3 AS ReitemrtGrp2, 2.6 AS ReitemrtGrp,
   ordchar_desc, itemStyle.COno, CS_Date, SIZ1TABID, itemStyle.MyApp_item_NO, itemStyle.STY_NO,
itemStyle.ABM_Date, itemStyle.RS_Date,itemStyle.CustCo_NO, itemStyle.Cust_Code, itemStyle.UCustCo_No, itemStyle.Prodiv_desc, itemStyle.Busunidesc,itemDELIVERY.itemDEL_SEQ  FROM
   item.itemORDERCHAR itemOrderChar INNER JOIN itemStyle_ itemStyle ON itemOrderChar.itemSty_Seq = itemStyle.itemSty_Seq
   INNER JOIN item.itemDELIVERY itemDELIVERY ON itemStyle.itemSTY_SEQ = itemDELIVERY.itemSTY_SEQ
),
Supp_Address AS (
SELECT ADDRESS.COMPANY1 AS SuppAdd_COMPANY1,
    ADDRESS.COMPANY2 AS SuppAdd_COMPANY2,
    ADDRESS.COMPANY3 AS SuppAdd_COMPANY3,
    ADDRESS.STREET1 AS SuppAdd_STREET1,
    ADDRESS.STREET2 AS SuppAdd_STREET2,
    ADDRESS.STREET3 AS SuppAdd_STREET3,
    ADDRESS.CITY AS SuppAdd_CITY,
    ADDRESS.STATENAME AS SuppAdd_STATENAME,
    ADDRESS.COUNTRY AS SuppAdd_COUNTRY,
    ADDRESS.ZIP_CODE AS SuppAdd_ZIP_CODE,
        SUPPLIER.SUP1COMID,
        CONTACTINF.C_PHONENO, CONTACTINF.A_PHONENO, CONTACTINF.M_PHONE ,
        ADDRESS.ZitemST_BOX , ADDRESS.itemST_BOX
FROM item.ADDRESS ADDRESS,
        item.ORGANZN ORGANZN
        LEFT OUTER JOIN item.SUPPLIER SUPPLIER
        ON      ORGANZN.ORG_ID=SUPPLIER.ORG_ID,
                item.CONTACTINF CONTACTINF WHERE
        (                ADDRESS.ORG_ID=ORGANZN.ORG_ID        )    AND
        (                CONTACTINF.ADDRESS_ID=ADDRESS.ADDRESS_ID        )    AND
        (
                SUPPLIER.SUPP_FLAG = 'Y'
        )) ,
Cust_Address AS (
    SELECT  VALUE(ADDRESS.COMPANY1,'') CustAdd_COMPANY1 ,
        VALUE(ADDRESS.COMPANY2,'') AS CustAdd_COMPANY2,
        VALUE(ADDRESS.COMPANY3,'') AS CustAdd_COMPANY3,
        VALUE(ADDRESS.STREET1,'')  AS CustAdd_STREET1,
        VALUE(ADDRESS.STREET2,'')  AS CustAdd_STREET2,
        VALUE(ADDRESS.STREET3 ,'') AS CustAdd_STREET3,
        VALUE(ADDRESS.CITY,'')     AS CustAdd_CITY,
        VALUE(ADDRESS.STATENAME,'') AS CustAdd_STATENAME,
        VALUE(ADDRESS.COUNTRY ,'') AS CustAdd_COUNTRY,
        VALUE(ADDRESS.ZIP_CODE ,'')AS  CustAdd_ZIPCODE,
        VALUE(CUSTOMER.CUST_ID ,'')AS CustAdd_CUST_ID,
        VALUE(ADDRESS.ZitemST_BOX,'') AS CustAdd_ZitemST_BOX ,
        VALUE(ADDRESS.itemST_BOX,'') AS CustAdd_itemST_BOX
FROM    item.ADDRESS ADDRESS,
        item.CUSTOMER CUSTOMER
        LEFT OUTER JOIN item.ORGANZN ORGANZN
        ON      ORGANZN.ORG_ID=CUSTOMER.ORG_ID,
                item.ORGDEFAULTS ORGDEFAULTSWHERE
        (                ADDRESS.ORG_ID=ORGANZN.ORG_ID        )
    AND        (
                ADDRESS.ADDRESS_ID=ORGDEFAULTS.DEFAULT_VALUE_ID        )    AND
        (                CUSTOMER.CUST_FLAG='Y'        )
    AND ORGDEFAULTS.DEFAULT_ITEM = 'MAILING_ADDRESS'
SELECT  VALUE(CustomsInfo.ReitemrtGrp, OrderChar.ReitemrtGrp, 3) AS ReitemrtGrp,
    VALUE(SizeInfo.ReitemrtGrp2,  OrderChar.ReitemrtGrp2, CustomsInfo.ReitemrtGrp2, 4) AS ReitemrtGrp2,
    VALUE(itemStyle.MyApp_item_NO, CUSTOMSINFO.MyApp_item_NO, SizeInfo.MyApp_item_NO,OrderChar .MyApp_item_NO) AS MyApp_item_NO ,
        itemStyle.COno       ,
        itemStyle.STAT_DESC       ,
        itemStyle.CUST_CODE       ,
        itemStyle.CUST_NAME       ,
        itemStyle.CUSTCO_NO       ,
        itemStyle.UCUST_CODE      ,
        itemStyle.UCUST_NAME      ,
        itemStyle.DSHIP_FLAG      ,
        itemStyle.STY_NO          ,
        itemStyle.STY_DESC        ,
        itemStyle.BRAND_DESC      ,
        itemStyle.PRODIV_DESC     ,
        itemStyle.CUSTY_DESC      ,
        itemStyle.SEA_DESC        ,
        itemStyle.LINNAMDESC      ,
        itemStyle.SUPP_CODE       ,
    itemStyle.SUPP_NAME,
        itemStyle.CONCEPDESC      ,
        itemStyle.RS_DATE         ,
        itemStyle.ABM_DATE        ,
        VALUE(itemStyle.CS_DATE, CustomsInfo.CS_DATE, SizeInfo.CS_DATE,  OrderChar.CS_Date) AS CS_DATE         ,
        itemStyle.REMARKS         ,
        itemStyle.LASTUPDATE      ,
        itemStyle.FACT_CODE       ,
        itemStyle.C_ORIGIN        ,
        itemStyle.itemDDESC,
        VALUE(itemDELIVERY.DS_NO, SizeInfo.DS_NO,CustomsInfo.DS_NO) AS DS_NO        ,
        itemDELIVERY.CUST_DS_NO   ,
        itemDELIVERY.ULTCUST_DS_NO,
        itemDELIVERY.LCS_DATE     ,
itemDELIVERY.DTERM_DESC   ,
itemSHIPINST.SHIP_MARKS   ,
itemDELIVERY.PACK_INST,
        itemStyle.KEY_SIZE        ,
        itemSHIPINST.SMODE_DESC   ,
        itemSHIPINST.ORIGN_itemRT   ,
        itemSHIPINST.DEST_itemRT    ,
        itemSHIPINST.CARR_DESC    ,
itemSHIPINST.SPL_INST,
        itemStyle.PAYM_DESC       ,
        itemStyle.PAYT_DESC       ,
        itemStyle.UCUSTCO_NO      ,
        itemStyle.ORD_RDATE       ,
        itemStyle.ORG_NAME        ,
        itemStyle.CUSTY_NO        ,
        VALUE(itemDELADDRESS.COMPANY1,'')  AS DELCOMPANY1 ,
        VALUE(itemDELADDRESS.COMPANY2,'')  AS DELCOMPANY2  ,
        VALUE(itemDELADDRESS.COMPANY3,'')   AS DELCOMPANY3  ,
        VALUE(itemDELADDRESS.STREET1,'')    AS DELSTREET1,
        VALUE(itemDELADDRESS.STREET2,'')    AS DELSTREET2,
        VALUE(itemDELADDRESS.STREET3,'')    AS DELSTREET3,
        VALUE(itemDELADDRESS.CITY,'')       AS DELCITY,
        VALUE(itemDELADDRESS.STATENAME,'')  AS DELSTATENAME,
        VALUE(itemDELADDRESS.COUNTRY,'')    AS DELCOUNTRY,
        VALUE(itemDELADDRESS.ZIP_CODE,'')  AS DELZIP ,
        VALUE(itemDELIVERY.itemDEL_SEQ , CustomsInfo.itemDEL_SEQ, SizeInfo.itemDEL_SEQ, OrderChar.itemDEL_SEQ)  AS itemDEL_SEQ ,
        itemStyle.DEBTOR_CODE     ,
        VALUE(itemADDRESS.STATENAME,'') AS STATENAME,
VALUE(itemADDRESS.COMPANY1,'') AS COMPANY1,
VALUE(itemADDRESS.COMPANY2,'') AS COMPANY2,
VALUE(itemADDRESS.COMPANY3,'') AS COMPANY3,
VALUE(itemADDRESS.STREET1,'') AS STREET1,
VALUE(itemADDRESS.STREET2,'') AS STREET2,
VALUE(itemADDRESS.STREET3,'') AS STREET3,
VALUE(itemADDRESS.CITY,'') AS CITY,
VALUE(itemADDRESS.COUNTRY,'') AS itemADDRCOUNTRY,
VALUE(itemADDRESS.ZIP_CODE,'') AS ZIP_CODE,
        itemStyle.CURRENCY        ,
        itemStyle.CREATEDATE      ,
        itemStyle.SIZE_TNAME      ,
        itemStyle.BUSUNIDESC      ,
        VALUE (itemStyle.SIZ1TABID, CustomsInfo.SIZ1TABID, SizeInfo.SIZ1TABID,   OrderChar.SIZ1TABID) AS SIZ1TABID,
        itemStyle.DISC_VALUE      ,
        HSYS_NO, NHSYS_NO       ,
        VALUE(itemColor.COL_NO, SizeInfo.COL_NO, CustomsInfo.COL_NO) AS COL_NO,
        itemColor.PROCH_DESC      ,
        itemColor.PROREQDESC      ,
        itemColor.COL_DESC        ,
        VALUE (itemColor.HAND_CHARGE,0) HAND_CHARGE     ,
        VALUE(itemColor.OTHER_CHARGES, 0) OTHER_CHARGES   ,
        itemColor.PERF_CODE,
        SizeInfo.QUANTITY       ,
        SizeInfo.OCP_FACTOR     ,
        SizeInfo.SKU_CODE       ,
        SizeInfo.SIZE_CODE      ,
        SizeInfo.UNIT_PRC       ,
        SizeInfo.SURCHARGE      ,
        SizeInfo.itemSIZE_NUM     ,
        SizeInfo.UNIT_DISC,
    SizeInfo.CUSIZ_CODE,
    SizeInfo.PACK_UNIT,
        YOUTSOLE.ITMDES AS OUTSOLEDESC, YOUTSOLE.OUTSOLE AS OUTSOLECODE,
/*        (SELECT ITMDES FROM item.YCATEGO YCATEGO WHERE YCATEGO.categoid = art1sty.categoid) AS CategoDesc,
        (SELECT ITMDES FROM item.YACTGRP YACTGRP WHERE YACTGRP.actgrpid = art1sty.actgrpid) AS ACTGRPDesc,*/
        LEADTM_DESC AS LeadTime,
/*        (SELECT SUM(VALUE(hand_charge,0) +  VALUE(other_charges,0)) AS TotalCharge FROM item.itemColor itemColor WHERE itemColor.itemSTY_SEQ = itemStyle.itemSTY_SEQ) AS TotalCharge,*/
        itemDelivery.AMD_Date,
        OrderChar.ordchar_desc,
        YPROCON.ITMDES AS PromotionContract,
        (SELECT SUM(QUANTITY) FROM SizeInfo WHERE SizeInfo.MyApp_item_NO = itemStyle.MyApp_item_NO) AS OrderTotalQty,
        Supp_Address.*,
    Cust_Address.*,
    CASE WHEN 'MyAppitemNo' = 'csDate' THEN VALUE(itemStyle.CS_Date, CustomsInfo.CS_Date, SizeInfo.CS_Date, OrderChar.CS_Date)
             WHEN 'MyAppitemNo' = 'rsDate' THEN VALUE(itemStyle.RS_Date, CustomsInfo.RS_Date,SizeInfo.RS_Date, OrderChar.RS_Date)
         WHEN 'MyAppitemNo' = 'lcsDate' THEN VALUE(itemStyle.CS_Date, CustomsInfo.CS_Date, SizeInfo.CS_Date, OrderChar.CS_Date)
         ELSE '2010-01-01'
        END AS SortDate,
    CASE WHEN 'MyAppitemNo' = 'MyAppitemNo' THEN VALUE(itemStyle.MyApp_item_NO, CustomsInfo.MyApp_item_NO, SizeInfo.MyApp_item_NO, OrderChar.MyApp_item_NO)
         WHEN 'MyAppitemNo' = 'MyAppCoNo' THEN VALUE(itemStyle.COno, CustomsInfo.COno, SizeInfo.COno, OrderChar.COno)
             WHEN 'MyAppitemNo' = 'custCoNo' THEN VALUE(itemStyle.CustCO_NO, CustomsInfo.CustCO_NO, SizeInfo.CustCO_NO, OrderChar.CustCO_NO)
         WHEN 'MyAppitemNo' = 'custCode' THEN VALUE(itemStyle.Cust_Code, CustomsInfo.Cust_Code,SizeInfo.Cust_Code, OrderChar.Cust_Code)
         WHEN 'MyAppitemNo' = 'ucustCoNo' THEN VALUE(itemStyle.UCustCO_NO, CustomsInfo.UCustCO_NO, SizeInfo.UCustCO_NO, OrderChar.UCustCO_NO)
         WHEN 'MyAppitemNo' = 'proDivDesc' THEN VALUE(itemStyle.Prodiv_Desc, CustomsInfo.Prodiv_Desc, SizeInfo.Prodiv_Desc, OrderChar.Prodiv_Desc)
         WHEN 'MyAppitemNo' = 'busUniDesc' THEN VALUE(itemStyle.BUSUNIDESC, CustomsInfo.BusuniDesc, SizeInfo.BusuniDesc, OrderChar.BusuniDesc)
         WHEN 'MyAppitemNo' = 'styNo' THEN VALUE(itemStyle.STY_NO, CustomsInfo.STY_NO, SizeInfo.STY_NO, OrderChar.STY_NO)
         ELSE 'xxx'
        END AS SortField
FROM itemStyle_ AS itemStyle
    INNER JOIN item.itemDELIVERY itemDELIVERY ON itemStyle.itemSTY_SEQ = itemDELIVERY.itemSTY_SEQ
        INNER JOIN item.itemDELCOLOR itemDELCOLOR ON itemDELCOLOR.itemDEL_SEQ = itemDELIVERY.itemDEL_SEQ
        INNER JOIN item.itemColor itemColor ON itemDELCOLOR.itemCOL_SEQ  = itemColor.itemCOL_SEQ
        INNER JOIN item.itemSHIPINST itemSHIPINST ON itemSHIPINST.itemDEL_SEQ = itemDELIVERY.itemDEL_SEQ
        INNER JOIN item.itemDELADDRESS itemDELADDRESS ON itemDELADDRESS.itemDEL_SEQ = itemDELIVERY.itemDEL_SEQ
        INNER JOIN item.itemADDRESS itemADDRESS ON itemADDRESS.itemSTY_SEQ = itemStyle.itemSTY_SEQ
        INNER JOIN item.ART1STY ART1STY ON ART1STY.ART1STYID = itemStyle.ART1STYID
INNER JOIN Supp_Address ON itemStyle.SUPP_ID = Supp_Address.SUP1COMID
INNER JOIN Cust_Address ON itemStyle.CUST_ID = Cust_Address.CustAdd_Cust_ID
                                LEFT OUTER JOIN item.ART4COS ART4COS ON itemColor.ART4COSID = ART4COS.ART4COSID
                                LEFT OUTER JOIN item.ART2STS ART2STS ON  ART2STS.ART2STSID = ART4COS.ART2STSID
                                LEFT JOIN item.YPROCON YPROCON ON ART2STS.PROCONID = YPROCON.PROCONID
        LEFT OUTER JOIN item.YOUTSOLE YOUTSOLE ON YOUTSOLE.OUTSOLEID  = ART1STY.OUTSOLEID
        FULL OUTER JOIN CustomsInfo ON 1=2
        FULL OUTER JOIN SizeInfo ON 1=2
                                FULL OUTER JOIN OrderChar ON 1=2
ORDER BY
SortDate DESC, SortField DESC,
MyApp_item_NO ,
VALUE(DS_NO,0),
VALUE(COL_NO,0),
itemDEL_SEQ,
ReitemrtGrp,
         ReitemrtGrp2 DESC, SizeInfo.itemSIZE_NUM
FOR READ ONLY

更新

我的数据库没有触发器和程序

Strange部分是针对那些(300)记录集查询失败但对1000行/记录/输入参数工作正常。任何想法。

1 个答案:

答案 0 :(得分:1)

这是因为查询语句超过了4KB的默认大小。您可以将语句堆大小设置为以下值。

db2 update db cfg for YOUR_DATABASE_NAME using STMTHEAP 8192 AUTOMATIC