Is doing an exact match filter based on a text column conceptually slower than grabbing a set of rows based on a key and filtering using the programming language?
For example:
select columns from table where textcolumn='exactphrase';
vs
select columns from table where key='key';
for (results : resultset) {
if (resulsts.getString(textcolumn).equals(exactphrase)) { ... } }
I’m basically curious as to how MySQL (Innodb) deals with filtering text columns and what the performance pitfalls may be (if any).
tldr; There will be no performance difference for “finding” the record.
Since the (indexed) PK is being used then at most a single record will be returned. The server is smart enough to not perform a table scan on the text column, even if it is not indexed because of the 1-1 cardinality of the PK. (Query planners are smart.)
The differences are then:
The server might return a “useless” record to the client; this may waste a small amount of bandwidth1 (and slightly more wasteful if the text isn’t required except for the test anyway), but more importantly it muddles semantics of the query.
The server supports different collation modes; it might therefor be case insensitive (e.g.) on the server and result in slightly different results than a client side filter.
1 While very degenerate cases can be imagined, this should be take as “equivalent time” without an explicit use/performance case. It is, however, IMOHO, still sloppy to do this on the client side without further reason.