Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Other Discussions
  3. The Weird and The Wonderful
  4. SQL Zoolander Trimming

SQL Zoolander Trimming

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasecom
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    AspDotNetDev
    wrote on last edited by
    #1

    SELECT Actions = REVERSE(RTRIM(REVERSE(@Plan))) -- LTRIM(@Plan)

    Copied verbatim from production code (including the code comment). :doh:

    [Forum Guidelines]

    P 1 Reply Last reply
    0
    • A AspDotNetDev

      SELECT Actions = REVERSE(RTRIM(REVERSE(@Plan))) -- LTRIM(@Plan)

      Copied verbatim from production code (including the code comment). :doh:

      [Forum Guidelines]

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Well, obviously right-trimming is more efficient than left-trimming.

      A 1 Reply Last reply
      0
      • P PIEBALDconsult

        Well, obviously right-trimming is more efficient than left-trimming.

        A Offline
        A Offline
        AspDotNetDev
        wrote on last edited by
        #3

        LOL, I couldn't think of why they would possibly do that, but a misguided attempt at optimization seems feasible.

        [Forum Guidelines]

        D 1 Reply Last reply
        0
        • A AspDotNetDev

          LOL, I couldn't think of why they would possibly do that, but a misguided attempt at optimization seems feasible.

          [Forum Guidelines]

          D Offline
          D Offline
          David Skelly
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups