インデックススキャンでnot nullカラムをcountする場合のテーブルルックアップ有無

(8.0.31)
https://dev.mysql.com/doc/refman/8.0/en/explain-output.html#jointype_index

drop table tab1;
create table tab1(col1 int primary key ,col2 int ,col3 int not null   );

create index ind1 on tab1(col1,col2);


explain
select /*+ INDEX(tab1 ind1) */ col1, sum(col2) ,count(col3)
from tab1
group by col1
order by col1
;

col3のnot null制約有無に関わらず
type=index,Extra=NULLのため、テーブルルックアップは発生する

(19c)

drop table tab1 purge;
create table tab1(col1 int primary key ,col2 int ,col3 int not null  );

create index ind1 on tab1(col1,col2);

explain plan for
select /*+ INDEX(tab1 ind1) */ col1, sum(col2) ,count(col3)
from tab1
group by col1
order by col1
;

select plan_table_output from table(dbms_xplan.display(format=>'ALL') );


col3にnot null制約がある場合、テーブルルックアップは発生しない★
col3にnot null制約がない場合、テーブルルックアップは発生する

 

(15)

drop table tab1;
create table tab1(col1 int primary key ,col2 int ,col3 int not null   );

create index ind1 on tab1(col1,col2);


/*+ IndexOnlyScan(tab1 ind1) */
explain analyze
select col1, sum(col2) ,count(col3)
from tab1
group by col1
order by col1
;

col3のnot null制約有無に関わらず、テーブルルックアップは発生する

 

 

(2019)

drop table tab1;
create table tab1(col1 int primary key ,col2 int ,col3 int not null   );

create index ind1 on tab1(col1,col2);


select col1, sum(col2) ,count(col3)
from tab1
group by col1
order by col1
OPTION( TABLE HINT ( tab1, index( ind1 ) ) )
;


col3のnot null制約有無に関わらず、テーブルルックアップは発生する