Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL Select with WHERE condition, what happens in the background?

Tags:

sql

sql-server

Assume I do not have text indexing on. Let say I have:

SELECT * FROM myTable WHERE myTable.columnA LIKE 'bobo'

Will the SQL engine go through every row and only return those matching conditions or is SQL smarter and does do some hidden native indexing?

I'm on MSSQL 2000, 2005, 2008 but if other versions of SQL have different approaches I'm all ears.

Is there a good online doc or even book that goes into how operations are carried out?

like image 875
Matt Avatar asked Jan 21 '26 04:01

Matt


2 Answers

Put that query into an SQL Server Management Studio query, and enable the "Include actual execution plan" option before you run it. It will give you a detailed diagram of all the steps that are undertaken to execute the query, along with all of the indexes that are being used and how.

like image 131
Welbog Avatar answered Jan 22 '26 18:01

Welbog


If you look into the execution plain for this query:

SELECT  *
FROM    mytable
WHERE   columnA LIKE 'bobo%'

you will see that it will be rewritten as:

SELECT  *
FROM    mytable
WHERE   columnA >= 'bobo'
        AND columnA < 'bobP'

, using INDEX SEEK over an index on columnA, if any.

like image 28
Quassnoi Avatar answered Jan 22 '26 18:01

Quassnoi



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!