From: Bruce Momjian <bruce@momjian.us>
To: Michael Paquier <michael@paquier.xyz>
Cc: Robins Tharakan <tharakan@gmail.com>
Cc: pgsql-bugs@postgresql.org
Subject: Re: ALTER TABLE ALTER COLUMN SET TYPE crash
Date: Tue, 25 Aug 2020 11:55:44 -0400
Message-ID: <20200825155544.GG32540@momjian.us> (raw)
In-Reply-To: <20200825060511.GF2017@paquier.xyz>
References: <CAEP4nAzwokLht2Bi3RCHNcCJBdOa8d7LnqJkDO1xiaH+biW8fw@mail.gmail.com>
<20200825060511.GF2017@paquier.xyz>
On Tue, Aug 25, 2020 at 03:05:11PM +0900, Michael Paquier wrote:
> On Tue, Aug 25, 2020 at 02:14:06PM +1000, Robins Tharakan wrote:
> > Unlike a recently reported similar issue, executing the following ALTER
> > TABLE on the regression database crashes Postgres (master).
> >
> > Admittedly it doesn't do anything constructive (and am new to the tool),
> > but do let me know if such reports are interesting and / or if you need
> > more details for reproduction.
>
> Such reports are constructive! I can reproduce the crash here down to
> 9.5. From what I can see, the problem comes from ATRewriteTable() ->
> ExecEvalExpr() when we evaluate expressions with inputs coming from
> the old tuple. It looks like a memory corruption issue or a context
> issue at quick glance, and I cannot get a clean backtrace.
OK, I have generated a attached backtrace by manually walking down
through the stack using break points. Notice len2 on the top line:
#0 varstr_cmp (arg1=0x55e0ef64262c "\252\061\306BT\026", len1=21,
arg2=0x7f274db17ebc "-\317\303=T\026", len2=-4, collid=100) at
varlena.c:1633 -------
-4 is not a good len. I will do more research to see why that -4 len is
happening.
--
Bruce Momjian <bruce@momjian.us> https://momjian.us
EnterpriseDB https://enterprisedb.com
The usefulness of a cup is in its emptiness, Bruce Lee
Attachments:bt.txt (text/plain, 6.5K) download
#0 memcpy () at ../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:128
#1 0x000055e0eef57501 in varstr_cmp (arg1=0x55e0ef63f40c "\252\061\306BT\026", len1=21, arg2=0x7f274db33ebc "-\317\303=T\026", len2=-4, collid=100) at varlena.c:1633
#2 0x000055e0eef577c8 in text_cmp (arg1=0x55e0ef63f408, arg2=0x7f274db33eb8, collid=100) at varlena.c:1723
#3 0x000055e0eef59591 in text_larger (fcinfo=0x55e0ef63ce00) at varlena.c:2825
#4 0x000055e0eebcc342 in ExecAggPlainTransByRef (aggstate=0x55e0ef63b5f8, pertrans=0x55e0ef63ca80, pergroup=0x55e0ef63ccb8, aggcontext=0x55e0ef63bb20, setno=0) at execExprInterp.c:4297
#5 0x000055e0eebc70d0 in ExecInterpExpr (state=0x55e0ef63ce78, econtext=0x55e0ef63ba30, isnull=0x7fff56ba8eff) at execExprInterp.c:1712
#6 0x000055e0eebead81 in ExecEvalExprSwitchContext (state=0x55e0ef63ce78, econtext=0x55e0ef63ba30, isNull=0x7fff56ba8eff) at ../../../src/include/executor/executor.h:313
#7 0x000055e0eebeb7ea in advance_aggregates (aggstate=0x55e0ef63b5f8) at nodeAgg.c:850
#8 0x000055e0eebee514 in agg_retrieve_direct (aggstate=0x55e0ef63b5f8) at nodeAgg.c:2446
#9 0x000055e0eebedf76 in ExecAgg (pstate=0x55e0ef63b5f8) at nodeAgg.c:2171
#10 0x000055e0eebdbfac in ExecProcNodeFirst (node=0x55e0ef63b5f8) at execProcnode.c:450
#11 0x000055e0eebd02b6 in ExecProcNode (node=0x55e0ef63b5f8) at ../../../src/include/executor/executor.h:245
#12 0x000055e0eebd2f1b in ExecutePlan (estate=0x55e0ef63b3c0, planstate=0x55e0ef63b5f8, use_parallel_mode=false, operation=CMD_SELECT, sendTuples=true, numberTuples=2, direction=ForwardScanDirection,
dest=0x55e0ef28cd40 <spi_printtupDR>, execute_once=true) at execMain.c:1646
#13 0x000055e0eebd0917 in standard_ExecutorRun (queryDesc=0x55e0ef638958, direction=ForwardScanDirection, count=2, execute_once=true) at execMain.c:364
#14 0x000055e0eebd072d in ExecutorRun (queryDesc=0x55e0ef638958, direction=ForwardScanDirection, count=2, execute_once=true) at execMain.c:308
#15 0x000055e0eec2de87 in _SPI_pquery (queryDesc=0x55e0ef638958, fire_triggers=true, tcount=2) at spi.c:2650
#16 0x000055e0eec2d8d3 in _SPI_execute_plan (plan=0x55e0ef633f60, paramLI=0x0, snapshot=0x0, crosscheck_snapshot=0x0, read_only=false, fire_triggers=true, tcount=2, caller_dest=0x0) at spi.c:2421
#17 0x000055e0eec2a36b in SPI_execute_plan_with_paramlist (plan=0x55e0ef633f60, params=0x0, read_only=false, tcount=2) at spi.c:578
#18 0x00007f274d2d3374 in exec_run_select (estate=0x7fff56ba9630, expr=0x55e0ef623288, maxtuples=2, portalP=0x0) at pl_exec.c:5958
#19 0x00007f274d2d3044 in exec_eval_expr (estate=0x7fff56ba9630, expr=0x55e0ef623288, isNull=0x7fff56ba9650, rettype=0x7fff56ba9654, rettypmod=0x7fff56ba9378) at pl_exec.c:5860
#20 0x00007f274d2ce18c in exec_stmt_return (estate=0x7fff56ba9630, stmt=0x55e0ef622df0) at pl_exec.c:3265
#21 0x00007f274d2cbaad in exec_stmts (estate=0x7fff56ba9630, stmts=0x55e0ef623358) at pl_exec.c:2035
#22 0x00007f274d2cb70a in exec_stmt_block (estate=0x7fff56ba9630, block=0x55e0ef6233b0) at pl_exec.c:1906
#23 0x00007f274d2caf14 in exec_toplevel_block (estate=0x7fff56ba9630, block=0x55e0ef6233b0) at pl_exec.c:1604
#24 0x00007f274d2c8f56 in plpgsql_exec_function (func=0x55e0ef554258, fcinfo=0x55e0ef6122b0, simple_eval_estate=0x0, simple_eval_resowner=0x0, atomic=true) at pl_exec.c:606
#25 0x00007f274d2e3a94 in plpgsql_call_handler (fcinfo=0x55e0ef6122b0) at pl_handler.c:265
#26 0x000055e0eebc5573 in ExecInterpExpr (state=0x55e0ef607f20, econtext=0x55e0ef5fe2c8, isnull=0x55e0ef6068f0) at execExprInterp.c:675
#27 0x000055e0eebc737d in ExecInterpExprStillValid (state=0x55e0ef607f20, econtext=0x55e0ef5fe2c8, isNull=0x55e0ef6068f0) at execExprInterp.c:1802
#28 0x000055e0eeb717e9 in ExecEvalExpr (state=0x55e0ef607f20, econtext=0x55e0ef5fe2c8, isNull=0x55e0ef6068f0) at ../../../src/include/executor/executor.h:294
#29 0x000055e0eeb7b109 in ATRewriteTable (tab=0x55e0ef5ba048, OIDNewHeap=180226, lockmode=8) at tablecmds.c:5373
#30 0x000055e0eeb7a44a in ATRewriteTables (parsetree=0x55e0ef521310, wqueue=0x7fff56ba9df8, lockmode=8, context=0x7fff56ba9e90) at tablecmds.c:5030
#31 0x000055e0eeb78218 in ATController (parsetree=0x55e0ef521310, rel=0x7f274d319ef0, cmds=0x55e0ef5212b8, recurse=false, lockmode=8, context=0x7fff56ba9e90) at tablecmds.c:4019
#32 0x000055e0eeb77e5c in AlterTable (stmt=0x55e0ef521310, lockmode=8, context=0x7fff56ba9e90) at tablecmds.c:3671
#33 0x000055e0eee0f5be in ProcessUtilitySlow (pstate=0x55e0ef541050, pstmt=0x55e0ef5213d8,
queryString=0x55e0ef5203f0 "ALTER TABLE ONLY public.xacttest ALTER COLUMN a SET DATA TYPE TEXT USING public.max_xacttest();", context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0,
dest=0x55e0ef5216b8, qc=0x7fff56baa570) at utility.c:1291
#34 0x000055e0eee0f000 in standard_ProcessUtility (pstmt=0x55e0ef5213d8, queryString=0x55e0ef5203f0 "ALTER TABLE ONLY public.xacttest ALTER COLUMN a SET DATA TYPE TEXT USING public.max_xacttest();",
context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0x55e0ef5216b8, qc=0x7fff56baa570) at utility.c:1069
#35 0x000055e0eee0e09a in ProcessUtility (pstmt=0x55e0ef5213d8, queryString=0x55e0ef5203f0 "ALTER TABLE ONLY public.xacttest ALTER COLUMN a SET DATA TYPE TEXT USING public.max_xacttest();",
context=PROCESS_UTILITY_TOPLEVEL, params=0x0, queryEnv=0x0, dest=0x55e0ef5216b8, qc=0x7fff56baa570) at utility.c:524
#36 0x000055e0eee0ce4c in PortalRunUtility (portal=0x55e0ef58e610, pstmt=0x55e0ef5213d8, isTopLevel=true, setHoldSnapshot=false, dest=0x55e0ef5216b8, qc=0x7fff56baa570) at pquery.c:1159
#37 0x000055e0eee0d079 in PortalRunMulti (portal=0x55e0ef58e610, isTopLevel=true, setHoldSnapshot=false, dest=0x55e0ef5216b8, altdest=0x55e0ef5216b8, qc=0x7fff56baa570) at pquery.c:1305
#38 0x000055e0eee0c558 in PortalRun (portal=0x55e0ef58e610, count=9223372036854775807, isTopLevel=true, run_once=true, dest=0x55e0ef5216b8, altdest=0x55e0ef5216b8, qc=0x7fff56baa570) at pquery.c:779
#39 0x000055e0eee062ee in exec_simple_query (query_string=0x55e0ef5203f0 "ALTER TABLE ONLY public.xacttest ALTER COLUMN a SET DATA TYPE TEXT USING public.max_xacttest();") at postgres.c:1239
#40 0x000055e0eee0a647 in PostgresMain (argc=1, argv=0x55e0ef5504e0, dbname=0x55e0ef5503b8 "tempdel", username=0x55e0ef550390 "postgres") at postgres.c:4315
#41 0x000055e0eed5033b in BackendRun (port=0x55e0ef548e60) at postmaster.c:4530
#42 0x000055e0eed4fab6 in BackendStartup (port=0x55e0ef548e60) at postmaster.c:4222
#43 0x000055e0eed4be4c in ServerLoop () at postmaster.c:1741
#44 0x000055e0eed4b69b in PostmasterMain (argc=1, argv=0x55e0ef519ed0) at postmaster.c:1414
#45 0x000055e0eec4dc42 in main (argc=1, argv=0x55e0ef519ed0) at main.c:209
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-bugs@postgresql.org
Cc: bruce@momjian.us, michael@paquier.xyz, tharakan@gmail.com
Subject: Re: ALTER TABLE ALTER COLUMN SET TYPE crash
In-Reply-To: <20200825155544.GG32540@momjian.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox