List:General Discussion« Previous MessageNext Message »
From:Dan Nelson Date:November 5 2012 12:05am
Subject:Re: UDF behaves non-deterministic
View as plain text  
In the last episode (Nov 04), Stefan Kuhn said:
> I have a weired (for me at least) problem with a user defined function,
> written in C.  The function seems to return different results in different
> runs (the code of the function does not contain random elements). 
> Basically, the function calculates a score based on a column in a table
> and an input value.  So I do something like this:
> select * from table order by udf(column, 'input_value') desc;
> For my understanding, this should give the same result always. But if I
> run many statements (execution is from a java program and I can do it in
> parallel threads) so that they overlap (the udf on a large table takes
> 5-10 s on a slow machine), the results of some queries are different.  If
> I have enough time between statements, it seems to work, i.  e.  the
> result is always the same.  I would have thought the statements are
> independent, even if executed on different jdbc connections in parallel.
> Does somebody have an idea?  Or could somebody give an idea on debugging? 
> Normally I would try to debug the code to see what goes on, but how can I
> do this in a udf?  Can I log in the udf?

The first thing I would do is examine your UDF and ensure that it is
thread-safe.  No global variables, no static variables within functions,
etc.  Also make sure that any libc functions you call that are documented as
non-threadsafe are wrapped by a mutex or otherwise protected against
multiple simultaneous access.

As for debugging, you should be able to write things to stderr which will
show up in the mysql logfile, or you could open your own logfile and write
to that.

	Dan Nelson
UDF behaves non-deterministicStefan Kuhn4 Nov
  • Re: UDF behaves non-deterministicDan Nelson5 Nov
  • Re: UDF behaves non-deterministicwalter harms5 Nov
  • Re: UDF behaves non-deterministichsv5 Nov
    • Re: UDF behaves non-deterministicStefan Kuhn5 Nov
Re: UDF behaves non-deterministicMichael Dykman4 Nov
  • Re: UDF behaves non-deterministicStefan Kuhn4 Nov