GetFinalSQL causing full table scans with Master/Detail
Posted: Thu 06 Mar 2014 20:46
When we updated our ODAC to build 9.2.7, we started noticing some screens taking quite a bit longer to open than we previously experienced.
Using dbMonitor, we started seeing where the queries run against the detail tables started having OR ( (DTLFld IS NULL ) AND ( :MSTFld IS NULL ) ) add for each of the linked fields to the master table. This is causing full table scans on huge tables. Here is are some examples of what we now see running:
SELECT T.*
FROM ORDERHDR T
WHERE ( ( LOADNO = :LOADNO ) OR ( ( LOADNO IS NULL ) AND ( :LOADNO IS NULL ) ) )
ORDER BY ORDERID,SHIPID
SELECT T.*
FROM ORDERHDRPASSTHRUS T
WHERE ( ( ORDERID = :ORDERID ) OR ( ( ORDERID IS NULL ) AND ( :ORDERID IS NULL ) ) ) AND ( ( SHIPID = :SHIPID ) OR ( ( SHIPID IS NULL ) AND ( :SHIPID IS NULL ) ) )
ORDER BY ORDERID,SHIPID
TCustomDADataSet.GetFinalSQL is where this code is added. Can the code be smart enough that if the fields are required fields then do not add the IS NULL portion?
Setting LocalMasterDetail = True does not speed up the process since the where clause is no longer there.
Using dbMonitor, we started seeing where the queries run against the detail tables started having OR ( (DTLFld IS NULL ) AND ( :MSTFld IS NULL ) ) add for each of the linked fields to the master table. This is causing full table scans on huge tables. Here is are some examples of what we now see running:
SELECT T.*
FROM ORDERHDR T
WHERE ( ( LOADNO = :LOADNO ) OR ( ( LOADNO IS NULL ) AND ( :LOADNO IS NULL ) ) )
ORDER BY ORDERID,SHIPID
SELECT T.*
FROM ORDERHDRPASSTHRUS T
WHERE ( ( ORDERID = :ORDERID ) OR ( ( ORDERID IS NULL ) AND ( :ORDERID IS NULL ) ) ) AND ( ( SHIPID = :SHIPID ) OR ( ( SHIPID IS NULL ) AND ( :SHIPID IS NULL ) ) )
ORDER BY ORDERID,SHIPID
TCustomDADataSet.GetFinalSQL is where this code is added. Can the code be smart enough that if the fields are required fields then do not add the IS NULL portion?
Setting LocalMasterDetail = True does not speed up the process since the where clause is no longer there.