ResultSet: Retrieving column values by index versus retrieving by label

Warning: I’m going to get bombastic here, because this drives me crazy.

99%* of the time, it’s a ridiculous micro-optimization that people have some vague idea makes things ‘better’. This completely ignores the fact that, unless you’re in an extremely tight and busy loop over millions of SQL results all the time, which is hopefully rare, you’ll never notice it. For everyone who’s not doing that, the developer time cost of maintaing, updating, and fixing bugs in the column indexing are far greater than the incremental cost of hardware for your infinitesimally-worse-performing application.

Don’t code optimizations like this in. Code for the person maintaining it. Then observe, measure, analyse, and optimize. Observe again, measure again, analyse again, and optimize again.

Optimization is pretty much the last step in development, not the first.

* Figure is made up.

Leave a Comment