I have the following query with high execution time, where current indexes are created on individual columns ENTER_TIME and EXIT_TIME and location_id is primary_key on both the tables.
Database server: Oracle Database 19c Standard Edition 2
Version : 19.11.0.0.0
SELECT
trp.location,
trp.enter_time,
trp.exit_time
SUM(TIMEDIFF(trp.enter_time,trp.exit_time)) AS stay_time
FROM
trip_route_point trp
INNER JOIN
location l ON trp.location_id = l.location_id
WHERE
trp.enter_time BETWEEN '20221010070000' AND '20221108070000'
AND trp.exit_time IS NOT NULL
AND trp.exit_time >= trp.enter_time
GROUP BY
trp.location_id
HAVING
SUM(TIMEDIFF(trp.enter_time, trp.exit_time)) > 0
ORDER BY
stay_time DESC
Query performance is at 3 secs with 2.5 million rows in the trip_route_point
table.
I suspect trp.exit_time >= trp.enter_time
condition is not making use of the indexes.
From the execution plan I can see the query requires full table scan.
Please advise the best indexes to use to improve the query performance