Bug #27545 NAME_CONST() fails to return
Submitted: 30 Mar 2007 10:21 Modified: 14 Dec 2007 17:59
Reporter: Martin Friebe (Gold Quality Contributor) (OCA) Email Updates:
Status: Closed Impact on me:
Category:MySQL Server Severity:S3 (Non-critical)
Version:5.0.40 OS:FreeBSD (freebsd)
Assigned to: Igor Babaev CPU Architecture:Any
Tags: Contribution, name_const
Triage: D3 (Medium)

[30 Mar 2007 10:21] Martin Friebe
name_const is documented as an internal function.

Therefore it is ok, if it produces generic, non intuitive errors such as:

 select name_const(x,2) from (select 1 x UNION select 2 union select 4) x ;
 ERROR 1105 (HY000): Unknown error

However queries containing it should either return a result of any kind or an error.
The following query never returns
 select * from ( select name_const(x,2) from (select 1 x UNION select 2 union select 4) x ) c;

It does seem to finish on the server (it disappears from the processlist), but nothing is ever returned to the mysql client.
The mysql client will hang indefinably waiting for a result (or error) to be returned)

How to repeat:
select * from ( select name_const(x,2) from (select 1 x UNION select 2 union select 4) x ) c;

Suggested fix:
[30 Mar 2007 10:59] Sveta Smirnova
Thank you for the report.

Verified as described.
[8 Apr 2007 20:36] Martin Friebe
proposal for a patch

Attachment: name_const.patch (text/x-patch), 1.74 KiB.

[8 Dec 2007 7:35] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:


ChangeSet@1.2597, 2007-12-07 23:36:58-08:00, igor@olga.mysql.com +3 -0
  Fixed bug #27545.
  Both arguments of the function NAME_CONST must be constant expressions.
  This constraint is checked in the Item_name_const::fix_fields method. 
  Yet if the argument of the function was not a constant expression no
  error message was reported. As a result the client hanged waiting for a
  Now the function Item_name_const::fix_fields reports an error message
  when any of the additional context conditions imposed on the function
  NAME_CONST is not satisfied.
[14 Dec 2007 8:15] Bugs System
Pushed into 5.0.54
[14 Dec 2007 8:19] Bugs System
Pushed into 5.1.23-rc
[14 Dec 2007 8:22] Bugs System
Pushed into 6.0.5-alpha
[14 Dec 2007 17:59] Jon Stephens
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at


Documented in the 5.0.54, 5.1.23, and 6.0.5 changelogs as follows:

        Some queries using the NAME_CONST() function failed to
        return either a result or an error to the client, causing it to
        hang. This was due to the fact that there was no check to insure
        that both arguments to this function were constant expressions.