• unknown's avatar
    BUG 11104 (same as changeset 1.1891 on the 5.0 tree, but realised this · 16c45930
    unknown authored
    needed to be fixed in earlier versions)
    Fixed the iteration of how substrings are handled with negative indexes in 
    SUBSTRING_INDEX
    
    
    mysql-test/r/func_str.result:
      New results for the fix to substring_index
    mysql-test/t/func_str.test:
      Added tests for fix to substring_index, various lenth search patterns. Also included
      are the queuries the user who reported the bug listed in the bug report
    sql/item_strfunc.cc:
      Fix to BUG 11104 
          Took out the offset-=delimiter_length-1 out of the for loop. It was causing
          basically this: 
          select substring_index('the king of the the hill', 'the', -2) to not work.
          The first iteration, offset would be initialised to 24, then strstr would 
          point at 'the king of the the* hill' ('*'means right before the 
          character following), returning a offset of 16. The for loop would then 
          decrement offset by two (3 - 1), to 14, now pointing at 
          "the king of th*e the hill", _skipping_ past the 'e' in the second to last
          'the', and therefore strstr would never have a chance of matching the 
          second to last 'the', then moving on to the 'the' at the begginning of the 
          string!
      
          In a nutshell, offset was being decremented by too great a value, preventing
          the second to last 'the' from being ever found, hence the result of 
          'king of the the hill' from the query that is reported in the bug report
    16c45930
item_strfunc.cc 54.6 KB