aboutsummaryrefslogtreecommitdiff
path: root/src/backend/executor/nodeMergejoin.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2022-02-05 11:59:30 -0500
committerTom Lane <tgl@sss.pgh.pa.us>2022-02-05 11:59:30 -0500
commitd13a838e1c19df5358d250b8d469544d7ab3dfda (patch)
treeeaecb4f899c20d9d55006511f7b3226cc24f5819 /src/backend/executor/nodeMergejoin.c
parentab22eea83169c8d0eb15050ce61cbe3d7dae4de6 (diff)
downloadpostgresql-d13a838e1c19df5358d250b8d469544d7ab3dfda.tar.gz
postgresql-d13a838e1c19df5358d250b8d469544d7ab3dfda.zip
Test, don't just Assert, that mergejoin's inputs are in order.
There are two Asserts in nodeMergejoin.c that are reachable if the input data is not in the expected order. This seems way too fragile. Alexander Lakhin reported a case where the assertions could be triggered with misconfigured foreign-table partitions, and bitter experience with unstable operating system collation definitions suggests another easy route to hitting them. Neither Assert is in a place where we can't afford one more test-and-branch, so replace 'em with plain test-and-elog logic. Per bug #17395. While the reported symptom is relatively recent, collation changes could happen anytime, so back-patch to all supported branches. Discussion: https://postgr.es/m/17395-8c326292078d1a57@postgresql.org
Diffstat (limited to 'src/backend/executor/nodeMergejoin.c')
-rw-r--r--src/backend/executor/nodeMergejoin.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/backend/executor/nodeMergejoin.c b/src/backend/executor/nodeMergejoin.c
index b41454ab6d9..5ff3f4c3a44 100644
--- a/src/backend/executor/nodeMergejoin.c
+++ b/src/backend/executor/nodeMergejoin.c
@@ -893,11 +893,10 @@ ExecMergeJoin(PlanState *pstate)
if (compareResult == 0)
node->mj_JoinState = EXEC_MJ_JOINTUPLES;
- else
- {
- Assert(compareResult < 0);
+ else if (compareResult < 0)
node->mj_JoinState = EXEC_MJ_NEXTOUTER;
- }
+ else /* compareResult > 0 should not happen */
+ elog(ERROR, "mergejoin input data is out of order");
break;
case MJEVAL_NONMATCHABLE:
@@ -1087,7 +1086,7 @@ ExecMergeJoin(PlanState *pstate)
node->mj_JoinState = EXEC_MJ_JOINTUPLES;
}
- else
+ else if (compareResult > 0)
{
/* ----------------
* if the new outer tuple didn't match the marked inner
@@ -1106,7 +1105,6 @@ ExecMergeJoin(PlanState *pstate)
* no more inners, no more matches are possible.
* ----------------
*/
- Assert(compareResult > 0);
innerTupleSlot = node->mj_InnerTupleSlot;
/* reload comparison data for current inner */
@@ -1140,6 +1138,8 @@ ExecMergeJoin(PlanState *pstate)
return NULL;
}
}
+ else /* compareResult < 0 should not happen */
+ elog(ERROR, "mergejoin input data is out of order");
break;
/*----------------------------------------------------------