Subject VIEW + UDF = CRASH
Author Riaan Nagel
Hi,

The second of the two following SQL statements (which make use of
the ib_udf function "ceiling") crashes the FireBird server (found on
both FB 1.0.3.972 and FB 1.5 RC 3.) The error reported in the
FireBird log is "... terminated abnormally (-1)" for FB 1.0.3,
whereas FB1.5 has 4294967295 as the error number (which is,
obviously, the same bit pattern interpreted as an unsigned 32 bit
integer). The only difference between "test_view" and "test_view_2"
is that "test_view" represents a UNION of four SELECT statements,
whereas "test_view_2" adds an additional UNION, making it five
SELECT statements in the UNION.

/* fine */
select ceiling((select max(id) from test_view)) from rdb$database

/* fails with server terminating abnormally (4294967295) */
select ceiling((select max(id) from test_view_2)) from rdb$database

The DDL script for an example database:

SET SQL DIALECT 3;

SET NAMES NONE;

CREATE DATABASE 'c:\working\example.fdb'
USER 'SYSDBA' PASSWORD 'masterkey'
PAGE_SIZE 4096
DEFAULT CHARACTER SET NONE;

DECLARE EXTERNAL FUNCTION CEILING
DOUBLE PRECISION
RETURNS DOUBLE PRECISION BY VALUE
ENTRY_POINT 'IB_UDF_ceiling' MODULE_NAME 'ib_udf';

CREATE TABLE TEST_TABLE (
ID INTEGER
);

CREATE VIEW TEST_VIEW(
ID)
AS
select ID from test_table
union select ID from test_table
union select ID from test_table
union select ID from test_table;


CREATE VIEW TEST_VIEW_2(
ID)
AS
select ID from test_table
union select ID from test_table
union select ID from test_table
union select ID from test_table
union select ID from test_table;

/************** END OF SCRIPT ******************/


Best Regards,
Riaan