Reputation: 8805
Is there's a noteworthy difference? I'm talking about a program that spends a lot of its time reading results from queries, and some runs (these are web hits) are taking upwards of 2 minutes. If I can shave a few seconds off just by using integers instead of field names, I figure I get some time for free.
Upvotes: 0
Views: 238
Reputation: 4686
I think this would depend on the implementation of the java.sql.ResultSet. As an example, the DB2 implementation for zOS must hash the java.lang.String back into the columned index whereas the indexed version uses the index directly. I'm guessing other implementations are similiar. The additional processing time would be negligible.
Unless you are needing to stretch every bit of performance you can, I think the cost of using indexes versus the actual column name is not worth it. There is a cost to maintainability.
Upvotes: 2
Reputation: 33082
There is not a noteworthy difference in this case.
If some queries are taking upwards of 2 minutes, I highly doubt this is from spending time comparing strings in this manner. It's much more likely that the queries are slow.
You should run a profiler on your database to isolate the long running queries. Then either re-index your database tables to better support those queries, or modify those queries to use the existing indices.
Upvotes: 3