PREPAREd statement optimization
Posted in 2005
A query. (4GL 7.20UD8 (both RDS & I4GL), IDS 9.30HC5, HP-UX 11i) Does anyone know the process whereby the optimizer decides on the best access path for a statement PREPAREd in 4GL? We've a query here in a 4GL which is prepared with placemarkers and opened in a logic loop later in the program, each time with different values in the (three) placemarkers. If you "SET EXPLAIN ON" in the 4GL, I note an sqexplain.out file is created AT THE TIME OF the "PREPARE" statement. Each time the cursor is OPENEd, no further sqexplain.out is produced. I've done some test 4GLs and narrowed it down to the point where I found that with a particular two sets of values run in one particular order, the "OPEN" for the cursor is quick for the first set of values and s-l-o-w for the second. If I reverse the order in which the values are presented to the OPEN, it is quick both times. e.g. OPEN some_curs USING TODAY, "12/05/1999", 1000 - quick (< 1 second) OPEN some_curs USING TODAY, "12/05/1999", 500 - s-l-o-w (2 minutes) but: OPEN some_curs USING TODAY, "12/05/1999", 500 - quick (1 second) OPEN some_curs USING TODAY, "12/05/1999", 1000 - quick (< 1 second) ... where the values used are retrieved from other tables earlier on. I did a test by preparing separate statements with the absolute values put in instead of placemarkers, and as expected the costs are different (due to data skew etc). So the query is, has the optimizer decided on a query plan when it got the PREPARE so when a set of values that don't meet the optimization goal are presented it uses the wrong path? How can I change this? Thanks Malc