SQL Zoolander Trimming
-
SELECT Actions = REVERSE(RTRIM(REVERSE(@Plan))) -- LTRIM(@Plan)
Copied verbatim from production code (including the code comment). :doh:
-
SELECT Actions = REVERSE(RTRIM(REVERSE(@Plan))) -- LTRIM(@Plan)
Copied verbatim from production code (including the code comment). :doh:
Well, obviously right-trimming is more efficient than left-trimming.
-
Well, obviously right-trimming is more efficient than left-trimming.
LOL, I couldn't think of why they would possibly do that, but a misguided attempt at optimization seems feasible.
-
LOL, I couldn't think of why they would possibly do that, but a misguided attempt at optimization seems feasible.
Almost certainly. If you are doing a search, then LTRIM(my_col) LIKE 'A%' may be much slower than RTRIM(my_col) LIKE 'A%'. That's because the second query can use an index on my_col, whereas the first one can't. So, from there someone might wrongly conclude that the LTRIM operation itself is slower than RTRIM, and avoid using LTRIM in all cases. It's not the LTRIM operation per se that's a problem, it's the fact that it precludes the use of indexes during searches.