-- Setup
--------
drop table T1 purge;

create table T1 tablespace USERS as
select 
    rownum id,
    case when rownum<10 then mod(rownum,4) else 999 end col1
from   ( select 1 just_a_column
         from DUAL
         connect by level <= 20
       )
/

drop table T2 purge;

create table T2 tablespace USERS as
select 
    rownum id,
    case when rownum<25 then mod(rownum,10) else 999 end col1
from   ( select 1 just_a_column
         from DUAL
         connect by level <= 100
       )
/

exec dbms_stats.gather_table_stats(user,'T1', method_opt=>'for all columns size 1');
exec dbms_stats.gather_table_stats(user,'T2', method_opt=>'for all columns size 1');


set lines 250 pages 999
alter system flush shared_pool;

drop table Q purge;
create table Q as
select /*+ GATHER_PLAN_STATISTICS */
    T1.ID    id1
  , T2.ID    id2
  , T1.COL1  val
from
    T1,
    T2
where
  T1.COL1=T2.ID
/

select * from table(dbms_xplan.display_cursor(null,null,'ALLSTATS LAST  +PEEKED_BINDS +PARALLEL +PARTITION +COST +BYTES'));

@stats_col SYS T1 % % % %
                                                                                                    b s                             Avg                                                                    Num
Object                                                                                              a e                             Col                                                                    Buc
Type     TableName                                     ColumnName                LastAnalyzed       l r Size (MB)       SampleSize  Len     NumDistinct       NumNulls            Density Histogram        ket
-------- --------------------------------------------- ------------------------- ------------------ - - --------- ---------------- ---- --------------- -------------- ------------------ --------------- ----
TABLE    SYS.T1                                        COL1                      11-FEB-23 09:20:04 Y N         0               20    4               5              0   .200000000000000 NONE               1
TABLE    SYS.T1                                        ID                        11-FEB-23 09:20:04 Y N         0               20    3              20              0   .050000000000000 NONE               1

SQL> @stats_col SYS T2 % % % %
                                                                                                    b s                             Avg                                                                    Num
Object                                                                                              a e                             Col                                                                    Buc
Type     TableName                                     ColumnName                LastAnalyzed       l r Size (MB)       SampleSize  Len     NumDistinct       NumNulls            Density Histogram        ket
-------- --------------------------------------------- ------------------------- ------------------ - - --------- ---------------- ---- --------------- -------------- ------------------ --------------- ----
TABLE    SYS.T2                                        COL1                      11-FEB-23 09:20:04 Y N         0              100    4              11              0   .090909090909091 NONE               1
TABLE    SYS.T2                                        ID                        11-FEB-23 09:20:04 Y N         0              100    3             100              0   .010000000000000 NONE               1


--------------------------------------------------------------------------------------------------------------------------------------------------
| Id  | Operation              | Name | Starts | E-Rows |E-Bytes| Cost (%CPU)| A-Rows |   A-Time   | Buffers | Writes |  OMem |  1Mem | Used-Mem |
--------------------------------------------------------------------------------------------------------------------------------------------------
|   0 | CREATE TABLE STATEMENT |      |      1 |        |       |     7 (100)|      0 |00:00:00.01 |      24 |      1 |       |       |          |
|   1 |  LOAD AS SELECT        | Q    |      1 |        |       |            |      0 |00:00:00.01 |      24 |      1 |  1043K|  1043K| 1043K (0)|
|*  2 |   HASH JOIN            |      |      1 |     20 |   180 |     6   (0)|      7 |00:00:00.01 |       4 |      0 |  2078K|  2078K| 1219K (0)|
|   3 |    TABLE ACCESS FULL   | T1   |      1 |     20 |   120 |     3   (0)|     20 |00:00:00.01 |       2 |      0 |       |       |          |
|   4 |    TABLE ACCESS FULL   | T2   |      1 |    100 |   300 |     3   (0)|    100 |00:00:00.01 |       2 |      0 |       |       |          |
--------------------------------------------------------------------------------------------------------------------------------------------------

-- rows1*rows2/max(distinct1,distinct1) = rows1*rows2*min(density1,density2)

SQL> select 20*100*.010000000000000 from dual;

20*100*.010000000000000
-----------------------
                     20

