Yet another quiz inspired by Freenode#mysql IRC discussions. If
you haven’t been around on the channel lately, you should have a
peek. Lots of interesting discussions going on!
mysql> SELECT c1, c2 FROM t WHERE c2 LIKE 'a%';
+------+------+
| c1 | c2 |
+------+------+
| a | abc |
+------+------+
Is the following construct for the LIKE clause legal?
SELECT c1, c2 FROM t WHERE c2 LIKE CONCAT('a', '%');
And how about this one?
SELECT c1, c2 FROM t WHERE c2 LIKE CONCAT(c1, '%');
Bonus question: Suppose the table has many rows, several more
columns and there’s an index on (c2, c1). Could that index be
utilized when running the legal versions of the query — and if
so, how?
[hint]Hint: Perhaps some parts of the statement
are optimized away before evaluation? [/hint]
[answer]Answer:Both the constructs shown are
legal. …
[Read more]