Bug #63250 Overloading undocumented function 'equals'
Submitted: 14 Nov 2011 16:48 Modified: 14 Dec 2011 17:05
Reporter: Anca Buit Email Updates:
Status: No Feedback Impact on me:
None 
Category:MySQL Server: Errors Severity:S3 (Non-critical)
Version:5.1.33 OS:Any
Assigned to: CPU Architecture:Any

[14 Nov 2011 16:48] Anca Buit
Description:
When defining a user function with the name 'equals' this function is accepted without any error. When executing however, it seems to use a native function with the same name and not the user created one.

The function 'equals' is not listed in the function list or in the reserved words list.

How to repeat:
CREATE FUNCTION equals ()
RETURNS CHAR(50) DETERMINISTIC
RETURN 'Userdefined equals';

select equals();

--> 1582 incorrect parameter count in the call to native function 'equals'

Suggested fix:
Display an error message when creating a function with a name that already exists, or adapt documentation to list it as a function / reserved word.
[14 Nov 2011 17:05] Valeriy Kravchuk
Indeed, this function can be created:

macbook-pro:trunk openxs$ bin/mysql -uroot test
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.4-m5 Source distribution

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> CREATE FUNCTION equals ()
    -> RETURNS CHAR(50) DETERMINISTIC
    -> RETURN 'Userdefined equals';
Query OK, 0 rows affected, 1 warning (0.02 sec)

mysql> show warnings\G
*************************** 1. row ***************************
  Level: Note
   Code: 1585
Message: This function 'equals' has the same name as a native function
1 row in set (0.00 sec)

Note that warning is produced, explaining the problem with it. Indeed, it can not be used the way you tried:

mysql> select equals();
ERROR 1582 (42000): Incorrect parameter count in the call to native function 'equals'

But it still makes sense to allow to create it, as you can just specify database name to call the function you defined:

mysql> select test.equals();
+--------------------+
| test.equals()      |
+--------------------+
| Userdefined equals |
+--------------------+
1 row in set, 1 warning (0.00 sec)

mysql> show warnings\G
*************************** 1. row ***************************
  Level: Note
   Code: 1585
Message: This function 'equals' has the same name as a native function
1 row in set (0.00 sec)

Please, check if results are the same on recent 5.1.x (5.1.59+), and, if they are, I'd say this is not a bug.
[15 Nov 2011 6:00] MySQL Verification Team
For the record, "equals" is a spatial function..
http://dev.mysql.com/doc/refman/5.5/en/functions-for-testing-spatial-relations-between-geo...
[15 Dec 2011 7:00] Bugs System
No feedback was provided for this bug for over a month, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".