0

How to fix the performance issue with the in operator.

SELECT * 
FROM Q1 
WHERE Q1.sample IN (SELECT COLUMN_VALUE 
                    FROM TABLE(APEX_STRING.SPLIT(NVL(:P34_ACC,Q1.sample ),',')))
1
  • Why should I "tag my RDBMS"? - please add a tag to specify whether you're using mysql, postgresql, sql-server, oracle or db2 - or something else entirely. Commented Jun 3, 2021 at 5:19

1 Answer 1

2

You are using a function to generate rows in your IN clause. Oracle cannot know whether this will result in say, one or two rows or five billion rows. Thus it can only come up with a general execution plan, that may or may not be good.

You can hint Oracle as to the number of expected rows using the undocumented CARDINALITY hint:

SELECT *
FROM Q1 
WHERE Q1.sample IN 
(
  SELECT /*+cardinality(t, 10)*/ COLUMN_VALUE 
  FROM TABLE( APEX_STRING.SPLIT(NVL(:P34_ACC,Q1.sample ),',')) t
);

For the case of few rows, you should have an index on Q1.sample:

CREATE INDEX idx ON q1(sample);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.