Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Is there a way to use Lower with out a full table scan

I'm currently using lower() function in my SQL.

As per this thread, using lower() on a column will cause a full table scan: Avoid full table scan

Is there a way to prevent this or minimise the impact of the scan? I'm using Oracle 10.

My Sql:

select * from USER u where lower(u.USERNAME) = lower(?)
like image 982
JackDev Avatar asked Jan 28 '26 23:01

JackDev


1 Answers

If you always search using low cases, you can create an index on the case-lowered Username, like I did in this demo.

Here the syntax from my demo:

CREATE TABLE t1
    (username varchar2(4))
;

CREATE INDEX t1_idx ON t1(lower(username));
like image 104
mucio Avatar answered Jan 30 '26 16:01

mucio



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!