ossc-db / pg_hint_plan

Extension adding support for optimizer hints in PostgreSQL
Other
674 stars 101 forks source link

SIGABRT when the parse_messages parameter equals to error. #162

Closed Xen-On-core closed 9 months ago

Xen-On-core commented 9 months ago

Hello! The following commands calls SIGABRT:

LOAD 'pg_hint_plan';
SET pg_hint_plan.parse_messages TO error;

/*+Set/SELECT 1;
/Set*/SELECT 1;
/*+Set/SELECT 1;
/*+Set*/SELECT 1;
/Set*/SELECT 1;
/*+Set*/SELECT 1;

This happens on the PG11-PG13 branches.

Here is the backtrace:

#0  __pthread_kill_implementation (no_tid=0, signo=6, threadid=139730467214464) at ./nptl/pthread_kill.c:44
#1  __pthread_kill_internal (signo=6, threadid=139730467214464) at ./nptl/pthread_kill.c:78
#2  __GI___pthread_kill (threadid=139730467214464, signo=signo@entry=6) at ./nptl/pthread_kill.c:89
#3  0x00007f1588442476 in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#4  0x00007f15884287f3 in __GI_abort () at ./stdlib/abort.c:79
#5  0x000056480df4b47a in ExceptionalCondition (
    conditionName=conditionName@entry=0x56480e1054c8 "!(((context) != ((void *)0) && (((((const Node*)((context)))->type) == T_AllocSetContext) || ((((const Node*)((context)))->type) == T_SlabContext) || ((((const Node*)((context)))->type) == T_Generatio"..., 
    errorType=errorType@entry=0x56480dfae879 "BadArgument", fileName=fileName@entry=0x56480e105438 "../../../../src/include/utils/memutils.h", lineNumber=lineNumber@entry=130) at assert.c:54
#6  0x000056480df7eabf in GetMemoryChunkContext (pointer=<optimized out>) at ../../../../src/include/utils/memutils.h:130
#7  pfree (pointer=<optimized out>) at mcxt.c:1082
#8  0x00007f1588f030cb in get_current_hint_string (pstate=0x56480f850a58, query=0x56480f850b70) at pg_hint_plan.c:3009
#9  0x000056480db951d7 in parse_analyze (parseTree=parseTree@entry=0x56480f8509c0, sourceText=sourceText@entry=0x56480f84fdc0 "/*+Set*/SELECT 1;", paramTypes=paramTypes@entry=0x0, numParams=numParams@entry=0, queryEnv=queryEnv@entry=0x0) at analyze.c:120
#10 0x000056480de18c90 in pg_analyze_and_rewrite (queryEnv=0x0, numParams=0, paramTypes=0x0, query_string=0x56480f84fdc0 "/*+Set*/SELECT 1;", parsetree=0x56480f8509c0) at postgres.c:774
#11 exec_simple_query (query_string=0x56480f84fdc0 "/*+Set*/SELECT 1;") at postgres.c:1235
#12 0x000056480de1a465 in PostgresMain (argc=<optimized out>, argv=argv@entry=0x56480f880208, dbname=<optimized out>, username=<optimized out>) at postgres.c:5105
#13 0x000056480dd76688 in BackendRun (port=0x56480f8774e0) at postmaster.c:5390
#14 BackendStartup (pool=<optimized out>, port=0x56480f8774e0) at postmaster.c:5036
#15 0x000056480dd76ce3 in ServerLoop () at postmaster.c:2040
#16 0x000056480dd784f1 in PostmasterMain (argc=argc@entry=3, argv=argv@entry=0x56480f84a580) at postmaster.c:1508
#17 0x000056480da77887 in main (argc=3, argv=0x56480f84a580) at main.c:230

Suggested fix by svglukhov is in the attachment. fix-invalid-hint-declarations.txt

michaelpq commented 9 months ago

Thanks for the report. I have applied a fix on PG12 and PG13 where the problem appears. In PG14 this code is much more careful. PG11 is not supported anymore, unfortunately.