Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL Operator >= has higher performance than >

I got asked one question in interview.

Below two SQL will get same result. but which one have higher performance?

SELECT * FROM EMP WHERE DEPTNO >= 4

SELECT * FROM EMP WHERE DEPTNO > 3

The answer is first one . In first SQL , Database will locate DEPT =4 directly where searching. it has higher performance. In second SQL , Database will locate DEPT =3, and forwardly scan row which is larger than 3 .

It is my first time heard that theory. I can't see any difference form execute plan and stat number.

Is there any official explanation for it ?

I found some Chinese website share the same tips.

http://edm.ares.com.tw/dm/newsletter-2014-03-uPKI-OTP-newrelease/it-1.php

like image 906
Gary Li Avatar asked Nov 26 '25 04:11

Gary Li


1 Answers

I find that to be a myth if the column has an index on that field. I tried with a primary key and both execution plans use an Index Range Scan which is quite fast on a primary key or unique index. The two queries performance is extremely close to each other and both return a similar cost, but the one with ">" was 0.3% better on the estimated CPU cost than ">=". I say BUSTED!

Besides, when I say something performs better, normally I would mean 10%+ if not more.

like image 66
Gui Avatar answered Nov 28 '25 19:11

Gui



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!