The following example is a smaller version of the query that I am trying to tune as I noticed that the wrongness of the plan emanates on this particular operation.
select count (*) from XVIEWMGR.XV_CASE_STAGES_DATA
where stage_id = max_initial_or_reopen_id
As mentioned, table stats and corresponding indexes have been recently gathered but no histograms has been created for each column as they are highly distinct. I've even created extended statistics for those to columns to no avail.
OWNER TABLE_NAME NUM_ROWS LAST_ANALYZED
-------------------- ------------------------------ ---------- -------------------
XVIEWMGR XV_CASE_STAGES_DATA 314079 09-11-2018 14:29:01
TABLE_NAME COLUMN_NAME LAST_ANAL SAMPLE_SIZE NUM_NULLS NUM_DISTINCT DENSITY
------------------------------ ------------------------------ --------- ----------- ---------- ------------ ----------
XV_CASE_STAGES_DATA STAGE_ID 09-NOV-18 314079 0 308733 .00000323904474
XV_CASE_STAGES_DATA MAX_INITIAL_OR_REOPEN_ID 09-NOV-18 314079 0 308728 .0000032390972
I hope you guys can help.
Dynamic statistics (also known as dynamic sampling) is pretty good at filling in gaps like this.
Test setup:
Test execution plans in 12.2 using xplanx.sql (some output removed for readability):
With dynamic sampling at level 4: