HiveBrain v1.2.0
Get Started
← Back to all entries
patternsqlMinor

Is this a new common pattern in Oracle Where exists ( Select NULL FROM...)?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
thisfromnewnullwhereexistsselectoraclecommonpattern

Problem

Years ago, it was common to write

where exists (Select * from some_table where some_condition)


Last year I noticed that many t-sql scripts switched to using the number 1 instead of the star

where exists (Select 1 from some_table where some_condition)


just on SO I saw this Oracle example

WHERE EXISTS (SELECT NULL FROM ...


Is this a common pattern with Oracle?
And which are the performance arguments to use something like this.

Solution

Short answer: I would hope not!

Even the SELECT 1 idiom may have outlived its usefulness, as database engines have advanced enough to recognize that you don't really want the rows, you just want to know if the rows exist. I've looked at execution plans in SQL 2005, and have generally seen these re-written as joins, even where SELECT * is used.

Context

StackExchange Database Administrators Q#287, answer score: 6

Revisions (0)

No revisions yet.