Quantcast
Channel: User AHungerArtist - Stack Overflow
Viewing all articles
Browse latest Browse all 38

Force SQL subquery to be run first

$
0
0

I have a (simplified) query like so:

SELECT DISTINCT this_.person_id AS y0_  FROM coded_entity this_ WHERE this_.code     = ?   AND this_.tenant_id  = ?   AND this_.person_id IN (SELECT person_id                             FROM person that                            WHERE that.date_voided IS NULL                              AND that.ssn            = ?                              AND that.tenant_id      = ? ) 

I would like to be able to force Oracle to always execute the innermost subquery first because I know it will always be more selective. Code only has a few values whereas the ssn has a far greater multitude. Each table will have the same number of rows.

However, in actual practice, sometimes the Oracle CBO decides to execute the coded_entity query first, causing much slower times.

Is there a way to force this behavior without splitting up the query into separate calls?


Viewing all articles
Browse latest Browse all 38

Latest Images

Trending Articles



Latest Images