2
select id, name from myTable; 

or

select id, name from myTable where name like "%";

Does Mysql optimize the second query?

Update: myTable has only three columns id(primary key), name and age .No of rows in myTable are in range(5-10)k.

what if we create an index on column "name"?

Joker
  • 157
  • 1
  • 7
  • 3
    This might depend on many factors (schema, # of entries, server, mysql-conf ..) I will vote to close your question, although it is an interesting topic. But, it is too broad and you deliver very few information about own benchmarks you did, how the table looks like etc. – Felix Sep 07 '15 at 05:55
  • 1
    The best way to know what horse is faster. `Put both to race in a track`. Mean do your testing, use query `analyzer` – Juan Carlos Oropeza Sep 07 '15 at 05:56
  • 3
    I don't think both are same. Second query is going to eliminate `NULL` values – Pரதீப் Sep 07 '15 at 06:00

1 Answers1

0

I think the execution of second query will be faster.
In the order of execution of queries WHERE clause comes before select. So if you are using Where then it will filter the no. of records. When select will work on top of it , Select will work faster(specially when you have huge data in DB).

Reference:
What is the order of execution for this SQL statement

Community
  • 1
  • 1
Biswabid
  • 1,378
  • 11
  • 26