Re: [HACKERS] SQL MERGE patches for PostgreSQL Versions

Поиск
Список
Период
Сортировка
От Kang Yuzhe
Тема Re: [HACKERS] SQL MERGE patches for PostgreSQL Versions
Дата
Msg-id CAH=t1kooF6e+wRdS0Hfv62LFkzLRexsXG4tV1JovV=uZ3T16qQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: [HACKERS] SQL MERGE patches for PostgreSQL Versions  (Craig Ringer <craig@2ndquadrant.com>)
Ответы Re: [HACKERS] SQL MERGE patches for PostgreSQL Versions  (Thomas Munro <thomas.munro@enterprisedb.com>)
Re: [HACKERS] SQL MERGE patches for PostgreSQL Versions  (Craig Ringer <craig@2ndquadrant.com>)
Список pgsql-hackers
On Thu, Jun 22, 2017 at 11:23 AM, Craig Ringer <craig@2ndquadrant.com> wrote:
> On 22 June 2017 at 16:05, Kang Yuzhe <tiggreen87@gmail.com> wrote:
>> Dear PG hackers,
>>
>> First my apology if I appear to be a jerk or not following the policy.
>>
>> I emailed Boxuan Zhai who was  in charge of the SQL Merge keyword in
>> 2010 of GSoC but without reply.
>>
>> I want to apply merge_v201.patch to specific PG version.
>>
>> It failed saying 1 or 2 of 5 hunk failed.
>>
>> My question is:
>>  1. Given x old patch of PG, is it possible to know  to which PG
>> version can be applied?
>
> If it's produced by git-format-patch you can look at the git ref
> information in the patch. Otherwise you have to rely on what's in the
> email thread.

If you were having merge_v201.patch, how would you determine whether
it was produced by git-format-patch ow email thread?

I just downloaded the patch from GSoC site.

A code snippet from the merge_v201.patch is shown below:

diff --git a/src/backend/executor/nodeModifyTable.c
b/src/backend/executor/nodeModifyTable.c
index 8619ce3..e3ac758 100644
--- a/src/backend/executor/nodeModifyTable.c
+++ b/src/backend/executor/nodeModifyTable.c
@@ -582,6 +582,113 @@ lreplace:;    return NULL;}

+static TupleTableSlot *
+MergeRaiseErr(void)
+{
+    elog(NOTICE, "one tuple is ERROR");
+    return NULL;
+}
+
+static TupleTableSlot *
+ExecMerge(ItemPointer tupleid,
+           TupleTableSlot *slot,
+           TupleTableSlot *planSlot,
+           MergeActionSet *actset,
+           EState *estate)
+{
+
+    TupleTableSlot *actslot = NULL;
+    ListCell *each;
+
+    /*
+     * Try the merge actions one by one until we have a match.
+     */
+    foreach(each, actset->actions)
+    {
+        ModifyTableState *mt_pstate;
+        MergeActionState *action_pstate;
+        ExprContext *econtext;
+        bool matched;
+
+        mt_pstate = (ModifyTableState *) lfirst(each);
+        Assert(IsA(mt_pstate, ModifyTableState));
+
+        /*
+         * mt_pstate is supposed to have only ONE mt_plans,
+         * which is a MergeActionState
+         */
+        action_pstate = (MergeActionState *) mt_pstate->mt_plans[0];
+        matched = ((MergeAction *)action_pstate->ps.plan)->matched;
+
+        /*
+         * If tupleid == NULL, it is a NOT MATCHED case,
+         * else, it is a MATCHED case,
+         */
+        if ((tupleid == NULL && matched) ||
+            (tupleid != NULL && !matched))
+            continue;
+
+        /* Setup the expression context. */
+        econtext = action_pstate->ps.ps_ExprContext;
+
+        /*
+         * Check that additional quals match, if any.
+         */
+        if (action_pstate->ps.qual)
+        {
+            ResetExprContext(econtext);
+
+            econtext->ecxt_scantuple = slot;
+            econtext->ecxt_outertuple = planSlot;
+
+            if (!ExecQual(action_pstate->ps.qual, econtext, false))
+                continue;
+        }
+
+        /* Ok, we have a match. Perform the action */
+
+        /* First project any RETURNING result tuple slot, if needed */
+        if (action_pstate->operation == CMD_INSERT ||
+            action_pstate->operation == CMD_UPDATE)
+            actslot = ExecProcessReturning(action_pstate->ps.ps_ProjInfo,
+                                           slot, planSlot);
+
+        switch (action_pstate->operation)
+        {
+            case CMD_INSERT:
+                return ExecInsert(actslot, planSlot, estate);
+
+            case CMD_UPDATE:
+                return ExecUpdate(tupleid,
+                                  actslot,
+                                  planSlot,
+                                  &mt_pstate->mt_epqstate,
+                                  estate);
+
+            case CMD_DELETE:
+                return ExecDelete(tupleid,
+                                  planSlot,
+                                  &mt_pstate->mt_epqstate,
+                                  estate);
+
+            case CMD_DONOTHING:
+                return NULL;
+
+            case CMD_RAISEERR:
+                return MergeRaiseErr();
+
+            default:
+                elog(ERROR, "unknown merge action type for excute");
+                break;
+        }
+    }
+
+    /*
+     * No matching action found. Perform the default action, which is
+     * RAISE ERROR.
+     */
+    return MergeRaiseErr();
+}



Now, is it possible to extract info from this code snippet whether it
was by git-format-patch or email thread?

Regards,
Zeray



В списке pgsql-hackers по дате отправления:

Предыдущее
От: Yugo Nagata
Дата:
Сообщение: Re: [HACKERS] Incorrect documentation about pg_stat_activity
Следующее
От: Thomas Munro
Дата:
Сообщение: Re: [HACKERS] SQL MERGE patches for PostgreSQL Versions