Re: ON CONFLICT DO SELECT (take 3)

Поиск
Список
Период
Сортировка
От Viktor Holmberg
Тема Re: ON CONFLICT DO SELECT (take 3)
Дата
Msg-id 3b846628-974f-48cf-b9a0-01f85b5f949c@Spark
обсуждение исходный текст
Ответ на Re: ON CONFLICT DO SELECT (take 3)  (jian he <jian.universality@gmail.com>)
Список pgsql-hackers
On 25 Nov 2025 at 09:33 +0100, jian he <jian.universality@gmail.com>, wrote:
On Mon, Nov 24, 2025 at 11:23 PM Viktor Holmberg <v@viktorh.net> wrote:

It did not. But this will.
For some reason, in this bit:

‘''
LockTupleMode lockmode;
….
case LCS_FORUPDATE:
lockmode = LockTupleExclusive;
break;
case LCS_NONE:
elog(ERROR, "unexpected lock strength %d", lockStrength);
}

if (!ExecOnConflictLockRow(context, existing, conflictTid,
resultRelInfo->ri_RelationDesc, lockmode, false))
return false;
‘''

GCC gives warning "error: ‘lockmode’ may be used uninitialized”. But if I switch the final exhaustive “case" to a “default” the warning goes away. Strange, if anyone know how to fix let me know. But also I don’t think it’s a big deal.

hi.
you can search ``/* keep compiler quiet */`` within the codebase.

after
``elog(ERROR, "unexpected lock strength %d", lockStrength);``
you can add
``
lockmode = LockTupleExclusive;
break;
``
Thanks! I now realise the problem wasn’t that GCC didn’t see that elog wasn’t reachable. It was the fact that there is no default. Even though all cases are covered. This is annoying but switching it back to a default as it was seems the best option. Setting lockmode is not needed if it’s kept as a default. 
My goal was to enumerate all cases so you’d get a compiler warning if one of them wasn’t handled like Dean did, but looks like I’ll have to give up on that until GCC gets improved.

in doc/src/sgml/mvcc.sgml:
<para>
<command>INSERT</command> with an <literal>ON CONFLICT DO
NOTHING</literal> clause may have insertion not proceed for a row due to
the outcome of another transaction whose effects are not visible
to the <command>INSERT</command> snapshot. Again, this is only
the case in Read Committed mode.
</para>
I think we need to add something after the above quoted paragraph.
I’ve added a bit about DO SELECT now. 

doc/src/sgml/ref/create_view.sgml, some places also need to be updated, I think.
see text ON CONFLICT UPDATE in there.
I checked this before and still think it’s not needed. It’s in a bit about *updatable* views, and seems obvious to me how DO SELECT would work with that? Not a hill I’m willing to die on though, but a suggested change would be appreciated.

--------

Re. Infection point testing - I think this is very cool but I’d be tempted to agree with Dean on leaving it out from this patch.

--------
Re. deferrable constraints - I’ve removed that bit from the docs. Thanks for handling that Dean.

--------

In conclusion:
Attached is v17, with: 
- Jians latest patches minus the injection point testing
- Doc for MVCC
- ExecOnConflictSelect with a default clause for lockStrength.

Thanks again for your help both Jian and Dean
Вложения

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