I was wondering if it’s faster to select all fields from a table like:
SELECT *
or select just the ones you really need:
SELECT field1, field2, field3, field4, field5...
assuming the table has around 10 fields, and I only need like 5 or 6 for this operation
Wherever possible, it’s faster to select precise fields. Your intuition is correct: anything you can conceptualize as wasted machine time is likely indeed wasted work, though the magnitude is always subject to question. This particular example is one reason generated code (through ORM) is so popular! With ORM, most basic and repetitive optimization stuff is in the hands of the ORM itself, and custom hand-written queries are the exception rather than the rule.