I am not a query performance expert and I am learning how Oracle optimizer works on different queries and tune them for its use. Below is such query from my project where I am stuck on optimizing it for the large data set (it's slowing down for large dataset).
SELECT
v1.id,
v1.date_created,
v1.name,
v1.size
FROM
ver v1
INNER JOIN (
SELECT
id,
MAX(date_created) AS last_date_created
FROM
ver
WHERE
id IN (
...500 ids
)
AND active = 'Y'
AND archived = 'N'
GROUP BY
id
) v2 ON v1.date_created = v2.last_date_created
AND v1.id = v2.id
I tried the SQL developer query tuning advisor, no recommendation. The problem here is it's going for full table scan on both parts of the query and not using any index and ver table contain nearly 1M records. Below is ver table script
create table ver
( "Ver_id" VARCHAR2(36 BYTE) Primary key
"NAME" VARCHAR2(255 BYTE)
"ACTIVE" VARCHAR2(1 BYTE)
"ARCHIVED" VARCHAR2(1 BYTE)
"DESCRIPTION" VARCHAR2(255 BYTE),
"ID" VARCHAR2(36 BYTE)
"DATE_CREATED" NUMBER(*,0)
"CREATED_BY_USER" VARCHAR2(64 BYTE)
"SIZE" NUMBER(*,0)
"LAST_MODIFIED" NUMBER(*,0))
and indexes are one nonunique index on id and one unique index on (id,name) and non unique on last_modified.
The query is taking nearly 2-3min for its execution now. Any suggestions on it.