Roland Bouman wrote:
> The UDF_INIT struct passed to UDF's contains a
> const_item member. It is not documented in the
> manual, but in mysql_com.h a comment sais this:
>
> my_bool const_item; /* 0 if result is
> independent of arguments */
>
> Does anyone know the exact semantics of this one?
I believe it's kind of both (plus see below)... If the function only returns the *same* value regardless of the arguments passed to it (or no arguments passed to it), then it should be marked as 1. If not, then 0, *unless* you are trying to "trick" MySQL into evaluating the function as the rows are sent to the client, and not during the ORDER BY or WHERE phase. See udf_example.cc for an example of how they are doing this for the fake SEQUENCE() function...
> I mean, the name suggests it should be set to TRUE
> to mark your udf as a constant. However this does
> not cover the meaning of "...independent of
> arguments..." : i can have a function that is
> neither constant, nor dependant upon the
> arguments.
>
> Also, the comment suggests we should set it to 0
> to mark it , i expected to need to set it to 1,
> not 0
>
> So what is it?
Set to 1, not 0, if the function returns a constant value. I believe the comments in the source are incorrect in mysql_com.h, and correct in udf_example.cc (lines 622-628).
Jay Pipes
Community Relations Manager, North America, MySQL Inc.
Got Cluster?
http://www.mysql.com/cluster
Personal:
http://jpipes.com
Edited 1 time(s). Last edit at 12/05/2005 07:07PM by Jay Pipes.