Subject | MAX() and index |
---|---|
Author | Tim Ward |
Post date | 2015-09-07T13:00:27Z |
Please can someone explain to me, again, why
select Max(MYCOL) from MYTAB
doesn't use the primary key
PLAN (MYTAB NATURAL)
Current memory = 3074072
Delta memory = -20
Max memory = 3217516
Elapsed time= 0.27 sec
Buffers = 150
Reads = 1811
Writes 0
Fetches = 894779
of which it is the first field
CONSTRAINT PK_MYTABPRIMARY KEY (MYCOL, OTHERCOL)
and instead reads thousands of pages from disk and takes over a quarter
of a second?
(I'm just curious and wanting to understand, really. I'm going to fix
the actual problem with a change of approach, that's needed for other
reasons anyway, which eliminates the problem query.)
--
Tim Ward
select Max(MYCOL) from MYTAB
doesn't use the primary key
PLAN (MYTAB NATURAL)
Current memory = 3074072
Delta memory = -20
Max memory = 3217516
Elapsed time= 0.27 sec
Buffers = 150
Reads = 1811
Writes 0
Fetches = 894779
of which it is the first field
CONSTRAINT PK_MYTABPRIMARY KEY (MYCOL, OTHERCOL)
and instead reads thousands of pages from disk and takes over a quarter
of a second?
(I'm just curious and wanting to understand, really. I'm going to fix
the actual problem with a change of approach, that's needed for other
reasons anyway, which eliminates the problem query.)
--
Tim Ward