The job run with error: SQL0437W Performance of this complex query may be sub-optimal. Reason code: "3". SQLSTATE=01602

Dear all,

I'm in problem when execute the job. The log show error: "SQL0437W  Performance of this complex query may be sub-optimal.  Reason code:  "3".  SQLSTATE=01602"
when run script of job. Please give me some advise for solving this. Thank you!

The psuedo script:

update CVG set cvg_amt = select cvg_amt from 
    (select CASE WHEN CVG.CVG_AMT IS NULL THEN COM.CVG_AMT ELSE CVG.CVG_AMT END AS CVG_AMT
	from cvg
	left join 
	(select A.id, A.cvg_amt, CASE WHEN A.PROCESS_DT > B.PROCESS_DT THEN A.CVG_AMT ELSE B.CVG_AMT END AS CVG_AMT
	from 
	( select A_first.id, A_first.cvg_amt, A_first.process_dt, A_first.gen_id from 
	  (select id, cvg_amt, process_dt, gen_id, eff_dt from A where eff_dt < '2015-10-28') as A_first,
		(select id, process_dt, max(gen_id ) as max_gen 
			from (select id, process_dt, gen_id  from A as A1 where eff_dt < '2015-10-28') , 
	       (select A2.id, max(A2.process_dt) as max_dt from A as A2 where eff_dt < '2015-10-28' group by A2.id)
        where eff_dt < '2015-10-28' and A2.id = A1.id and A2.max_dt=A1.process_dt group by A1.id, A1.process_dt) as A_second
	  where A_first.eff_dt<'2015-10-28'
			and A_first.id=A_second.id 
			and A_first.process_dt = A_second.process_dt
			and A_first.gen_id = A_second.gen_id
	 ) A
	 left join
	 
	 ( select B_first.id, B_first.cvg_amt, B_first.process_dt, B_first.gen_id from 
	  (select id, cvg_amt, process_dt, gen_id, eff_dt from B where eff_dt < '2015-10-28') as B_first,
		(select id, process_dt, max(gen_id ) as max_gen 
			from (select id, process_dt, gen_id  from B as B1 where eff_dt < '2015-10-28') , 
	       (select B2.id, max(B2.process_dt) as max_dt from B as B2 where eff_dt < '2015-10-28' group by B2.id)
        where eff_dt < '2015-10-28' and B2.id = B1.id and B2.max_dt=B1.process_dt group by B1.id, B1.process_dt) as B_second
	  where B_first.eff_dt<'2015-10-28'
			and B_first.id=B_second.id 
			and B_first.process_dt = B_second.process_dt
			and B_first.gen_id = B_second.gen_id
	 ) B on B.id = A.id
	 ) COM ON COM.ID = CVG.ID)

Open in new window

Tu NguyenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

waynezhuCommented:
From db2 help page, reason code 3 means "Optimizer cost underflow"

Possible User response:

If the performance of your query is sub-optimal, perform one or more of
the following actions:

*  Break the statement up into less complex SQL statements. (Reason
   codes 1, 2, 3, 4)
*  Ensure predicates do not over-specify the answer set. (Reason code 3)
*  Issue Runstats for the tables involved in the query. (Reason codes 3,
   4)
*  Set server options CPU_RATIO, IO_RATIO, COMM_RATE or function mapping
   options IOS_PER_INVOC, INSTS_PER_INVOC, IOS_PER_ARGBYTE,
   INSTS_PER_ARGBYTE, PERCENT_ARGBYTES, INITIAL_IOS, INITIAL_INSTS to a
   value that is not too high or too low. (Reason codes 3, 4)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Tomas Helgi JohannssonCommented:
Hi!

This is a fairly complex update query which should be broken up in more simpler queries as the error states.

How big is the CVS table that the query is running against ?
If it is over 5 million records, is it partitioned ? If not I strongly suggest you partition the table.

Have you run runstats on the table reasently ? If not do so.
After that issue a explain on the query and post it here. If the output of the explain indicates tablescan somewhere and your table is large (  > 5 million ) then you are in serious trouble and you should break the update into more simpler statement as well as the table partitioning I mentioned above.

Regards,
     Tomas Helgi
0
Tu NguyenAuthor Commented:
Thanks Waynezhu and TomasHelgi!

Thanks for your comment!

I can't have to authorize for configing again as the database.
So the solution "partitioning the table CVG" , I can't do.

I can only write the sql statement such that it's simpler.
The sql statement for update a field from table CVG as script I atached.
So can you suggest me the way I can enhance it more simpler?
Thanks for your guide!

Tu
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
DB2

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.