Hi,

>When gdb will be active, then use command c, and then run query in session. 
>gdb should to catch segfault. 



Thank you very much. It's been helpfull.

BTW behaviour is strange. When I'm executing following, I do have always a SEGV 
:

psql (11.1)
Type "help" for help.

herve=# CREATE OR REPLACE FUNCTION public.test_bug2(text,integer,timestamp with 
time zone)
herve-#  RETURNS integer
herve-# 
herve-# AS '
herve'# 
herve'#     select coalesce(max(id),1) from sact_v1.autocalls where  label=$1 
and machine_id=$2 and created_date=$3;
herve'#     '
herve-#  LANGUAGE sql;
CREATE FUNCTION
herve=# select test_bug2('BSM_CRITICAL_SYSLOG',18843,now());

The GDB session :

Continuing.

Program received signal SIGSEGV, Segmentation fault.
prepare_query_params (param_types=0x1c86ac8, param_values=0x1c86ac0, 
param_exprs=0x1c86ab8, param_flinfo=0x1c86ab0, numParams=3, 
fdw_exprs=0x1c6b5b8, node=0x1c792d8) at mysql_fdw.c:2139
2139                    *param_types[i] = exprType(param_expr);
(gdb) bt
#0  prepare_query_params (param_types=0x1c86ac8, param_values=0x1c86ac0, 
param_exprs=0x1c86ab8, param_flinfo=0x1c86ab0, numParams=3, 
fdw_exprs=0x1c6b5b8, node=0x1c792d8)
    at mysql_fdw.c:2139
#1  mysqlBeginForeignScan (node=0x1c792d8, eflags=<optimized out>) at 
mysql_fdw.c:503
#2  0x000000000062ae94 in ExecInitForeignScan ()
#3  0x00000000006077bf in ExecInitNode ()
#4  0x000000000061117d in ExecInitAgg ()
#5  0x0000000000607717 in ExecInitNode ()
#6  0x0000000000601cf4 in standard_ExecutorStart ()
#7  0x000000000060d6ec in fmgr_sql ()
#8  0x00000000005fd504 in ExecInterpExpr ()
#9  0x00000000006258fb in ExecResult ()
#10 0x00000000006009aa in standard_ExecutorRun ()
#11 0x000000000073eaec in PortalRunSelect ()
#12 0x000000000073fede in PortalRun ()
#13 0x000000000073bd82 in exec_simple_query ()
#14 0x000000000073d249 in PostgresMain ()
#15 0x000000000047cff6 in ServerLoop ()
#16 0x00000000006cf7b3 in PostmasterMain ()
#17 0x000000000047ded1 in main ()

What is confusing, is that if I do the same with a pl/pgsql function (see 
below) I can run it 5 times, and the 6th exec hit the same SEGV...


CREATE OR REPLACE FUNCTION public.test_bug(text,text)
 RETURNS integer
 LANGUAGE plpgsql
AS $function$
DECLARE
    plabel ALIAS FOR $1;
    spmachine_id ALIAS FOR $2;
    rid integer;
    lnow timestamp with time zone;
    pmachine_id INTEGER;

BEGIN
    pmachine_id := cast(spmachine_id as INTEGER);
    lnow:=now();

    select max(id) into rid from sact_v1.autocalls where  label=plabel and 
machine_id=pmachine_id and created_date=lnow;
    rid := coalesce(rid,-1);

    return  rid;
END;
$function$;

CREATE FUNCTION
herve=# select test_bug('BSM_CRITICAL_SYSLOG','18843');
 test_bug 
----------
       -1
(1 row)

herve=# select test_bug('BSM_CRITICAL_SYSLOG','18843');
 test_bug 
----------
       -1
(1 row)

herve=# select test_bug('BSM_CRITICAL_SYSLOG','18843');
 test_bug 
----------
       -1
(1 row)

herve=# select test_bug('BSM_CRITICAL_SYSLOG','18843');
 test_bug 
----------
       -1
(1 row)

herve=# select test_bug('BSM_CRITICAL_SYSLOG','18843');
 test_bug 
----------
       -1
(1 row)

herve=# select test_bug('BSM_CRITICAL_SYSLOG','18843');



Program received signal SIGSEGV, Segmentation fault.
prepare_query_params (param_types=0x1ca3558, param_values=0x1ca3550, 
param_exprs=0x1ca3548, param_flinfo=0x1ca3540, numParams=3, 
fdw_exprs=0x1ca8638, node=0x1cade28) at mysql_fdw.c:2139
2139                    *param_types[i] = exprType(param_expr);
(gdb) bt
#0  prepare_query_params (param_types=0x1ca3558, param_values=0x1ca3550, 
param_exprs=0x1ca3548, param_flinfo=0x1ca3540, numParams=3, 
fdw_exprs=0x1ca8638, node=0x1cade28)
    at mysql_fdw.c:2139
#1  mysqlBeginForeignScan (node=0x1cade28, eflags=<optimized out>) at 
mysql_fdw.c:503
#2  0x000000000062ae94 in ExecInitForeignScan ()
#3  0x00000000006077bf in ExecInitNode ()
#4  0x000000000061117d in ExecInitAgg ()
#5  0x0000000000607717 in ExecInitNode ()
#6  0x0000000000601cf4 in standard_ExecutorStart ()
#7  0x0000000000632946 in _SPI_execute_plan ()
#8  0x0000000000632d0b in SPI_execute_plan_with_paramlist ()
#9  0x00007ffb349aba22 in exec_stmt_execsql () from 
/usr/local/pgsql/lib/plpgsql.so
#10 0x00007ffb349ace43 in exec_stmts () from /usr/local/pgsql/lib/plpgsql.so
#11 0x00007ffb349af6d3 in exec_stmt_block () from 
/usr/local/pgsql/lib/plpgsql.so
#12 0x00007ffb349af88f in plpgsql_exec_function () from 
/usr/local/pgsql/lib/plpgsql.so
#13 0x00007ffb349a3375 in plpgsql_call_handler () from 
/usr/local/pgsql/lib/plpgsql.so
#14 0x00000000005fd504 in ExecInterpExpr ()
#15 0x00000000006258fb in ExecResult ()
#16 0x00000000006009aa in standard_ExecutorRun ()
#17 0x000000000073eaec in PortalRunSelect ()
#18 0x000000000073fede in PortalRun ()
#19 0x000000000073bd82 in exec_simple_query ()
#20 0x000000000073d249 in PostgresMain ()
#21 0x000000000047cff6 in ServerLoop ()
#22 0x00000000006cf7b3 in PostmasterMain ()
#23 0x000000000047ded1 in main ()






Reply via email to