I read some of the discussion in this question and thought to myself that in my PL/SQL code I have "exists" style queries all over the place that don't use the ROWNUM=1 optimisation.
The questions I have are:
- Does the introduction of ROWNUM=1 significantly increase performance?
- If so, under what conditions would performance be particularly improved (e.g lots of joins, constraints on unindexed columns, large tables, large result sets)
I'm trying to determine of it is worth rewriting all of my existing queries to add a ROWNUM=1 optimisation.
The queries I'm thinking of are ones that may have multiple joins and may query large tables. They have the general form of:
SELECT 1
INTO ln_count
FROM table_1, table_2...., table_n
WHERE <various joins and conditions>;
IF ln_count > 0 THEN
<do stuff>
END IF;
I'm considering changing them to:
SELECT 1
INTO ln_count
FROM table_1, table_2...., table_n
WHERE <various joins and conditions>
AND ROWNUM = 1;
IF <local variable> > 0 THEN
<do stuff>
END IF;