DB2 performance issue while executing select query

2019-08-19 00:26发布

问题:

I have this query:

SELECT INVOICE_NUMBER, INVOICE_SEQ_NUMBER, FILE_NUMBER, MAX(INVOICE_SEQ_NUMBER) OVER (PARTITION BY INVOICE_NUMBER) AS MAX_INV_SEQ_NUM
FROM (SELECT A.INVOICE_NUMBER, A.INVOICE_SEQ_NUMBER, B.FILE_NUMBER,
             DENSE_RANK() OVER (ORDER BY A.INVOICE_NUMBER) as seqnum
      FROM TABLE1 A JOIN
           TABLE2 B 
           ON A.INVOICE_NUMBER = B.INVOICE_NUMBER AND 
              A.INVOICE_SEQ_NUMBER = B.INVOICE_SEQ_NUMBER
     ) t
WHERE seqnum <= 500;

It was working fine with 10000 records in the tables but we added more today(+30k) and planing to add even more(+250-300k) to the table. Now I am getting this error:

DB2 SQL Error: SQLCODE=-905, SQLSTATE=57014, SQLERRMC=ASUTIME;000000000007;000000009000;SYSTEM PARAMETER, DRIVER=3.65.77

Is the query not correct or is not optimized for tables with big number of records? How we should handle this? Index some columns or restructure the query?

UPDATE: apparently, I was mistaken about number of records added to the table, at this moment we have 2 million records in TABLE1 and 4 million records in TABLE2, instead of 30k I mentioned initially.