DEV Community

Query Filter
Query Filter

Posted on

bridge129


SQL Explanation
This is a complex cleanup query designed to find "Orphaned" records in a parent table that no longer have corresponding entries in a child table.

select INTERNIDENTITY from ZOrderVersion 
where INTERNTIMESTAMP < ? and INTERNINSTID = ? and 1=2 
union 
select INTERNIDENTITY from ZOrderVersion /*+ INDEX(ZOrderVersion ZOrderVersionPIDX) */ 
where INTERNINSTID = 104000101 and ORDERPRIKEY in (
    select ORDERPRIKEY from ZOrderVersion e /*+ INDEX(e ZOrderVersionPIDX) */ 
    where not exists (
        select * from ZOrderDetail d /*+ INDEX(d ZOrderDetailPIDX) */ 
        where d.ORDERID = e.ORDERPRIKEY
    )
)


Summary of What the System is Doing
The log states: "Objects to remove using..." The system has identified 569,125 objects (in the first log) and 125,985 objects (in the second) that are "orphans." It is collecting their INTERNIDENTITY (primary keys) so it can delete them from the database to save space and improve performance.
Enter fullscreen mode Exit fullscreen mode

Top comments (0)