CTAS. FB crashes when query contains too long arithmetic expression

2 views
Skip to first unread message

Pavel Zotov

unread,
6:54 AM (7 hours ago) 6:54 AM
to firebird-devel
Consider script (based on #8255):

select first (1+1+ ... +1+1) rdb$relation_name from rdb$relations;
// "1+1+ ... +1+1" contains 100'000 terms; full example see in attached .7z

If we run it on *Windows* then after ~20 seconds message about stack overflow appears
("SQLSTATE = HY001 / Stack overflow. The resource requirements ... exceeded the memory available to it." -- and it occurs on any Windows host with RAM = 16 ... 96 Gb).
But Firebird process alive, no crash occurs.

Now lets 'enclose' this query in CTAS:

recreate table ctas_test as (
    select first (1+1+ ... +1+1) rdb$relation_name from rdb$relations
);

This causes FB crash (checked on 6.0.0.2067-bf10ae1).

Full script is in attachment.
Run it:
isql -q -e -i CTAS-crash-on-too-long-arith-expr.sql

Tail of output will be:
===============
select 'point-0' from rdb$database;
CONSTANT                        point-0
out nul;

Statement failed, SQLSTATE = HY001
Stack overflow.  The resource requirements of the runtime stack have exceeded the memory available to it.
After line 11 in file CTAS-crash-on-too-long-arith-expr.sql

select 'point-1' from rdb$database;
CONSTANT                        point-1
out nul;

Statement failed, SQLSTATE = 08006
Error reading data from the connection.
After line 16 in file CTAS-crash-on-too-long-arith-expr.sql

select 'point-2' from rdb$database;
Statement failed, SQLSTATE = 08006
Error writing data to the connection.
After line 20 in file CTAS-crash-on-too-long-arith-expr.sql
quit; 
===============

Dump, stack-trace, firebird.conf and snapshot 6.0.0.2067-bf10ae1 are here.

CTAS-crash-on-too-long-arith-expr.sql.7z

Adriano dos Santos Fernandes

unread,
7:18 AM (7 hours ago) 7:18 AM
to firebir...@googlegroups.com
On 7/7/26 07:54, Pavel Zotov wrote:
> Consider script (based on #8255 <https://github.com/FirebirdSQL/
> firebird/issues/8255>):
>
> select first (1+1+ ... +1+1) rdb$relation_name from rdb$relations;
> // "1+1+ ... +1+1" contains 100'000 terms; full example see in attached .7z
>
> If we run it on *Windows* then after ~20 seconds message about stack
> overflow appears
> ("SQLSTATE = HY001 / Stack overflow. The resource requirements ...
> exceeded the memory available to it." -- and it occurs on any Windows
> host with RAM = 16 ... 96 Gb).
> But Firebird process *alive*, no crash occurs.
> here <https://drive.google.com/drive/
> folders/1YCoD_94FPNQ2y1a8pp_Cfh95RfJos7DI?usp=sharing>.
>

The stack overflow detection in Windows is least measure, not correct
and definitive solution for this problem. The problem is not CTA-specific.

The select query (without CREATE TABLE) crashes in Linux and weird
enough, inside the memory manager.


Adriano

Reply all
Reply to author
Forward
0 new messages