I have the below query which i want to tune as the query takes more time to run. Please help me out.
select info_id
from info_table
where info_id not in (select info_id
from some_table
where info_id is not null)
AND rownum <= 1000 ;
The innerquery is returning millions of rows and hence the problem.
The following recommendations will help you in your SQL tuning process.
You'll find 3 sections below:
ALTER TABLE `info_table` ADD INDEX `info_table_idx_rownum` (`rownum`);
ALTER TABLE `some_table` ADD INDEX `some_table_idx_info_id` (`info_id`);
SELECT
info_table.info_id
FROM
info_table
WHERE
NOT EXISTS (
SELECT
1
FROM
some_table
WHERE
(
some_table.info_id IS NOT NULL
)
AND (
info_table.info_id = some_table.info_id
)
)
AND info_table.rownum <= 1000