pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedPostgreSQL12 crash bug report
17+ messages / 3 participants
[nested] [flat]
Commits from this thread:
2019-09-09 27cc7cd2bc 3fb307bc4a Reorder EPQ work, to fix rowmark related bugs and improve efficiency.
* PostgreSQL12 crash bug report
@ 2019-07-28 18:56 yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 17+ messages in thread
From: yi huang @ 2019-07-28 18:56 UTC (permalink / raw)
To: pgsql-bugs@lists.postgresql.org
1、Run the docker version of PostgreSQL 12
$ docker run --rm -p 5432:5432 -v /tmp:/data -e POSTGRES_USER=exchange
-e POSTGRES_DB=exchange -e POSTGRES_PASSWORD=123456 postgres:12-alpine
2、Download the attached files to /tmp
3、Import the schema and data
$ docker exec -it $CONTAINER psql -U exchange exchange -f
/data/t_order_schema.sql
$ docker exec -it $CONTAINER psql -U exchange exchange -f /data/t_order_data.sql
4、Run pgbench with provided test script
$ pgbench -h 127.0.0.1 -p 5432 -U exchange exchange -T 2 -c 4 -f /tmp/test.sql
Attachments:
t_order_schema.sql (application/octet-stream, 18.3K) download
test.sql (application/octet-stream, 379B) download
t_order_data.sql (application/octet-stream, 27.4K) download
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
@ 2019-07-28 20:11 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 17+ messages in thread
From: Tom Lane @ 2019-07-28 20:11 UTC (permalink / raw)
To: yi huang <yi.codeplayer@gmail.com>; +Cc: pgsql-bugs@lists.postgresql.org, Andres Freund <andres@anarazel.de>
yi huang <yi.codeplayer@gmail.com> writes:
> [ crashes with ]
> $ pgbench -h 127.0.0.1 -p 5432 -U exchange exchange -T 2 -c 4 -f /tmp/test.sql
Thanks for the report!
Note that this doesn't fail if you just run test.sql by itself, but
it does soon fall over as described when running multiple copies in
parallel. Unsurprisingly given that, the crash is inside EvalPlanQual:
(gdb) bt
#0 memcpy () at ../sysdeps/x86_64/memcpy.S:526
#1 0x00000000004863b1 in fill_val (tupleDesc=0x18c7060,
values=<value optimized out>, isnull=0x195e198,
data=<value optimized out>, data_size=148670068,
infomask=<value optimized out>, bit=0x7f07aef4207f "\017")
at heaptuple.c:247
#2 heap_fill_tuple (tupleDesc=0x18c7060, values=<value optimized out>,
isnull=0x195e198, data=<value optimized out>, data_size=148670068,
infomask=<value optimized out>, bit=0x7f07aef4207f "\017")
at heaptuple.c:336
#3 0x0000000000486921 in heap_form_tuple (tupleDescriptor=0x18c7060,
values=0x7ffc691d58b0, isnull=0x195e198) at heaptuple.c:1090
#4 0x00000000004ddf78 in toast_build_flattened_tuple (tupleDesc=0x18c7060,
values=<value optimized out>, isnull=0x195e198) at tuptoaster.c:1336
#5 0x00000000006441f0 in ExecEvalWholeRowVar (state=<value optimized out>,
op=0x1958030, econtext=<value optimized out>) at execExprInterp.c:4019
#6 0x0000000000647602 in ExecInterpExpr (state=0x1957ea0, econtext=0x19576a0,
isnull=0x7ffc691d8dff) at execExprInterp.c:519
#7 0x00000000006543ef in ExecEvalExprSwitchContext (
node=<value optimized out>, accessMtd=0x67a140 <ValuesNext>,
recheckMtd=0x679f00 <ValuesRecheck>)
at ../../../src/include/executor/executor.h:307
#8 ExecProject (node=<value optimized out>, accessMtd=0x67a140 <ValuesNext>,
recheckMtd=0x679f00 <ValuesRecheck>)
at ../../../src/include/executor/executor.h:341
#9 ExecScan (node=<value optimized out>, accessMtd=0x67a140 <ValuesNext>,
recheckMtd=0x679f00 <ValuesRecheck>) at execScan.c:199
#10 0x00000000006698dc in ExecProcNode (node=0x19573d8)
at ../../../src/include/executor/executor.h:239
#11 MultiExecPrivateHash (node=0x19573d8) at nodeHash.c:164
#12 MultiExecHash (node=0x19573d8) at nodeHash.c:114
#13 0x000000000066b685 in ExecHashJoinImpl (pstate=0x1939d08)
at nodeHashjoin.c:291
#14 ExecHashJoin (pstate=0x1939d08) at nodeHashjoin.c:572
#15 0x000000000064af7f in ExecProcNode (epqstate=<value optimized out>)
at ../../../src/include/executor/executor.h:239
#16 EvalPlanQualNext (epqstate=<value optimized out>) at execMain.c:2692
#17 0x000000000064b502 in EvalPlanQual (estate=<value optimized out>,
epqstate=0x18b5420, relation=<value optimized out>, rti=4,
inputslot=0x195dfc0) at execMain.c:2475
#18 0x0000000000675f09 in ExecUpdate (mtstate=0x18b5328,
tupleid=0x7ffc691d9130, oldtuple=0x0, slot=<value optimized out>,
planSlot=0x18ca138, epqstate=0x18b5420, estate=0x18b4558, canSetTag=true)
at nodeModifyTable.c:1389
#19 0x000000000067668d in ExecModifyTable (pstate=0x18b5328)
at nodeModifyTable.c:2226
#20 0x000000000064d547 in ExecProcNode (queryDesc=0x18b4148,
direction=<value optimized out>, count=0, execute_once=40)
at ../../../src/include/executor/executor.h:239
#21 ExecutePlan (queryDesc=0x18b4148, direction=<value optimized out>,
count=0, execute_once=40) at execMain.c:1648
#22 standard_ExecutorRun (queryDesc=0x18b4148,
direction=<value optimized out>, count=0, execute_once=40)
at execMain.c:365
#23 0x00000000007c32ab in ProcessQuery (plan=<value optimized out>,
sourceText=0x17b7f28 "with tmp(id, avail_amount, deal_value, update_id) as (values (76107497731002368,0.00,16546.90746,76107519298113537),(76107514491441155,0.606,5808.03795,76107519298113537))\nupdate t_order set avail_amo"...,
params=0x0, queryEnv=0x0, dest=<value optimized out>,
completionTag=0x7ffc691d9430 "") at pquery.c:161
#24 0x00000000007c3613 in PortalRunMulti (portal=0x181dc48, isTopLevel=true,
setHoldSnapshot=false, dest=0x7f07b7f9fce0, altdest=0x7f07b7f9fce0,
completionTag=0x7ffc691d9430 "") at pquery.c:1283
#25 0x00000000007c3d80 in PortalRun (portal=0x181dc48,
count=9223372036854775807, isTopLevel=true, run_once=true,
dest=0x7f07b7f9fce0, altdest=0x7f07b7f9fce0,
completionTag=0x7ffc691d9430 "") at pquery.c:796
#26 0x00000000007c0001 in exec_simple_query (
...
As per the stack trace, we're trying to build a new tuple for the output
of a ValuesScan node, but the targetlist for that seems completely insane:
heap_form_tuple is being given a 15-column tupdesc that includes
(gdb) p tupleDescriptor->attrs[1]
$8 = {attrelid = 0, attname = {data = "side", '\000' <repeats 59 times>},
atttypid = 35644, attstattarget = -1, attlen = 4, attnum = 2, attndims = 0,
attcacheoff = 8, atttypmod = -1, attbyval = true, attstorage = 112 'p',
attalign = 105 'i', attnotnull = false, atthasdef = false,
atthasmissing = false, attidentity = 0 '\000', attgenerated = 0 '\000',
attisdropped = false, attislocal = true, attinhcount = 0, attcollation = 0}
which seems to be the column that we have a bogus Datum for. But what's
the code doing expecting that to be available from the ValueScan? It's a
column of t_order. And the other data is all wrong too: that composite
type should surely not have attlen = 4 nor attbyval = true.
"explain verbose" claims that the Values node should be returning
-> Values Scan on "*VALUES*" (cost=0.00..0.03 rows=2 width=184)
Output: "*VALUES*".column2, "*VALUES*".column3, "*VALUES*".column4, "*VALUES*".*, "*VALUES*".column1
so it seems like somehow we've got wrong info in the EPQ context.
I wonder if this is related to the "Hash join explain is broken"
thread.
regards, tom lane
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-07-31 23:07 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 17+ messages in thread
From: Tom Lane @ 2019-07-31 23:07 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
I wrote:
> yi huang <yi.codeplayer@gmail.com> writes:
>> [ crashes with ]
>> $ pgbench -h 127.0.0.1 -p 5432 -U exchange exchange -T 2 -c 4 -f /tmp/test.sql
> As per the stack trace, we're trying to build a new tuple for the output
> of a ValuesScan node, but the targetlist for that seems completely insane:
After digging through this, it seems clear that it's the fault of
ad0bda5d2, specifically this code in EvalPlanQualSlot:
*slot = ExecAllocTableSlot(&epqstate->estate->es_tupleTable,
epqstate->origslot->tts_tupleDescriptor,
&TTSOpsVirtual);
It's setting up an es_epqTupleSlot[] entry on the assumption that it
should have the same tupdesc as the output tuple that's to be rechecked.
This might accidentally fail to malfunction in single-table cases,
but it's quite broken for any join case --- in particular, for the
given test case, the scan tuple for the VALUES node surely doesn't have
the same tupdesc as the join result.
I think we need to change the API of EvalPlanQualSlot, because it
cannot determine the correct tupdesc when it's not handed a Relation.
I'm not entirely sure that its immediate callers can either :-( so
this might propagate out a ways. Or perhaps we should move the
slot-making someplace else.
I'll go make an open item for this.
regards, tom lane
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-08-01 00:40 ` Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 17+ messages in thread
From: Andres Freund @ 2019-08-01 00:40 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
Hi,
On 2019-07-31 19:07:29 -0400, Tom Lane wrote:
> I wrote:
> > yi huang <yi.codeplayer@gmail.com> writes:
> >> [ crashes with ]
> >> $ pgbench -h 127.0.0.1 -p 5432 -U exchange exchange -T 2 -c 4 -f /tmp/test.sql
>
> > As per the stack trace, we're trying to build a new tuple for the output
> > of a ValuesScan node, but the targetlist for that seems completely insane:
>
> After digging through this, it seems clear that it's the fault of
> ad0bda5d2, specifically this code in EvalPlanQualSlot:
>
> *slot = ExecAllocTableSlot(&epqstate->estate->es_tupleTable,
> epqstate->origslot->tts_tupleDescriptor,
> &TTSOpsVirtual);
>
> It's setting up an es_epqTupleSlot[] entry on the assumption that it
> should have the same tupdesc as the output tuple that's to be rechecked.
> This might accidentally fail to malfunction in single-table cases,
> but it's quite broken for any join case --- in particular, for the
> given test case, the scan tuple for the VALUES node surely doesn't have
> the same tupdesc as the join result.
:(
We really need to improve the test coverage for EPQ :(. I tried to add a
few cases, but it's still one of the least tested complicated areas in
PG.
To make sure I understand - the problem isn't the slot that we've
created in nodeModifyTable.c via EvalPlanQualSlot(), right? It's the one
we create in EvalPlanQualFetchRowMarks(), because we don't have a proper
tuple type handy to create the slot with? And then ExecScanFetch() (on
behalf of ValueScan in this case) expects something with the correct
format in that slot, which causes the backtrace you show. And this
problem occurs "only" for ROW_MARK_COPY, because for everything else we
have an associated relation.
Previously we simply didn't need to know the type during EPQ setup,
because we only stored a HeapTuple anyway. And we'd know the appropriate
tupledesc at the places that access the tuple.
Right?
> I think we need to change the API of EvalPlanQualSlot, because it
> cannot determine the correct tupdesc when it's not handed a Relation.
> I'm not entirely sure that its immediate callers can either :-( so
> this might propagate out a ways. Or perhaps we should move the
> slot-making someplace else.
I think we'll probably have to split EvalPlanQualSlot() into two
functions. One for nodeModifyTable.c and nodeLockRows.c, and the
!ROW_MARK_COPY cases in EvalPlanQualFetchRowMarks().
One bigger change - but possibly one worth it - would be to basically
move the work done in EvalPlanQualFetchRowMarks() to be done on-demand,
at least for ROW_MARK_COPY. We don't need to do
/* fetch the whole-row Var for the relation */
datum = ExecGetJunkAttribute(epqstate->origslot,
aerm->wholeAttNo,
&isNull);
/* non-locked rels could be on the inside of outer joins */
if (isNull)
continue;
that early in the query. We could call EvalPlanQualFetchRowMark() (note
the singular) from ExecScanFetch(), that ought to currently be the only
place that accesses ROW_MARK_COPY type rowmarks?
We could do the same for the other types of rowmarks, but I think that'd
be semantically somewhat murkier.
That would have the advantage that we'd not unnecessarily put row
marks we might never need into slots. There's probably not that many
cases where that matters, though.
Or we could keep enough information for ROW_MARK_COPY RowMarks around to
create the necessary tupledesc (there's a number of variants as to how -
don't zap the information in add_rte_to_flat_rtable, have setrefs.c
somehow keep maintain rti indexed pointers to Plan nodes, ...).
Not sure yet what's best here.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
@ 2019-08-01 02:37 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 04:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 17+ messages in thread
From: Tom Lane @ 2019-08-01 02:37 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
Andres Freund <andres@anarazel.de> writes:
> On 2019-07-31 19:07:29 -0400, Tom Lane wrote:
>> It's setting up an es_epqTupleSlot[] entry on the assumption that it
>> should have the same tupdesc as the output tuple that's to be rechecked.
>> This might accidentally fail to malfunction in single-table cases,
>> but it's quite broken for any join case --- in particular, for the
>> given test case, the scan tuple for the VALUES node surely doesn't have
>> the same tupdesc as the join result.
> To make sure I understand - the problem isn't the slot that we've
> created in nodeModifyTable.c via EvalPlanQualSlot(), right? It's the one
> we create in EvalPlanQualFetchRowMarks(), because we don't have a proper
> tuple type handy to create the slot with?
Yeah, I think nodeModifyTable.c is fine, because it always passes the
target relation. EvalPlanQualFetchRowMarks is not fine, and I'm unsure
about the call in nodeLockRows.c.
> Previously we simply didn't need to know the type during EPQ setup,
> because we only stored a HeapTuple anyway. And we'd know the appropriate
> tupledesc at the places that access the tuple.
Right. So we gotta refactor that somehow.
> One bigger change - but possibly one worth it - would be to basically
> move the work done in EvalPlanQualFetchRowMarks() to be done on-demand,
> at least for ROW_MARK_COPY.
Hm. Too tired to think that through right now.
regards, tom lane
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-08-01 04:36 ` Andres Freund <andres@anarazel.de>
2019-08-24 16:13 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 17+ messages in thread
From: Andres Freund @ 2019-08-01 04:36 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
Hi,
On 2019-07-31 22:37:40 -0400, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > On 2019-07-31 19:07:29 -0400, Tom Lane wrote:
> >> It's setting up an es_epqTupleSlot[] entry on the assumption that it
> >> should have the same tupdesc as the output tuple that's to be rechecked.
> >> This might accidentally fail to malfunction in single-table cases,
> >> but it's quite broken for any join case --- in particular, for the
> >> given test case, the scan tuple for the VALUES node surely doesn't have
> >> the same tupdesc as the join result.
>
> > To make sure I understand - the problem isn't the slot that we've
> > created in nodeModifyTable.c via EvalPlanQualSlot(), right? It's the one
> > we create in EvalPlanQualFetchRowMarks(), because we don't have a proper
> > tuple type handy to create the slot with?
>
> Yeah, I think nodeModifyTable.c is fine, because it always passes the
> target relation. EvalPlanQualFetchRowMarks is not fine, and I'm unsure
> about the call in nodeLockRows.c.
I think nodeLockRows.c itself should be fine - the slots it gets with
EvalPlanQualSlot() are either used for the FDWs to store tuples in it,
or nodeLockRows.c directly fetches tuples into them with
table_tuple_lock(). It itself is only dealing with locking rowmarks, for
which we obviously have a relation. It does trigger
EvalPlanQualFetchRowMarks() for the non-locking marks - that part is
obviously broken, but not in nodeLockRows.c itself.
> > Previously we simply didn't need to know the type during EPQ setup,
> > because we only stored a HeapTuple anyway. And we'd know the appropriate
> > tupledesc at the places that access the tuple.
>
> Right. So we gotta refactor that somehow.
One way to avoid doing so would be to just not deal with slots in the
case of ROW_MARK_COPY. The reason why EPQ was made to use to use slots
instead of HeapTuples is that not doing so would require expensive
conversions for AMs that don't use HeapTuple. But for COPY rowmarks
that's not an issue, because the source already is a HeapTuple (in the
form of a Datum).
That's imo not a particularly pretty approach, but might be the most
viable approach for v12. Attached is a quick WIP implementation, which
indeed fixes the crash reported here, and passes all our
tests. Obviously it'd need some polish if we went for that.
I think it's pretty darn ugly that we don't know what kind of tuples
we're dealing with at the top-level of EPQ. But changing that seems far
from trivial.
The way things set up we don't have a good way to map from rtis to the
associated PlanStates, and currently only the PlanStates have enough
information to infer the slot type. In fact, if we knew the ScanState
nodes for specific rtis, we could perhaps even just use each node's
ScanState->ss_ScanTupleSlot - seems fragile, but we've effectively done
so before v12.
And we can't easy add a way to map from rti to PlanState, without adding
work to ExecInit* for every Scan node. If ExecInitNode() knew whether
the relevant nodes were Scan nodes, we could maintain the mapping at
that stage, but we afaict don't know that.
I briefly looked at hacking something like ExecInitScanTupleSlot() to
maintain an EState rti->ScanState mapping, but we have ScanState
executor nodes for planner nodes that do *not* inherit from Scan
(e.g. Material). While that's ugly, it's not something we seem likely to
change all that soon - and using ExecInitScanTupleSlot() as a proxy is
just a hack anyway. It sure would be nice if IsA() actually worked when
inheriting from a node...
We could easily maintain a mapping from Plan->plan_node_id to the
corresponding PlanState from within ExecInitNode(). But I don't think
that'd help that much, as we'd need an rti -> plan_node_id mapping,
which'd again not be trivial to maintain. We could do so in
set_plan_refs(), as that knows both the relevant plan_node_id, and the
adjusted scanrelid.
I'm not exactly sure what the intended uses of plan_node_id are - it was
introduce in d1b7c1ffe72e86932b5395f29e006c3f503bc53d and is,
exclusively?, used as a unique key into dynamic shared memory for
parallel query (so each node can cheaply can build a key for its own
data). So perhaps it'd be a gross misuse of that system. But it doesn't
look like that to me.
Not sure if there's other things that could benefit from the
rti -> ScanState or plan_node_id -> PlanState mapping. It'd be nice for
debugging, I guess, but that doesn't quite seem enough.
> > One bigger change - but possibly one worth it - would be to basically
> > move the work done in EvalPlanQualFetchRowMarks() to be done on-demand,
> > at least for ROW_MARK_COPY.
>
> Hm. Too tired to think that through right now.
I briefly tried to implement that. The problem is that, as things are
currently set up, we don't have access to the corresponding epqstate
from within executor nodes. That prevents us from accessing
EPQState->{origslot, arowMarks}, which we need to actually be able to
fetch the rows to return.
We could solve that by referencing the EPQState from its EState (but not
from the "main" estate). I've wondered before whether that'd be better
than having various es_epq* fields in EState. I don't think it'd make
the modularity any worse, given that we're already referencing EPQstate
fields from with EState. If we moved es_epqTupleSlot into EPQState and
allocated it from within EvalPlanQualInit(), instead of
EvalPlanQualBegin(), we'd address your complaint that we now call that
earlier too.
Doesn't sound that hard. Seems like a big change for v12 though.
As far as I can tell, the only behavioural change of fetching rows later
instead of in EvalPlanQualFetchRowMarks would be that we'd fetch
(locally or via FDW) rows that are referenced, but not locked, at the
same time we lock rows, and that we would not fetch them if any of the
locked rows couldn't be locked. Which seems like a mild improvement.
Greetings,
Andres Freund
Attachments:
v1-0001-WIP-fix-crash-ROW_MARK_COPY.patch (text/x-diff, 0B) download
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 04:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
@ 2019-08-24 16:13 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-08-24 22:54 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
0 siblings, 1 reply; 17+ messages in thread
From: Tom Lane @ 2019-08-24 16:13 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
Andres Freund <andres@anarazel.de> writes:
> On 2019-07-31 22:37:40 -0400, Tom Lane wrote:
>> Andres Freund <andres@anarazel.de> writes:
>>> Previously we simply didn't need to know the type during EPQ setup,
>>> because we only stored a HeapTuple anyway. And we'd know the appropriate
>>> tupledesc at the places that access the tuple.
>> Right. So we gotta refactor that somehow.
> One way to avoid doing so would be to just not deal with slots in the
> case of ROW_MARK_COPY. The reason why EPQ was made to use to use slots
> instead of HeapTuples is that not doing so would require expensive
> conversions for AMs that don't use HeapTuple. But for COPY rowmarks
> that's not an issue, because the source already is a HeapTuple (in the
> form of a Datum).
> That's imo not a particularly pretty approach, but might be the most
> viable approach for v12. Attached is a quick WIP implementation, which
> indeed fixes the crash reported here, and passes all our
> tests. Obviously it'd need some polish if we went for that.
I agree that that's mighty ugly. But it does have the advantage of being
not very invasive, so at this late date maybe it's what we should do
for v12.
>>> One bigger change - but possibly one worth it - would be to basically
>>> move the work done in EvalPlanQualFetchRowMarks() to be done on-demand,
>>> at least for ROW_MARK_COPY.
>> Hm. Too tired to think that through right now.
> I briefly tried to implement that. The problem is that, as things are
> currently set up, we don't have access to the corresponding epqstate
> from within executor nodes. That prevents us from accessing
> EPQState->{origslot, arowMarks}, which we need to actually be able to
> fetch the rows to return.
> We could solve that by referencing the EPQState from its EState (but not
> from the "main" estate). I've wondered before whether that'd be better
> than having various es_epq* fields in EState. I don't think it'd make
> the modularity any worse, given that we're already referencing EPQstate
> fields from with EState. If we moved es_epqTupleSlot into EPQState and
> allocated it from within EvalPlanQualInit(), instead of
> EvalPlanQualBegin(), we'd address your complaint that we now call that
> earlier too.
> Doesn't sound that hard. Seems like a big change for v12 though.
I feel that this seems like a promising solution for the longer term.
I agree that keeping a pointer to the whole EPQState in EState is no
worse than having pointers to some of its fields there.
Perhaps the next step is to draft a patch for this and see just how
big it is compared to the minimal fix. I'd rather not have v12 be
different from later branches in this area if the change doesn't
seem entirely unreasonable for late beta.
regards, tom lane
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 04:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-24 16:13 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-08-24 22:54 ` Andres Freund <andres@anarazel.de>
2019-08-25 17:04 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-26 05:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
0 siblings, 2 replies; 17+ messages in thread
From: Andres Freund @ 2019-08-24 22:54 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
Hi,
On 2019-08-24 12:13:22 -0400, Tom Lane wrote:
> Andres Freund <andres@anarazel.de> writes:
> > On 2019-07-31 22:37:40 -0400, Tom Lane wrote:
> > I briefly tried to implement that. The problem is that, as things are
> > currently set up, we don't have access to the corresponding epqstate
> > from within executor nodes. That prevents us from accessing
> > EPQState->{origslot, arowMarks}, which we need to actually be able to
> > fetch the rows to return.
> > We could solve that by referencing the EPQState from its EState (but not
> > from the "main" estate). I've wondered before whether that'd be better
> > than having various es_epq* fields in EState. I don't think it'd make
> > the modularity any worse, given that we're already referencing EPQstate
> > fields from with EState. If we moved es_epqTupleSlot into EPQState and
> > allocated it from within EvalPlanQualInit(), instead of
> > EvalPlanQualBegin(), we'd address your complaint that we now call that
> > earlier too.
> > Doesn't sound that hard. Seems like a big change for v12 though.
>
> I feel that this seems like a promising solution for the longer term.
> I agree that keeping a pointer to the whole EPQState in EState is no
> worse than having pointers to some of its fields there.
>
> Perhaps the next step is to draft a patch for this and see just how
> big it is compared to the minimal fix.
Working on that.
I just had a slightly crazy idea: What if we just blessed wholerow
rowmark types? Then we'd pretty trivially have access to the relevant
types? Or alternatively even just add type information to the
PlanRowMark for ROW_MARK_COPY instead of reconstructing it at runtime?
- Andres
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 04:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-24 16:13 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-24 22:54 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
@ 2019-08-25 17:04 ` Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 0 replies; 17+ messages in thread
From: Tom Lane @ 2019-08-25 17:04 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
Andres Freund <andres@anarazel.de> writes:
> I just had a slightly crazy idea: What if we just blessed wholerow
> rowmark types? Then we'd pretty trivially have access to the relevant
> types?
What would be trivial about that? You'd still need access to RTE-specific
information. I'm a little worried about the extra load on the typcache,
too.
> Or alternatively even just add type information to the
> PlanRowMark for ROW_MARK_COPY instead of reconstructing it at runtime?
Maybe, but I'm not sure that leads to a less invasive solution.
regards, tom lane
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 04:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-24 16:13 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-24 22:54 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
@ 2019-08-26 05:36 ` Andres Freund <andres@anarazel.de>
2019-08-27 01:08 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
1 sibling, 1 reply; 17+ messages in thread
From: Andres Freund @ 2019-08-26 05:36 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
Hi,
On 2019-08-24 15:54:01 -0700, Andres Freund wrote:
> Working on that.
Think it's going to look not too invasive. Needs a good bit more
cleanup, but I'm getting there.
One thing I'm struggling with is understanding and testing nested EPQ
states:
/*
* Each EState must have its own es_epqScanDone state, but if we have
* nested EPQ checks they should share es_epqTupleSlot arrays. This
* allows sub-rechecks to inherit the values being examined by an outer
* recheck.
*/
At the moment I don't understand what the point here is. When/why do we
want to inherit values from the parent epqstate? I know how to construct
queries with nested EPQ, but I don't see why we'd ever want to inherit
the values from the outer check? Nor how we're doing so -
EvalPlanQualFetchRowMarks() unconditionally clears out the old tuple,
and nodeLockRows.c unconditionally fetches the source tuples too?
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 04:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-24 16:13 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-24 22:54 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-26 05:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
@ 2019-08-27 01:08 ` Andres Freund <andres@anarazel.de>
2019-08-27 17:06 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 1 reply; 17+ messages in thread
From: Andres Freund @ 2019-08-27 01:08 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
Hi,
On 2019-08-25 22:36:52 -0700, Andres Freund wrote:
> On 2019-08-24 15:54:01 -0700, Andres Freund wrote:
> > Working on that.
>
> Think it's going to look not too invasive. Needs a good bit more
> cleanup, but I'm getting there.
>
>
> One thing I'm struggling with is understanding and testing nested EPQ
> states:
>
> /*
> * Each EState must have its own es_epqScanDone state, but if we have
> * nested EPQ checks they should share es_epqTupleSlot arrays. This
> * allows sub-rechecks to inherit the values being examined by an outer
> * recheck.
> */
>
> At the moment I don't understand what the point here is. When/why do we
> want to inherit values from the parent epqstate? I know how to construct
> queries with nested EPQ, but I don't see why we'd ever want to inherit
> the values from the outer check? Nor how we're doing so -
> EvalPlanQualFetchRowMarks() unconditionally clears out the old tuple,
> and nodeLockRows.c unconditionally fetches the source tuples too?
As far as I can tell it's not worth preserving this bit - it doesn't
seem to be working in a way one might infer from the comment, and the
current behaviour is pretty weird: In a nested EPQState, we'll overwrite
the tuples accessed by an outer layer of EPQ. I'm not sure, but I could
even see that causing crash type problems, e.g. if a columns from the
slot fetched by the outer EPQ is passed to the inner EPQ, which then
stores a new tuple in that slot, potentially leaving the argument be a
dangling pointer into that tuple.
Second, and somewhat related, question:
Why are we passing the surrounding EState to both EvalPlanQualInit() and
to EvalPlanQual()? Seems to not make much sense anymore? As I needed to
have accesses to the parent EState from the EPQState, to be able to
allocate slots for EvalPlanQualSlot() before EvalPlanQualBegin() has
been called, that seems even less necessary.
I've verified that the attached fixes the crash reported upthread. All
tests pass. I think it needs a bit of cleanup, and a lot more test
coverage.
On the latter point, it seems that we are missing coverage around:
1) most of ROW_MARK_COPY
2) no nested EPQ
3) index only scan as an EPQ source
4) FDWs
I'll not be able to add complete coverage, but clearly we need more than
now.
Tom, everyone, what do you think of the attached approach? It
implements what I described upthread.
The problem with fixing this bug is that we currently don't know the row
types for ExecAuxRowMarks at the site that is calling EvalPlanQual, and
that that is not easy to fix. But we don't really need the type that
early as there is no real need to fetch row marks that early. The
difficulty moving it to ExecScanFetch is that at that stage we currently
don't access to the information about row marks from the EPQState.
To fix that, this patch moves most of the EPQ related information out of
the ESTate into the EPQState, and sets es_active_epq to the EPQState for
ESTates that are created by EvalPlanQualStart(). That then allows us to
have ExecScanFetch() fetch the rowmark on demand with the new
EvalPlanQualFetchRowMark (which basically is just the old
EvalPlanQualFetchRowMarks without a loop).
For EvalPlanQualFetchRowMark to work efficiently, I added an rti - 1
indexed EPQState->substitute_rowmark.
This also fixes Tom's complain elswhere that nodeLockRows.c does
EvalPlanQualBegin() earlier, by allowing EvalPlanQualSlot() to be called
before that. That seems considerably nicer to me.
Questions:
- Is there any potential downside to not fetching non-locking rowmarks
eagerly? It's observable for FDWs, but it shouldn't matter? As far as
I can tell the new behaviour should always be at least as efficient as
before?
- Other names for EPQState->substitute_*?
- Should the RTI indexed version of arowmarks be computed as an array
directly in nodeModifyTable.c etc? Right now we build it first as a
list, and then convert it as an array? We could also just use an rti
indexed List, and store NULLs where there are no RTIs? But there's no
good API for that.
- We currently - and haven't in recent history - free epq test tuples
until EPQ is needed the next time. Perhaps we should? But that'd
probably not be a candidate for backpatching.
Todo:
- tests
- remove isolationtester rescheduling
Greetings,
Andres Freund
Attachments:
epq.diff (text/x-diff, 32.9K) download
diff --git i/src/backend/commands/trigger.c w/src/backend/commands/trigger.c
index 2d9a8e9d541..cdb1105b4a7 100644
--- i/src/backend/commands/trigger.c
+++ w/src/backend/commands/trigger.c
@@ -3363,8 +3363,7 @@ GetTupleForTrigger(EState *estate,
{
TupleTableSlot *epqslot;
- epqslot = EvalPlanQual(estate,
- epqstate,
+ epqslot = EvalPlanQual(epqstate,
relation,
relinfo->ri_RangeTableIndex,
oldslot);
diff --git i/src/backend/executor/execMain.c w/src/backend/executor/execMain.c
index 7f494abf14a..047c69553a6 100644
--- i/src/backend/executor/execMain.c
+++ w/src/backend/executor/execMain.c
@@ -98,8 +98,8 @@ static char *ExecBuildSlotValueDescription(Oid reloid,
TupleDesc tupdesc,
Bitmapset *modifiedCols,
int maxfieldlen);
-static void EvalPlanQualStart(EPQState *epqstate, EState *parentestate,
- Plan *planTree);
+static void EvalPlanQualStart(EPQState *epqstate, Plan *planTree);
+static void EvalPlanQualSetAuxRowMarks(EPQState *epqstate, List *auxrowmarks);
/*
* Note that GetAllUpdatedColumns() also exists in commands/trigger.c. There does
@@ -979,9 +979,8 @@ InitPlan(QueryDesc *queryDesc, int eflags)
*/
estate->es_tupleTable = NIL;
- /* mark EvalPlanQual not active */
- estate->es_epqTupleSlot = NULL;
- estate->es_epqScanDone = NULL;
+ /* mark EState as not belonging to EPQ */
+ estate->es_active_epq = NULL;
/*
* Initialize private state information for each SubPlan. We must do this
@@ -2425,7 +2424,6 @@ ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist)
* Check the updated version of a tuple to see if we want to process it under
* READ COMMITTED rules.
*
- * estate - outer executor state data
* epqstate - state for EvalPlanQual rechecking
* relation - table containing tuple
* rti - rangetable index of table containing tuple
@@ -2443,8 +2441,8 @@ ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist)
* NULL if we determine we shouldn't process the row.
*/
TupleTableSlot *
-EvalPlanQual(EState *estate, EPQState *epqstate,
- Relation relation, Index rti, TupleTableSlot *inputslot)
+EvalPlanQual(EPQState *epqstate, Relation relation,
+ Index rti, TupleTableSlot *inputslot)
{
TupleTableSlot *slot;
TupleTableSlot *testslot;
@@ -2454,7 +2452,7 @@ EvalPlanQual(EState *estate, EPQState *epqstate,
/*
* Need to run a recheck subquery. Initialize or reinitialize EPQ state.
*/
- EvalPlanQualBegin(epqstate, estate);
+ EvalPlanQualBegin(epqstate);
/*
* Callers will often use the EvalPlanQualSlot to store the tuple to avoid
@@ -2464,11 +2462,6 @@ EvalPlanQual(EState *estate, EPQState *epqstate,
if (testslot != inputslot)
ExecCopySlot(testslot, inputslot);
- /*
- * Fetch any non-locked source rows
- */
- EvalPlanQualFetchRowMarks(epqstate);
-
/*
* Run the EPQ query. We assume it will return at most one tuple.
*/
@@ -2502,17 +2495,34 @@ EvalPlanQual(EState *estate, EPQState *epqstate,
* with EvalPlanQualSetPlan.
*/
void
-EvalPlanQualInit(EPQState *epqstate, EState *estate,
+EvalPlanQualInit(EPQState *epqstate, EState *parentestate,
Plan *subplan, List *auxrowmarks, int epqParam)
{
+ Index rtsize = parentestate->es_range_table_size;
+
/* Mark the EPQ state inactive */
epqstate->estate = NULL;
epqstate->planstate = NULL;
epqstate->origslot = NULL;
+ epqstate->tuple_table = NIL;
/* ... and remember data that EvalPlanQualBegin will need */
+ epqstate->parentestate = parentestate;
epqstate->plan = subplan;
- epqstate->arowMarks = auxrowmarks;
epqstate->epqParam = epqParam;
+
+ /*
+ * Allocate resources that depend on the query. These arrays are reused
+ * across different plans set with EvalPlanQualSetPlan(), which works
+ * because they all use a compatible EState.
+ */
+ epqstate->substitute_rowmark = (ExecAuxRowMark **)
+ palloc0(rtsize * sizeof(ExecAuxRowMark *));
+ epqstate->substitute_done = (bool *)
+ palloc0(rtsize * sizeof(bool));
+ epqstate->substitute_slot = (TupleTableSlot **)
+ palloc0(rtsize * sizeof(TupleTableSlot *));
+
+ EvalPlanQualSetAuxRowMarks(epqstate, auxrowmarks);
}
/*
@@ -2528,11 +2538,14 @@ EvalPlanQualSetPlan(EPQState *epqstate, Plan *subplan, List *auxrowmarks)
/* And set/change the plan pointer */
epqstate->plan = subplan;
/* The rowmarks depend on the plan, too */
- epqstate->arowMarks = auxrowmarks;
+ EvalPlanQualSetAuxRowMarks(epqstate, auxrowmarks);
}
/*
* Return, and create if necessary, a slot for an EPQ test tuple.
+ *
+ * Note this only requires EvalPlanQualInit() to have been called,
+ * EvalPlanQualBegin() is not necessary.
*/
TupleTableSlot *
EvalPlanQualSlot(EPQState *epqstate,
@@ -2540,23 +2553,16 @@ EvalPlanQualSlot(EPQState *epqstate,
{
TupleTableSlot **slot;
- Assert(rti > 0 && rti <= epqstate->estate->es_range_table_size);
- slot = &epqstate->estate->es_epqTupleSlot[rti - 1];
+ Assert(relation);
+ Assert(rti > 0 && rti <= epqstate->parentestate->es_range_table_size);
+ slot = &epqstate->substitute_slot[rti - 1];
if (*slot == NULL)
{
MemoryContext oldcontext;
- oldcontext = MemoryContextSwitchTo(epqstate->estate->es_query_cxt);
-
- if (relation)
- *slot = table_slot_create(relation,
- &epqstate->estate->es_tupleTable);
- else
- *slot = ExecAllocTableSlot(&epqstate->estate->es_tupleTable,
- epqstate->origslot->tts_tupleDescriptor,
- &TTSOpsVirtual);
-
+ oldcontext = MemoryContextSwitchTo(epqstate->parentestate->es_query_cxt);
+ *slot = table_slot_create(relation, &epqstate->tuple_table);
MemoryContextSwitchTo(oldcontext);
}
@@ -2564,117 +2570,112 @@ EvalPlanQualSlot(EPQState *epqstate,
}
/*
- * Fetch the current row values for any non-locked relations that need
- * to be scanned by an EvalPlanQual operation. origslot must have been set
- * to contain the current result row (top-level row) that we need to recheck.
+ * Fetch the current row value for a non-locked relation, identified by rti,
+ * that needs to be scanned by an EvalPlanQual operation. origslot must have
+ * been set to contain the current result row (top-level row) that we need to
+ * recheck.
*/
-void
-EvalPlanQualFetchRowMarks(EPQState *epqstate)
+bool
+EvalPlanQualFetchRowMark(EPQState *epqstate, Index rti, TupleTableSlot *slot)
{
- ListCell *l;
+ ExecAuxRowMark *earm = epqstate->substitute_rowmark[rti - 1];
+ ExecRowMark *erm = earm->rowmark;
+ Datum datum;
+ bool isNull;
Assert(epqstate->origslot != NULL);
- foreach(l, epqstate->arowMarks)
+ if (RowMarkRequiresRowShareLock(erm->markType))
+ elog(ERROR, "EvalPlanQual doesn't support locking rowmarks");
+
+ /* if child rel, must check whether it produced this row */
+ if (erm->rti != erm->prti)
{
- ExecAuxRowMark *aerm = (ExecAuxRowMark *) lfirst(l);
- ExecRowMark *erm = aerm->rowmark;
- Datum datum;
- bool isNull;
- TupleTableSlot *slot;
+ Oid tableoid;
- if (RowMarkRequiresRowShareLock(erm->markType))
- elog(ERROR, "EvalPlanQual doesn't support locking rowmarks");
+ datum = ExecGetJunkAttribute(epqstate->origslot,
+ earm->toidAttNo,
+ &isNull);
+ /* non-locked rels could be on the inside of outer joins */
+ if (isNull)
+ return false;
- /* clear any leftover test tuple for this rel */
- slot = EvalPlanQualSlot(epqstate, erm->relation, erm->rti);
- ExecClearTuple(slot);
+ tableoid = DatumGetObjectId(datum);
- /* if child rel, must check whether it produced this row */
- if (erm->rti != erm->prti)
+ Assert(OidIsValid(erm->relid));
+ if (tableoid != erm->relid)
{
- Oid tableoid;
-
- datum = ExecGetJunkAttribute(epqstate->origslot,
- aerm->toidAttNo,
- &isNull);
- /* non-locked rels could be on the inside of outer joins */
- if (isNull)
- continue;
- tableoid = DatumGetObjectId(datum);
-
- Assert(OidIsValid(erm->relid));
- if (tableoid != erm->relid)
- {
- /* this child is inactive right now */
- continue;
- }
+ /* this child is inactive right now */
+ return false;
}
+ }
- if (erm->markType == ROW_MARK_REFERENCE)
+ if (erm->markType == ROW_MARK_REFERENCE)
+ {
+ Assert(erm->relation != NULL);
+
+ /* fetch the tuple's ctid */
+ datum = ExecGetJunkAttribute(epqstate->origslot,
+ earm->ctidAttNo,
+ &isNull);
+ /* non-locked rels could be on the inside of outer joins */
+ if (isNull)
+ return false;
+
+ /* fetch requests on foreign tables must be passed to their FDW */
+ if (erm->relation->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
{
- Assert(erm->relation != NULL);
+ FdwRoutine *fdwroutine;
+ bool updated = false;
- /* fetch the tuple's ctid */
- datum = ExecGetJunkAttribute(epqstate->origslot,
- aerm->ctidAttNo,
- &isNull);
- /* non-locked rels could be on the inside of outer joins */
- if (isNull)
- continue;
+ fdwroutine = GetFdwRoutineForRelation(erm->relation, false);
+ /* this should have been checked already, but let's be safe */
+ if (fdwroutine->RefetchForeignRow == NULL)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("cannot lock rows in foreign table \"%s\"",
+ RelationGetRelationName(erm->relation))));
- /* fetch requests on foreign tables must be passed to their FDW */
- if (erm->relation->rd_rel->relkind == RELKIND_FOREIGN_TABLE)
- {
- FdwRoutine *fdwroutine;
- bool updated = false;
+ fdwroutine->RefetchForeignRow(epqstate->estate,
+ erm,
+ datum,
+ slot,
+ &updated);
+ if (TupIsNull(slot))
+ elog(ERROR, "failed to fetch tuple for EvalPlanQual recheck");
- fdwroutine = GetFdwRoutineForRelation(erm->relation, false);
- /* this should have been checked already, but let's be safe */
- if (fdwroutine->RefetchForeignRow == NULL)
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("cannot lock rows in foreign table \"%s\"",
- RelationGetRelationName(erm->relation))));
-
- fdwroutine->RefetchForeignRow(epqstate->estate,
- erm,
- datum,
- slot,
- &updated);
- if (TupIsNull(slot))
- elog(ERROR, "failed to fetch tuple for EvalPlanQual recheck");
-
- /*
- * Ideally we'd insist on updated == false here, but that
- * assumes that FDWs can track that exactly, which they might
- * not be able to. So just ignore the flag.
- */
- }
- else
- {
- /* ordinary table, fetch the tuple */
- if (!table_tuple_fetch_row_version(erm->relation,
- (ItemPointer) DatumGetPointer(datum),
- SnapshotAny, slot))
- elog(ERROR, "failed to fetch tuple for EvalPlanQual recheck");
- }
+ /*
+ * Ideally we'd insist on updated == false here, but that
+ * assumes that FDWs can track that exactly, which they might
+ * not be able to. So just ignore the flag.
+ */
+ return true;
}
else
{
- Assert(erm->markType == ROW_MARK_COPY);
-
- /* fetch the whole-row Var for the relation */
- datum = ExecGetJunkAttribute(epqstate->origslot,
- aerm->wholeAttNo,
- &isNull);
- /* non-locked rels could be on the inside of outer joins */
- if (isNull)
- continue;
-
- ExecStoreHeapTupleDatum(datum, slot);
+ /* ordinary table, fetch the tuple */
+ if (!table_tuple_fetch_row_version(erm->relation,
+ (ItemPointer) DatumGetPointer(datum),
+ SnapshotAny, slot))
+ elog(ERROR, "failed to fetch tuple for EvalPlanQual recheck");
+ return true;
}
}
+ else
+ {
+ Assert(erm->markType == ROW_MARK_COPY);
+
+ /* fetch the whole-row Var for the relation */
+ datum = ExecGetJunkAttribute(epqstate->origslot,
+ earm->wholeAttNo,
+ &isNull);
+ /* non-locked rels could be on the inside of outer joins */
+ if (isNull)
+ return false;
+
+ ExecStoreHeapTupleDatum(datum, slot);
+ return true;
+ }
}
/*
@@ -2699,14 +2700,15 @@ EvalPlanQualNext(EPQState *epqstate)
* Initialize or reset an EvalPlanQual state tree
*/
void
-EvalPlanQualBegin(EPQState *epqstate, EState *parentestate)
+EvalPlanQualBegin(EPQState *epqstate)
{
EState *estate = epqstate->estate;
+ EState *parentestate = epqstate->parentestate;
if (estate == NULL)
{
/* First time through, so create a child EState */
- EvalPlanQualStart(epqstate, parentestate, epqstate->plan);
+ EvalPlanQualStart(epqstate, epqstate->plan);
}
else
{
@@ -2716,7 +2718,7 @@ EvalPlanQualBegin(EPQState *epqstate, EState *parentestate)
Index rtsize = parentestate->es_range_table_size;
PlanState *planstate = epqstate->planstate;
- MemSet(estate->es_epqScanDone, 0, rtsize * sizeof(bool));
+ MemSet(epqstate->substitute_done, 0, rtsize * sizeof(bool));
/* Recopy current values of parent parameters */
if (parentestate->es_plannedstmt->paramExecTypes != NIL)
@@ -2759,19 +2761,20 @@ EvalPlanQualBegin(EPQState *epqstate, EState *parentestate)
* the top-level estate rather than initializing it fresh.
*/
static void
-EvalPlanQualStart(EPQState *epqstate, EState *parentestate, Plan *planTree)
+EvalPlanQualStart(EPQState *epqstate, Plan *planTree)
{
+ EState *parentestate = epqstate->parentestate;
EState *estate;
- Index rtsize;
MemoryContext oldcontext;
ListCell *l;
- rtsize = parentestate->es_range_table_size;
-
epqstate->estate = estate = CreateExecutorState();
oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
+ /* mark ESTate as being part of EvalPlanQual */
+ estate->es_active_epq = epqstate;
+
/*
* Child EPQ EStates share the parent's copy of unchanging state such as
* the snapshot, rangetable, result-rel info, and external Param info.
@@ -2874,28 +2877,6 @@ EvalPlanQualStart(EPQState *epqstate, EState *parentestate, Plan *planTree)
}
}
- /*
- * Each EState must have its own es_epqScanDone state, but if we have
- * nested EPQ checks they should share es_epqTupleSlot arrays. This
- * allows sub-rechecks to inherit the values being examined by an outer
- * recheck.
- */
- estate->es_epqScanDone = (bool *) palloc0(rtsize * sizeof(bool));
- if (parentestate->es_epqTupleSlot != NULL)
- {
- estate->es_epqTupleSlot = parentestate->es_epqTupleSlot;
- }
- else
- {
- estate->es_epqTupleSlot = (TupleTableSlot **)
- palloc0(rtsize * sizeof(TupleTableSlot *));
- }
-
- /*
- * Each estate also has its own tuple table.
- */
- estate->es_tupleTable = NIL;
-
/*
* Initialize private state information for each SubPlan. We must do this
* before running ExecInitNode on the main query tree, since
@@ -2939,11 +2920,27 @@ void
EvalPlanQualEnd(EPQState *epqstate)
{
EState *estate = epqstate->estate;
+ Index rtsize;
MemoryContext oldcontext;
ListCell *l;
+ rtsize = epqstate->parentestate->es_range_table_size;
+
+ /*
+ * We may have a tuple table, even if EPQ wasn't started, because we allow
+ * use of EvalPlanQualSlot() without calling EvalPlanQualBegin().
+ */
+ if (epqstate->tuple_table != NIL)
+ {
+ memset(epqstate->substitute_slot, 0,
+ sizeof(rtsize * sizeof(TupleTableSlot *)));
+ ExecResetTupleTable(epqstate->tuple_table, true);
+ epqstate->tuple_table = NIL;
+ }
+
+ /* EPQ wasn't started, nothing further to do */
if (estate == NULL)
- return; /* idle, so nothing to do */
+ return;
oldcontext = MemoryContextSwitchTo(estate->es_query_cxt);
@@ -2956,7 +2953,7 @@ EvalPlanQualEnd(EPQState *epqstate)
ExecEndNode(subplanstate);
}
- /* throw away the per-estate tuple table */
+ /* throw away the per-estate tuple table, some node may have used it */
ExecResetTupleTable(estate->es_tupleTable, false);
/* close any trigger target relations attached to this EState */
@@ -2970,4 +2967,24 @@ EvalPlanQualEnd(EPQState *epqstate)
epqstate->estate = NULL;
epqstate->planstate = NULL;
epqstate->origslot = NULL;
+ memset(epqstate->substitute_done, 0, rtsize * sizeof(bool));
+}
+
+static void
+EvalPlanQualSetAuxRowMarks(EPQState *epqstate, List *auxrowmarks)
+{
+ Index rtsize;
+ ListCell *lc;
+
+ rtsize = epqstate->parentestate->es_range_table_size;
+
+ memset(epqstate->substitute_rowmark, 0,
+ sizeof(rtsize * sizeof(ExecAuxRowMark *)));
+
+ foreach(lc, auxrowmarks)
+ {
+ ExecAuxRowMark *earm = (ExecAuxRowMark *) lfirst(lc);
+
+ epqstate->substitute_rowmark[earm->rowmark->rti - 1] = earm;
+ }
}
diff --git i/src/backend/executor/execScan.c w/src/backend/executor/execScan.c
index c0e4a5376c3..84652ccbbcf 100644
--- i/src/backend/executor/execScan.c
+++ w/src/backend/executor/execScan.c
@@ -40,8 +40,10 @@ ExecScanFetch(ScanState *node,
CHECK_FOR_INTERRUPTS();
- if (estate->es_epqTupleSlot != NULL)
+ if (estate->es_active_epq != NULL)
{
+ EPQState *epqstate = estate->es_active_epq;
+
/*
* We are inside an EvalPlanQual recheck. Return the test tuple if
* one is available, after rechecking any access-method-specific
@@ -49,6 +51,8 @@ ExecScanFetch(ScanState *node,
*/
Index scanrelid = ((Scan *) node->ps.plan)->scanrelid;
+ // FIXME: less duplicated code
+
if (scanrelid == 0)
{
TupleTableSlot *slot = node->ss_ScanTupleSlot;
@@ -63,17 +67,23 @@ ExecScanFetch(ScanState *node,
ExecClearTuple(slot); /* would not be returned by scan */
return slot;
}
- else if (estate->es_epqTupleSlot[scanrelid - 1] != NULL)
+ else if (epqstate->substitute_done[scanrelid - 1])
{
TupleTableSlot *slot = node->ss_ScanTupleSlot;
- /* Return empty slot if we already returned a tuple */
- if (estate->es_epqScanDone[scanrelid - 1])
- return ExecClearTuple(slot);
- /* Else mark to remember that we shouldn't return more */
- estate->es_epqScanDone[scanrelid - 1] = true;
+ /* Return empty slot, as we already returned a tuple */
+ return ExecClearTuple(slot);
+ }
+ else if (epqstate->substitute_slot[scanrelid - 1] != NULL)
+ {
+ TupleTableSlot *slot;
- slot = estate->es_epqTupleSlot[scanrelid - 1];
+ Assert(epqstate->substitute_rowmark[scanrelid - 1] == NULL);
+
+ slot = epqstate->substitute_slot[scanrelid - 1];
+
+ /* Mark to remember that we shouldn't return more */
+ epqstate->substitute_done[scanrelid - 1] = true;
/* Return empty slot if we haven't got a test tuple */
if (TupIsNull(slot))
@@ -83,7 +93,26 @@ ExecScanFetch(ScanState *node,
if (!(*recheckMtd) (node, slot))
return ExecClearTuple(slot); /* would not be returned by
* scan */
+ return slot;
+ }
+ else if (epqstate->substitute_rowmark[scanrelid - 1] != NULL)
+ {
+ TupleTableSlot *slot = node->ss_ScanTupleSlot;
+ /* Mark to remember that we shouldn't return more */
+ epqstate->substitute_done[scanrelid - 1] = true;
+
+ if (!EvalPlanQualFetchRowMark(epqstate, scanrelid, slot))
+ return NULL;
+
+ /* Return empty slot if we haven't got a test tuple */
+ if (TupIsNull(slot))
+ return NULL;
+
+ /* Check if it meets the access-method conditions */
+ if (!(*recheckMtd) (node, slot))
+ return ExecClearTuple(slot); /* would not be returned by
+ * scan */
return slot;
}
}
@@ -268,12 +297,13 @@ ExecScanReScan(ScanState *node)
ExecClearTuple(node->ss_ScanTupleSlot);
/* Rescan EvalPlanQual tuple if we're inside an EvalPlanQual recheck */
- if (estate->es_epqScanDone != NULL)
+ if (estate->es_active_epq != NULL)
{
+ EPQState *epqstate = estate->es_active_epq;
Index scanrelid = ((Scan *) node->ps.plan)->scanrelid;
if (scanrelid > 0)
- estate->es_epqScanDone[scanrelid - 1] = false;
+ epqstate->substitute_done[scanrelid - 1] = false;
else
{
Bitmapset *relids;
@@ -295,7 +325,7 @@ ExecScanReScan(ScanState *node)
while ((rtindex = bms_next_member(relids, rtindex)) >= 0)
{
Assert(rtindex > 0);
- estate->es_epqScanDone[rtindex - 1] = false;
+ epqstate->substitute_done[rtindex - 1] = false;
}
}
}
diff --git i/src/backend/executor/execUtils.c w/src/backend/executor/execUtils.c
index afd9bebdbdc..ee0239b146a 100644
--- i/src/backend/executor/execUtils.c
+++ w/src/backend/executor/execUtils.c
@@ -156,8 +156,6 @@ CreateExecutorState(void)
estate->es_per_tuple_exprcontext = NULL;
- estate->es_epqTupleSlot = NULL;
- estate->es_epqScanDone = NULL;
estate->es_sourceText = NULL;
estate->es_use_parallel_mode = false;
diff --git i/src/backend/executor/nodeIndexonlyscan.c w/src/backend/executor/nodeIndexonlyscan.c
index 652a9afc752..5580645011c 100644
--- i/src/backend/executor/nodeIndexonlyscan.c
+++ w/src/backend/executor/nodeIndexonlyscan.c
@@ -420,26 +420,28 @@ void
ExecIndexOnlyMarkPos(IndexOnlyScanState *node)
{
EState *estate = node->ss.ps.state;
+ EPQState *epqstate = estate->es_active_epq;
- if (estate->es_epqTupleSlot != NULL)
+ if (epqstate != NULL)
{
/*
* We are inside an EvalPlanQual recheck. If a test tuple exists for
* this relation, then we shouldn't access the index at all. We would
* instead need to save, and later restore, the state of the
- * es_epqScanDone flag, so that re-fetching the test tuple is
+ * substitute_done flag, so that re-fetching the test tuple is
* possible. However, given the assumption that no caller sets a mark
- * at the start of the scan, we can only get here with es_epqScanDone
- * already set, and so no state need be saved.
+ * at the start of the scan, we can only get here with
+ * substitute_done[i] already set, and so no state need be saved.
*/
Index scanrelid = ((Scan *) node->ss.ps.plan)->scanrelid;
Assert(scanrelid > 0);
- if (estate->es_epqTupleSlot[scanrelid - 1] != NULL)
+ if (epqstate->substitute_slot[scanrelid - 1] != NULL ||
+ epqstate->substitute_rowmark[scanrelid - 1] != NULL)
{
/* Verify the claim above */
- if (!estate->es_epqScanDone[scanrelid - 1])
- elog(ERROR, "unexpected ExecIndexOnlyMarkPos call in EPQ recheck");
+ if (!epqstate->substitute_done[scanrelid - 1])
+ elog(ERROR, "unexpected ExecIndexMarkPos call in EPQ recheck");
return;
}
}
@@ -455,18 +457,20 @@ void
ExecIndexOnlyRestrPos(IndexOnlyScanState *node)
{
EState *estate = node->ss.ps.state;
+ EPQState *epqstate = estate->es_active_epq;
- if (estate->es_epqTupleSlot != NULL)
+ if (estate->es_active_epq != NULL)
{
- /* See comments in ExecIndexOnlyMarkPos */
+ /* See comments in ExecIndexMarkPos */
Index scanrelid = ((Scan *) node->ss.ps.plan)->scanrelid;
Assert(scanrelid > 0);
- if (estate->es_epqTupleSlot[scanrelid - 1])
+ if (epqstate->substitute_slot[scanrelid - 1] != NULL ||
+ epqstate->substitute_rowmark[scanrelid - 1] != NULL)
{
/* Verify the claim above */
- if (!estate->es_epqScanDone[scanrelid - 1])
- elog(ERROR, "unexpected ExecIndexOnlyRestrPos call in EPQ recheck");
+ if (!epqstate->substitute_done[scanrelid - 1])
+ elog(ERROR, "unexpected ExecIndexRestrPos call in EPQ recheck");
return;
}
}
diff --git i/src/backend/executor/nodeIndexscan.c w/src/backend/executor/nodeIndexscan.c
index ac7aa81f674..dd7dcc093eb 100644
--- i/src/backend/executor/nodeIndexscan.c
+++ w/src/backend/executor/nodeIndexscan.c
@@ -827,25 +827,27 @@ void
ExecIndexMarkPos(IndexScanState *node)
{
EState *estate = node->ss.ps.state;
+ EPQState *epqstate = estate->es_active_epq;
- if (estate->es_epqTupleSlot != NULL)
+ if (epqstate != NULL)
{
/*
* We are inside an EvalPlanQual recheck. If a test tuple exists for
* this relation, then we shouldn't access the index at all. We would
* instead need to save, and later restore, the state of the
- * es_epqScanDone flag, so that re-fetching the test tuple is
+ * substitute_done flag, so that re-fetching the test tuple is
* possible. However, given the assumption that no caller sets a mark
- * at the start of the scan, we can only get here with es_epqScanDone
- * already set, and so no state need be saved.
+ * at the start of the scan, we can only get here with
+ * substitute_done[i] already set, and so no state need be saved.
*/
Index scanrelid = ((Scan *) node->ss.ps.plan)->scanrelid;
Assert(scanrelid > 0);
- if (estate->es_epqTupleSlot[scanrelid - 1] != NULL)
+ if (epqstate->substitute_slot[scanrelid - 1] != NULL ||
+ epqstate->substitute_rowmark[scanrelid - 1] != NULL)
{
/* Verify the claim above */
- if (!estate->es_epqScanDone[scanrelid - 1])
+ if (!epqstate->substitute_done[scanrelid - 1])
elog(ERROR, "unexpected ExecIndexMarkPos call in EPQ recheck");
return;
}
@@ -862,17 +864,19 @@ void
ExecIndexRestrPos(IndexScanState *node)
{
EState *estate = node->ss.ps.state;
+ EPQState *epqstate = estate->es_active_epq;
- if (estate->es_epqTupleSlot != NULL)
+ if (estate->es_active_epq != NULL)
{
/* See comments in ExecIndexMarkPos */
Index scanrelid = ((Scan *) node->ss.ps.plan)->scanrelid;
Assert(scanrelid > 0);
- if (estate->es_epqTupleSlot[scanrelid - 1] != NULL)
+ if (epqstate->substitute_slot[scanrelid - 1] != NULL ||
+ epqstate->substitute_rowmark[scanrelid - 1] != NULL)
{
/* Verify the claim above */
- if (!estate->es_epqScanDone[scanrelid - 1])
+ if (!epqstate->substitute_done[scanrelid - 1])
elog(ERROR, "unexpected ExecIndexRestrPos call in EPQ recheck");
return;
}
diff --git i/src/backend/executor/nodeLockRows.c w/src/backend/executor/nodeLockRows.c
index 41513ceec65..72c5b7cab2d 100644
--- i/src/backend/executor/nodeLockRows.c
+++ w/src/backend/executor/nodeLockRows.c
@@ -64,12 +64,6 @@ lnext:
/* We don't need EvalPlanQual unless we get updated tuple version(s) */
epq_needed = false;
- /*
- * Initialize EPQ machinery. Need to do that early because source tuples
- * are stored in slots initialized therein.
- */
- EvalPlanQualBegin(&node->lr_epqstate, estate);
-
/*
* Attempt to lock the source tuple(s). (Note we only have locking
* rowmarks in lr_arowMarks.)
@@ -259,12 +253,14 @@ lnext:
*/
if (epq_needed)
{
+ /* Initialize EPQ machinery */
+ EvalPlanQualBegin(&node->lr_epqstate);
+
/*
- * Now fetch any non-locked source rows --- the EPQ logic knows how to
- * do that.
+ * To fetch non-locked source rows the EPQ logic needs to access junk
+ * columns from the tuple being tested.
*/
EvalPlanQualSetSlot(&node->lr_epqstate, slot);
- EvalPlanQualFetchRowMarks(&node->lr_epqstate);
/*
* And finally we can re-evaluate the tuple.
diff --git i/src/backend/executor/nodeModifyTable.c w/src/backend/executor/nodeModifyTable.c
index 9e0c8794c40..64793d94279 100644
--- i/src/backend/executor/nodeModifyTable.c
+++ w/src/backend/executor/nodeModifyTable.c
@@ -828,7 +828,7 @@ ldelete:;
* Already know that we're going to need to do EPQ, so
* fetch tuple directly into the right slot.
*/
- EvalPlanQualBegin(epqstate, estate);
+ EvalPlanQualBegin(epqstate);
inputslot = EvalPlanQualSlot(epqstate, resultRelationDesc,
resultRelInfo->ri_RangeTableIndex);
@@ -843,8 +843,7 @@ ldelete:;
{
case TM_Ok:
Assert(tmfd.traversed);
- epqslot = EvalPlanQual(estate,
- epqstate,
+ epqslot = EvalPlanQual(epqstate,
resultRelationDesc,
resultRelInfo->ri_RangeTableIndex,
inputslot);
@@ -1370,7 +1369,6 @@ lreplace:;
* Already know that we're going to need to do EPQ, so
* fetch tuple directly into the right slot.
*/
- EvalPlanQualBegin(epqstate, estate);
inputslot = EvalPlanQualSlot(epqstate, resultRelationDesc,
resultRelInfo->ri_RangeTableIndex);
@@ -1386,8 +1384,7 @@ lreplace:;
case TM_Ok:
Assert(tmfd.traversed);
- epqslot = EvalPlanQual(estate,
- epqstate,
+ epqslot = EvalPlanQual(epqstate,
resultRelationDesc,
resultRelInfo->ri_RangeTableIndex,
inputslot);
@@ -2014,7 +2011,7 @@ ExecModifyTable(PlanState *pstate)
* case it is within a CTE subplan. Hence this test must be here, not in
* ExecInitModifyTable.)
*/
- if (estate->es_epqTupleSlot != NULL)
+ if (estate->es_active_epq != NULL)
elog(ERROR, "ModifyTable should not be called during EvalPlanQual");
/*
diff --git i/src/include/executor/executor.h w/src/include/executor/executor.h
index affe6ad6982..17a47b3b92f 100644
--- i/src/include/executor/executor.h
+++ w/src/include/executor/executor.h
@@ -198,9 +198,9 @@ extern void ExecWithCheckOptions(WCOKind kind, ResultRelInfo *resultRelInfo,
extern LockTupleMode ExecUpdateLockMode(EState *estate, ResultRelInfo *relinfo);
extern ExecRowMark *ExecFindRowMark(EState *estate, Index rti, bool missing_ok);
extern ExecAuxRowMark *ExecBuildAuxRowMark(ExecRowMark *erm, List *targetlist);
-extern TupleTableSlot *EvalPlanQual(EState *estate, EPQState *epqstate,
- Relation relation, Index rti, TupleTableSlot *testslot);
-extern void EvalPlanQualInit(EPQState *epqstate, EState *estate,
+extern TupleTableSlot *EvalPlanQual(EPQState *epqstate, Relation relation,
+ Index rti, TupleTableSlot *testslot);
+extern void EvalPlanQualInit(EPQState *epqstate, EState *parentestate,
Plan *subplan, List *auxrowmarks, int epqParam);
extern void EvalPlanQualSetPlan(EPQState *epqstate,
Plan *subplan, List *auxrowmarks);
@@ -209,8 +209,9 @@ extern TupleTableSlot *EvalPlanQualSlot(EPQState *epqstate,
#define EvalPlanQualSetSlot(epqstate, slot) ((epqstate)->origslot = (slot))
extern void EvalPlanQualFetchRowMarks(EPQState *epqstate);
+extern bool EvalPlanQualFetchRowMark(EPQState *epqstate, Index rti, TupleTableSlot *slot);
extern TupleTableSlot *EvalPlanQualNext(EPQState *epqstate);
-extern void EvalPlanQualBegin(EPQState *epqstate, EState *parentestate);
+extern void EvalPlanQualBegin(EPQState *epqstate);
extern void EvalPlanQualEnd(EPQState *epqstate);
/*
diff --git i/src/include/nodes/execnodes.h w/src/include/nodes/execnodes.h
index f42189d2bf6..c6e3617808b 100644
--- i/src/include/nodes/execnodes.h
+++ w/src/include/nodes/execnodes.h
@@ -506,6 +506,12 @@ typedef struct EState
Index es_range_table_size; /* size of the range table arrays */
Relation *es_relations; /* Array of per-range-table-entry Relation
* pointers, or NULL if not yet opened */
+
+ /*
+ * FIXME: This should possible be moved into EPQState as well, but that
+ * would require some changes for execCurrent.c, which references
+ * es_rowmarks.
+ */
struct ExecRowMark **es_rowmarks; /* Array of per-range-table-entry
* ExecRowMarks, or NULL if none */
PlannedStmt *es_plannedstmt; /* link to top of plan tree */
@@ -570,18 +576,8 @@ typedef struct EState
*/
ExprContext *es_per_tuple_exprcontext;
- /*
- * These fields are for re-evaluating plan quals when an updated tuple is
- * substituted in READ COMMITTED mode. es_epqTupleSlot[] contains test
- * tuples that scan plan nodes should return instead of whatever they'd
- * normally return, or an empty slot if there is nothing to return; if
- * es_epqTupleSlot[] is not NULL if a particular array entry is valid; and
- * es_epqScanDone[] is state to remember if the tuple has been returned
- * already. Arrays are of size es_range_table_size and are indexed by
- * scan node scanrelid - 1.
- */
- TupleTableSlot **es_epqTupleSlot; /* array of EPQ substitute tuples */
- bool *es_epqScanDone; /* true if EPQ tuple has been fetched */
+ /* if not NULL this is an EPQState's ESTate */
+ struct EPQState *es_active_epq;
bool es_use_parallel_mode; /* can we use parallel workers? */
@@ -1062,12 +1058,38 @@ typedef struct PlanState
*/
typedef struct EPQState
{
- EState *estate; /* subsidiary EState */
- PlanState *planstate; /* plan state tree ready to be executed */
- TupleTableSlot *origslot; /* original output tuple to be rechecked */
Plan *plan; /* plan tree to be executed */
- List *arowMarks; /* ExecAuxRowMarks (non-locking only) */
+ EState *parentestate; /* parent EState */
int epqParam; /* ID of Param to force scan node re-eval */
+
+ EState *estate; /* subsidiary EState, created on demand */
+ PlanState *planstate; /* plan state tree ready to be executed */
+ List *tuple_table;
+
+ TupleTableSlot *origslot; /* original output tuple to be rechecked */
+
+ /*
+ * Per-relation state for EPQ.
+ *
+ * Arrays are of size es_range_table_size and are indexed by scan node
+ * scanrelid - 1.
+ */
+
+ /*
+ * Substitute tuples that have been set up, before calling
+ * EvalPlanQual()/EvalPlanQualNext(), in a slot returned by
+ * EvalPlanQualSlot().
+ */
+ TupleTableSlot **substitute_slot;
+
+ /*
+ * Rowmarks that can be fetched on-demand using
+ * EvalPlanQualFetchRowMark(). Only non-locking rowmarks are supported.
+ */
+ ExecAuxRowMark **substitute_rowmark;
+
+ /* true if EPQ tuple has been fetched for relation */
+ bool *substitute_done;
} EPQState;
diff --git i/src/test/isolation/isolation_schedule w/src/test/isolation/isolation_schedule
index 69ae2279533..4578aefa260 100644
--- i/src/test/isolation/isolation_schedule
+++ w/src/test/isolation/isolation_schedule
@@ -1,3 +1,6 @@
+test: eval-plan-qual
+test: lock-update-delete
+test: lock-update-traversal
test: read-only-anomaly
test: read-only-anomaly-2
test: read-only-anomaly-3
@@ -28,9 +31,6 @@ test: fk-deadlock
test: fk-deadlock2
test: fk-partitioned-1
test: fk-partitioned-2
-test: eval-plan-qual
-test: lock-update-delete
-test: lock-update-traversal
test: inherit-temp
test: insert-conflict-do-nothing
test: insert-conflict-do-nothing-2
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 04:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-24 16:13 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-24 22:54 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-26 05:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-27 01:08 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
@ 2019-08-27 17:06 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-08-28 03:02 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-09-05 19:59 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
0 siblings, 2 replies; 17+ messages in thread
From: Tom Lane @ 2019-08-27 17:06 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
Andres Freund <andres@anarazel.de> writes:
>> One thing I'm struggling with is understanding and testing nested EPQ
>> states:
>> * Each EState must have its own es_epqScanDone state, but if we have
>> * nested EPQ checks they should share es_epqTupleSlot arrays. This
>> * allows sub-rechecks to inherit the values being examined by an outer
>> * recheck.
>> At the moment I don't understand what the point here is. When/why do we
>> want to inherit values from the parent epqstate? I know how to construct
>> queries with nested EPQ, but I don't see why we'd ever want to inherit
>> the values from the outer check? Nor how we're doing so -
>> EvalPlanQualFetchRowMarks() unconditionally clears out the old tuple,
>> and nodeLockRows.c unconditionally fetches the source tuples too?
It's been a really long time, but I think that the idea might have been
to avoid useless repeat tuple fetches in nested-EPQ cases. However,
those are such extreme corner cases that I agree it's not worth contorting
the logic to make them a shade faster (if indeed it works at all at
present, which it might not).
> This also fixes Tom's complain elswhere that nodeLockRows.c does
> EvalPlanQualBegin() earlier, by allowing EvalPlanQualSlot() to be called
> before that. That seems considerably nicer to me.
Yay.
> Tom, everyone, what do you think of the attached approach? It
> implements what I described upthread.
Seems reasonable to store a pointer in the EPQState rather than pass
that as a separate argument, but I think you need a bit more documentation
work to keep the two EState pointers from being impossibly confusing.
It might help to write something like "estate is an executor state node
instantiated for the same rangetable as parentestate (though it might
be running only a sub-tree of the main plan). While parentestate
represents the "real" plan execution, estate runs EPQ rechecks in
which the table scan nodes are changed to return only the current tuple
of interest for each table. Those current tuples are found using the
rowmark mechanisms." Maybe we should change the "estate" field name
to something else, too --- "childestate" is the first thing that comes
to mind but it's rather generic. "recheckestate", perhaps?
Also I dislike the field name "es_active_epq", as what that suggests
to me is exactly backwards from the way you apparently are using it.
Maybe "es_parent_epq" instead? The comment for it is pretty opaque
as well, not to mention that it misspells EState.
I don't agree with the FIXME comment in execnodes.h. The rowmarks
state is used for things that are outside of EPQ, particularly the
actual row locking ;-), so I wouldn't want to move that even if it
didn't create notational issues.
I'm confused by the removal of the EvalPlanQualBegin call at
nodeModifyTable.c:1373 ... why is that OK?
The original intent of EvalPlanQualInit was to do an absolutely
minimal amount of work, since we don't know yet whether EPQ will
ever be needed (and, generally, the way to bet is that it won't be).
You've added some pallocs and list-to-array conversion, which
while not terribly expensive still seem like they don't belong
there. Can't we move most of that to EvalPlanQualBegin? I see that
we want the substitute_slot array to exist so that EvalPlanQualSlot
can work without EvalPlanQualBegin, but if we're postponing
non-locking-rowmark work then we don't need the rest.
You seem to have removed EvalPlanQualFetchRowMarks, but the
extern for it is still there?
The bool result of EvalPlanQualFetchRowMark needs documented.
In ExecIndexOnlyMarkPos and ExecIndexOnlyRestrPos, you seem to have
incorrectly changed the function names given in comments and elog messages
(copy&pasto?)
> Questions:
> - Is there any potential downside to not fetching non-locking rowmarks
> eagerly? It's observable for FDWs, but it shouldn't matter? As far as
> I can tell the new behaviour should always be at least as efficient as
> before?
It's possible that in some cases we'd not re-fetch a tuple that the
existing code would re-fetch, but I have a hard time seeing how that's
bad.
> - Should the RTI indexed version of arowmarks be computed as an array
> directly in nodeModifyTable.c etc? Right now we build it first as a
> list, and then convert it as an array? We could also just use an rti
> indexed List, and store NULLs where there are no RTIs? But there's no
> good API for that.
Do that as a follow-on patch if at all. I'm not sure it's worth changing.
> - We currently - and haven't in recent history - free epq test tuples
> until EPQ is needed the next time. Perhaps we should?
Can't get excited about it.
regards, tom lane
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 04:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-24 16:13 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-24 22:54 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-26 05:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-27 01:08 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-27 17:06 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-08-28 03:02 ` Andres Freund <andres@anarazel.de>
1 sibling, 0 replies; 17+ messages in thread
From: Andres Freund @ 2019-08-28 03:02 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
On 2019-08-27 13:06:37 -0400, Tom Lane wrote:
> > Tom, everyone, what do you think of the attached approach? It
> > implements what I described upthread.
>
> Seems reasonable to store a pointer in the EPQState rather than pass
> that as a separate argument, but I think you need a bit more documentation
> work to keep the two EState pointers from being impossibly confusing.
Agreed.
> Also I dislike the field name "es_active_epq", as what that suggests
> to me is exactly backwards from the way you apparently are using it.
> Maybe "es_parent_epq" instead? The comment for it is pretty opaque
> as well, not to mention that it misspells EState.
I think what I was trying to signal was that EPQ is currently active
from the POV of executor nodes. Ought to have been es_epq_active, for
that, I guess. For me "if (estate->es_epq_active)" explains the meaning
of the check more than "if (estate->es_parent_epq)".
> I don't agree with the FIXME comment in execnodes.h. The rowmarks
> state is used for things that are outside of EPQ, particularly the
> actual row locking ;-), so I wouldn't want to move that even if it
> didn't create notational issues.
Yea, I wasn't sure about that.
> I'm confused by the removal of the EvalPlanQualBegin call at
> nodeModifyTable.c:1373 ... why is that OK?
EvalPlanQual() calls EvalPlanQualBegin(), it was just needed to initiate
enough state to be able to get a slot.
> The original intent of EvalPlanQualInit was to do an absolutely
> minimal amount of work, since we don't know yet whether EPQ will
> ever be needed (and, generally, the way to bet is that it won't be).
> You've added some pallocs and list-to-array conversion, which
> while not terribly expensive still seem like they don't belong
> there. Can't we move most of that to EvalPlanQualBegin? I see that
> we want the substitute_slot array to exist so that EvalPlanQualSlot
> can work without EvalPlanQualBegin, but if we're postponing
> non-locking-rowmark work then we don't need the rest.
Yea, we can move the other fields without much trouble.
> > - Should the RTI indexed version of arowmarks be computed as an array
> > directly in nodeModifyTable.c etc? Right now we build it first as a
> > list, and then convert it as an array? We could also just use an rti
> > indexed List, and store NULLs where there are no RTIs? But there's no
> > good API for that.
>
> Do that as a follow-on patch if at all. I'm not sure it's worth changing.
Well, it'd at least partially address your concern above that we ought
to do less work during EvalPlanQualInit - if we had it in array form
we'd just need to set a variable, rather than do the transformation.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 04:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-24 16:13 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-24 22:54 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-26 05:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-27 01:08 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-27 17:06 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
@ 2019-09-05 19:59 ` Andres Freund <andres@anarazel.de>
2019-09-05 20:04 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-09-09 14:05 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
1 sibling, 2 replies; 17+ messages in thread
From: Andres Freund @ 2019-09-05 19:59 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
Hi,
On 2019-08-27 13:06:37 -0400, Tom Lane wrote:
> Seems reasonable to store a pointer in the EPQState rather than pass
> that as a separate argument, but I think you need a bit more documentation
> work to keep the two EState pointers from being impossibly confusing.
> It might help to write something like "estate is an executor state node
> instantiated for the same rangetable as parentestate (though it might
> be running only a sub-tree of the main plan). While parentestate
> represents the "real" plan execution, estate runs EPQ rechecks in
> which the table scan nodes are changed to return only the current tuple
> of interest for each table. Those current tuples are found using the
> rowmark mechanisms."
I tried that for a while, but was unsatisfied with putting it to the
EState(s) - felt like too general a comment. Moved it to the top of the
struct instead. This basically ended up reordering all of struct
EState, so it'd be good to have a second look.
> Maybe we should change the "estate" field name to something else, too
> --- "childestate" is the first thing that comes to mind but it's
> rather generic. "recheckestate", perhaps?
I went with recheckestate, and then also renamed the PlanState to follow
recheck* pattern, to make clearer it's not the main plan's PlanState
(sub-)tree.
> Also I dislike the field name "es_active_epq", as what that suggests
> to me is exactly backwards from the way you apparently are using it.
> Maybe "es_parent_epq" instead?
I went with es_epq_active, as I suggested in my earlier email, which
still seems accurate to me.
I really want to move consideration of es_ep_active to ExecInitNode()
time, rather than execution time. If we add an execScan helper, we can
have it set the corresponding executor node's ExecProcNode to
a) a function that performs qual checks and projection
b) a function that performs projection
c) the fetch method from the scan node
d) basically the current ExecScan, when es_epq_active
> The original intent of EvalPlanQualInit was to do an absolutely
> minimal amount of work, since we don't know yet whether EPQ will
> ever be needed (and, generally, the way to bet is that it won't be).
> You've added some pallocs and list-to-array conversion, which
> while not terribly expensive still seem like they don't belong
> there. Can't we move most of that to EvalPlanQualBegin? I see that
> we want the substitute_slot array to exist so that EvalPlanQualSlot
> can work without EvalPlanQualBegin, but if we're postponing
> non-locking-rowmark work then we don't need the rest.
Did that.
> In ExecIndexOnlyMarkPos and ExecIndexOnlyRestrPos, you seem to have
> incorrectly changed the function names given in comments and elog messages
> (copy&pasto?)
Fixed.
Did a good bit more comment polishing, renamed a few more variables.
I also added tests for things that I thought were clearly missing
(including a test that errors out before the code changes in the
patch).
For one of the new tests I added a noisy_oper(comment, a, oper, b)
function, to see which EPQ tests are performed with which
values. Without that I found it to be really hard to be confident that
we actually are using the right column values. I think it might make
sense to expand it's use a bit more - but that seems like something for
later.
I tried for a while to develop one for mark/restore of IndexOnlyScans,
but I concluded that that code is basically dead right now. Every scan
node of a normal that gets modified or needs a rowmark implies having
ctid as part of the targetlist. And we neither allow ctid to be part of
index definitions, nor understand that we actually kinda know the ctid
from within the index scan (HOT would make using the tid hard). So the
relevant code in nodeIndexOnly.c seems dead?
Greetings,
Andres Freund
Attachments:
0001-Fix-rowmark-related-EPQ-bug-improve-EPQ-efficiency-a.patch (text/x-diff, 0B) download
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 04:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-24 16:13 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-24 22:54 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-26 05:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-27 01:08 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-27 17:06 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-09-05 19:59 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
@ 2019-09-05 20:04 ` Andres Freund <andres@anarazel.de>
1 sibling, 0 replies; 17+ messages in thread
From: Andres Freund @ 2019-09-05 20:04 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
Hi,
On 2019-09-05 12:59:11 -0700, Andres Freund wrote:
> @@ -562,6 +831,7 @@ LockRows
> Merge Cond: (a.id = b.id)
> -> Index Scan using jointest_id_idx on jointest a
> -> Index Scan using jointest_id_idx on jointest b
> +s1: WARNING: it's me, brother ExecIndexMarkPos()
> id data id data
>
> 1 0 1 0
Err, I forgot to amend the commit with the stashed removal of debugging
cruft in the output file...
Greetings,
Andres Freund
Attachments:
0001-Fix-rowmark-related-EPQ-bug-improve-EPQ-efficiency-a.patch (text/x-diff, 0B) download
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 04:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-24 16:13 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-24 22:54 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-26 05:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-27 01:08 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-27 17:06 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-09-05 19:59 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
@ 2019-09-09 14:05 ` Andres Freund <andres@anarazel.de>
2019-09-09 14:20 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
1 sibling, 1 reply; 17+ messages in thread
From: Andres Freund @ 2019-09-09 14:05 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
Hi,
On 2019-09-05 12:59:11 -0700, Andres Freund wrote:
> Did a good bit more comment polishing, renamed a few more variables.
Pushed now, after some more polishing.
> I also added tests for things that I thought were clearly missing
> (including a test that errors out before the code changes in the
> patch).
For 12, I had to replace the NOTICE with WARNING (including SET
client_min_messages). I wonder if we ought to backpatch
commit ebd49928215e3854d91167e798949a75b34958d0
Author: Tom Lane <tgl@sss.pgh.pa.us>
Date: 2019-07-27 15:59:57 -0400
Don't drop NOTICE messages in isolation tests.
to avoid backpatching pain?
> I tried for a while to develop one for mark/restore of IndexOnlyScans,
> but I concluded that that code is basically dead right now. Every scan
> node of a normal that gets modified or needs a rowmark implies having
> ctid as part of the targetlist. And we neither allow ctid to be part of
> index definitions, nor understand that we actually kinda know the ctid
> from within the index scan (HOT would make using the tid hard). So the
> relevant code in nodeIndexOnly.c seems dead?
I wonder if, on master, we should make ExecIndexOnlyMarkPos(),
ExecIndexOnlyRestrPos() ERROR out in case they're hit for an EPQ
relation, given that they ought to be unreachable.
Greetings,
Andres Freund
^ permalink raw reply [nested|flat] 17+ messages in thread
* Re: PostgreSQL12 crash bug report
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 04:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-24 16:13 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-08-24 22:54 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-26 05:36 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-27 01:08 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-08-27 17:06 ` Re: PostgreSQL12 crash bug report Tom Lane <tgl@sss.pgh.pa.us>
2019-09-05 19:59 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
2019-09-09 14:05 ` Re: PostgreSQL12 crash bug report Andres Freund <andres@anarazel.de>
@ 2019-09-09 14:20 ` Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 17+ messages in thread
From: Tom Lane @ 2019-09-09 14:20 UTC (permalink / raw)
To: Andres Freund <andres@anarazel.de>; +Cc: yi huang <yi.codeplayer@gmail.com>; pgsql-bugs@lists.postgresql.org
Andres Freund <andres@anarazel.de> writes:
> On 2019-09-05 12:59:11 -0700, Andres Freund wrote:
>> I tried for a while to develop one for mark/restore of IndexOnlyScans,
>> but I concluded that that code is basically dead right now. Every scan
>> node of a normal that gets modified or needs a rowmark implies having
>> ctid as part of the targetlist. And we neither allow ctid to be part of
>> index definitions, nor understand that we actually kinda know the ctid
>> from within the index scan (HOT would make using the tid hard). So the
>> relevant code in nodeIndexOnly.c seems dead?
> I wonder if, on master, we should make ExecIndexOnlyMarkPos(),
> ExecIndexOnlyRestrPos() ERROR out in case they're hit for an EPQ
> relation, given that they ought to be unreachable.
I'd vote against. The chain of reasoning that says they're unreachable
is long and involves mostly code that's nowhere near there, so when/if
somebody made a change that broke that reasoning, they'd not necessarily
notice that the ERROR has to be undone.
regards, tom lane
^ permalink raw reply [nested|flat] 17+ messages in thread
end of thread, other threads:[~2019-09-09 14:20 UTC | newest]
Thread overview: 17+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2019-07-28 18:56 PostgreSQL12 crash bug report yi huang <yi.codeplayer@gmail.com>
2019-07-28 20:11 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-07-31 23:07 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 00:40 ` Andres Freund <andres@anarazel.de>
2019-08-01 02:37 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-08-01 04:36 ` Andres Freund <andres@anarazel.de>
2019-08-24 16:13 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-08-24 22:54 ` Andres Freund <andres@anarazel.de>
2019-08-25 17:04 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-08-26 05:36 ` Andres Freund <andres@anarazel.de>
2019-08-27 01:08 ` Andres Freund <andres@anarazel.de>
2019-08-27 17:06 ` Tom Lane <tgl@sss.pgh.pa.us>
2019-08-28 03:02 ` Andres Freund <andres@anarazel.de>
2019-09-05 19:59 ` Andres Freund <andres@anarazel.de>
2019-09-05 20:04 ` Andres Freund <andres@anarazel.de>
2019-09-09 14:05 ` Andres Freund <andres@anarazel.de>
2019-09-09 14:20 ` Tom Lane <tgl@sss.pgh.pa.us>
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