Bug #79036 SUBSTRING_INDEX works incorrectly with negative count
Submitted: 30 Oct 2015 14:11 Modified: 30 Oct 2015 17:42
Reporter: Su Dylan Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server: Data Types Severity:S3 (Non-critical)
Version:5.7.8 OS:Any
Assigned to: CPU Architecture:Any

[30 Oct 2015 14:11] Su Dylan
Description:
Output:
======
mysql> select SUBSTRING_INDEX( 'www.mysql.com','.', -9223372036854775806);
+-------------------------------------------------------------+
| SUBSTRING_INDEX( 'www.mysql.com','.', -9223372036854775806) |
+-------------------------------------------------------------+
| www.mysql                                                   |
+-------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select SUBSTRING_INDEX( 'www.mysql.com','.', -9223372036854775807);
+-------------------------------------------------------------+
| SUBSTRING_INDEX( 'www.mysql.com','.', -9223372036854775807) |
+-------------------------------------------------------------+
| www                                                         |
+-------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select version();
+-----------+
| version() |
+-----------+
| 5.7.8-rc  |
+-----------+
1 row in set (0.00 sec)

Problem:
=======
Quote from manual 
https://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_substring-index
:
=====
 SUBSTRING_INDEX(str,delim,count)

Returns the substring from string str before count occurrences of the delimiter delim. If count is positive, everything to the left of the final delimiter (counting from the left) is returned. If count is negative, everything to the right of the final delimiter (counting from the right) is returned. SUBSTRING_INDEX() performs a case-sensitive match when searching for delim.
=====
When count is negative, the result should return right part/all of str.
However, in the provided two examples, left part of str is returned, which is incorrect.

How to repeat:
select SUBSTRING_INDEX( 'www.mysql.com','.', -9223372036854775806);
select SUBSTRING_INDEX( 'www.mysql.com','.', -9223372036854775807);

Suggested fix:
For the following two SQLs, the whole str ("www.mysql.com") is returned.
[30 Oct 2015 17:42] MySQL Verification Team
Hi,

There is nothing wrong with the above function. If you read our manual carefully, you will find out that the range of values for the signed 64-bit integer is the following one:

-9223372036854775806 to  9223372036854775807

Hence, reduce your negative number . Also , there is no need, absolutely that parameter counts gets maximum so large or small values.
[30 Oct 2015 17:42] MySQL Verification Team
Hence, not a bug !!!