If I have two queries
SELECT Id, Forename, Surname
FROM Person
WHERE PersonName Like(‘%frank%’)
And
SELECT *
FROM Person
WHERE PersonName Like(‘%frank%’)
Which query will run faster? Is the where clause / table joining the biggest factor, or the number of columns returned?
I’m asking because I’m building a series of objects that map to database tables. Typically each object will have at least these three methods:
Select
– Selects everything
List
– Selects enough that is can be used to populate a dropdown list
Search
– Selects everything that is viewable in the results, typically about 6 or so columns.
If each query returned exactly the same set of columns the maintenance and testing of the code should be more trivial. The database is unlikely to get above 50,000 rows in any given table, so if the difference in performance is small then I’ll take the saving in development time. If the performance is going to drop through the floor, then I’ll work at in from a different angle.
So, for ease of development, is SELECT *
sensible, or is it naive?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…