In MySQL there are 3 ways to return the first occurrence of a substring in a string:
LOCATE(substr,str), LOCATE(substr,str,pos)
INSTR(str,substr)
POSITION(substr IN str)
In addition to LOCATE allow the search start position parameter, according to Beginning MySQL Database Design and Optimization: From Novice to Professional (Chad Russell, Jon Stephens, 2004: 208):
POSITION () is standard SQL, LOCATE () is specific to MySQL (), INSTR () is
supported for compatibility with ORACLE.
That is: POSITION () would be the default mysql, LOCATE () MySQL native function () and INSTR () would be present to maintain compatibility with ORACLE banks.
And everything indicates that they have the same implementation, since Item_func_instr extends the Item_func_locate class inside the MySQL source code in sql / item_func.h:
class Item_func_instr : public Item_func_locate
{
public:
Item_func_instr(const POS &pos, Item *a, Item *b) :Item_func_locate(pos, a, b)
{}
const char *func_name() const { return "instr"; }
};
It is important to note that in the MySQL manual, POSITION (substr IN str) appears as synonymous with LOCATE (substr, str). However, with INSTR and LOCATE, although the function description is the same for the INSTR (str, substr) vs LOCATE (substr, str) format, there are no mentions about the implementation.