Bug #68946 | UDF *_init and *_deinit functions called only once for multiple-row select | ||
---|---|---|---|
Submitted: | 13 Apr 2013 10:13 | Modified: | 17 Apr 2013 5:36 |
Reporter: | Sveta Smirnova | Email Updates: | |
Status: | Not a Bug | Impact on me: | |
Category: | MySQL Server: User-defined functions ( UDF ) | Severity: | S3 (Non-critical) |
Version: | 5.5.32, 5.6.12, 5.1.70, 5.0.97 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[13 Apr 2013 10:13]
Sveta Smirnova
[13 Apr 2013 10:14]
Sveta Smirnova
test case
Attachment: initid_bug.zip (application/zip, text), 172 bytes.
[14 Apr 2013 16:47]
Daniël van Eeden
The attached zip file seems to be empty. $ unzip -l initid_bug.zip Archive: initid_bug.zip Length Date Time Name --------- ---------- ----- ---- 0 2013-04-13 11:23 initid_bug/ --------- ------- 0 1 file
[15 Apr 2013 0:04]
Sveta Smirnova
fixed test case
Attachment: initid_bug.zip (application/zip, text), 17.68 KiB.
[15 Apr 2013 0:05]
Sveta Smirnova
Ups! Sorry for that. Fixed archive attached.
[15 Apr 2013 10:56]
Roland Bouman
Please, don't change the UDF interface, and keep the calling sequences as is. In addition, I personally don't think the current documentation is unclear or incomplete in any way. The way I read it, it says that the UDF interface provides a 255byte pre-allocated buffer that we may or may not use, and that it also provides an additional ptr member which can be used to keep track of additional resources. The nature of C/C++ is such that one must explicitly allocate and deallocate memory; therefore it stands to reason that if the user finds the pre-allocated buffer does not suit their needs they will need to allocate memory themselves and free it again too. The documentation provides a few helpful hints that allocating may be done in the init and xxx function, and that it *must* be deallocated again no later than the deinit function.
[15 Apr 2013 11:44]
Sveta Smirnova
Roland, I still think it is not clear when exactly *_init and *_deinit functions called.
[17 Apr 2013 5:36]
Erlend Dahl
[16 Apr 2013 1:22] Georgi Kodinov This is expected behavior. According to http://dev.mysql.com/doc/refman/5.6/en/adding-udf.html : "When an SQL statement invokes XXX(), MySQL calls the initialization function xxx_init() to let it perform any required setup, such as argument checking or memory allocation. If xxx_init() returns an error, MySQL aborts the SQL statement with an error message and does not call the main or deinitialization functions. Otherwise, MySQL calls the main function xxx() once for each row. After all rows have been processed, MySQL calls the deinitialization function xxx_deinit() so that it can perform any required cleanup."