Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Would you send this simple SQL back for rework?

Tags:

sql

oracle

We have a web application in which the users perform ad-hoc queries based on parameters that have been entered. I might also mention that response time is of high importance to the users.

The web page dynamically construct a SQL to execute based on the parameters entered. For example, if the user enters "1" for "Business Unit" we construct a SQL like this:

SELECT * FROM FACT WHERE 
BUSINESS_UNIT = '1'
--AND other criteria based on the input params

I found that where the user does not specify a BUSINESS_UNIT the following query is constructed

SELECT * FROM FACT WHERE 
BUSINESS_UNIT LIKE '%'
--AND other criteria based on the input params

IMHO, this is unnecessarily (if not grossly) inefficient and warrants sending the code bad for modification but since I have a much higher rate of sending code back for rework than others, I believe that I may be earning a reputation as being "too picky."

If this is an inappropriate question because it is not a direct coding Q, let me know and I will delete it immediately. I am very confused whether subjective questions like this are allowed or not! I'll be watching your replies.

ty


Update:

I am using an Oracle database.

My impression is that Oracle does not optimize "LIKE '%'" by removing the condition and that leaving it in is less efficient. Could someone confirm?

like image 751
Chad Avatar asked Jan 11 '10 23:01

Chad


1 Answers

The two queries are completely different (from the point of view of a result set)

SELECT * FROM FACT;

and

SELECT * FROM FACT WHERE  
BUSINESS_UNIT LIKE '%';

The first will return all rows, the second, if there are NULL values those rows will not be returned because anything compared to NULL is NULL and therefore does not satisfy the predicate. This is how it would work in Oracle.

like image 99
Stellios Avatar answered Sep 23 '22 05:09

Stellios