I don't know enough about Mongo to comment on it; I suggest finding Mongo experts and asking them if you need precise details on how this works in that database.
Oracle has to perform 5 index comparesNo it doesn't!
The default index structure in Oracle Database is a B-Tree. This is an ordered data structure. So the entries in the index will be in this sequence - regardless of which order you inserted them or how they're physically stored in the table:
1, 1, 2, 2, 8, 9.
So in this case Oracle Database
has to read index entries 2, 2, 8. It
might also access 1, 1 if they happen to be in the same block. If that's the only data in the table by default everything will fit in one block so the database will report one consistent get.
For example, here both queries report one get (Buffers = 1) for the index range scan despite the first only returning rows = 2 and the other reading all the entries in the index:
create table t ( c1 int, c2 varchar2(100) default rpad ( 'stuff', 100, 'f' ) );
insert into t ( c1 )
values ( 1 ), ( 2 ), ( 2 ), ( 1 ), ( 8 ), ( 9 );
create index i on t ( c1 ) ;
exec dbms_stats.gather_table_stats ( user, 't' );
alter session set statistics_level = all;
set serveroutput off
select * from t
where c1 = 2;
select * from dbms_xplan.display_cursor ( format => 'IOSTATS' ) ;
------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 2 |00:00:00.01 | 2 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T | 1 | 2 | 2 |00:00:00.01 | 2 |
|* 2 | INDEX RANGE SCAN | I | 1 | 2 | 2 |00:00:00.01 | 1 |
------------------------------------------------------------------------------------------------------
select * from t
where c1 >= 1;
select * from dbms_xplan.display_cursor ( format => 'IOSTATS' ) ;
------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 6 |00:00:00.01 | 2 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T | 1 | 6 | 6 |00:00:00.01 | 2 |
|* 2 | INDEX RANGE SCAN | I | 1 | 6 | 6 |00:00:00.01 | 1 |
------------------------------------------------------------------------------------------------------
If we recreate the index with pctfree 99 this reserves lots of space in each block, so each leaf will only contain one entry.
Rerun the queries and you'll find
- c1 = 2 does 4 gets; 1 for the root block + three for the leaves 2, 2, 8
- c1 >= 1 does 7 gets; 1 for the root block + one get for each of the six rows
drop index i;
create index i on t ( c1 ) pctfree 99;
select * from t
where c1 = 2;
---------------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads |
---------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 2 |00:00:00.01 | 5 | 12 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T | 1 | 2 | 2 |00:00:00.01 | 5 | 12 |
|* 2 | INDEX RANGE SCAN | I | 1 | 2 | 2 |00:00:00.01 | 4 | 12 |
---------------------------------------------------------------------------------------------------------------
select * from dbms_xplan.display_cursor ( format => 'IOSTATS' ) ;
select /*+ index ( t ( c1 ) ) */* from t
where c1 >= 1;
select * from dbms_xplan.display_cursor ( format => 'IOSTATS' ) ;
------------------------------------------------------------------------------------------------------
| Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers |
------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1 | | 6 |00:00:00.01 | 8 |
| 1 | TABLE ACCESS BY INDEX ROWID BATCHED| T | 1 | 6 | 6 |00:00:00.01 | 8 |
|* 2 | INDEX RANGE SCAN | I | 1 | 6 | 6 |00:00:00.01 | 7 |
------------------------------------------------------------------------------------------------------
Oracle Database doesn't have an "index keys examined" metric that I know of. I don't think you can compare this Mongo metric directly to the work in Oracle Database.