Focal Point
[WORKAROUND] Disable query "optimizer"?

This topic can be found at:
http://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/2037015076

May 07, 2014, 09:12 AM
Wep5622
[WORKAROUND] Disable query "optimizer"?
I'm having an issue with what the query optimizer is doing to one of my TABLE-requests and I wonder whether there's some setting I can put in my procedure to turn it off (or at least temporarily)?

The problem in case is that I have a couple of conditional joins that significantly limit the size of the data-set. They are in my TABLE request (and with differing JOIN aliases too), but when I look at the trace output they are missing from the generated SQL.

Apparently the optimizer thinks it doesn't need those tables and conditions, but it doesn't even tell me why...

All I get are messages about 1:n joins not using the entire primary key of the foreign relation:
 FOC2525 - FOREIGN KEY IS NOT A SUPERSET OF PRIMARY KEY FOR SEGMENT: UVSCII
 FOC2525 - FOREIGN KEY IS NOT A SUPERSET OF PRIMARY KEY FOR SEGMENT: UVPP
 FOC2509 - RDBMS-MANAGED JOIN SELECTED BUT RESULTS MAY BE INACCURATE
 FOC2524 - JOIN TO A UNIQUE SEGMENT DOES NOT COVER ITS PRIMARY KEY AGGREGATION DONE ... 


That looks pretty harmless to me and there doesn't appear to be a way around it.

This message has been edited. Last edited by: Wep5622,


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
May 07, 2014, 09:40 AM
Francis Mariani
quote:
How to Optimize Requests
SQL SQLORA SET {OPTIMIZATION|SQLJOIN} setting where:
SQLORA - Is the target RDBMS. You can omit this value if you previously issued the SET SQLENGINE command.

SQLJOIN - Is a synonym for OPTIMIZATION.

setting - Is the optimization setting. Valid values are as follows:

ON - instructs the adapter to create SQL statements that take advantage of RDBMS join,
sort, and aggregation capabilities. Note that the multiplicative effect may disable
optimization in some cases. However, misjoined unique segments and multiplied lines
in PRINT-based and LIST-based report requests do not disable optimization. This is the
default.

OFF - instructs the adapter to create SQL statements for simple data retrieval from each
table. The server handles all aggregation, sorting, and joining in your address space or
virtual machine to produce the report.



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
May 07, 2014, 11:08 AM
Wep5622
That's not really what I'm looking for. The problem is that the WF-server already performs partially unoptimized joins by requesting far too much data and then joining that (on the reporting server) to the contents of a fairly large table.

What I'm looking for is a way to make it not try to be smart about the SQL it generates, but instead do a straight conversion from the TABLE request to SQL.

If not, I'm probably forced to use SQL passthru and do the type-conversion for each field by hand to make it match the master files again.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
May 08, 2014, 12:03 AM
njsden
Wep5622, the reason why those 2 JOINS are missing from the generated SQL may not be related to the warnings you're seeing but likely to the fact the WebFOCUS excludes any tables when building the SQL statement if no fields from those tables are being used anywhere in the request.

Please try to adjust your TABLE FILE request and reference at least one field from each of the 2 tables you're joining to, either as a display field in your PRINT/SUM verb (you can use NOPRINT if you don't actually want to see the value being displayed), as part of a DEFINE/COMPUTE expression or perhaps in a WHERE condition. By doing so, the iWay translator would know to include a join to those tables when building the SQL statement as it would be the only way to access the fields specified in your request. Smiler



Prod/Dev: WF Server 8008/Win 2008 - WF Client 8008/Win 2008 - Dev. Studio: 8008/Windows 7 - DBMS: Oracle 11g Rel 2
Test: Dev. Studio 8008 /Windows 7 (Local) Output:HTML, EXL2K.
May 08, 2014, 08:50 AM
j.gross
Sounds (from the FOC2524 message) like:
your join structure includes a "unique" join, but based on the primary key of the joined-to table (as determined from the keys= value in the acx file of its synonym) what you are joining to does not include the primary key field(s). This might happen if you are joining to an alternate key.

Is that the case?


- Jack Gross
WF through 8.1.05
May 08, 2014, 11:31 AM
Wep5622
Right, of course! Even though some of those columns were in the WHERE-clause...

I don't suppose there's an option to turn off that optimization?


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
May 14, 2014, 04:13 AM
Wep5622
quote:
Originally posted by j.gross:
Sounds (from the FOC2524 message) like:
your join structure includes a "unique" join, but based on the primary key of the joined-to table (as determined from the keys= value in the acx file of its synonym) what you are joining to does not include the primary key field(s). This might happen if you are joining to an alternate key.

Is that the case?


No, I'm joining to the primary key.

The tables I'm joining have a 1:N relationship, so naturally the primary key on the right side of the join spans more columns than the one on the left side of the join.

It is a UNIQUE join however, since we constrain the (conditional) join on a single constant value at the right side, completing the PK there. Apparently WebFOCUS does not realise that[1].

The join is done like this:
JOIN
 FILE UVSC AT SC TAG left TO UNIQUE
 FILE UVSCIC AT SC TAG right AS Jn
 WHERE left.SC EQ right.SC;
 WHERE right.IC EQ 'foo';
END


With the PK of UVSC as (SC) and the PK of UVSCIC as (SC, IC).

The error message seems to indicate that WebFOCUS got things backwards, as it's claiming that the foreign key of "some unmentioned segment" is not a superset of the primary key for segment uvscii. That makes no sense.

In fact, uvscii is the foreign key segment, not the primary, so it's actually the other way around.
Is it just the error message that's got it reversed or is it the JOIN?

If that's not confusing enough for you, have a look at the output of
? 2525
That's just a really complicated way to not explain anything at all...

Ad.1. I got a response on a case I opened on a related matter and it appears that WF server 7704M sometimes optimizes away relevant join conditions, where 7705M does not. I suspect that might be related, as it could make the join non-unique.


WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :
May 14, 2014, 04:21 PM
j.gross
quote:
It is a UNIQUE join however, since we constrain the (conditional) join on a single constant value at the right side, completing the PK there. Apparently WebFOCUS does not realise that.


Welcome to the club. I encountered the identical situation about a year ago at a former client. I tilted with the CSS windmill long and hard until they finally comprehended it and admitted it's a defect.

I wound up, as a temporary work-around, creating an alternate synonym that omitted the component from the declared primary key (rearranged the FIELDNAME lines and reduced KEYS= by one), so that, with no change to the JOIN declaration, WF believed me when I asserted it's a unique join. Basically "Who cares what WebFOCUS thinks so long as it generates the correct SQL." But make sure your workaround is documented well.
May 15, 2014, 04:01 AM
Wep5622
Good to know I'm not the first one running into this issue. I suppose anyone reporting on an EAV-modelled database will run into this at some point.

The trick with the access-file makes sense, I'll keep that in mind.

I ended up replacing the table-request with pass-thru SQL, as I was running into several other issues with these queries.

I already mentioned the optimizer bug, but another issue was that Oracle (11g) did something peculiar to a comparison between a TIMESTAMP WITH LOCAL TIME ZONE field and a constant datetime value: for some reason it decided to convert both sides of the equation to UTC, while it is of course rather more efficient to just convert the constant to the correct time zone. Doing that explicitly by casting the constant value to the correct type fixed that.

For the archives, an example of a (SQL) conversion of such a constant datetime value (in this example '24 hours ago'):
CAST(CURRENT_TIMESTAMP - INTERVAL '24' HOUR AS TIMESTAMP(0) WITH LOCAL TIME ZONE)



WebFOCUS 8.1.03, Windows 7-64/2008-64, IBM DB2/400, Oracle 11g & RDB, MS SQL-Server 2005, SAP, PostgreSQL 11, Output: HTML, PDF, Excel 2010
: Member of User Group Benelux :